Skip to content

Commit

Permalink
refs #9364 Working performance test
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Apr 24, 2014
1 parent 5ee366d commit d7d614e
Showing 1 changed file with 17 additions and 7 deletions.
Expand Up @@ -21,6 +21,7 @@
#include "MantidGeometry/Instrument/ComponentHelper.h"
#include <stdexcept>


using namespace Mantid::Algorithms;
using namespace Mantid::API;
using namespace Mantid::Kernel;
Expand Down Expand Up @@ -209,7 +210,7 @@ class CopyInstrumentParametersTestPerformance : public CxxTest::TestSuite
size_t n_detectors=44327;
size_t n_Parameters=200;
// Create input workspace with parameterized instrument and put into data store
MatrixWorkspace_sptr ws1 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(n_detectors+2, 10, true,false,true,"Instr_calibrated");
MatrixWorkspace_sptr ws1 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(static_cast<int>(n_detectors+2), 10, true,false,true,"Instr_calibrated");
AnalysisDataServiceImpl & dataStore = AnalysisDataService::Instance();
dataStore.add(m_SourceWSName, ws1);

Expand All @@ -225,12 +226,12 @@ class CopyInstrumentParametersTestPerformance : public CxxTest::TestSuite
// calibrate detectors;
for(size_t i=0;i<n_detectors;i++)
{
IComponent_const_sptr det =instrument->getDetector(1);
IComponent_const_sptr det =instrument->getDetector(static_cast<Mantid::detid_t>(i+1));
Geometry::ComponentHelper::moveComponent(*det, *pmap, V3D(sin(3.1415926*double(i)),cos(3.1415926*double(i/500)),7), Absolute );
}

// Create output workspace with another parameterized instrument and put into data store
MatrixWorkspace_sptr ws2 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(n_detectors, 10, true,false,true,"Instr_base");
MatrixWorkspace_sptr ws2 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument(static_cast<int>(n_detectors), 10, true,false,true,"Instr_base");
dataStore.add(m_TargetWSName, ws2);


Expand All @@ -242,17 +243,27 @@ class CopyInstrumentParametersTestPerformance : public CxxTest::TestSuite

void test_copy_performance()
{

// Set properties
TS_ASSERT_THROWS_NOTHING(copyInstParam.setPropertyValue("InputWorkspace", m_SourceWSName ));
TS_ASSERT_THROWS_NOTHING(copyInstParam.setPropertyValue("OutputWorkspace", m_TargetWSName ));


// Execute Algorithm, should warn but proceed
copyInstParam.setRethrows(true);

clock_t t_start = clock();
TS_ASSERT(copyInstParam.execute());
clock_t t_end = clock();

double seconds=static_cast<double>(t_end-t_start)/static_cast<double>(CLOCKS_PER_SEC);
std::cout<<" Time to copy all parameters is: "<<seconds<<" sec\n";

TS_ASSERT( copyInstParam.isExecuted() );
TS_ASSERT(copyInstParam.isInstrumentDifferent());

MatrixWorkspace_sptr ws2 =copyInstParam.getProperty("OutputWorkspace");
AnalysisDataServiceImpl & dataStore = AnalysisDataService::Instance();
MatrixWorkspace_sptr ws2 =dataStore.retrieveWS<API::MatrixWorkspace>(m_TargetWSName);
auto instr2=ws2->getInstrument();


Expand All @@ -263,7 +274,7 @@ class CopyInstrumentParametersTestPerformance : public CxxTest::TestSuite
auto name = *it;
double num = boost::lexical_cast<double>(name.substr(6,name.size()-6));
double val = instr2->getNumberParameter(name)[0];
TS_ASSERT_DELTA(num,val,1.e-8);
TS_ASSERT_DELTA(num*10,val,1.e-8);
}

// new detector allocation applied
Expand All @@ -274,13 +285,12 @@ class CopyInstrumentParametersTestPerformance : public CxxTest::TestSuite
int id = deto1->getID();
V3D newPos1 = deto1->getPos();
TS_ASSERT_EQUALS( id, i+1);
TS_ASSERT_DELTA( newPos1.X() ,sin(3.1415926*double(id)), 0.0001);
TS_ASSERT_DELTA( newPos1.X() ,sin(3.1415926*double(i)), 0.0001);
TS_ASSERT_DELTA( newPos1.Y() ,cos(3.1415926*double(i/500)), 0.0001);
TS_ASSERT_DELTA( newPos1.Z() , 7, 1.e-6);

}

AnalysisDataServiceImpl & dataStore = AnalysisDataService::Instance();
dataStore.remove(m_SourceWSName);
dataStore.remove(m_TargetWSName);

Expand Down

0 comments on commit d7d614e

Please sign in to comment.