27template <
typename MDE,
size_t nd>
28std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>> createOutputWorkspace(
size_t splitInto) {
29 std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>> out(
32 bc->setSplitThreshold(100);
33 bc->setSplitInto(splitInto);
37template <
typename MDE,
size_t nd>
39 Mantid::coord_t max,
const std::string &axisNameFormat,
const std::string &axisIdFormat) {
45 for (
size_t d = 0;
d < nd;
d++) {
47 sprintf(name, axisNameFormat.c_str(), d);
49 sprintf(
id, axisIdFormat.c_str(), d);
53 out->addDimension(dim);
58template <
typename MDE,
size_t nd>
61 const std::string &axisNameFormat,
const std::string &axisIdFormat) {
62 for (
size_t d = 0;
d < nd;
d++) {
64 sprintf(name, axisNameFormat.c_str(), d);
66 sprintf(
id, axisIdFormat.c_str(), d);
70 std::make_shared<Mantid::Geometry::MDHistoDimension>(std::string(name), std::string(
id), frame, min, max, 10);
71 out->addDimension(dim);
76template <
typename MDE,
size_t nd>
79 const std::vector<Mantid::Geometry::MDFrame_sptr> &frame,
80 const std::string &axisNameFormat,
const std::string &axisIdFormat) {
81 for (
size_t d = 0;
d < nd;
d++) {
83 sprintf(name, axisNameFormat.c_str(), d);
85 sprintf(
id, axisIdFormat.c_str(), d);
88 auto dim = std::make_shared<Mantid::Geometry::MDHistoDimension>(std::string(name), std::string(
id), *frame[d], min,
90 out->addDimension(dim);
95template <
typename MDE,
size_t nd>
98 if (numEventsPerBox > 0) {
102 size_t index_max[nd];
104 bool allDone =
false;
106 for (
size_t i = 0; i < numEventsPerBox; i++) {
109 for (
size_t d = 0;
d < nd;
d++)
112 out->addEvent(
MDE(1.0, 1.0, centers));
120 out->addExperimentInfo(ei);
125namespace DataObjects {
132namespace MDEventsTestHelper {
154 double errorSquared = 1.0,
const std::string &name =
"",
159 size_t numBins = 10,
coord_t max = 10.0,
double errorSquared = 1.0,
160 const std::string &name =
"",
double numEvents = 1.0);
164 double errorSquared,
size_t *numBins,
166 const std::string &name =
"");
170 coord_t *max, std::vector<std::string> names,
const std::string &name =
"");
187template <
typename MDE,
size_t nd>
188std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>>
190 const std::string &axisNameFormat =
"Axis%d",
const std::string &axisIdFormat =
"Axis%d") {
192 auto out = createOutputWorkspace<MDE, nd>(splitInto);
195 addMDDimensions<MDE, nd>(out, min, max, axisNameFormat, axisIdFormat);
198 addData<MDE, nd>(out, splitInto, min, max, numEventsPerBox);
223template <
typename MDE,
size_t nd>
224std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>>
226 std::vector<Mantid::Geometry::MDFrame_sptr> frames,
size_t numEventsPerBox = 0,
227 const std::string &wsName =
"", std::string axisNameFormat =
"Axis%d",
228 std::string axisIdFormat =
"Axis%d") {
230 auto out = createOutputWorkspace<MDE, nd>(splitInto);
233 addMDDimensionsWithIndividualFrames<MDE, nd>(out, min, max, frames, axisNameFormat, axisIdFormat);
236 addData<MDE, nd>(out, splitInto, min, max, numEventsPerBox);
262template <
typename MDE,
size_t nd>
263std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>>
265 size_t numEventsPerBox = 0,
const std::string &wsName =
"",
266 const std::string &axisNameFormat =
"Axis%d",
const std::string &axisIdFormat =
"Axis%d") {
268 auto out = createOutputWorkspace<MDE, nd>(splitInto);
271 addMDDimensionsWithFrames<MDE, nd>(out, min, max, frame, axisNameFormat, axisIdFormat);
274 addData<MDE, nd>(out, splitInto, min, max, numEventsPerBox);
286 size_t numEventsPerBox = 0) {
287 return makeAnyMDEW<MDLeanEvent<nd>, nd>(splitInto, min, max, numEventsPerBox);
294 size_t numEventsPerBox = 0) {
295 return makeAnyMDEWWithFrames<MDLeanEvent<nd>, nd>(splitInto, min, max, frame, numEventsPerBox);
300std::shared_ptr<MDEventWorkspace<MDLeanEvent<nd>, nd>>
302 const std::vector<Mantid::Geometry::MDFrame_sptr> &frame,
size_t numEventsPerBox = 0) {
303 return makeAnyMDEWWithIndividualFrames<MDLeanEvent<nd>, nd>(splitInto, min, max, frame, numEventsPerBox);
310 size_t numEventsPerBox = 0) {
311 return makeAnyMDEW<MDEvent<nd>, nd>(splitInto, min, max, numEventsPerBox);
344 splitter->setSplitThreshold(5);
346 splitter->setSplitInto(split0);
347 splitter->setSplitInto(0, split0);
349 splitter->setSplitInto(1, split1);
351 auto box = std::make_unique<MDBox<MDLeanEvent<nd>, nd>>(splitter);
352 for (
size_t d = 0;
d < nd;
d++)
354 box->setExtents(
d, dimensionMin, dimensionMax);
378 size_t index_max[nd];
381 bool allDone =
false;
385 for (
size_t d = 0;
d < nd;
d++)
386 centers[
d] =
static_cast<coord_t>(counters[
d]) * step + start;
389 for (
size_t i = 0; i < repeat; ++i)
395 box->refreshCache(
nullptr);
407 using boxVector = std::vector<MDBoxBase<MDLeanEvent<nd>, nd> *>;
408 if (atRecurseLevel >= recurseLimit)
413 boxes = box->getBoxes();
414 for (
size_t i = 0; i < boxes.size(); i++)
415 box->splitContents(i);
418 boxes = box->getBoxes();
421 for (
size_t i = 0; i < boxes.size(); i++) {
424 recurseSplit(containedbox, atRecurseLevel + 1, recurseLimit);
439 splitter->setSplitThreshold(5);
440 splitter->resetNumBoxes();
441 splitter->setMaxDepth(levels + 1);
443 splitter->setSplitInto(splitInto);
445 auto box = std::make_unique<MDBox<MDLeanEvent<nd>, nd>>(splitter);
446 for (
size_t d = 0;
d < nd;
d++)
447 box->setExtents(
d, 0.0,
static_cast<coord_t>(splitInto));
458template <
typename MDBOX>
static void extents_match(MDBOX box,
size_t dim,
double min,
double max) {
459 TSM_ASSERT_DELTA(dim, box->getExtents(dim).getMin(), min, 1e-6);
460 TSM_ASSERT_DELTA(dim, box->getExtents(dim).getMax(), max, 1e-6);
std::map< DeltaEMode::Type, std::string > index
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
This class is shared by a few Workspace types and holds information related to a particular experimen...
Templated super-class of a multi-dimensional event "box".
Templated class for a multi-dimensional event "box".
Templated class for the multi-dimensional event workspace.
std::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
Templated class for a GRIDDED multi-dimensional event "box".
Templated class holding data about a neutron detection event in N-dimensions (for example,...
GeneralFrame : Any MDFrame that isn't related to momemtum transfer.
static const std::string GeneralFrameDistance
MDFrame : The coordinate frame for a dimension, or set of dimensions in a multidimensional workspace.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ExperimentInfo > ExperimentInfo_sptr
Shared pointer to ExperimentInfo.
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
std::size_t numEvents(::NeXus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix, const NexusHDF5Descriptor &descriptor)
Get the number of events in the currently opened group.
MDBox< MDLeanEvent< 1 >, 1 > * makeMDBox1(size_t splitInto=10, API::BoxController *splitter=nullptr)
Generate an empty MDBox.
std::shared_ptr< MDEventWorkspace< MDEvent< nd >, nd > > makeMDEWFull(size_t splitInto, coord_t min, coord_t max, size_t numEventsPerBox=0)
Make a MDEventWorkspace with MDEvents - updated to split dims by splitInto, not 10.
static void feedMDBox(MDBoxBase< MDLeanEvent< nd >, nd > *box, size_t repeat=1, size_t numPerSide=10, coord_t start=0.5, coord_t step=1.0)
Feed a MDGridBox with evenly-spaced events.
Mantid::DataObjects::EventWorkspace_sptr createDiffractionEventWorkspace(int numEvents, int numPixels=400, int numBins=160)
Create an EventWorkspace containing fake data of single-crystal diffraction.
MDHistoWorkspace_sptr makeFakeMDHistoWorkspace(double signal, size_t numDims, size_t numBins=10, coord_t max=10.0, double errorSquared=1.0, const std::string &name="", double numEvents=1.0)
Make a fake n-dimensional MDHistoWorkspace.
std::vector< MDLeanEvent< 1 > > makeMDEvents1(size_t num)
Return a vector with this many MDEvents, spaced evenly from 0.5, 1.5, etc.
Mantid::DataObjects::MDHistoWorkspace_sptr makeFakeMDHistoWorkspaceGeneral(size_t numDims, double signal, double errorSquared, size_t *numBins, coord_t *min, coord_t *max, const std::string &name="")
More general fake n-dimensionsal MDHistoWorkspace.
std::shared_ptr< MDEventWorkspace< MDLeanEvent< nd >, nd > > makeMDEW(size_t splitInto, coord_t min, coord_t max, size_t numEventsPerBox=0)
Make a MDEventWorkspace with MDLeanEvents.
std::shared_ptr< Mantid::DataObjects::MDEventWorkspace< MDE, nd > > makeAnyMDEWWithIndividualFrames(size_t splitInto, coord_t min, coord_t max, std::vector< Mantid::Geometry::MDFrame_sptr > frames, size_t numEventsPerBox=0, const std::string &wsName="", std::string axisNameFormat="Axis%d", std::string axisIdFormat="Axis%d")
Create a test MDEventWorkspace<nd> .
std::shared_ptr< MDEventWorkspace< MDLeanEvent< nd >, nd > > makeMDEWWithFrames(size_t splitInto, coord_t min, coord_t max, const Mantid::Geometry::MDFrame &frame, size_t numEventsPerBox=0)
Make a MDEventWorkspace with MDLeanEvents nad MDFrames.
MDBox< MDLeanEvent< 3 >, 3 > * makeMDBox3()
Generate an empty MDBox with 3 dimensions, split 10x5x2.
std::shared_ptr< Mantid::DataObjects::MDEventWorkspace< MDE, nd > > makeAnyMDEW(size_t splitInto, coord_t min, coord_t max, size_t numEventsPerBox=0, const std::string &wsName="", const std::string &axisNameFormat="Axis%d", const std::string &axisIdFormat="Axis%d")
Create a test MDEventWorkspace<nd> .
static MDGridBox< MDLeanEvent< nd >, nd > * makeRecursiveMDGridBox(size_t splitInto, size_t levels)
Generate a recursively gridded MDGridBox.
void checkAndDeleteFile(const std::string &filename)
Delete a file from disk.
std::shared_ptr< MDEventWorkspace< MDLeanEvent< nd >, nd > > makeMDEWWithIndividualFrames(size_t splitInto, coord_t min, coord_t max, const std::vector< Mantid::Geometry::MDFrame_sptr > &frame, size_t numEventsPerBox=0)
Make a MDEventWorkspace with MDLeanEvents and individual MDFrames.
std::shared_ptr< Mantid::DataObjects::MDEventWorkspace< MDE, nd > > makeAnyMDEWWithFrames(size_t splitInto, coord_t min, coord_t max, const Mantid::Geometry::MDFrame &frame, size_t numEventsPerBox=0, const std::string &wsName="", const std::string &axisNameFormat="Axis%d", const std::string &axisIdFormat="Axis%d")
Create a test MDEventWorkspace<nd> .
static void recurseSplit(MDGridBox< MDLeanEvent< nd >, nd > *box, size_t atRecurseLevel, size_t recurseLimit)
Recursively split an existing MDGridBox.
MDEventWorkspace3Lean::sptr makeFakeMDEventWorkspace(const std::string &wsName, long numEvents=10000, Kernel::SpecialCoordinateSystem coord=Kernel::None)
Make a (optionally) file backed MDEventWorkspace with 10000 fake random data points.
static MDGridBox< MDLeanEvent< nd >, nd > * makeMDGridBox(size_t split0=10, size_t split1=10, coord_t dimensionMin=0.0, coord_t dimensionMax=10.0)
Generate an empty MDBox with 2 dimensions, splitting in (default) 10x10 boxes.
static void extents_match(MDBOX box, size_t dim, double min, double max)
Helper function compares the extents of the given box.
Mantid::DataObjects::MDHistoWorkspace_sptr makeFakeMDHistoWorkspaceWithMDFrame(double signal, size_t numDims, const Mantid::Geometry::MDFrame &frame, size_t numBins=10, coord_t max=10.0, double errorSquared=1.0, const std::string &name="", double numEvents=1.0)
Creates a fake MDHistoWorkspace with MDFrame selection.
std::shared_ptr< MDHistoWorkspace > MDHistoWorkspace_sptr
A shared pointer to a MDHistoWorkspace.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::shared_ptr< MDHistoDimension > MDHistoDimension_sptr
Shared pointer to a MDHistoDimension.
bool Increment(const size_t numDims, size_t *index, size_t *index_max, size_t *index_min)
Utility function for performing arbitrarily nested for loops in a serial way.
void SetUp(const size_t numDims, size_t *out, const size_t value=0)
Set up a nested for loop by setting an array of counters.
SpecialCoordinateSystem
Special coordinate systems for Q3D.
DataObjects::MDLeanEvent< 3 > MDE
Our MDLeanEvent dimension.
Helper class which provides the Collimation Length for SANS instruments.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...