Skip to content

Commit

Permalink
refs #6852 W_matrix is the workspace property and can be retrieved
Browse files Browse the repository at this point in the history
tests show that.
  • Loading branch information
abuts committed Apr 16, 2013
1 parent 8d84141 commit 6b0f6e8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
6 changes: 6 additions & 0 deletions Code/Mantid/Framework/API/src/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ Kernel::Logger& LogManager::g_log = Kernel::Logger::get("LogManager");
INSTANTIATE(uint32_t);
INSTANTIATE(std::string);
INSTANTIATE(bool);

template MANTID_API_DLL uint16_t LogManager::getPropertyValueAsType(const std::string &) const;
template MANTID_API_DLL std::vector<double> LogManager::getPropertyValueAsType(const std::string &) const;
template MANTID_API_DLL std::vector<size_t> LogManager::getPropertyValueAsType(const std::string &) const;
template MANTID_API_DLL std::vector<int> LogManager::getPropertyValueAsType(const std::string &) const;
template MANTID_API_DLL std::vector<long> LogManager::getPropertyValueAsType(const std::string &) const;
/** @endcond */

} //API namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@ namespace MDAlgorithms
void exec();
/// Sets documentation strings for this algorithm
virtual void initDocs();
/// the pointer to class which keeps output MD workspace and is responsible for adding data to N-dimensional workspace;
boost::shared_ptr<MDEvents::MDEventWSWrapper> m_OutWSWrapper;
/// progress reporter
boost::scoped_ptr<API::Progress > m_Progress;
/// pointer to the class, which does the particular conversion
boost::shared_ptr<MDEvents::ConvToMDBase> m_Convertor;

/// logger -> to provide logging, for MD dataset file operations
static Mantid::Kernel::Logger& g_Log;
//------------------------------------------------------------------------------------------------------------------------------------------
protected: //for testing, otherwise private:
/// the pointer to class which keeps output MD workspace and is responsible for adding data to N-dimensional workspace;
boost::shared_ptr<MDEvents::MDEventWSWrapper> m_OutWSWrapper;
/// pointer to the input workspace;
Mantid::API::MatrixWorkspace_sptr m_InWS2D;
/// pointer to the class, which does the particular conversion
boost::shared_ptr<MDEvents::ConvToMDBase> m_Convertor;


