Skip to content

Commit

Permalink
Re #11508 Looks like can get a parameter description
Browse files Browse the repository at this point in the history
and unit test for accessor.
  • Loading branch information
abuts committed Apr 20, 2015
1 parent 837dcc1 commit b1d9aef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
24 changes: 17 additions & 7 deletions Code/Mantid/Framework/DataHandling/test/LoadParameterFileTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ class LoadParameterFileTest : public CxxTest::TestSuite

void testExecIDF_for_unit_testing2() // IDF stands for Instrument Definition File
{
MatrixWorkspace_sptr output;

// Create workspace wsName
load_IDF2();
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName));
ParameterMap& paramMap = output->instrumentParameters();
std::string descr = paramMap.getDescription("nickel-holder","fjols");
TS_ASSERT_EQUALS(descr,"test fjols description.");


// load in additional parameters
LoadParameterFile loaderPF;
Expand All @@ -44,30 +50,36 @@ class LoadParameterFileTest : public CxxTest::TestSuite


// Get back the saved workspace
MatrixWorkspace_sptr output;
TS_ASSERT_THROWS_NOTHING(output = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName));

ParameterMap& paramMap = output->instrumentParameters();
paramMap = output->instrumentParameters();
boost::shared_ptr<const Instrument> i = output->getInstrument();
boost::shared_ptr<const IDetector> ptrDet = i->getDetector(1008);
TS_ASSERT_EQUALS( ptrDet->getID(), 1008);
TS_ASSERT_EQUALS( ptrDet->getName(), "combined translation6");
Parameter_sptr param = paramMap.get(&(*ptrDet), "fjols");
TS_ASSERT_DELTA( param->value<double>(), 20.0, 0.0001);
auto descr = param->getDescription();
// TS_ASSERT_EQUAL(descr,"test fjols description");

param = paramMap.get(&(*ptrDet), "nedtur");
TS_ASSERT_DELTA( param->value<double>(), 77.0, 0.0001);
param = paramMap.get(&(*ptrDet), "fjols-test-paramfile");
TS_ASSERT_DELTA( param->value<double>(), 50.0, 0.0001);
descr = param->getDescription();
TS_ASSERT_EQUALS(descr,"test description. Full test description.");


ptrDet = i->getDetector(1301);
TS_ASSERT_EQUALS( ptrDet->getID(), 1301);
TS_ASSERT_EQUALS( ptrDet->getName(), "pixel");
param = paramMap.get(ptrDet.get(), "testDouble");
TS_ASSERT_DELTA( param->value<double>(), 25.0, 0.0001);
TS_ASSERT_EQUALS( paramMap.getString(ptrDet.get(), "testString"), "hello world");
TS_ASSERT_EQUALS(paramMap.getString(ptrDet.get(), "testString"), "hello world");

param = paramMap.get(ptrDet.get(), "testString");
TS_ASSERT_EQUALS(param->getTooltip(),"its test hello word.");
TS_ASSERT_EQUALS(param->getDescription(),"its test hello word.");
TS_ASSERT_EQUALS(paramMap.getDescription("pixel","testString"),"its test hello word.");


std::vector<double> dummy = paramMap.getDouble("nickel-holder", "klovn");
TS_ASSERT_DELTA( dummy[0], 1.0, 0.0001);
Expand All @@ -79,8 +91,6 @@ class LoadParameterFileTest : public CxxTest::TestSuite
TS_ASSERT_DELTA (dummy[0], 200.0, 0.0001);
dummy = paramMap.getDouble("nickel-holder", "mistake");
TS_ASSERT_EQUALS (dummy.size(), 0);
param = paramMap.getRecursive(i.get(),"mistake");
// TS_ASSERT_EQUALS(param->getTooltip(),"You made a terrible mistake")

dummy = paramMap.getDouble("nickel-holder", "fjols-test-paramfile");
TS_ASSERT_DELTA (dummy[0], 2000.0, 0.0001);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ void InstrumentDefinitionParser::setComponentLinks(
Check that the cache file does actually exist and that it was modified last
after the last modification to the xml def file. i.e. the vtp file contains the
most recent set of changes.
@param cacheCandiate : candiate cache file object to use the the geometries.
@param cacheCandiate : candidate cache file object to use the geometries.
*/
bool InstrumentDefinitionParser::canUseProposedCacheFile(
IDFObject_const_sptr cacheCandiate) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ const std::string ParameterMap::getDescription(const std::string &compName,
if (compName.compare(((const IComponent *)(*it).first)->getName()) == 0) {
boost::shared_ptr<Parameter> param =
get((const IComponent *)(*it).first, name);
if (param)
if (param){
result = param->getDescription();
if(!result.empty())
return result;
}
}
}
return result;
Expand All @@ -163,10 +164,11 @@ const std::string ParameterMap::getTooltip(const std::string &compName,
if (compName.compare(((const IComponent *)(*it).first)->getName()) == 0) {
boost::shared_ptr<Parameter> param =
get((const IComponent *)(*it).first, name);
if (param)
if (param){
result = param->getTooltip();
if(!result.empty())
return result;
}
}
}
return result;
Expand Down Expand Up @@ -325,7 +327,7 @@ void ParameterMap::add(const IComponent *comp,
auto existing_par = positionOf(comp, par->name().c_str(), "");
// As this is only an add method it should really throw if it already
// exists.
// However, this is old behaviour and many things rely on this actually be
// However, this is old behavior and many things rely on this actually be
// an
// add/replace-style function
if (existing_par != m_map.end()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
</defaults>

<parameter name="somefunction:toplevel" type="fitting"> <value val="100.0" /> <min val="80"/> <max val="120"/>
<description is = "Test description for the fitting parameter toplevel\n
<description is = "Test description for the fitting parameter toplevel.
long long test description for toplevel fitting parameter"/>
</parameter>

Expand All @@ -34,7 +33,7 @@

<component-link name="nickel-holder" >
<parameter name="fjols"> <value val="200.0" />
<description is = "test fjols description" />
<description is = "test fjols description." />
</parameter>
<parameter name="fjols-string" type="string"> <value val="boevs" /> </parameter>
</component-link>
Expand Down Expand Up @@ -103,7 +102,6 @@
<value val="200.0" />
</parameter>
<parameter name="mistake">
<description is = "You made a terrible mistake"/>
</parameter>
</component>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
<component-link name="IDF_for_UNIT_TESTING2.xml/combined translation6" >
<parameter name="fjols-test-paramfile">
<value val="50.0" />
<description is="test description
full test description" />
<description is="test description.
Full test description." />
</parameter>
</component-link>

<component-link id="1301" >
<parameter name="testDouble"> <value val="25.0" /> </parameter>
<parameter name="testString" type="string">
<value val="hello world" />
<description is="its test hello word"/>
<description is="its test hello word."/>
</parameter>
</component-link>

Expand Down

0 comments on commit b1d9aef

Please sign in to comment.