Mantid
Loading...
Searching...
No Matches
MDEventFactory.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10#include <memory>
11
20
21// We need to include the .cpp files so that the declarations are picked up
22// correctly. Weird, I know.
23// See http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13
24#include "MantidDataObjects/MDBin.tcc"
25#include "MantidDataObjects/MDBox.tcc"
26#include "MantidDataObjects/MDBoxBase.tcc"
27#include "MantidDataObjects/MDBoxIterator.tcc"
28#include "MantidDataObjects/MDEventWorkspace.tcc"
29#include "MantidDataObjects/MDGridBox.tcc"
30
31namespace Mantid::DataObjects {
32//### BEGIN AUTO-GENERATED CODE
33/* Code below Auto-generated by 'generate_mdevent_declarations.py'
34 * on 2016-06-03 10:28:44.608989
35 *
36 * DO NOT EDIT!
37 */
38
39// Instantiations for MDLeanEvent
49// Instantiations for MDEvent
50template class DLLExport MDEvent<1>;
51template class DLLExport MDEvent<2>;
52template class DLLExport MDEvent<3>;
53template class DLLExport MDEvent<4>;
54template class DLLExport MDEvent<5>;
55template class DLLExport MDEvent<6>;
56template class DLLExport MDEvent<7>;
57template class DLLExport MDEvent<8>;
58template class DLLExport MDEvent<9>;
59// Instantiations for MDBoxBase
78
79// Instantiations for MDBox
89template class DLLExport MDBox<MDEvent<1>, 1>;
90template class DLLExport MDBox<MDEvent<2>, 2>;
91template class DLLExport MDBox<MDEvent<3>, 3>;
92template class DLLExport MDBox<MDEvent<4>, 4>;
93template class DLLExport MDBox<MDEvent<5>, 5>;
94template class DLLExport MDBox<MDEvent<6>, 6>;
95template class DLLExport MDBox<MDEvent<7>, 7>;
96template class DLLExport MDBox<MDEvent<8>, 8>;
97template class DLLExport MDBox<MDEvent<9>, 9>;
98
99// Instantiations for MDEventWorkspace
118
119// Instantiations for MDGridBox
138
139// Instantiations for MDBin
149template class DLLExport MDBin<MDEvent<1>, 1>;
150template class DLLExport MDBin<MDEvent<2>, 2>;
151template class DLLExport MDBin<MDEvent<3>, 3>;
152template class DLLExport MDBin<MDEvent<4>, 4>;
153template class DLLExport MDBin<MDEvent<5>, 5>;
154template class DLLExport MDBin<MDEvent<6>, 6>;
155template class DLLExport MDBin<MDEvent<7>, 7>;
156template class DLLExport MDBin<MDEvent<8>, 8>;
157template class DLLExport MDBin<MDEvent<9>, 9>;
158
159// Instantiations for MDBoxIterator
178
179/* CODE ABOVE WAS AUTO-GENERATED BY generate_mdevent_declarations.py - DO NOT
180 * EDIT! */
181
182//### END AUTO-GENERATED CODE
183//##################################################################
184
185//------------------------------- FACTORY METHODS
186//------------------------------------------------------------------------------------------------------------------
187
199MDEventFactory::CreateMDWorkspace(size_t nd, const std::string &eventType,
200 const Mantid::API::MDNormalization &preferredNormalization,
201 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
202 if (nd > MAX_MD_DIMENSIONS_NUM)
203 throw std::invalid_argument(" there are more dimensions requested then instantiated");
204 API::IMDEventWorkspace *pWs = (*(wsCreatorFP[nd]))(eventType, preferredNormalization, preferredNormalizationHisto);
205 return std::shared_ptr<API::IMDEventWorkspace>(pWs);
206}
207
226 API::BoxController_sptr &splitter,
227 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
228 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
229
230 if (nDimensions > MAX_MD_DIMENSIONS_NUM)
231 throw std::invalid_argument(" there are more dimensions requested then instantiated");
232
233 size_t id = nDimensions * MDEventFactory::NumBoxTypes + Type;
234 if (extentsVector.size() != nDimensions) // set defaults
235 {
236 std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> defaultExtents(nDimensions);
237 for (size_t i = 0; i < nDimensions; i++) {
238 // set to smaller than float max, so the entire range fits in a float.
239 defaultExtents[i].setExtents(-1e30f, 1e30f);
240 }
241 return (*(boxCreatorFP[id]))(splitter.get(), defaultExtents, depth, nBoxEvents, boxID);
242 }
243
244 return (*(boxCreatorFP[id]))(splitter.get(), extentsVector, depth, nBoxEvents, boxID);
245}
246
247//------------------------------- FACTORY METHODS END
248//--------------------------------------------------------------------------------------------------------------
249
251std::vector<MDEventFactory::fpCreateBox>
253// static vector, conaining the pointers to the functions creating MD Workspaces
254std::vector<MDEventFactory::fpCreateMDWS> MDEventFactory::wsCreatorFP(MDEventFactory::MAX_MD_DIMENSIONS_NUM + 1,
255 nullptr);
256
257//########### Teplate methaprogrammed CODE SOURCE start:
258//-------------------------------------
259
260//-------------------------------------------------------------- MD Workspace
261// constructor wrapper
269template <size_t nd>
271MDEventFactory::createMDWorkspaceND(const std::string &eventType,
272 const Mantid::API::MDNormalization &preferredNormalization,
273 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
274 if (eventType == "MDEvent")
275 return new MDEventWorkspace<MDEvent<nd>, nd>(preferredNormalization, preferredNormalizationHisto);
276 else if (eventType == "MDLeanEvent")
277 return new MDEventWorkspace<MDLeanEvent<nd>, nd>(preferredNormalization, preferredNormalizationHisto);
278 else
279 throw std::invalid_argument("Unknown event type " + eventType + " passed to CreateMDWorkspace.");
280}
290template <>
292MDEventFactory::createMDWorkspaceND<0>(const std::string &eventType,
293 const Mantid::API::MDNormalization &preferredNormalization,
294 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
295 UNUSED_ARG(eventType);
296 UNUSED_ARG(preferredNormalization);
297 UNUSED_ARG(preferredNormalizationHisto);
298 throw std::invalid_argument("Workspace can not have 0 dimensions");
299}
300
301//-------------------------------------------------------------- MD BOX
302// constructor wrapper
307 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> & /*unused*/,
308 const uint32_t /*unused*/, const size_t /*unused*/, const size_t /*unused*/) {
309 throw std::invalid_argument("MDBox/MDGridBox can not have 0 dimensions");
310}
320template <size_t nd>
323 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
324 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
325 return new MDBox<MDLeanEvent<nd>, nd>(splitter, depth, extentsVector, nBoxEvents, boxID);
326}
336template <size_t nd>
339 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
340 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
341 return new MDBox<MDEvent<nd>, nd>(splitter, depth, extentsVector, nBoxEvents, boxID);
342}
352template <size_t nd>
355 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
356 const uint32_t depth, const size_t /*nBoxEvents*/, const size_t /*boxID*/) {
357 return new MDGridBox<MDLeanEvent<nd>, nd>(splitter, depth, extentsVector);
358}
368template <size_t nd>
371 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
372 const uint32_t depth, const size_t /*nBoxEvents*/, const size_t /*boxID*/) {
373 return new MDGridBox<MDEvent<nd>, nd>(splitter, depth, extentsVector);
374}
375//-------------------------------------------------------------- MD BOX
376// constructor wrapper -- END
377
378// the class instantiated by compiler at compilation time and generates the map,
379// between the number of dimensions and the function, which process this number
380// of dimensions
381template <size_t nd> class LOOP {
382public:
383 LOOP() { EXEC(); }
384 static inline void EXEC() {
386 MDEventFactory::wsCreatorFP[nd] = &MDEventFactory::createMDWorkspaceND<nd>;
387
389 &MDEventFactory::createMDBoxLean<nd>;
391 &MDEventFactory::createMDBoxFat<nd>;
393 &MDEventFactory::createMDGridBoxLean<nd>;
395 &MDEventFactory::createMDGridBoxFat<nd>;
396 }
397};
398// the class terminates the compitlation-time metaloop and sets up functions
399// which process 0-dimension workspace operations (throw invalid argument)
400template <> class LOOP<0> {
401public:
402 static inline void EXEC() {
403 MDEventFactory::wsCreatorFP[0] = &MDEventFactory::createMDWorkspaceND<0>;
404
409 }
410};
411//########### Teplate methaprogrammed CODE SOURCE END:
412//-------------------------------------
413// statically instantiate the code, defined by the class above and assocoate it
414// with events factory
416
417} // namespace Mantid::DataObjects
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
Definition: BoxController.h:33
Abstract base class for multi-dimension event workspaces (MDEventWorkspace).
MDEventFactory : collection of methods to create MDLeanEvent* instances, by specifying the number of ...
MDBin : Class describing a single bin in a dense, Multidimensional histogram.
Definition: MDBin.h:32
Templated super-class of a multi-dimensional event "box".
Definition: MDBoxBase.h:50
MDBoxIterator: iterate through MDBoxBase hierarchy down to a given maximum depth.
Definition: MDBoxIterator.h:28
Templated class for a multi-dimensional event "box".
Definition: MDBox.h:45
static LOOP< MAX_MD_DIMENSIONS_NUM > CODE_GENERATOR
static API::IMDNode * createMDBoxLean(API::BoxController *splitter, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, const uint32_t depth, const size_t nBoxEvents, const size_t boxID)
Method to create MDBox for lean events (Constructor wrapper) with given number of dimensions.
BoxType
enum defines fifferent box types generated by createBox factory We will use typecast from integer to ...
static API::IMDNode * createMDGridBoxFat(API::BoxController *splitter, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, const uint32_t depth, const size_t nBoxEvents=0, const size_t boxID=0)
Method to create MDGridBox for events (Constructor wrapper) with given number of dimensions.
static API::IMDNode * createMDGridBoxLean(API::BoxController *splitter, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, const uint32_t depth, const size_t nBoxEvents=0, const size_t boxID=0)
Method to create MDGridBox for lean events (Constructor wrapper) with given number of dimensions.
static std::vector< fpCreateMDWS > wsCreatorFP
static API::IMDNode * createMDBoxWrong(API::BoxController *, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &, const uint32_t, const size_t, const size_t)
Method to create any MDBox type with 0 number of dimensions.
static API::IMDEventWorkspace * createMDWorkspaceND(const std::string &eventType, const Mantid::API::MDNormalization &preferredNormalization, const Mantid::API::MDNormalization &preferredNormalizationHisto)
Template to create md workspace with specific number of dimensions.
static API::IMDNode * createMDBoxFat(API::BoxController *splitter, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, const uint32_t depth, const size_t nBoxEvents, const size_t boxID)
Method to create MDBox for events (Constructor wrapper) with given number of dimensions.
static std::vector< fpCreateBox > boxCreatorFP
static vector, conaining the pointers to the functions creating MD boxes
static API::IMDEventWorkspace_sptr CreateMDWorkspace(size_t nd, const std::string &eventType="MDLeanEvent", const Mantid::API::MDNormalization &preferredNormalization=Mantid::API::MDNormalization::VolumeNormalization, const Mantid::API::MDNormalization &preferredNormalizationHisto=Mantid::API::MDNormalization::VolumeNormalization)
Create a MDEventWorkspace of the given type.
static API::IMDNode * createBox(size_t nDimensions, BoxType Type, API::BoxController_sptr &splitter, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector=std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > >(), const uint32_t depth=0, const size_t nBoxEvents=UNDEF_SIZET, const size_t boxID=UNDEF_SIZET)
Create a MDBox or MDGridBoxof the given type.
Templated class for the multi-dimensional event workspace.
Templated class holding data about a neutron detection event in N-dimensions (for example,...
Definition: MDEvent.h:36
Templated class for a GRIDDED multi-dimensional event "box".
Definition: MDGridBox.h:42
Templated class holding data about a neutron detection event in N-dimensions (for example,...
Definition: MDLeanEvent.h:60
Simple class that holds the extents (min/max) of a given dimension in a MD workspace or MDBox.
std::shared_ptr< IMDEventWorkspace > IMDEventWorkspace_sptr
Shared pointer to Mantid::API::IMDEventWorkspace.
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
MDNormalization
Enum describing different ways to normalize the signal in a MDWorkspace.
Definition: IMDIterator.h:25