static Mantid::Kernel::Logger & getLogger();

Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/MDAlgorithms/src/ConvertToMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void ConvertToMD::copyMetaData(API::IMDEventWorkspace_sptr mdEventWS, MDEvents::
// Copy ExperimentInfo (instrument, run, sample) to the output WS
API::ExperimentInfo_sptr ei(m_InWS2D->cloneExperimentInfo());

ei->mutableRun().addProperty("W_MATRIX",targWSDescr.m_Wtransf,true);
ei->mutableRun().addProperty("W_MATRIX",targWSDescr.m_Wtransf.getVector(),true);
uint16_t runIndex = mdEventWS->addExperimentInfo(ei);

const MantidVec & binBoundaries = m_InWS2D->readX(0);
Expand All @@ -427,7 +427,7 @@ void ConvertToMD::copyMetaData(API::IMDEventWorkspace_sptr mdEventWS, MDEvents::
}

// and add it to the target workspace description for further usage as identifier for the workspaces, which come from this run.
targWSDescr.setProperty<uint16_t>("RUN_INDEX",runIndex);
targWSDescr.addProperty("RUN_INDEX",runIndex,true);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class Convert2MDComponentsTestHelper: public ConvertToMD
}
void setSourceWS(Mantid::API::MatrixWorkspace_sptr InWS2D)
{
m_InWS2D = InWS2D;
this->m_InWS2D = InWS2D;
// and create the class, which will deal with the target workspace
if(!this->m_OutWSWrapper) this->m_OutWSWrapper = boost::shared_ptr<MDEvents::MDEventWSWrapper>(new MDEvents::MDEventWSWrapper());
}
Convert2MDComponentsTestHelper()
{
Expand Down Expand Up @@ -203,25 +205,34 @@ void testCopyMethadata()
Mantid::API::MatrixWorkspace_sptr ws2Dp = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("testWSProcessed");

API::IMDEventWorkspace_sptr spws;
// create testing part of the algorithm
Convert2MDComponentsTestHelper subAlgo;
// set source workspace as it would be used by the algorithm iteslt;
subAlgo.setSourceWS(ws2Dp);
// and min-max values (they are still needed by the algorithm)
subAlgo.setPropertyValue("MinValues","-10");
subAlgo.setPropertyValue("MaxValues","10");

bool createNewTargetWs;
std::vector<std::string> Q_modes = MDEvents::MDTransfFactory::Instance().getKeys();
std::vector<std::string> dE_modes = Kernel::DeltaEMode().availableTypes();
std::string dE_mode = Kernel::DeltaEMode().asString(Kernel::DeltaEMode::Elastic);
MDWSTransform QScl;
std::vector<std::string> QScales = QScl.getQScalings();

MDEvents::MDWSDescription targWSDescr;
TS_ASSERT_THROWS_NOTHING(createNewTargetWs=subAlgo.buildTargetWSDescription(spws,Q_modes[0],dE_modes[0],std::vector<std::string>(),QScales[CnvrtToMD::NoScaling],targWSDescr));
MDEvents::MDWSDescription targWSDescr;
TS_ASSERT_THROWS_NOTHING(createNewTargetWs=subAlgo.buildTargetWSDescription(spws,Q_modes[0],dE_mode,std::vector<std::string>(),QScales[CnvrtToMD::NoScaling],targWSDescr));

TSM_ASSERT("as spws is null pointer, this should request creating new workspace ",createNewTargetWs)

TS_ASSERT_THROWS_NOTHING(spws = subAlgo.createNewMDWorkspace(targWSDescr));
TS_ASSERT(spws);
if(!spws)return;

// copy the necessary methadata and get the unique number, that identifies the run, the source workspace came from.
TS_ASSERT_THROWS_NOTHING(subAlgo.copyMetaData(spws,targWSDescr));

uint16_t runIndex(1000);
TS_ASSERT_THROWS_NOTHING(runIndex=targWSDescr.getProperty("RUN_INDEX"));
TS_ASSERT_THROWS_NOTHING(runIndex=targWSDescr.getPropertyValueAsType<uint16_t>("RUN_INDEX"));
TS_ASSERT_EQUALS(0,runIndex);

// target workspace has W-matrix, which should be unit matrix
Expand All @@ -232,9 +243,9 @@ void testCopyMethadata()
Kernel::DblMatrix UnitMatr(3,3,true),wMatr;
std::vector<double> libWMatr;

TS_ASSERT_THROWS_NOTHING(wMatr=spws->getExperimentInfo(0)->run().getPropertyValueAsType<Kernel::DblMatrix >("W_MATRIX"));
TS_ASSERT_THROWS_NOTHING(libWMatr=spws->getExperimentInfo(0)->run().getPropertyValueAsType<std::vector<double> >("W_MATRIX"));

TSM_ASSERT("We have not set up anything so it should be unit matrix",wMatr.equals(UnitMatr));
//TSM_ASSERT("We have not set up anything so it should be unit matrix",wMatr.equals(UnitMatr));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#include "MantidMDEvents/MDEvent.h"
#include "MantidMDEvents/ConvToMDPreprocDet.h"
//#include "MantidMDEvents/MDTransfDEHelper.h"
#include "MantidDataObjects/TableWorkspace.h"
#include "MantidAPI/LogManager.h"


namespace Mantid
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace MDEvents


/// helper class describes the properties of target MD workspace, which should be obtained as the result of conversion algorithm.
class DLLExport MDWSDescription : public Kernel::PropertyManager
class DLLExport MDWSDescription : public API::LogManager
{
public: // for the time being
/// the string which describes ChildAlgorithm, used to convert source ws to target MD ws. At the moment, it coinsides with Q-mode
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/src/ConvToMDBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Mantid
m_OutWSWrapper = inWSWrapper;
// get the index which identify the run the source workspace came from.
// This index will mark the workspace' events for diffetent worksapces to combine
m_RunIndex = WSD.getProperty("RUN_INDEX");
m_RunIndex = WSD.getPropertyValueAsType<uint16_t>("RUN_INDEX");

m_NDims = m_OutWSWrapper->nDimensions();
// allocate space for single MDEvent coordinates
Expand Down

0 comments on commit 6b0f6e8

Please sign in to comment.