20#include <boost/algorithm/string.hpp>
21#include <boost/regex.hpp>
44 auto validator = std::make_shared<CompositeValidator>();
49 "Dimensionality of the data in the file.");
52 "A comma separated list of min, max for each dimension,\n"
53 "specifying the extents of each dimension.");
58 "A comma separated list of the name of each dimension. "
59 "e.g. ('[H,0,0]','[0,K,0]','[0,0,L]') ");
62 "A comma separated list of the units of each dimension.");
65 "MDHistoWorkspace reflecting the input text file.");
67 " A comma separated list of the frames of each dimension. "
69 " **General Frame**: Any frame which is not a Q-based frame."
70 " **QLab**: Wave-vector converted into the lab frame."
71 " **QSample**: Wave-vector converted into the frame of the sample."
72 " **HKL**: Wave-vector converted into the crystal's HKL indices."
73 " Note if nothing is specified then the **General Frame** is being "
74 "selected. Also note that if you select a frame then this might override "
75 "your unit selection if it is not compatible with the frame.");
90 std::vector<double> extents =
getProperty(
"Extents");
93 std::vector<std::string> names =
parseNames(dimensions_string);
94 std::vector<std::string> units =
getProperty(
"Units");
95 std::vector<std::string> frames =
getProperty(
"Frames");
98 if (extents.size() != ndims * 2)
99 throw std::invalid_argument(
"You must specify twice as many extents "
100 "(min,max) as there are dimensions.");
101 if (
nbins.size() != ndims)
102 throw std::invalid_argument(
"You must specify as number of bins as there are dimensions.");
103 if (names.size() != ndims)
104 throw std::invalid_argument(
"You must specify as many names as there are dimensions.");
105 if (units.size() != ndims)
106 throw std::invalid_argument(
"You must specify as many units as there are dimensions.");
112 if (!frames.empty() && frames.size() != ndims) {
113 throw std::invalid_argument(
"You must specify as many frames as there are dimensions.");
116 if (frames.empty()) {
117 frames.resize(ndims);
122 std::vector<MDHistoDimension_sptr> dimensions;
123 for (
size_t k = 0; k < ndims; ++k) {
125 dimensions.emplace_back(
127 static_cast<coord_t>(extents[(k * 2) + 1]),
nbins[k])));
147 return frameFactory->create(frameArg);
152 std::map<std::string, std::string> errors;
153 std::string framePropertyName =
"Frames";
154 std::vector<std::string> frames =
getProperty(framePropertyName);
156 auto ndims =
static_cast<size_t>(ndims_prop);
158 std::vector<std::string> targetFrames;
164 auto isValidFrame =
true;
165 for (
auto &frame : frames) {
168 isValidFrame = result;
172 if (!frames.empty() && frames.size() != ndims) {
173 isValidFrame =
false;
177 std::string message =
"The selected frames can be 'HKL', 'QSample', 'QLab' "
178 "or 'General Frame'. You must specify as many frames "
179 "as there are dimensions.";
180 errors.emplace(framePropertyName, message);
192 const std::vector<std::string> &targetFrames) {
193 return std::any_of(targetFrames.cbegin(), targetFrames.cend(),
194 [&frame](
const auto &targetFrame) { return targetFrame == frame; });
211 regex expression(R
"(\[([^\[]*)\]|[^,]+)");
213 boost::sregex_token_iterator iter(names_string.begin(), names_string.end(), expression, 0);
214 boost::sregex_token_iterator end;
216 std::vector<std::string> names_result(iter, end);
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.
A property class for workspaces.
static const std::string GeneralFrameName
static const std::string HKLName
Input argument type for MDFrameFactory chainable factory.
static const std::string QLabName
static const std::string QSampleName
Support for a property that holds an array of values.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
Validator to check that a property is not left empty.
The concrete, templated class for properties.
std::vector< int > nbins
Vector containing the number of bins in each dimension.
void initGenericImportProps()
Initialise the properties associated with the generic import (those to do with dimensionality).
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
Mantid::Geometry::MDFrame_uptr createMDFrame(const std::string &frame, const std::string &unit)
Create an MDFrame.
std::vector< std::string > parseNames(const std::string &names_string)
bool checkIfFrameValid(const std::string &frame, const std::vector< std::string > &targetFrames)
Check if the specified frame matches a target frame.
DataObjects::MDHistoWorkspace_sptr createEmptyOutputWorkspace()
Creates an empty md histo workspace (with dimensions)
std::shared_ptr< MDHistoWorkspace > MDHistoWorkspace_sptr
A shared pointer to a MDHistoWorkspace.
std::unique_ptr< MDFrame > MDFrame_uptr
MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain()
Make a complete factory chain.
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
@ Input
An input workspace.
@ Output
An output workspace.
Functor to compute the product of the set.
void operator()(size_t x)