Skip to content

Commit

Permalink
Merge remote-tracking branch 'feature/6667_ISISReductionInMantid'
Browse files Browse the repository at this point in the history
Refs #6667
Conflicts:
	Code/Mantid/scripts/CMakeLists.txt
	Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
  • Loading branch information
martyngigg committed Jul 26, 2013
2 parents c1ed9e3 + 9741bfb commit c336241
Show file tree
Hide file tree
Showing 30 changed files with 3,698 additions and 525 deletions.
38 changes: 35 additions & 3 deletions Code/Mantid/Framework/API/src/ExperimentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,21 @@ namespace API
std::string paramName;
double value; };

/** HACK -- the internal function which allows to interpret string values found in IDF parameters file as boolean
* it is hack as this funtion should be somewhere else.
*
*@param boolType -- the string representation of the boolean value one wants to compare.
*@return True if the name within of the list of true names, and false otherwise
*/
const char * TrueNames[2 ]={"True","Yes"};
bool convertBool(const std::string &boolType)
{
for(int i=0;i<2;i++)
{
if(std::strcmp(boolType.c_str(),TrueNames[i])==0)return true;
}
return false;
}

//---------------------------------------------------------------------------------------
/** Add parameters to the instrument parameter map that are defined in instrument
Expand Down Expand Up @@ -256,9 +271,14 @@ namespace API
std::string paramN = ((*it).second)->m_paramName;
std::string category = ((*it).second)->m_type;

// if category is sting no point in trying to generate a double from parameter
bool is_int_val = (category.compare("int") == 0);
bool is_string_val = (category.compare("string") == 0);
bool is_bool_val = (category.compare("bool") == 0);
bool is_double_val = !(is_string_val || is_bool_val || is_int_val);

// if category is not double sting no point in trying to generate a double from parameter
double value = 0.0;
if ( category.compare("string") != 0 )
if ( is_double_val)
value = ((*it).second)->createParamValue(dummy);

if ( category.compare("fitting") == 0 )
Expand All @@ -270,10 +290,22 @@ namespace API
<< ((*it).second)->m_formulaUnit << " , " << ((*it).second)->m_resultUnit << " , " << (*(((*it).second)->m_interpolation));
paramMap.add("fitting",((*it).second)->m_component, paramN, str.str());
}
else if ( category.compare("string") == 0 )
else if (is_string_val)
{
paramMap.addString(((*it).second)->m_component, paramN, ((*it).second)->m_value);
}
else if (is_bool_val )
{
bool b_val = convertBool(((*it).second)->m_value);
paramMap.addBool(((*it).second)->m_component,paramN,b_val);
}
else if (is_int_val )
{
int i_val = boost::lexical_cast<int>(((*it).second)->m_value);
paramMap.addInt(((*it).second)->m_component,paramN,i_val);
}


else
{
if (paramN.compare("x") == 0 || paramN.compare("y") == 0 || paramN.compare("z") == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ class DLLExport CheckWorkspacesMatch : public API::Algorithm
/// Execution code
void exec();

// property indicate that relative error tolerance in data is set up rather then absolute error.
bool m_ErrorIsRelative;
void doComparison();
// Compare two MD workspaces
void doMDComparison(API::Workspace_sptr w1, API::Workspace_sptr w2);
Expand Down
43 changes: 40 additions & 3 deletions Code/Mantid/Framework/Algorithms/src/CheckWorkspacesMatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,19 @@ void CheckWorkspacesMatch::init()
declareProperty("CheckSample",false, "Whether to check that the sample (e.g. logs)."); // Have this one false by default - the logs are brittle

declareProperty("Result","",Direction::Output);

declareProperty("ToleranceRelErr",false, "Treat tolerance as relative error rather then the absolute error");
declareProperty("CheckAllData",false, "Usually checking data ends when first mismatch occurs. This forces algorithm to check all data and print mismatch to the debug log.\n"\
"Very often such logs are huge so making it true should be the last option."); // Have this one false by default - it can be a lot of printing.



}

void CheckWorkspacesMatch::exec()
{
result.clear();
m_ErrorIsRelative = getProperty("ToleranceRelerr");
this->doComparison();

if ( result != "")
Expand Down Expand Up @@ -446,6 +454,9 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
const size_t numHists = ws1->getNumberHistograms();
const size_t numBins = ws1->blocksize();
const bool histogram = ws1->isHistogramData();
bool checkAllData=getProperty("CheckAllData");



// First check that the workspace are the same size
if ( numHists != ws2->getNumberHistograms() || numBins != ws2->blocksize() )
Expand Down Expand Up @@ -481,24 +492,50 @@ bool CheckWorkspacesMatch::checkData(API::MatrixWorkspace_const_sptr ws1, API::M
const MantidVec& Y2 = ws2->readY(i);
const MantidVec& E2 = ws2->readE(i);

bool RelErr = m_ErrorIsRelative;
for ( int j = 0; j < static_cast<int>(numBins); ++j )
{
if ( std::abs(X1[j]-X2[j]) > tolerance || std::abs(Y1[j]-Y2[j]) > tolerance || std::abs(E1[j]-E2[j]) > tolerance )
bool err;
if (RelErr)
{
double s1=0.5*(X1[j]+X2[j]);
if (s1>tolerance)
err = (std::abs(X1[j]-X2[j])/s1 > tolerance);
else
err = (std::abs(X1[j]-X2[j]) > tolerance);

double s2=0.5*(Y1[j]+Y2[j]);
if (s2>tolerance)
err = ((std::abs(Y1[j]-Y2[j])/s2 > tolerance)||err);
else
err = ((std::abs(Y1[j]-Y2[j]) > tolerance)||err);


double s3=0.5*(E1[j]+E2[j]);
if (s3>tolerance)
err = ((std::abs(E1[j]-E2[j])/s3 > tolerance)||err);
else
err = ((std::abs(E1[j]-E2[j]) > tolerance)||err);
}
else
err = (std::abs(X1[j]-X2[j]) > tolerance || std::abs(Y1[j]-Y2[j]) > tolerance || std::abs(E1[j]-E2[j]) > tolerance);

if (err)
{
g_log.debug() << "Data mismatch at cell (hist#,bin#): (" << i << "," << j << ")\n";
g_log.debug() << " Dataset #1 (X,Y,E) = (" << X1[j] << "," << Y1[j] << "," << E1[j] << ")\n";
g_log.debug() << " Dataset #2 (X,Y,E) = (" << X2[j] << "," << Y2[j] << "," << E2[j] << ")\n";
g_log.debug() << " Difference (X,Y,E) = (" << std::abs(X1[j]-X2[j]) << "," << std::abs(Y1[j]-Y2[j]) << "," << std::abs(E1[j]-E2[j]) << ")\n";
result = "Data mismatch";
resultBool = false;
resultBool = checkAllData;
}
}

// Extra one for histogram data
if ( histogram && std::abs(X1.back()-X2.back()) > tolerance )
{
result = "Data mismatch";
resultBool = false;
resultBool = checkAllData;
}
}
PARALLEL_END_INTERUPT_REGION
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/DataHandling/src/LoadMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,13 +815,13 @@ namespace DataHandling
continue;

// c. parse
g_log.notice() << "Input: " << isisline << std::endl;
g_log.debug() << "Input: " << isisline << std::endl;
parseISISStringToVector(isisline, mask_specid_pair_low, mask_specid_pair_up);
}

for (size_t i = 0; i < mask_specid_pair_low.size(); i ++)
{
g_log.notice() << i << ": " << mask_specid_pair_low[i] << ", " <<
g_log.debug() << i << ": " << mask_specid_pair_low[i] << ", " <<
mask_specid_pair_up[i] << std::endl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ namespace Mantid
virtual std::set<std::string> getParameterNames(bool recursive = true) const = 0;
/// Returns a boolean indicating if the component has the named parameter
virtual bool hasParameter(const std::string & name, bool recursive = true) const = 0;
//Hack untill proper python export functions are defined
virtual std::string getParameterType(const std::string& pname, bool recursive = true)const=0;
// 06/05/2010 MG: Templated virtual functions cannot be defined so we have to resort to
// one for each type, luckily there won't be too many
/// Get a parameter defined as a double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,51 @@ namespace Mantid
return getParameter<double>(pname, recursive);
}

/**
* Get a parameter defined as an int
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns A list of values
*/
std::vector<int> getIntParameter(const std::string& pname, bool recursive = true) const
{
return getParameter<int>(pname, recursive);
}


