Skip to content
Snippets Groups Projects
Unverified Commit 93824aaa authored by Gagik Vardanyan's avatar Gagik Vardanyan Committed by GitHub
Browse files

Merge pull request #26720 from rosswhitfield/SaveMD_options

Add options to SaveMD for MDHistoWorkspace
parents 3857295c 57753654
No related branches found
No related tags found
No related merge requests found
...@@ -116,6 +116,9 @@ public: ...@@ -116,6 +116,9 @@ public:
/// Saves this experiment description to the open NeXus file /// Saves this experiment description to the open NeXus file
void saveExperimentInfoNexus(::NeXus::File *file) const; void saveExperimentInfoNexus(::NeXus::File *file) const;
/// Saves this experiment description to the open NeXus file
void saveExperimentInfoNexus(::NeXus::File *file, bool saveInstrument,
bool saveSample, bool saveLogs) const;
/// Loads an experiment description from the open NeXus file /// Loads an experiment description from the open NeXus file
void loadExperimentInfoNexus(const std::string &nxFilename, void loadExperimentInfoNexus(const std::string &nxFilename,
::NeXus::File *file, std::string &parameterStr); ::NeXus::File *file, std::string &parameterStr);
......
...@@ -1156,6 +1156,26 @@ void ExperimentInfo::saveExperimentInfoNexus(::NeXus::File *file) const { ...@@ -1156,6 +1156,26 @@ void ExperimentInfo::saveExperimentInfoNexus(::NeXus::File *file) const {
run().saveNexus(file, "logs"); run().saveNexus(file, "logs");
} }
/** Save the object to an open NeXus file.
* @param file :: open NeXus file
* @param saveInstrument :: option to save Instrument
* @param saveSample :: option to save Sample
* @param saveLogs :: option to save Logs
*/
void ExperimentInfo::saveExperimentInfoNexus(::NeXus::File *file,
bool saveInstrument,
bool saveSample,
bool saveLogs) const {
Instrument_const_sptr instrument = getInstrument();
if (saveInstrument)
instrument->saveNexus(file, "instrument");
if (saveSample)
sample().saveNexus(file, "sample");
if (saveLogs)
run().saveNexus(file, "logs");
}
/** Load the sample and log info from an open NeXus file. /** Load the sample and log info from an open NeXus file.
* @param file :: open NeXus file * @param file :: open NeXus file
*/ */
......
...@@ -70,6 +70,17 @@ void SaveMD2::init() { ...@@ -70,6 +70,17 @@ void SaveMD2::init() {
setPropertySettings("MakeFileBacked", setPropertySettings("MakeFileBacked",
std::make_unique<EnabledWhenProperty>("UpdateFileBackEnd", std::make_unique<EnabledWhenProperty>("UpdateFileBackEnd",
IS_EQUAL_TO, "0")); IS_EQUAL_TO, "0"));
declareProperty(
"SaveHistory", true,
"Option to not save the Mantid history in the file. Only for MDHisto");
declareProperty(
"SaveInstrument", true,
"Option to not save the instrument in the file. Only for MDHisto");
declareProperty(
"SaveSample", true,
"Option to not save the sample in the file. Only for MDHisto");
declareProperty("SaveLogs", true,
"Option to not save the logs in the file. Only for MDHisto");
} }
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
...@@ -94,8 +105,9 @@ void SaveMD2::doSaveHisto(Mantid::DataObjects::MDHistoWorkspace_sptr ws) { ...@@ -94,8 +105,9 @@ void SaveMD2::doSaveHisto(Mantid::DataObjects::MDHistoWorkspace_sptr ws) {
file->putAttr("SaveMDVersion", 2); file->putAttr("SaveMDVersion", 2);
// Write out the coordinate system // Write out the coordinate system
file->writeData("coordinate_system", if (getProperty("SaveSample"))
static_cast<uint32_t>(ws->getSpecialCoordinateSystem())); file->writeData("coordinate_system",
static_cast<uint32_t>(ws->getSpecialCoordinateSystem()));
// Write out the Qconvention // Write out the Qconvention
// ki-kf for Inelastic convention; kf-ki for Crystallography convention // ki-kf for Inelastic convention; kf-ki for Crystallography convention
...@@ -104,28 +116,36 @@ void SaveMD2::doSaveHisto(Mantid::DataObjects::MDHistoWorkspace_sptr ws) { ...@@ -104,28 +116,36 @@ void SaveMD2::doSaveHisto(Mantid::DataObjects::MDHistoWorkspace_sptr ws) {
file->putAttr("QConvention", m_QConvention); file->putAttr("QConvention", m_QConvention);
// Write out the visual normalization // Write out the visual normalization
file->writeData("visual_normalization", if (getProperty("SaveSample"))
static_cast<uint32_t>(ws->displayNormalization())); file->writeData("visual_normalization",
static_cast<uint32_t>(ws->displayNormalization()));
// Save the algorithm history under "process" // Save the algorithm history under "process"
ws->getHistory().saveNexus(file); if (getProperty("SaveHistory"))
ws->getHistory().saveNexus(file);
// Save all the ExperimentInfos // Save all the ExperimentInfos
for (uint16_t i = 0; i < ws->getNumExperimentInfo(); i++) { if (getProperty("SaveInstrument") || (getProperty("SaveSample")) ||
ExperimentInfo_sptr ei = ws->getExperimentInfo(i); getProperty("SaveLogs")) {
std::string groupName = "experiment" + Strings::toString(i); for (uint16_t i = 0; i < ws->getNumExperimentInfo(); i++) {
if (ei) { ExperimentInfo_sptr ei = ws->getExperimentInfo(i);
// Can't overwrite entries. Just add the new ones std::string groupName = "experiment" + Strings::toString(i);
file->makeGroup(groupName, "NXgroup", true); if (ei) {
file->putAttr("version", 1); // Can't overwrite entries. Just add the new ones
ei->saveExperimentInfoNexus(file); file->makeGroup(groupName, "NXgroup", true);
file->closeGroup(); file->putAttr("version", 1);
ei->saveExperimentInfoNexus(file, getProperty("SaveInstrument"),
getProperty("SaveSample"),
getProperty("SaveLogs"));
file->closeGroup();
}
} }
} }
// Write out the affine matrices // Write out the affine matrices
MDBoxFlatTree::saveAffineTransformMatricies( if (getProperty("SaveSample"))
file, boost::dynamic_pointer_cast<const IMDWorkspace>(ws)); MDBoxFlatTree::saveAffineTransformMatricies(
file, boost::dynamic_pointer_cast<const IMDWorkspace>(ws));
// Check that the typedef has not been changed. The NeXus types would need // Check that the typedef has not been changed. The NeXus types would need
// changing if it does! // changing if it does!
......
...@@ -189,6 +189,60 @@ public: ...@@ -189,6 +189,60 @@ public:
Poco::File(this_filename).remove(); Poco::File(this_filename).remove();
} }
void test_saveOptions() {
std::string filename("OptionsSaveMD2Test.nxs");
MDHistoWorkspace_sptr ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(
2.5, 2, 10, 10.0, 3.5, "histo2", 4.5);
Mantid::Geometry::Goniometer gon;
gon.pushAxis("Psi", 0, 1, 0);
// add experiment infos
for (int i = 0; i < 80; i++) {
ExperimentInfo_sptr ei = boost::make_shared<ExperimentInfo>();
ei->mutableRun().addProperty("Psi", double(i));
ei->mutableRun().addProperty("Ei", 400.);
ei->mutableRun().setGoniometer(gon, true);
ws->addExperimentInfo(ei);
}
AnalysisDataService::Instance().addOrReplace("SaveMD2Test_ws", ws);
// Save everything
SaveMD2 alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize())
TS_ASSERT(alg.isInitialized())
TS_ASSERT_THROWS_NOTHING(
alg.setPropertyValue("InputWorkspace", "SaveMD2Test_ws"));
TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", filename));
alg.execute();
TS_ASSERT(alg.isExecuted());
std::string this_filename = alg.getProperty("Filename");
long unsigned int fileSize = Poco::File(this_filename).getSize();
if (Poco::File(this_filename).exists())
Poco::File(this_filename).remove();
// Only save data
SaveMD2 alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize())
TS_ASSERT(alg2.isInitialized())
TS_ASSERT_THROWS_NOTHING(
alg2.setPropertyValue("InputWorkspace", "SaveMD2Test_ws"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("Filename", filename));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("SaveHistory", "0"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("SaveInstrument", "0"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("SaveSample", "0"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("SaveLogs", "0"));
alg2.execute();
TS_ASSERT(alg2.isExecuted());
std::string this_filename2 = alg2.getProperty("Filename");
long unsigned int fileSize2 = Poco::File(this_filename2).getSize();
if (Poco::File(this_filename2).exists())
Poco::File(this_filename2).remove();
// The second file should be small since less is saved
TS_ASSERT_LESS_THAN(fileSize2, fileSize);
}
void test_saveAffine() { void test_saveAffine() {
std::string filename("MDAffineSaveMD2Test.nxs"); std::string filename("MDAffineSaveMD2Test.nxs");
// Make a 4D MDEventWorkspace // Make a 4D MDEventWorkspace
......
...@@ -16,6 +16,7 @@ Algorithms ...@@ -16,6 +16,7 @@ Algorithms
---------- ----------
* :ref:`MaskAngle <algm-MaskAngle>` has an additional option of ``Angle='InPlane'`` * :ref:`MaskAngle <algm-MaskAngle>` has an additional option of ``Angle='InPlane'``
* Whitespace is now ignored anywhere in the string when setting the Filename parameter in :ref:`Load <algm-Load>`. * Whitespace is now ignored anywhere in the string when setting the Filename parameter in :ref:`Load <algm-Load>`.
* Added options to :ref:`SaveMD <algm-SaveMD>` to allow selection of what will be saved. For MDHistoWorkspace only.
Data Objects Data Objects
------------ ------------
......
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