44 "An input MDEventWorkspace or MDHistoWorkspace.");
47 "The name of the Nexus file to write, as a full or relative path.\n"
48 "Optional if UpdateFileBackEnd is checked.");
50 setPropertySettings(
"Filename", std::make_unique<EnabledWhenProperty>(
"UpdateFileBackEnd",
IS_EQUAL_TO,
"0"));
52 declareProperty(
"UpdateFileBackEnd",
false,
53 "Only for MDEventWorkspaces with a file back end: check this to update "
54 "the NXS file on disk\n"
55 "to reflect the current data structure. Filename parameter is ignored.");
56 setPropertySettings(
"UpdateFileBackEnd", std::make_unique<EnabledWhenProperty>(
"MakeFileBacked",
IS_EQUAL_TO,
"0"));
58 declareProperty(
"MakeFileBacked",
false,
59 "For an MDEventWorkspace that was created in memory:\n"
60 "This saves it to a file AND makes the workspace into a "
62 setPropertySettings(
"MakeFileBacked", std::make_unique<EnabledWhenProperty>(
"UpdateFileBackEnd",
IS_EQUAL_TO,
"0"));
63 declareProperty(
"SaveHistory",
true,
"Option to not save the Mantid history in the file. Only for MDHisto");
64 declareProperty(
"SaveInstrument",
true,
"Option to not save the instrument in the file. Only for MDHisto");
65 declareProperty(
"SaveSample",
true,
"Option to not save the sample in the file. Only for MDHisto");
66 declareProperty(
"SaveLogs",
true,
"Option to not save the logs in the file. Only for MDHisto");
78 Poco::File oldFile(filename);
83 auto file = std::make_unique<::NeXus::File>(filename, NXACC_CREATE5);
86 file->makeGroup(
"MDHistoWorkspace",
"NXentry",
true);
87 file->putAttr(
"SaveMDVersion", 2);
91 file->writeData(
"coordinate_system",
static_cast<uint32_t
>(ws->getSpecialCoordinateSystem()));
96 file->putAttr(
"QConvention", m_QConvention);
100 file->writeData(
"visual_normalization",
static_cast<uint32_t
>(ws->displayNormalization()));
104 ws->getHistory().saveNexus(file.get());
108 for (uint16_t i = 0; i < ws->getNumExperimentInfo(); i++) {
113 file->makeGroup(groupName,
"NXgroup",
true);
114 file->putAttr(
"version", 1);
126 file->makeGroup(
"data",
"NXdata",
true);
129 size_t numDims = ws->getNumDims();
130 std::string axes_label;
131 for (
size_t d = 0;
d < numDims;
d++) {
132 std::vector<double> axis;
134 auto nbounds = dim->getNBoundaries();
135 for (
size_t n = 0;
n < nbounds;
n++)
136 axis.emplace_back(dim->getX(
n));
137 file->makeData(dim->getDimensionId(), ::NeXus::FLOAT64,
static_cast<int>(dim->getNBoundaries()),
true);
138 file->putData(&axis[0]);
139 file->putAttr(
"units", std::string(dim->getUnits()));
140 file->putAttr(
"long_name", std::string(dim->getName()));
141 file->putAttr(
"frame", dim->getMDFrame().name());
144 axes_label.insert(0,
":");
145 axes_label.insert(0, dim->getDimensionId());
151 std::vector<int> size(numDims);
152 for (
size_t d = 0;
d < numDims;
d++) {
155 size[numDims - 1 -
d] = int(dim->getNBins());
158 std::vector<int> chunks = size;
162 file->makeCompData(
"signal", ::NeXus::FLOAT64, size, ::NeXus::LZW, chunks,
true);
163 file->putData(ws->getSignalArray());
164 file->putAttr(
"signal", 1);
165 file->putAttr(
"axes", axes_label);
168 file->makeCompData(
"errors_squared", ::NeXus::FLOAT64, size, ::NeXus::LZW, chunks,
true);
169 file->putData(ws->getErrorSquaredArray());
172 file->makeCompData(
"num_events", ::NeXus::FLOAT64, size, ::NeXus::LZW, chunks,
true);
173 file->putData(ws->getNumEventsArray());
176 file->makeCompData(
"mask", ::NeXus::INT8, size, ::NeXus::LZW, chunks,
true);
177 file->putData(ws->getMaskArray());
200 saveMDv1->setProperty<std::string>(
"Filename",
getProperty(
"Filename"));
201 saveMDv1->setProperty<
bool>(
"UpdateFileBackEnd",
getProperty(
"UpdateFileBackEnd"));
202 saveMDv1->setProperty<
bool>(
"MakeFileBacked",
getProperty(
"MakeFileBacked"));
204 }
else if (histoWS) {
207 throw std::runtime_error(
"SaveMD can only save MDEventWorkspaces and "
208 "MDHistoWorkspaces.\nPlease use SaveNexus or "
209 "another algorithm appropriate for this workspace "
#define DECLARE_ALGORITHM(classname)
std::unique_ptr<::NeXus::File > file_holder_type
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
@ OptionalSave
to specify a file to write to but an empty string is
A property class for workspaces.
static void saveAffineTransformMatricies(::NeXus::File *const file, const API::IMDWorkspace_const_sptr &ws)
Save the affine matrices to both directional conversions to the data.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Save a MDEventWorkspace to a .nxs file.
void exec() override
Run the algorithm.
void doSaveHisto(const Mantid::DataObjects::MDHistoWorkspace_sptr &ws)
Save the MDHistoWorkspace.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
std::shared_ptr< MDHistoWorkspace > MDHistoWorkspace_sptr
A shared pointer to a MDHistoWorkspace.
std::shared_ptr< const IMDDimension > IMDDimension_const_sptr
Shared Pointer to const IMDDimension.
std::string toString(const T &value)
Convert a number to a string.
@ Input
An input workspace.