Skip to content
Snippets Groups Projects
Commit 9c45cd6c authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #6352 #6364. load and save system.

parent de5023fd
No related merge requests found
......@@ -515,6 +515,46 @@ public:
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_ */
......
......@@ -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);
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......@@ -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);
......@@ -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
......
......@@ -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);
......@@ -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
......
......@@ -593,7 +593,7 @@ public:
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());
}
......
......@@ -964,6 +964,10 @@ public:
TS_ASSERT_EQUALS(Mantid::API::QLab, ws->getSpecialCoordinateSystem());
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment