33 "An input MDWorkspace.");
36 this->initSlicingProps();
39 "Name of the output MDEventWorkspace.");
42 "Optional: Specify a NeXus file to write if you want the output "
43 "workspace to be file-backed.");
46 "If OutputFilename is specified to use a file back end:\n"
47 " The amount of memory (in MB) to allocate to the in-memory cache.\n"
48 " If not specified, a default of 40% of free physical memory is used.");
50 declareProperty(
"TakeMaxRecursionDepthFromInput",
true,
"Copy the maximum recursion depth from the input workspace.");
52 auto mustBePositiveInteger = std::make_shared<BoundedValidator<int>>();
53 mustBePositiveInteger->setLower(0);
55 declareProperty(
"MaxRecursionDepth", 1000, mustBePositiveInteger,
56 "Sets the maximum recursion depth to use. Can be used to "
57 "constrain the workspaces internal structure");
58 setPropertySettings(
"MaxRecursionDepth",
59 std::make_unique<EnabledWhenProperty>(
"TakeMaxRecursionDepthFromInput",
IS_EQUAL_TO,
"0"));
61 setPropertyGroup(
"OutputFilename",
"File Back-End");
62 setPropertyGroup(
"Memory",
"File Back-End");
99template <
typename MDE,
size_t nd,
typename OMDE,
size_t ond>
122 obc->setSplitInto(od, bc->getSplitInto(od));
124 obc->setSplitThreshold(bc->getSplitThreshold());
126 bool bTakeDepthFromInputWorkspace =
getProperty(
"TakeMaxRecursionDepthFromInput");
128 size_t maxDepth = bTakeDepthFromInputWorkspace ? bc->getMaxDepth() : size_t(tempDepth);
129 obc->setMaxDepth(maxDepth);
134 obc->resetNumBoxes();
137 size_t lastNumBoxes = obc->getTotalNumMDBoxes();
140 std::string filename =
getProperty(
"OutputFilename");
141 if (!filename.empty()) {
144 g_log.
notice() <<
"Running SaveMD to create file back-end\n";
146 alg->setPropertyValue(
"Filename", filename);
147 alg->setProperty(
"InputWorkspace", outWS);
148 alg->setProperty(
"MakeFileBacked",
true);
149 alg->executeAsChildAlg();
151 if (!obc->isFileBacked())
152 throw std::runtime_error(
"SliceMD with file-backed output: Can not set "
153 "up file-backed output workspace ");
155 auto IOptr = obc->getFileIO();
156 size_t outBufSize = IOptr->getWriteBufferSize();
159 if (outBufSize < 10 * IOptr->getDataChunk()) {
160 outBufSize = 10 * IOptr->getDataChunk();
161 IOptr->setWriteBufferSize(outBufSize);
169 std::vector<API::IMDNode *> boxes;
171 ws->
getBox()->getBoxes(boxes, 1000,
true, function.get());
174 bool fileBackedWS = bc->isFileBacked();
178 auto prog = std::make_unique<Progress>(
this, 0.0, 1.0, boxes.size());
185 uint64_t numSinceSplit = 0;
189 for (
int i = 0; i < int(boxes.size()); i++) {
192 if (box && !box->getIsMasked()) {
198 for (
auto it = events.cbegin(); it != events.cend(); ++it) {
200 const coord_t *inCenter = it->getCenter();
202 if (function->isPointContained(inCenter)) {
207 OMDE newEvent(it->getSignal(), it->getErrorSquared(), outCenter);
215 box->releaseEvents();
218 if (obc->shouldSplitBoxes(totalAdded, numSinceSplit, lastNumBoxes))
227 totalAdded += numSinceSplit;
229 lastNumBoxes = obc->getTotalNumMDBoxes();
248 totalAdded += numSinceSplit;
249 g_log.
notice() << totalAdded <<
" " << OMDE::getTypeName() <<
"s added to the output workspace.\n";
255 alg->setProperty(
"UpdateFileBackEnd",
true);
256 alg->setProperty(
"InputWorkspace", outWS);
257 alg->executeAsChildAlg();
262 }
catch (std::runtime_error &) {
263 g_log.
warning() << this->
name() <<
" was not able to copy experiment info to output workspace " << outWS->
getName()
281 throw std::runtime_error(
"No output dimensions specified!");
287 this->slice<MDE, nd, MDLeanEvent<1>, 1>(ws);
289 this->slice<MDE, nd, MDLeanEvent<2>, 2>(ws);
291 this->slice<MDE, nd, MDLeanEvent<3>, 3>(ws);
293 this->slice<MDE, nd, MDLeanEvent<4>, 4>(ws);
295 throw std::runtime_error(
"Number of output dimensions > 4. This is not currently handled.");
298 this->slice<MDE, nd, MDEvent<1>, 1>(ws);
300 this->slice<MDE, nd, MDEvent<2>, 2>(ws);
302 this->slice<MDE, nd, MDEvent<3>, 3>(ws);
304 this->slice<MDE, nd, MDEvent<4>, 4>(ws);
306 throw std::runtime_error(
"Number of output dimensions > 4. This is not currently handled.");
308 throw std::runtime_error(
"Unexpected MDEvent type '" +
MDE::getTypeName() +
"'. This is not currently handled.");
#define DECLARE_ALGORITHM(classname)
static std::unique_ptr< QThreadPool > tp
#define CALL_MDEVENT_FUNCTION(funcname, workspace)
Macro that makes it possible to call a templated method for a MDEventWorkspace using a IMDEventWorksp...
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
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
static void sortObjByID(std::vector< IMDNode * > &boxes)
Static method for sorting a list of MDBoxBase pointers by their file position, ascending.
void addDimension(const std::shared_ptr< Mantid::Geometry::IMDDimension > &dim)
Add a dimension.
void copyExperimentInfos(const MultipleExperimentInfos &other)
Copy the experiment infos from another.
A property class for workspaces.
const std::string & getName() const override
Get the workspace name.
Templated super-class of a multi-dimensional event "box".
virtual size_t addEvent(const MDE &point)=0
Add a single event.
Templated class for a multi-dimensional event "box".
const std::vector< MDE > & getConstEvents() const
Get vector of constant events to use.
Templated class for the multi-dimensional event workspace.
Mantid::API::MDNormalization displayNormalization() const override
void splitBox() override
Split the top-level MDBox into a MDGridBox.
std::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
MDBoxBase< MDE, nd > * getBox()
void splitAllIfNeeded(Kernel::ThreadScheduler *ts) override
Split all boxes that exceed the split threshold.
void setCoordinateSystem(const Kernel::SpecialCoordinateSystem coordSystem) override
Set the coordinate system.
Mantid::API::MDNormalization displayNormalizationHisto() const override
Kernel::SpecialCoordinateSystem getSpecialCoordinateSystem() const override
Get the coordinate system.
void refreshCache() override
Refresh the cache (integrated signal of each box)
void initialize() override
Perform initialization after dimensions (and others) have been set.
Mantid::API::BoxController_sptr getBoxController() override
Returns the BoxController used in this workspace.
uint64_t getNEvents() const override
bool isFileBacked() const override
Templated class holding data about a neutron detection event in N-dimensions (for example,...
uint16_t getExpInfoIndex() const
void setDetectorId(int32_t id)
Sets the detectorId of this event.
void setExpInfoIndex(uint16_t index)
Sets the expInfoIndex of this event.
int32_t getDetectorID() const
Templated class holding data about a neutron detection event in N-dimensions (for example,...
static std::string getTypeName()
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void warning(const std::string &msg)
Logs at warning level.
The concrete, templated class for properties.
A Thread Pool implementation that keeps a certain number of threads running (normally,...
A First-In-First-Out Thread Scheduler.
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
Algorithm that can take a slice out of an original MDEventWorkspace while preserving all the events c...
const std::string name() const override
Algorithm's name for identification.
void exec() override
Run the algorithm.
void slice(typename DataObjects::MDEventWorkspace< MDE, nd >::sptr ws)
Method to actually do the slice.
void doExec(typename DataObjects::MDEventWorkspace< MDE, nd >::sptr ws)
Helper method.
std::unique_ptr< API::CoordTransform > m_transformFromOriginal
Coordinate transformation to save in the output workspace (original->binned)
std::unique_ptr< Mantid::Geometry::MDImplicitFunction > getImplicitFunctionForChunk(const size_t *const chunkMin, const size_t *const chunkMax)
Create an implicit function for picking boxes, based on the indexes in the output MDHistoWorkspace.
void createTransform()
Read the algorithm properties and creates the appropriate transforms for slicing the MDEventWorkspace...
Mantid::API::IMDWorkspace_sptr m_inWS
Input workspace.
size_t m_outD
Number of dimensions in the output (binned) workspace.
std::vector< Mantid::Geometry::MDHistoDimension_sptr > m_binDimensions
Bin dimensions to actually use.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
void copyEvent(const MDLeanEvent< nd > &srcEvent, MDLeanEvent< ond > &newEvent, const uint16_t expInfoIndexOffset)
Copy the extra data (not signal, error or coordinates) from one event to another with different numbe...
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.