43 "An input MDEventWorkspace or MDHistoWorkspace.");
46 "The name of the Nexus file to write, as a full or relative path.\n"
47 "Optional if UpdateFileBackEnd is checked.");
49 setPropertySettings(
"Filename", std::make_unique<EnabledWhenProperty>(
"UpdateFileBackEnd",
IS_EQUAL_TO,
"0"));
51 declareProperty(
"UpdateFileBackEnd",
false,
52 "Only for MDEventWorkspaces with a file back end: check this to update "
53 "the NXS file on disk\n"
54 "to reflect the current data structure. Filename parameter is ignored.");
55 setPropertySettings(
"UpdateFileBackEnd", std::make_unique<EnabledWhenProperty>(
"MakeFileBacked",
IS_EQUAL_TO,
"0"));
57 declareProperty(
"MakeFileBacked",
false,
58 "For an MDEventWorkspace that was created in memory:\n"
59 "This saves it to a file AND makes the workspace into a "
61 setPropertySettings(
"MakeFileBacked", std::make_unique<EnabledWhenProperty>(
"UpdateFileBackEnd",
IS_EQUAL_TO,
"0"));
62 declareProperty(
"SaveHistory",
true,
"Option to not save the Mantid history in the file. Only for MDHisto");
63 declareProperty(
"SaveInstrument",
true,
"Option to not save the instrument in the file. Only for MDHisto");
64 declareProperty(
"SaveSample",
true,
"Option to not save the sample in the file. Only for MDHisto");
65 declareProperty(
"SaveLogs",
true,
"Option to not save the logs in the file. Only for MDHisto");
77 Poco::File oldFile(filename);
85 file->makeGroup(
"MDHistoWorkspace",
"NXentry",
true);
86 file->putAttr(
"SaveMDVersion", 2);
90 file->writeData(
"coordinate_system",
static_cast<uint32_t
>(ws->getSpecialCoordinateSystem()));
94 std::string m_QConvention = Kernel::ConfigService::Instance().getString(
"Q.convention");
95 file->putAttr(
"QConvention", m_QConvention);
99 file->writeData(
"visual_normalization",
static_cast<uint32_t
>(ws->displayNormalization()));
103 ws->getHistory().saveNexus(file.get());
107 for (uint16_t i = 0; i < ws->getNumExperimentInfo(); i++) {
112 file->makeGroup(groupName,
"NXgroup",
true);
113 file->putAttr(
"version", 1);
125 file->makeGroup(
"data",
"NXdata",
true);
128 size_t numDims = ws->getNumDims();
129 std::string axes_label;
130 for (
size_t d = 0;
d < numDims;
d++) {
131 std::vector<double> axis;
135 auto nbounds = dim->getNBoundaries();
136 for (
size_t n = 0;
n < nbounds;
n++)
137 axis.emplace_back(dim->getX(
n));
138 file->makeData(axis_title,
NXnumtype::FLOAT64,
static_cast<int>(dim->getNBoundaries()),
true);
139 file->putData(&axis[0]);
140 file->putAttr(
"units", std::string(dim->getUnits()));
141 file->putAttr(
"long_name", std::string(dim->getName()));
142 file->putAttr(
"frame", dim->getMDFrame().name());
145 axes_label.insert(0,
":");
146 axes_label.insert(0, axis_title);
153 for (
size_t d = 0;
d < numDims;
d++) {
156 size[numDims - 1 -
d] = dim->getNBins();
164 file->putData(ws->getSignalArray());
165 file->putAttr(
"signal", 1);
166 file->putAttr(
"axes", axes_label);
170 file->putData(ws->getErrorSquaredArray());
174 file->putData(ws->getNumEventsArray());
178 file->putData(ws->getMaskArray());
201 saveMDv1->setProperty<std::string>(
"Filename",
getProperty(
"Filename"));
202 saveMDv1->setProperty<
bool>(
"UpdateFileBackEnd",
getProperty(
"UpdateFileBackEnd"));
203 saveMDv1->setProperty<
bool>(
"MakeFileBacked",
getProperty(
"MakeFileBacked"));
205 }
else if (histoWS) {
208 throw std::runtime_error(
"SaveMD can only save MDEventWorkspaces and "
209 "MDHistoWorkspaces.\nPlease use SaveNexus or "
210 "another algorithm appropriate for this workspace "
#define DECLARE_ALGORITHM(classname)
std::unique_ptr< Mantid::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(Mantid::Nexus::File *const file, const API::IMDWorkspace_const_sptr &ws)
Save the affine matrices to both directional conversions to the data.
Save a MDEventWorkspace to a .nxs file.
void exec() override
Run the algorithm.
void doSaveHisto(const Mantid::DataObjects::MDHistoWorkspace_sptr &ws)
Save the MDHistoWorkspace.
static unsigned short constexpr INT8
static unsigned short constexpr FLOAT64
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.
std::vector< dimsize_t > DimVector
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.