Skip to content

Commit

Permalink
refs #5161 detectors clear behind themselves
Browse files Browse the repository at this point in the history
refs #4401 a performance test skeleton
  • Loading branch information
abuts committed Apr 27, 2012
1 parent 535e68a commit 81dba05
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class DLLExport ConvToMDPreprocDetectors{
/** function builds fake cpectra-detector map and all other detectors position for the case when detector information has been lost */
void buildFakeDetectorsPositions(const API::MatrixWorkspace_sptr inputWS);

void clearAll();
ConvToMDPreprocDetectors();
private:
// function allocates the class detectors memory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ConvertToMDEventsWS<ConvertToMD::EventWSType,Q,MODE,CONV,Sample>: public I
{
/// shalow class which is invoked from processQND procedure and describes the transformation from workspace coordinates to target coordinates
/// presumably will be completely inlined
// the instanciation of the class which does the transformation itself
// the instantiation of the class which does the transformation itself
CoordTransformer<Q,MODE,CONV,ConvertToMD::Centered,Sample> trn;
// the pointer to underlying event workspace
DataObjects::EventWorkspace_sptr pEventWS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,20 @@ ConvToMDPreprocDetectors::ConvToMDPreprocDetectors():
emode(-2),
efix(std::numeric_limits<double>::quiet_NaN()),
L1(-1)
{}
// destructor
void ConvToMDPreprocDetectors::clearAll()
{
emode = -2,
efix = std::numeric_limits<double>::quiet_NaN();
L1 = -1;

this->det_dir.clear();
this->det_id.clear();
this->L2.clear();
this->TwoTheta.clear();
this->detIDMap.clear();
this->spec2detMap.clear();
}

} // END MDAlgorithms ns
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMDEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void ConvertToMDEvents::initDocs()
*/
ConvertToMDEvents::~ConvertToMDEvents()
{
// if the algorithm has gone, then the preprocessed detectors should probably too
det_loc.clearAll();
}
//
//const double rad2deg = 180.0 / M_PI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,63 @@ using namespace Mantid::MDAlgorithms::ConvertToMD;

class ConvertToMDEventsTestPerformance : public CxxTest::TestSuite
{
size_t numHist;
MDWSDescription WSD;

Mantid::API::MatrixWorkspace_sptr inWs2D;
Mantid::API::MatrixWorkspace_sptr inWsEv;
// static Mantid::Kernel::Logger &g_log;
std::auto_ptr<API::Progress > pProg;

WorkspaceCreationHelper::MockAlgorithm reporter;
std::auto_ptr<IConvertToMDEventsWS> pConvMethods;
ConvToMDPreprocDetectors det_loc;
// pointer to mock algorithm to work with progress bar
std::auto_ptr<WorkspaceCreationHelper::MockAlgorithm> pMockAlgorithm;

boost::shared_ptr<MDEvents::MDEventWSWrapper> pTargWS;

public:
static ConvertToMDEventsTestPerformance *createSuite() { return new ConvertToMDEventsTestPerformance(); }
static void destroySuite(ConvertToMDEventsTestPerformance * suite) { delete suite; }

void setUp()
{

WSD.emode = 2;
WSD.Ei = 10;

det_loc.setEmode(WSD.emode);
det_loc.setL1(10);
det_loc.setEfix(WSD.Ei);


}

void test_EventNoUnitsConv()
{
pTargWS->createEmptyMDWS(WSD);

pConvMethods = std::auto_ptr<IConvertToMDEventsWS>(new ConvertToMDEventsWS<EventWSType,Q3D,Direct,ConvertNo,CrystType>());
pConvMethods->setUPConversion(inWsEv,det_loc,WSD,pTargWS);

pMockAlgorithm->resetProgress(numHist);
TS_ASSERT_THROWS_NOTHING(pConvMethods->runConversion(pMockAlgorithm->getProgress()));
}


ConvertToMDEventsTestPerformance()
ConvertToMDEventsTestPerformance():
WSD(4)
{
int numHist=100*100;
Mantid::API::MatrixWorkspace_sptr inWsEv = boost::dynamic_pointer_cast<MatrixWorkspace>(WorkspaceCreationHelper::CreateRandomEventWorkspace(1000, numHist, 0.1));
numHist=100*100;
inWsEv = boost::dynamic_pointer_cast<MatrixWorkspace>(WorkspaceCreationHelper::CreateRandomEventWorkspace(1000, numHist, 0.1));
inWsEv->setInstrument( ComponentCreationHelper::createTestInstrumentCylindrical(numHist) );



pMockAlgorithm = std::auto_ptr<WorkspaceCreationHelper::MockAlgorithm>(new WorkspaceCreationHelper::MockAlgorithm(numHist));
det_loc.processDetectorsPositions(inWsEv,pMockAlgorithm->getLogger(),pMockAlgorithm->getProgress());


pTargWS = boost::shared_ptr<MDEventWSWrapper>(new MDEventWSWrapper());

}

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ namespace WorkspaceCreationHelper
inline FibSeries() : x1(1),x2(1) {}
inline T operator()() { const T out(x1+x2); x1=x2; x2=out; return out; }
};
/** mock algorithn for doing logging/progress reporting*/
class MockAlgorithm : public Mantid::API::Algorithm
{
public:
MockAlgorithm(size_t nSteps=100);
~MockAlgorithm(){};

/// Algorithm's name for identification
virtual const std::string name() const { return "MockAlgorithm";};
/// Algorithm's version for identification
virtual int version() const { return 1;};
/// Algorithm's category for identification
virtual const std::string category() const { return "Test";}

Mantid::Kernel::Logger & getLogger(){return a_log;}

Mantid::API::Progress *getProgress(){return pProg.get();}
void resetProgress(size_t nSteps)
{
pProg = std::auto_ptr<Mantid::API::Progress >(new Mantid::API::Progress(this,0,1,nSteps));
}
private:
void init(){};
void exec(){};
/// Sets documentation strings for this algorithm
virtual void initDocs(){};

std::auto_ptr<Mantid::API::Progress > pProg;
/// logger -> to provide logging, for MD dataset file operations
static Mantid::Kernel::Logger &a_log;

};

Mantid::DataObjects::Workspace2D_sptr Create1DWorkspaceRand(int size);
Mantid::DataObjects::Workspace2D_sptr Create1DWorkspaceConstant(int size, double value, double error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@
namespace WorkspaceCreationHelper
{


using namespace Mantid;
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::Geometry;
using Mantid::MantidVec;
using Mantid::MantidVecPtr;
// mock algorighm
Kernel::Logger& MockAlgorithm::a_log =Logger::get("test-Algorithms");
MockAlgorithm::MockAlgorithm(size_t nSteps)
{
pProg = std::auto_ptr<API::Progress >(new API::Progress(this,0,1,nSteps));
}


Workspace2D_sptr Create1DWorkspaceRand(int size)
{
Expand Down

0 comments on commit 81dba05

Please sign in to comment.