Skip to content

Commit

Permalink
refs #6352 #6364. load and save system.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 15, 2013
1 parent de5023f commit 9c45cd6
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 21 deletions.
40 changes: 40 additions & 0 deletions Code/Mantid/Framework/MDAlgorithms/test/LoadMDTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,46 @@ class LoadMDTest : public CxxTest::TestSuite
doTestHisto(ws);
}

/// More of an integration test as it uses both load and save.
void test_save_and_load_special_coordinates()
{
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 2);
// Set the special coordinate system
const SpecialCoordinateSystem appliedCoordinateSystem = QSample;
ws->setCoordinateSystem(appliedCoordinateSystem);

const std::string inputWSName = "SaveMDSpecialCoordinatesTest";
const std::string fileName = inputWSName + ".nxs";
AnalysisDataService::Instance().addOrReplace(inputWSName, ws);

SaveMD saveAlg;
saveAlg.initialize();
saveAlg.isInitialized();
saveAlg.setPropertyValue("InputWorkspace", inputWSName);
saveAlg.setPropertyValue("Filename", fileName);
saveAlg.execute();
TS_ASSERT( saveAlg.isExecuted() );

LoadMD loadAlg;
loadAlg.initialize();
loadAlg.isInitialized();
loadAlg.setPropertyValue("Filename", fileName);
loadAlg.setProperty("FileBackEnd", false);
loadAlg.setPropertyValue("OutputWorkspace", "reloaded_again");
loadAlg.execute();
TS_ASSERT( loadAlg.isExecuted() );

// Check that the special coordinate system is the same before the save-load cycle.
TS_ASSERT_EQUALS(appliedCoordinateSystem, ws->getSpecialCoordinateSystem());

if (Poco::File(fileName).exists())
{
Poco::File(fileName).remove();
}
AnalysisDataService::Instance().remove(inputWSName);
AnalysisDataService::Instance().remove("OutputWorkspace");
}

};

#endif /* MANTID_MDEVENTS_LOADMDEWTEST_H_ */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ namespace MDEvents
void clearMDMasking();

/// Get the special coordinate system.
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const
{
return m_coordinateSystem;
}
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const;

/// Set the special coordinate system.
void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem);
Expand All @@ -164,9 +161,6 @@ namespace MDEvents
boost::shared_ptr<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > > m_BoxController;
private:

/// The special coordinate system of the workspace.
Mantid::API::SpecialCoordinateSystem m_coordinateSystem;

public:
/// Typedef for a shared pointer of this kind of event workspace
typedef boost::shared_ptr<MDEventWorkspace<MDE, nd> > sptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ namespace MDEvents
}

/// Get the special coordinate system.
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const
{
return m_coordinateSystem;
}
virtual Mantid::API::SpecialCoordinateSystem getSpecialCoordinateSystem() const;

/// Set the special coordinate system.
void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem);
Expand Down
41 changes: 36 additions & 5 deletions Code/Mantid/Framework/MDEvents/src/MDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <algorithm>
#include "MantidMDEvents/MDBoxIterator.h"
#include "MantidKernel/Memory.h"
#include "MantidKernel/Exception.h"

using namespace Mantid;
using namespace Mantid::Kernel;
Expand All @@ -38,8 +39,7 @@ namespace MDEvents
TMDE(
MDEventWorkspace)::MDEventWorkspace()
//m_BoxController(boost::make_shared<BoxController>(nd))
: m_BoxController(boost::make_shared<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > >(nd)),
m_coordinateSystem(Mantid::API::None)
: m_BoxController(boost::make_shared<BoxCtrlChangesList<MDBoxToChange<MDE,nd> > >(nd))
{
// First box is at depth 0, and has this default boxController
data = new MDBox<MDE, nd>(m_BoxController, 0);
Expand Down Expand Up @@ -819,10 +819,41 @@ namespace MDEvents
Set the special coordinate system (if any) to use.
@param coordinateSystem : Special coordinate system to use.
*/
TMDE(
void MDEventWorkspace)::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem)
TMDE(
void MDEventWorkspace)::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem)
{
m_coordinateSystem = coordinateSystem;
// If there isn't an experiment info, create one.
if(this->getNumExperimentInfo() == 0)
{
ExperimentInfo_sptr expInfo = boost::shared_ptr<ExperimentInfo>(new ExperimentInfo());
this->addExperimentInfo(expInfo);
}
this->getExperimentInfo(0)->mutableRun().addProperty("CoordinateSystem", (int)coordinateSystem, true);
}

