27const
std::
string SaveZODS::name()
const {
return "SaveZODS"; }
39 "An input MDHistoWorkspace in HKL space.");
42 "The name of the HDF5 file to write, as a full or relative path.");
52 throw std::runtime_error(
"InputWorkspace is not a MDHistoWorkspace");
53 if (ws->getNumDims() != 3)
54 throw std::runtime_error(
"InputWorkspace must have 3 dimensions (having "
55 "one bin in the 3rd dimension is OK).");
57 if (ws->getDimension(0)->getName() !=
"[H,0,0]")
58 g_log.
warning() <<
"SaveZODS expects the workspace to be in HKL space! "
62 auto file = std::make_unique<::NeXus::File>(Filename, NXACC_CREATE5);
66 file->makeGroup(
"CoordinateSystem",
"NXgroup",
true);
67 file->putAttr(
"isLocal", isLocal);
69 if (ws->getNumExperimentInfo() > 0) {
72 if (ei->sample().hasOrientedLattice()) {
73 std::vector<double> unitCell;
75 unitCell.emplace_back(latt.
a());
76 unitCell.emplace_back(latt.
b());
77 unitCell.emplace_back(latt.
c());
78 unitCell.emplace_back(latt.
alpha());
79 unitCell.emplace_back(latt.
beta());
80 unitCell.emplace_back(latt.
gamma());
83 std::vector<int> unit_cell_size(1, 6);
84 file->writeData(
"unit_cell", unitCell, unit_cell_size);
91 uint64_t numPoints = ws->getNPoints();
93 file->makeGroup(
"Data",
"NXgroup",
true);
94 file->makeGroup(
"Data_0",
"NXgroup",
true);
97 std::vector<double> origin(3, 0.0);
101 std::vector<int> size(3, 0);
104 std::vector<int> size_field(3, 0);
107 for (
size_t d = 0;
d < 3;
d++) {
109 std::vector<double> direction(3, 0.0);
110 direction[
d] = dim->getBinWidth();
112 origin[
d] = dim->getMinimum() + dim->getBinWidth() / 2;
114 size[2 -
d] = int(dim->getNBins());
116 size_field[
d] = int(dim->getNBins());
119 file->writeData(
"origin", origin);
120 file->writeData(
"size", size_field);
123 const auto signal = ws->getSignalArray();
124 std::vector<double> data;
126 for (
int i = 0; i < size_field[0]; i++)
127 for (
int j = 0; j < size_field[1]; j++)
128 for (
int k = 0; k < size_field[2]; k++) {
129 int l = i + size_field[0] * j + size_field[0] * size_field[1] * k;
130 data.emplace_back(signal[l]);
133 file->writeData(
"Data", data, size);
136 const auto errorSquared = ws->getErrorSquaredArray();
137 std::vector<double>
sigma;
138 sigma.reserve(numPoints);
139 for (
int i = 0; i < size_field[0]; i++)
140 for (
int j = 0; j < size_field[1]; j++)
141 for (
int k = 0; k < size_field[2]; k++) {
142 int l = i + size_field[0] * j + size_field[0] * size_field[1] * k;
143 sigma.emplace_back(sqrt(errorSquared[l]));
145 file->writeData(
"sigma",
sigma, size);
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
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.
@ Save
to specify a file to write to, the file may or may not exist
A property class for workspaces.
Class to implement UB matrix.
double alpha() const
Get lattice parameter.
double a(int nd) const
Get lattice parameter a1-a3 as function of index (0-2)
double c() const
Get lattice parameter.
double beta() const
Get lattice parameter.
double b() const
Get lattice parameter.
double gamma() const
Get lattice parameter.
void warning(const std::string &msg)
Logs at warning level.
Save a MDHistoWorkspace to a HDF5 format for use with the ZODS analysis software.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
std::shared_ptr< const ExperimentInfo > ExperimentInfo_const_sptr
Shared pointer to const ExperimentInfo.
std::shared_ptr< IMDHistoWorkspace > IMDHistoWorkspace_sptr
shared pointer to Mantid::API::IMDHistoWorkspace
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.