/**
* Get a parameter's type -- this is HACK untill Python can export property regardless of the property type
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns std::string describing parameter type or empty string if the type is not found
*/
std::string getParameterType(const std::string& pname, bool recursive = true)const
{
Parameter_sptr param = Parameter_sptr(); //Null shared pointer
if( recursive )
{
param = m_map->getRecursive(this, pname);
}
else
{
param = m_map->get(this, pname);
}
if(param)
return std::string(param->type());
else
return std::string("");
}
/**
* Get a parameter defined as a bool
* @param pname :: The name of the parameter
* @param recursive :: If true the search will walk up through the parent components
* @returns A list of values
*/
std::vector<bool> getBoolParameter(const std::string& pname, bool recursive = true) const
{
return getParameter<bool>(pname, recursive);
}

/**
* Get a parameter defined as a Kernel::V3D
* @param pname :: The name of the parameter
Expand Down Expand Up @@ -224,6 +269,7 @@ namespace Mantid
virtual void writeXML(Poco::XML::XMLWriter & writer) const;
virtual void appendXML(std::ostream& xmlStream) const;


protected:
/// Parent component in the tree
const IComponent* m_parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace Mantid
virtual std::set<std::string> getParameterNames(bool recursive = true) const;
/// Returns a boolean indicating whether the parameter exists or not
bool hasParameter(const std::string & name, bool recursive = true) const;
// Hack used untill Geomertry can not exprot different types parematers properly
std::string getParameterType(const std::string & name, bool recursive = true) const;
/**
* Get a parameter defined as a double
* @param pname :: The name of the parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Geometry

}


/** Empty constructor
* Create a component with null parent
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ namespace Mantid
(void) name; //Avoid compiler warning
return false;
}
/** Detectors group assumed to be non-parameterized */
std::string DetectorGroup::getParameterType(const std::string & /*name*/, bool /*recursive = true*/) const
{
return std::string("");
}

