52 "Name of the output *MDEventWorkspace*.");
55 "By default (\"1\"), existing Output Workspace will be replaced. Select "
56 "false (\"0\") if you want to add new events to the workspace, which "
58 "\nChoosing \"0\" can be very inefficient for file-based workspaces");
61 "It has to be N comma separated values, where N is the "
62 "number of dimensions of the target workspace. Values "
63 "smaller then specified here will not be added to "
64 "workspace.\n Number N is defined by properties 4,6 and 7 "
66 "described on *MD Transformation factory* page. See also "
67 ":ref:`algm-ConvertToMDMinMaxLocal`");
73 "A list of the same size and the same units as MinValues "
74 "list. Values higher or equal to the specified by "
75 "this list will be ignored");
80 this->initBoxControllerProps(
"5" , 1000 , 20 );
82 auto mustBeMoreThan1 = std::make_shared<BoundedValidator<int>>();
83 mustBeMoreThan1->setLower(1);
86 "Optional. If specified, then all the boxes will be split to this "
87 "minimum recursion depth. 0 = no splitting, "
88 "1 = one level of splitting, etc. \n Be careful using this since it can "
89 "quickly create a huge number of :math:`boxes = "
90 "SplitInto^{MinRercursionDepth \\times NumDimensions}`. \n But setting "
91 "this property equal to MaxRecursionDepth "
92 "is necessary if one wants to generate multiple file based "
93 "workspaces in order to merge them later.");
94 setPropertyGroup(
"MinRecursionDepth", getBoxSettingsGroupName());
97 "This option causes a split of the top level, i.e. level0, of 50 for the "
98 "first four dimensions.");
101 "The name of the Nexus file to write, as a full or relative path.\n"
102 "Only used if FileBackEnd is true.");
103 setPropertySettings(
"Filename", std::make_unique<EnabledWhenProperty>(
"FileBackEnd",
IS_EQUAL_TO,
"1"));
105 declareProperty(
"FileBackEnd",
false,
106 "If true, Filename must also be specified. The algorithm "
107 "will create the specified file in addition to an output "
108 "workspace. The workspace will load data from the file on "
109 "demand in order to reduce memory use.");
111 std::vector<std::string> converterType{
"Default",
"Indexed"};
113 auto loadTypeValidator = std::make_shared<StringListValidator>(converterType);
114 declareProperty(
"ConverterType",
"Default", loadTypeValidator,
115 "[Default, Indexed], indexed is the experimental type that "
116 "can speedup the conversion process"
117 "for the big files using the indexing.");
126 std::map<std::string, std::string> result;
128 const std::string treeBuilderType = this->
getProperty(
"ConverterType");
129 const bool topLevelSplittingChecked = this->
getProperty(
"TopLevelSplitting");
130 std::vector<int> split_into = this->
getProperty(
"SplitInto");
131 const std::string filename = this->
getProperty(
"Filename");
132 const bool fileBackEnd = this->
getProperty(
"FileBackEnd");
134 if (fileBackEnd && filename.empty()) {
135 result[
"Filename"] =
"Filename must be given if FileBackEnd is required.";
138 if (treeBuilderType.find(
"Indexed") != std::string::npos) {
140 result[
"ConverterType"] +=
"No file back end implemented "
141 "for indexed version of algorithm. ";
143 if (topLevelSplittingChecked)
144 result[
"ConverterType"] +=
"The usage of top level splitting is "
145 "not possible for indexed version of algorithm. ";
149 result[
"ConverterType"] +=
"The split parameter should be the same for"
150 " all dimensions and be equal the power of 2"
151 " (2 ,4, 8, 16,..) for indexed version of algorithm. ";
154 std::vector<double> minVals = this->
getProperty(
"MinValues");
155 std::vector<double> maxVals = this->
getProperty(
"MaxValues");
157 if (minVals.size() != maxVals.size()) {
158 std::stringstream msg;
159 msg <<
"Rank of MinValues != MaxValues (" << minVals.size() <<
"!=" << maxVals.size() <<
")";
160 result[
"MinValues"] = msg.str();
161 result[
"MaxValues"] = msg.str();
163 std::stringstream msg;
165 size_t rank = minVals.size();
166 for (
size_t i = 0; i < rank; ++i) {
167 if (minVals[i] >= maxVals[i]) {
168 if (msg.str().empty())
169 msg <<
"max not bigger than min ";
172 msg <<
"at index=" << (i + 1) <<
" (" << minVals[i] <<
">=" << maxVals[i] <<
")";
176 if (!msg.str().empty()) {
177 result[
"MinValues"] = msg.str();
178 result[
"MaxValues"] = msg.str();
196 const std::string out_filename = this->
getProperty(
"Filename");
197 const bool fileBackEnd = this->
getProperty(
"FileBackEnd");
207 std::string dEModReq =
getProperty(
"dEAnalysisMode");
209 std::vector<std::string> otherDimNames =
getProperty(
"OtherDimensions");
215 std::string convertTo_ =
getProperty(
"QConversionScales");
218 std::vector<double> dimMin =
getProperty(
"MinValues");
219 std::vector<double> dimMax =
getProperty(
"MaxValues");
225 if (QFrame != autoSelect) {
230 if (convertTo_ != noScaling) {
232 convertTo_ = noScaling;
241 bool createNewTargetWs =
245 if (createNewTargetWs)
266 bool ignoreZeros =
getProperty(
"IgnoreZeroSignals");
285 savemd->setProperty(
"InputWorkspace", spws);
286 savemd->setPropertyValue(
"Filename", out_filename);
287 savemd->setProperty(
"UpdateFileBackEnd",
true);
288 savemd->setProperty(
"MakeFileBacked",
false);
289 savemd->executeAsChildAlg();
293 setProperty(
"OutputWorkspace", std::dynamic_pointer_cast<IMDEventWorkspace>(spws));
313 ei->mutableRun().addProperty(
"W_MATRIX", targWSDescr.
getPropertyValueAsType<std::vector<double>>(
"W_MATRIX"),
true);
318 uint16_t expInfoIndex = mdEventWS->addExperimentInfo(ei);
322 targWSDescr.
addProperty(
"EXP_INFO_INDEX", expInfoIndex,
true);
335 size_t spectra_index(0);
336 bool detector_found(
false);
337 const auto &spectrumInfo =
m_InWS2D->spectrumInfo();
338 for (
size_t i = 0; i <
m_InWS2D->getNumberHistograms(); ++i) {
339 if (spectrumInfo.hasDetectors(i) && !spectrumInfo.isMonitor(i)) {
341 detector_found =
true;
343 <<
" as the source of the bin "
344 "boundaries for the resolution corrections \n";
348 if (!detector_found) {
349 g_log.
information() <<
"No spectra in the workspace have detectors associated "
350 "with them. Storing bin boundaries from first spectrum for"
351 "resolution calculation\n";
355 auto binBoundaries =
m_InWS2D->x(spectra_index);
358 if (
m_Convertor->getUnitConversionHelper().isUnitConverted()) {
362 "the bin boundaries are copied from the first "
363 "workspace spectra. The resolution estimates can "
364 "be incorrect if unit conversion depends on "
369 std::transform(binBoundaries.cbegin(), binBoundaries.cend(), binBoundaries.begin(),
370 [&unitConv](
const auto &binBoundary) { return unitConv.convertUnits(binBoundary); });
373 if (binBoundaries[0] > binBoundaries.back()) {
375 "Sorting performed\n";
376 std::sort(binBoundaries.begin(), binBoundaries.end());
383 uint16_t nexpts = mdEventWS->getNumExperimentInfo();
385 ExperimentInfo_sptr expt = mdEventWS->getExperimentInfo(
static_cast<uint16_t
>(nexpts - 1));
386 expt->mutableRun().storeHistogramBinBoundaries(binBoundaries.rawData());
410 const std::string &dEModReq,
const std::vector<std::string> &otherDimNames,
411 std::vector<double> &dimMin, std::vector<double> &dimMax,
412 const std::string &QFrame,
const std::string &convertTo_,
416 std::vector<int> split_into;
418 if (createNewTargetWs) {
422 this->
findMinMax(
m_InWS2D, QModReq, dEModReq, QFrame, convertTo_, otherDimNames, dimMin, dimMax);
428 size_t NDims = spws->getNumDims();
429 dimMin.resize(NDims);
430 dimMax.resize(NDims);
431 split_into.resize(NDims);
432 for (
size_t i = 0; i < NDims; i++) {
437 split_into[i] =
static_cast<int>(pDim->
getNBins());
447 bool LorentzCorrections =
getProperty(
"LorentzCorrection");
460 }
catch (std::invalid_argument &) {
461 g_log.
warning() <<
"The projections are coplanar. Will use defaults "
462 "[1,0,0],[0,1,0] and [0,0,1]\n";
465 auto warnIfSet = [
this](
const std::string &propName) {
471 for (
const auto &
name : {
"UProj",
"VProj",
"WProj"}) {
476 if (createNewTargetWs) {
500 targWSDescr = oldWSDescr;
502 return createNewTargetWs;
514 const bool filebackend,
const std::string &filename) {
519 g_log.
error() <<
"can not create target event workspace with :" << targWSDescr.
nDimensions() <<
" dimensions\n";
520 throw(std::invalid_argument(
"can not create target workspace"));
532 bool topLevelSplittingChecked = this->
getProperty(
"TopLevelSplitting");
534 if (topLevelSplittingChecked) {
543 int minDepth = this->
getProperty(
"MinRecursionDepth");
544 int maxDepth = this->
getProperty(
"MaxRecursionDepth");
545 if (minDepth > maxDepth)
546 throw std::invalid_argument(
"MinRecursionDepth must be >= MaxRecursionDepth ");
547 spws->setMinRecursionDepth(
size_t(minDepth));
558 const size_t topLevelSplitSetting = 50;
559 const size_t dimCutoff = 4;
562 for (
size_t dim = 0; dim < bc->getNDims(); dim++) {
563 if (dim < dimCutoff) {
564 bc->setSplitTopInto(dim, topLevelSplitSetting);
566 bc->setSplitTopInto(dim, bc->getSplitInto(dim));
580 bool createNewWs(
false);
584 bool shouldOverwrite =
getProperty(
"OverwriteExisting");
585 createNewWs = shouldOverwrite;
608 const std::string &dEMode,
const std::string &QFrame,
const std::string &ConvertTo,
609 const std::vector<std::string> &otherDim, std::vector<double> &minVal,
610 std::vector<double> &maxVal) {
621 size_t nDim = nMatrixDim + otherDim.size();
625 bool wellDefined(
true);
626 if ((nDim == minVal.size()) && (minVal.size() == maxVal.size())) {
628 for (
size_t i = 0; i < minVal.size(); i++) {
629 if (minVal[i] >= maxVal[i])
631 g_log.
information() <<
" Min Value: " << minVal[i] <<
" for dimension N: " << i
632 <<
" equal or exceeds max value:" << maxVal[i] <<
'\n';
645 throw(std::runtime_error(
"Can not create child ChildAlgorithm to found min/max values"));
647 childAlg->setProperty(
"InputWorkspace", inWS);
648 childAlg->setProperty(
"QDimensions", QMode);
649 childAlg->setProperty(
"dEAnalysisMode", dEMode);
650 childAlg->setProperty(
"Q3DFrames", QFrame);
651 childAlg->setProperty(
"OtherDimensions", otherDim);
652 childAlg->setProperty(
"QConversionScales", ConvertTo);
653 childAlg->setProperty(
"PreprocDetectorsWS", std::string(
getProperty(
"PreprocDetectorsWS")));
655 if (!childAlg->isExecuted())
656 throw(std::runtime_error(
"Can not properly execute child algorithm to find "
657 "min/max workspace values"));
659 minVal = childAlg->getProperty(
"MinValues");
660 maxVal = childAlg->getProperty(
"MaxValues");
664 for (
unsigned int i = 0; i < nDim; i++) {
665 if (minVal[i] >= maxVal[i]) {
666 g_log.
debug() <<
"identified min-max values for dimension N: " << i
667 <<
" are equal. Modifying min-max value to produce "
668 "dimension with 0.2*dimValue width\n";
672 }
else if (minVal[i] == 0) {
689 std::vector<double> minAlgValues = this->
getProperty(
"MinValues");
690 std::vector<double> maxAlgValues = this->
getProperty(
"MaxValues");
691 bool allMinDefined = (minAlgValues.size() == nDim);
692 bool allMaxDefined = (maxAlgValues.size() == nDim);
693 if (allMinDefined || allMaxDefined) {
694 for (
size_t i = 0; i < nDim; i++) {
696 minVal[i] = minAlgValues[i];
698 maxVal[i] = maxAlgValues[i];
713 savemd->setProperty(
"InputWorkspace", outputWS);
714 savemd->setPropertyValue(
"Filename", filebackPath);
715 savemd->setProperty(
"UpdateFileBackEnd",
false);
716 savemd->setProperty(
"MakeFileBacked",
false);
717 savemd->executeAsChildAlg();
720 auto boxControllerMem = outputWS->getBoxController();
721 auto boxControllerIO = std::make_shared<BoxControllerNeXusIO>(boxControllerMem.get());
722 boxControllerMem->setFileBacked(boxControllerIO, filebackPath);
723 outputWS->setFileBacked();
724 boxControllerMem->getFileIO()->setWriteBufferSize(1000000);
#define DECLARE_ALGORITHM(classname)
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.
void setBoxController(const Mantid::API::BoxController_sptr &bc, const Mantid::Geometry::Instrument_const_sptr &instrument)
Set the settings in the given box controller.
@ OptionalSave
to specify a file to write to but an empty string is
void addProperty(Kernel::Property *prop, bool overwrite=false)
Add data to the object in the form of a property.
HeldType getPropertyValueAsType(const std::string &name) const
Get the value of a property as the given TYPE.
Helper class for reporting progress from algorithms.
A property class for workspaces.
The class responsible for saving events into nexus file using generic box controller interface Expect...
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
The class describes one dimension of multidimensional dataset representing an orthogonal dimension an...
virtual coord_t getMaximum() const =0
virtual coord_t getMinimum() const =0
virtual size_t getNBins() const =0
MDHistoDimensionBuilder :
static void resizeToFitMDBox(CoordT &min, CoordT &max)
Push the min/max values out by a defined amount.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
std::vector< T > getVector() const
The concrete, templated class for properties.
Base class for properties.
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
static bool isSplitValid(const std::vector< T > &split_into)
small class to select proper solver as function of the workspace kind and (possibly,...
std::shared_ptr< ConvToMDBase > convSelector(const API::MatrixWorkspace_sptr &inputWS, std::shared_ptr< ConvToMDBase > ¤tSolver) const
function which selects the convertor depending on workspace type and (possibly, in a future) some wor...
std::shared_ptr< MDAlgorithms::ConvToMDBase > m_Convertor
pointer to the class, which does the particular conversion
DataObjects::TableWorkspace_const_sptr preprocessDetectorsPositions(const Mantid::API::MatrixWorkspace_const_sptr &InWS2D, const std::string &dEModeRequested, bool updateMasks, const std::string &OutWSName)
The method responsible for analyzing input workspace parameters and preprocessing detectors positions...
void init() override
Initialize the algorithm's properties.
ConvertToMD : Transform a workspace into MD workspace with components defined by user.
int version() const override
Algorithm's version for identification.
void findMinMax(const Mantid::API::MatrixWorkspace_sptr &inWS, const std::string &QMode, const std::string &dEMode, const std::string &QFrame, const std::string &ConvertTo, const std::vector< std::string > &otherDim, std::vector< double > &minVal, std::vector< double > &maxVal)
Method takes min-max values from algorithm parameters if they are present or calculates default min-m...
bool doWeNeedNewTargetWorkspace(const API::IMDEventWorkspace_sptr &spws)
Check if target workspace new or existing one and we need to create new workspace.
Mantid::API::MatrixWorkspace_sptr m_InWS2D
pointer to the input workspace;
void setupFileBackend(const std::string &filebackPath, const API::IMDEventWorkspace_sptr &outputWS)
Setup the filebackend for the output workspace.
void addExperimentInfo(API::IMDEventWorkspace_sptr &mdEventWS, MDAlgorithms::MDWSDescription &targWSDescr) const
par of store metadata routine which generate metadata necessary for initializing ConvertToMD plugin
const std::string name() const override
Algorithm's name for identification.
boost::scoped_ptr< API::Progress > m_Progress
progress reporter
std::shared_ptr< MDAlgorithms::MDEventWSWrapper > m_OutWSWrapper
void copyMetaData(API::IMDEventWorkspace_sptr &mdEventWS) const
Store metadata and set some metadata, needed for plugin to run on the target workspace description.
void exec() override
Virtual method - must be overridden by concrete algorithm.
void setupTopLevelSplitting(const Mantid::API::BoxController_sptr &bc)
Sets up the top level splitting, i.e. of level 0, for the box controller.
API::IMDEventWorkspace_sptr createNewMDWorkspace(const MDAlgorithms::MDWSDescription &targWSDescr, const bool filebackend, const std::string &filename)
Create new MD workspace using existing parameters for algorithm.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
bool buildTargetWSDescription(const API::IMDEventWorkspace_sptr &spws, const std::string &QModReq, const std::string &dEModReq, const std::vector< std::string > &otherDimNames, std::vector< double > &dimMin, std::vector< double > &dimMax, const std::string &QFrame, const std::string &convertTo_, MDAlgorithms::MDWSDescription &targWSDescr)
handle the input parameters and build target workspace description as function of input parameters
Interface to set of sub-classes used by ConvertToMD algorithm and responsible for conversion of input...
virtual unsigned int getNMatrixDimensions(Kernel::DeltaEMode::Type mode, API::MatrixWorkspace_const_sptr inWS) const =0
return the number of dimensions, calculated by the transformation from the workspace.
Class responsible for conversion of input workspace data into proper number of output dimensions for ...
helper class describes the properties of target MD workspace, which should be obtained as the result ...
void setMinMax(const std::vector< double > &minVal, const std::vector< double > &maxVal)
function sets up min-max values to the dimensions, described by the class
bool m_buildingNewWorkspace
void setUpMissingParameters(const MDWSDescription &SourceMatrWS)
copy some parameters from the input workspace, as target md WS do not have all information about the ...
void setNumBins(const std::vector< int > &nBins_toSplit)
sets number of bins each dimension is split
void buildFromMDWS(const API::IMDEventWorkspace_const_sptr &pWS)
method builds MD Event description from existing MD event workspace
void buildFromMatrixWS(const API::MatrixWorkspace_sptr &pWS, const std::string &QMode, const std::string &dEMode, const std::vector< std::string > &dimPropertyNames=std::vector< std::string >())
method builds MD Event ws description from a matrix workspace and the transformations,...
unsigned int nDimensions() const
void setAbsMin(double absMin)
Kernel::DblMatrix m_Wtransf
std::vector< double > m_RotMatrix
DataObjects::TableWorkspace_const_sptr m_PreprDetTable
void setLorentsCorr(bool On=false)
do we need to perform Lorentz corrections
void checkWSCorresponsMDWorkspace(const MDWSDescription &NewMDWorkspaceD)
compare two descriptions and select the complimentary result.
void updateConversion(size_t i)
Method updates unit conversion given the index of detector parameters in the array of detectors.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
static Type fromString(const std::string &modeStr)
Returns the emode from the given string.
@ Input
An input workspace.
@ Output
An output workspace.