13#include <boost/algorithm/string.hpp>
14#include <boost/regex.hpp>
36 regex expression(R
"(\[([^\[]*)\]|[^,]+)");
38 boost::sregex_token_iterator iter(names_string.begin(), names_string.end(), expression, 0);
39 boost::sregex_token_iterator end;
41 std::vector<std::string> names_result(iter, end);
77 "Clears any existing masks before applying the provided masking.");
79 "An input/output workspace.");
82 "Dimension ids/names all comma separated.\n"
83 "According to the dimensionality of the workspace, these names will be "
85 "so the number of entries must be n*(number of dimensions in the "
90 "Extents {min, max} corresponding to each of the dimensions specified, "
91 "according to the order those identifies have been specified.");
105 size_t dimWorkspaceIndex;
107 dimWorkspaceIndex = ws->getDimensionIndexById(candidateNameOrId);
108 }
catch (
const std::runtime_error &) {
110 dimWorkspaceIndex = ws->getDimensionIndexByName(candidateNameOrId);
112 return dimWorkspaceIndex;
121 std::vector<double> extents =
getProperty(
"Extents");
128 g_log.
debug() <<
"Dimension names parsed as: \n";
129 for (
const auto &
name : dimensions) {
133 size_t nDims = ws->getNumDims();
134 size_t nDimensionIds = dimensions.size();
136 size_t nGroups = nDimensionIds / nDims;
138 bool bClearExistingMasks =
getProperty(
"ClearExistingMasks");
139 if (bClearExistingMasks) {
140 ws->clearMDMasking();
148 const auto nGroups_double =
static_cast<double>(nGroups);
150 for (
size_t group = 0; group < nGroups; ++group) {
151 std::vector<InputArgument> arguments(nDims);
155 for (
size_t i = 0; i < nDims; ++i) {
156 size_t index = i + (group * nDims);
162 arg.min = extents[
index * 2];
163 arg.max = extents[(
index * 2) + 1];
169 std::sort(arguments.begin(), arguments.end(), comparator);
174 for (
size_t i = 0; i < nDims; ++i) {
175 mins[i] = float(arguments[i].min);
176 maxs[i] = float(arguments[i].max);
180 ws->setMDMasking(std::make_unique<MDBoxImplicitFunction>(mins, maxs));
182 auto group_double =
static_cast<double>(group);
183 this->
progress(group_double / nGroups_double);
190 std::map<std::string, std::string> validation_output;
195 std::vector<double> extents =
getProperty(
"Extents");
199 std::stringstream messageStream;
202 for (
const auto &dimension_name : dimensions) {
205 }
catch (
const std::runtime_error &) {
206 messageStream <<
"Dimension '" << dimension_name <<
"' not found. ";
209 if (messageStream.rdbuf()->in_avail() != 0) {
210 validation_output[
"Dimensions"] = messageStream.str();
211 messageStream.str(std::string());
214 size_t nDims = ws->getNumDims();
215 size_t nDimensionIds = dimensions.size();
218 if (nDimensionIds % nDims != 0) {
219 messageStream <<
"Number of dimension ids/names must be n * " << nDims <<
". The following names were given: ";
220 for (
const auto &
name : dimensions) {
221 messageStream <<
name <<
", ";
224 validation_output[
"Dimensions"] = messageStream.str();
225 messageStream.str(std::string());
229 if (extents.size() != (2 * dimensions.size())) {
230 messageStream <<
"Number of extents must be " << 2 * dimensions.size() <<
". ";
231 validation_output[
"Extents"] = messageStream.str();
234 for (
size_t i = 0; (i < nDimensionIds) && ((i * 2 + 1) < extents.size()); ++i) {
235 double min = extents[i * 2];
236 double max = extents[(i * 2) + 1];
238 messageStream <<
"Cannot have minimum extents " << min <<
" larger than maximum extents " << max <<
". ";
239 validation_output[
"Extents"] = messageStream.str();
243 return validation_output;
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
A property class for workspaces.
Support for a property that holds an array of values.
void debug(const std::string &msg)
Logs at debug level.
Validator to check that a property is not left empty.
The concrete, templated class for properties.
const std::string name() const override
Algorithm's name for identification.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
std::vector< std::string > MANTID_MDALGORITHMS_DLL parseDimensionNames(const std::string &names_string)
size_t tryFetchDimensionIndex(const Mantid::API::IMDWorkspace_sptr &ws, const std::string &candidateNameOrId)
Free helper function.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
Comparator to allow sorting by dimension index.
bool operator()(const InputArgument &a, const InputArgument &b) const