/// Default implementation
std::vector<double> DetectorGroup::getNumberParameter(const std::string&, bool) const
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Geometry/test/ComponentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class ComponentTest : public CxxTest::TestSuite
TS_ASSERT(ancs.size() == 1);
TS_ASSERT_EQUALS(ancs[0]->getName(), parent.getName());
TS_ASSERT(ancs[0]->isParametrized());

}

void testGetFullName()
Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/Framework/Geometry/test/ParametrizedComponentTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ParametrizedComponentTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(pq.getRelativeRot(),Quat(1,1,1,1));
}

void testGetParameter()
void testGetParameterAndItsType()
{
Component * paramComp = createSingleParameterizedComponent();
TS_ASSERT_EQUALS(paramComp->getStringParameter(m_strName).size(), 1);
Expand All @@ -88,6 +88,16 @@ class ParametrizedComponentTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(paramComp->getPositionParameter(m_posName)[0], m_posValue);
TS_ASSERT_EQUALS(paramComp->getRotationParameter(m_quatName)[0], m_quatValue);

std::string typeName;
TS_ASSERT_THROWS_NOTHING(typeName= paramComp->getParameterType(m_strName));
TS_ASSERT_EQUALS(ParameterMap::pString(),typeName);
TS_ASSERT_THROWS_NOTHING(typeName= paramComp->getParameterType(m_dblName));
TS_ASSERT_EQUALS(ParameterMap::pDouble(),typeName);
TS_ASSERT_THROWS_NOTHING(typeName= paramComp->getParameterType(m_posName));
TS_ASSERT_EQUALS(ParameterMap::pV3D(),typeName);
TS_ASSERT_THROWS_NOTHING(typeName= paramComp->getParameterType(m_quatName));
TS_ASSERT_EQUALS(ParameterMap::pQuat(),typeName);

cleanUpComponent();
}

