Skip to content

Commit

Permalink
refs #9082 Intermediate checkout
Browse files Browse the repository at this point in the history
Test for desired behavior and some simplification in CopyInstrumentParameters algorithm (will need further improvement)
  • Loading branch information
abuts committed Apr 22, 2014
1 parent 5977de5 commit 1ec7c45
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
18 changes: 10 additions & 8 deletions Code/Mantid/Framework/Algorithms/src/CopyInstrumentParameters.cpp
Expand Up @@ -124,18 +124,20 @@ void CopyInstrumentParameters::exec()
targComp = inst2->getComponentByName(targ_name).get();
if (!targComp)
{
auto old_comp_map = oldComponent->getParameterMap();
auto it = old_comp_map->begin();
for(;it!=old_comp_map->end();it++)
{
auto pParam = (*it).second.get();
targMap.add(pParam->type(),inst2.get(),targ_name,pParam->asString());
}
g_log.warning()<<"Target instrument does not have component with full name "<<targ_name<<'\n';
continue;
}

}
// process existing target component
// merge maps for existing target component

//auto old_comp_map = oldComponent->getParameterMap();
//auto it = old_comp_map->begin();
//for(;it!=old_comp_map->end();it++)
//{
// auto pParam = (*it).second.get();
// targMap.add(pParam->type(),inst2.get(),targ_name,pParam->asString());
//}


}
Expand Down
Expand Up @@ -113,7 +113,7 @@ class CopyInstrumentParametersTest : public CxxTest::TestSuite
void testDifferent_BaseInstrument_Warns()
{
// Create input workspace with parameterized instrument and put into data store
MatrixWorkspace_sptr ws1 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(3, 10, true);
MatrixWorkspace_sptr ws1 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(4, 10, true,false,true,"testInstr_new");
const std::string wsName1("CopyInstParamWs1");
AnalysisDataServiceImpl & dataStore = AnalysisDataService::Instance();
dataStore.add(wsName1, ws1);
Expand All @@ -134,6 +134,12 @@ class CopyInstrumentParametersTest : public CxxTest::TestSuite
const std::string wsName2("CopyInstParamWs2");
dataStore.add(wsName2, ws2);

pmap = &(ws2->instrumentParameters());
instrument = ws2->getInstrument();
pmap->addDouble(instrument.get(),"T",10);
pmap->addString(instrument.get(),"some_param","other_value");


// Set properties
TS_ASSERT_THROWS_NOTHING(copyInstParam.setPropertyValue("InputWorkspace", wsName1 ));
TS_ASSERT_THROWS_NOTHING(copyInstParam.setPropertyValue("OutputWorkspace", wsName2 ));
Expand All @@ -148,6 +154,10 @@ class CopyInstrumentParametersTest : public CxxTest::TestSuite
std::set<std::string> param_names = instr2->getParameterNames();
TS_ASSERT(param_names.find("Ei")!=param_names.end());
TS_ASSERT(param_names.find("some_param")!=param_names.end());
TS_ASSERT(param_names.find("T")!=param_names.end());
TS_ASSERT(std::string("some_value")==instr2->getStringParameter("some_param"));
TS_ASSERT_EQUALS("100",instr2->getNumberParameter("Ei"));
TS_ASSERT_EQUALS("10",instr2->getNumberParameter("T"));

IDetector_const_sptr deto1 = ws2->getDetector(0);
int id1 = deto1->getID();
Expand Down
Expand Up @@ -153,7 +153,7 @@ namespace WorkspaceCreationHelper
return ws;
}

/// Add random noise to the signal
/// Add random noise to the signalcreate2DWorkspaceWithFullInstrument
void addNoise(Mantid::API::MatrixWorkspace_sptr ws, double noise, const double lower=-0.5, const double upper=0.5);

/**
Expand All @@ -163,7 +163,7 @@ namespace WorkspaceCreationHelper
* Data filled with: Y: 2.0, E: sqrt(2.0), X: nbins of width 1 starting at 0
*/
Mantid::DataObjects::Workspace2D_sptr create2DWorkspaceWithFullInstrument(int nHist, int nBins,
bool includeMonitors = false, bool startYNegative = false, bool isHistogram = true);
bool includeMonitors = false, bool startYNegative = false, bool isHistogram = true,const std::string instrumentName= std::string("testInstr"));

/**
* Create a test workspace with a Theta numeric axis instead of a spectrum axis
Expand Down
Expand Up @@ -312,7 +312,7 @@ namespace WorkspaceCreationHelper
* Data filled with: Y: 2.0, E: sqrt(2.0), X: nbins of width 1 starting at 0
*/
Workspace2D_sptr create2DWorkspaceWithFullInstrument(int nhist, int nbins, bool includeMonitors,
bool startYNegative, bool isHistogram)
bool startYNegative, bool isHistogram,const std::string instrumentName)
{
if( includeMonitors && nhist < 2 )
{
Expand All @@ -326,7 +326,7 @@ namespace WorkspaceCreationHelper
space->getAxis(0)->setUnit("TOF");
space->setYUnit("Counts");

boost::shared_ptr<Instrument> testInst(new Instrument("testInst"));
boost::shared_ptr<Instrument> testInst(new Instrument("instrumentName"));
testInst->setReferenceFrame(boost::shared_ptr<ReferenceFrame>(new ReferenceFrame(Y,X,Left,"")));
space->setInstrument(testInst);

Expand Down

0 comments on commit 1ec7c45

Please sign in to comment.