28template <
typename MDE,
size_t nd>
29std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>> createOutputWorkspace(
size_t splitInto) {
30 std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>> out(
33 bc->setSplitThreshold(100);
34 bc->setSplitInto(splitInto);
38template <
typename MDE,
size_t nd>
40 Mantid::coord_t max,
const std::string &axisNameFormat,
const std::string &axisIdFormat) {
46 for (
size_t d = 0;
d < nd;
d++) {
48 sprintf(
name, axisNameFormat.c_str(), d);
50 sprintf(
id, axisIdFormat.c_str(), d);
54 out->addDimension(dim);
59template <
typename MDE,
size_t nd>
62 const std::string &axisNameFormat,
const std::string &axisIdFormat) {
63 for (
size_t d = 0;
d < nd;
d++) {
65 sprintf(
name, axisNameFormat.c_str(), d);
67 sprintf(
id, axisIdFormat.c_str(), d);
71 std::make_shared<Mantid::Geometry::MDHistoDimension>(std::string(
name), std::string(
id), frame, min, max, 10);
72 out->addDimension(dim);
77template <
typename MDE,
size_t nd>
80 const std::vector<Mantid::Geometry::MDFrame_sptr> &frame,
81 const std::string &axisNameFormat,
const std::string &axisIdFormat) {
82 for (
size_t d = 0;
d < nd;
d++) {
84 sprintf(
name, axisNameFormat.c_str(), d);
86 sprintf(
id, axisIdFormat.c_str(), d);
89 auto dim = std::make_shared<Mantid::Geometry::MDHistoDimension>(std::string(
name), std::string(
id), *frame[d], min,
91 out->addDimension(dim);
96template <
typename MDE,
size_t nd>
99 if (numEventsPerBox > 0) {
103 size_t index_max[nd];
105 bool allDone =
false;
107 for (
size_t i = 0; i < numEventsPerBox; i++) {
110 for (
size_t d = 0;
d < nd;
d++)
113 out->addEvent(
MDE(1.0, 1.0, centers));
121 out->addExperimentInfo(ei);
126namespace DataObjects {
133namespace MDEventsTestHelper {
150 double errorSquared = 1.0,
const std::string &
name =
"",
155 size_t numBins = 10,
coord_t max = 10.0,
double errorSquared = 1.0,
160 double errorSquared,
size_t *numBins,
162 const std::string &
name =
"");
166 coord_t *max, std::vector<std::string> names,
const std::string &
name =
"");
183template <
typename MDE,
size_t nd>
184std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>>
186 const std::string &axisNameFormat =
"Axis%d",
const std::string &axisIdFormat =
"Axis%d") {
188 auto out = createOutputWorkspace<MDE, nd>(splitInto);
191 addMDDimensions<MDE, nd>(out, min, max, axisNameFormat, axisIdFormat);
194 addData<MDE, nd>(out, splitInto, min, max, numEventsPerBox);
198 Mantid::API::AnalysisDataService::Instance().addOrReplace(wsName, out);
219template <
typename MDE,
size_t nd>
220std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>>
222 std::vector<Mantid::Geometry::MDFrame_sptr> frames,
size_t numEventsPerBox = 0,
223 const std::string &wsName =
"", std::string axisNameFormat =
"Axis%d",
224 std::string axisIdFormat =
"Axis%d") {
226 auto out = createOutputWorkspace<MDE, nd>(splitInto);
229 addMDDimensionsWithIndividualFrames<MDE, nd>(out, min, max, frames, axisNameFormat, axisIdFormat);
232 addData<MDE, nd>(out, splitInto, min, max, numEventsPerBox);
236 Mantid::API::AnalysisDataService::Instance().addOrReplace(wsName, out);
258template <
typename MDE,
size_t nd>
259std::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>>
261 size_t numEventsPerBox = 0,
const std::string &wsName =
"",
262 const std::string &axisNameFormat =
"Axis%d",
const std::string &axisIdFormat =
"Axis%d") {
264 auto out = createOutputWorkspace<MDE, nd>(splitInto);
267 addMDDimensionsWithFrames<MDE, nd>(out, min, max, frame, axisNameFormat, axisIdFormat);
270 addData<MDE, nd>(out, splitInto, min, max, numEventsPerBox);
274 Mantid::API::AnalysisDataService::Instance().addOrReplace(wsName, out);
282 size_t numEventsPerBox = 0) {
283 return makeAnyMDEW<MDLeanEvent<nd>, nd>(splitInto, min, max, numEventsPerBox);
290 size_t numEventsPerBox = 0) {
291 return makeAnyMDEWWithFrames<MDLeanEvent<nd>, nd>(splitInto, min, max, frame, numEventsPerBox);
296std::shared_ptr<MDEventWorkspace<MDLeanEvent<nd>, nd>>
298 const std::vector<Mantid::Geometry::MDFrame_sptr> &frame,
size_t numEventsPerBox = 0) {
299 return makeAnyMDEWWithIndividualFrames<MDLeanEvent<nd>, nd>(splitInto, min, max, frame, numEventsPerBox);
306 size_t numEventsPerBox = 0) {
307 return makeAnyMDEW<MDEvent<nd>, nd>(splitInto, min, max, numEventsPerBox);
346 splitter->setSplitThreshold(5);
348 splitter->setSplitInto(split0);
349 splitter->setSplitInto(0, split0);
351 splitter->setSplitInto(1, split1);
353 auto box = std::make_unique<MDBox<MDLeanEvent<nd>, nd>>(splitter);
354 for (
size_t d = 0;
d < nd;
d++)
356 box->setExtents(
d, dimensionMin, dimensionMax);
382 size_t index_max[nd];
385 bool allDone =
false;
389 for (
size_t d = 0;
d < nd;
d++)
390 centers[
d] =
static_cast<coord_t>(counters[
d]) * step + start;
393 for (
size_t i = 0; i < repeat; ++i)
399 box->refreshCache(
nullptr);
411 using boxVector = std::vector<MDBoxBase<MDLeanEvent<nd>, nd> *>;
412 if (atRecurseLevel >= recurseLimit)
417 boxes = box->getBoxes();
418 for (
size_t i = 0; i < boxes.size(); i++)
419 box->splitContents(i);
422 boxes = box->getBoxes();
425 for (
size_t i = 0; i < boxes.size(); i++) {
428 recurseSplit(containedbox, atRecurseLevel + 1, recurseLimit);
443 splitter->setSplitThreshold(5);
444 splitter->resetNumBoxes();
445 splitter->setMaxDepth(levels + 1);
447 splitter->setSplitInto(splitInto);
449 auto box = std::make_unique<MDBox<MDLeanEvent<nd>, nd>>(splitter);
450 for (
size_t d = 0;
d < nd;
d++)
451 box->setExtents(
d, 0.0,
static_cast<coord_t>(splitInto));
462template <
typename MDBOX>
static void extents_match(MDBOX box,
size_t dim,
double min,
double max) {
463 TSM_ASSERT_DELTA(dim, box->getExtents(dim).getMin(), min, 1e-6);
464 TSM_ASSERT_DELTA(dim, box->getExtents(dim).getMax(), max, 1e-6);
std::map< DeltaEMode::Type, std::string > index
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
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.
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 Nexus::NexusDescriptor &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, const size_t *index_max, const 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,...