Expand Down
8 changes: 8 additions & 0 deletions Code/Mantid/Framework/PythonAPI/src/geometry_exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ namespace Mantid
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getPositionParameter,Geometry::Component::getPositionParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getRotationParameter,Geometry::Component::getRotationParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getStringParameter,Geometry::Component::getStringParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getBoolParameter,Geometry::Component::getBoolParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getIntParameter,Geometry::Component::getIntParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterType,Geometry::Component::getParameterType,1,2);

void export_components()
{
Expand Down Expand Up @@ -124,6 +127,11 @@ namespace Mantid
.def("getPositionParameter", &Geometry::Component::getPositionParameter, Component_getPositionParameter())
.def("getRotationParameter", &Geometry::Component::getRotationParameter, Component_getRotationParameter())
.def("getStringParameter", &Geometry::Component::getStringParameter, Component_getStringParameter())

.def("getBoolParameter", &Geometry::Component::getBoolParameter, Component_getBoolParameter())
.def("getIntParameter", &Geometry::Component::getIntParameter, Component_getIntParameter())
.def("getParameterType", &Geometry::Component::getParameterType, Component_getParameterType())


;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ namespace
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterNames,Component::getParameterNames,0,1);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_hasParameter,Component::hasParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getNumberParameter,Component::getNumberParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getBoolParameter,Component::getBoolParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getPositionParameter,Component::getPositionParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getRotationParameter,Component::getRotationParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getStringParameter,Component::getStringParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getIntParameter,Component::getIntParameter,1,2);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(Component_getParameterType,Component::getParameterType,1,2);


}

void export_Component()
Expand All @@ -23,9 +28,20 @@ void export_Component()
.def("getParameterNames", &Component::getParameterNames, Component_getParameterNames())
.def("hasParameter", &Component::hasParameter, Component_hasParameter())
.def("getNumberParameter", &Component::getNumberParameter, Component_getNumberParameter())
.def("getBoolParameter", &Component::getBoolParameter, Component_getBoolParameter())
.def("getPositionParameter", &Component::getPositionParameter, Component_getPositionParameter())
.def("getRotationParameter", &Component::getRotationParameter, Component_getRotationParameter())
.def("getStringParameter", &Component::getStringParameter, Component_getStringParameter())
.def("getIntParameter", &Component::getIntParameter, Component_getIntParameter())
// HACK -- python should return parameters regardless of type. this is untill rows below do not work
.def("getParameterType", &Component::getParameterType, Component_getParameterType())
//// this does not work for some obvious or not obvious reasons
//.def("getParameter", &Component::getNumberParameter, Component_getNumberParameter())
//.def("getParameter", &Component::getBoolParameter, Component_getBoolParameter())
//.def("getParameter", &Component::getStringParameter, Component_getStringParameter())
//.def("getParameter", &Component::getPositionParameter, Component_getPositionParameter())
//.def("getParameter", &Component::getRotationParameter, Component_getRotationParameter())

;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "MantidKernel/FacilityInfo.h"
#include <boost/python/class.hpp>
#include <boost/python/copy_const_reference.hpp>
#include <boost/python/register_ptr_to_python.hpp>

using Mantid::Kernel::FacilityInfo;
using Mantid::Kernel::InstrumentInfo;
Expand All @@ -9,6 +10,8 @@ using namespace boost::python;
void export_FacilityInfo()
{

register_ptr_to_python<FacilityInfo*>();

class_<FacilityInfo>("FacilityInfo", no_init)

.def("name", &FacilityInfo::name, return_value_policy<copy_const_reference>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ void export_InstrumentInfo()

.def("facility", &InstrumentInfo::facility, return_value_policy<copy_const_reference>(),
"Returns the facility that contains this instrument.")

.def("instdae", &InstrumentInfo::liveDataAddress, return_value_policy<copy_const_reference>(),
"Returns the host name and the port of the machine hosting DAE and providing port to connect to for a live data stream")

;
}

0 comments on commit c336241

Please sign in to comment.