/**
Get the special coordinate system (if any) to use.
@return Special coordinate system if any.
*/
TMDE(
Mantid::API::SpecialCoordinateSystem MDEventWorkspace)::getSpecialCoordinateSystem() const
{
Mantid::API::SpecialCoordinateSystem result = None;
try
{
auto nInfos = this->getNumExperimentInfo();
if(nInfos > 0)
{
Property* prop = this->getExperimentInfo(0)->run().getProperty("CoordinateSystem");
PropertyWithValue<int>* p = dynamic_cast<PropertyWithValue<int>* >(prop);
int temp = *p;
result = (SpecialCoordinateSystem)temp;
}
}
catch(Mantid::Kernel::Exception::NotFoundError&)
{
}
return result;
}

}//namespace MDEvents
Expand Down
36 changes: 32 additions & 4 deletions Code/Mantid/Framework/MDEvents/src/MDHistoWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ namespace MDEvents
Mantid::Geometry::MDHistoDimension_sptr dimZ, Mantid::Geometry::MDHistoDimension_sptr dimT)
: IMDHistoWorkspace(),
numDimensions(0),
m_nEventsContributed(std::numeric_limits<uint64_t>::quiet_NaN()),
m_coordinateSystem(None)
m_nEventsContributed(std::numeric_limits<uint64_t>::quiet_NaN())
{
std::vector<Mantid::Geometry::MDHistoDimension_sptr> dimensions;
if (dimX) dimensions.push_back(dimX);
Expand Down Expand Up @@ -1264,9 +1263,38 @@ namespace MDEvents
Set the special coordinate system (if any) to use.
@param coordinateSystem : Special coordinate system to use.
*/
void MDHistoWorkspace::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem)
void MDHistoWorkspace::setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem)
{
// If there isn't an experiment info, create one.
if(this->getNumExperimentInfo() == 0)
{
ExperimentInfo_sptr expInfo = boost::shared_ptr<ExperimentInfo>(new ExperimentInfo());
this->addExperimentInfo(expInfo);
}
this->getExperimentInfo(0)->mutableRun().addProperty("CoordinateSystem", (int)coordinateSystem, true);
}

/**
Get the special coordinate system (if any) to use.
*/
Mantid::API::SpecialCoordinateSystem MDHistoWorkspace::getSpecialCoordinateSystem() const
{
m_coordinateSystem = coordinateSystem;
Mantid::API::SpecialCoordinateSystem result = None;
try
{
auto nInfos = this->getNumExperimentInfo();
if(nInfos > 0)
{
Property* prop = this->getExperimentInfo(0)->run().getProperty("CoordinateSystem");
PropertyWithValue<int>* p = dynamic_cast<PropertyWithValue<int>* >(prop);
int temp = *p;
result = (SpecialCoordinateSystem)temp;
}
}
catch(Mantid::Kernel::Exception::NotFoundError&)
{
}
return result;
}

} // namespace Mantid
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/Framework/MDEvents/test/MDEventWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class MDEventWorkspaceTest : public CxxTest::TestSuite

void test_getSpecialCoordinateSystem_default()
{
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 1 /*event per box*/);
MDEventWorkspace1Lean::sptr ws = MDEventsTestHelper::makeMDEW<1>(10, 0.0, 10.0, 1 /*event per box*/);
TSM_ASSERT_EQUALS("Should default to no special coordinate system.", Mantid::API::None, ws->getSpecialCoordinateSystem());
}

Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/MDEvents/test/MDHistoWorkspaceTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ class MDHistoWorkspaceTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(Mantid::API::QLab, ws->getSpecialCoordinateSystem());
}





};


Expand Down

0 comments on commit 9c45cd6

Please sign in to comment.