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 +
9#include "MantidDataObjects/DllConfig.h"
11#include <memory>
12
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
29
30namespace Mantid::DataObjects {
31// ### BEGIN AUTO-GENERATED CODE
32/* Code below Auto-generated by 'generate_mdevent_declarations.py'
33 * on 2016-06-03 10:28:44.608989
34 *
35 * DO NOT EDIT!
36 */
37
38// Instantiations for MDLeanEvent
39template class MANTID_DATAOBJECTS_DLL MDLeanEvent<1>;
40template class MANTID_DATAOBJECTS_DLL MDLeanEvent<2>;
41template class MANTID_DATAOBJECTS_DLL MDLeanEvent<3>;
42template class MANTID_DATAOBJECTS_DLL MDLeanEvent<4>;
43template class MANTID_DATAOBJECTS_DLL MDLeanEvent<5>;
44template class MANTID_DATAOBJECTS_DLL MDLeanEvent<6>;
45template class MANTID_DATAOBJECTS_DLL MDLeanEvent<7>;
46template class MANTID_DATAOBJECTS_DLL MDLeanEvent<8>;
47template class MANTID_DATAOBJECTS_DLL MDLeanEvent<9>;
48// Instantiations for MDEvent
49template class MANTID_DATAOBJECTS_DLL MDEvent<1>;
50template class MANTID_DATAOBJECTS_DLL MDEvent<2>;
51template class MANTID_DATAOBJECTS_DLL MDEvent<3>;
52template class MANTID_DATAOBJECTS_DLL MDEvent<4>;
53template class MANTID_DATAOBJECTS_DLL MDEvent<5>;
54template class MANTID_DATAOBJECTS_DLL MDEvent<6>;
55template class MANTID_DATAOBJECTS_DLL MDEvent<7>;
56template class MANTID_DATAOBJECTS_DLL MDEvent<8>;
57template class MANTID_DATAOBJECTS_DLL MDEvent<9>;
58// Instantiations for MDBoxBase
59template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<1>, 1>;
60template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<2>, 2>;
61template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<3>, 3>;
62template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<4>, 4>;
63template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<5>, 5>;
64template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<6>, 6>;
65template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<7>, 7>;
66template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<8>, 8>;
67template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDLeanEvent<9>, 9>;
68template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<1>, 1>;
69template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<2>, 2>;
70template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<3>, 3>;
71template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<4>, 4>;
72template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<5>, 5>;
73template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<6>, 6>;
74template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<7>, 7>;
75template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<8>, 8>;
76template class MANTID_DATAOBJECTS_DLL MDBoxBase<MDEvent<9>, 9>;
77
78// Instantiations for MDBox
79template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<1>, 1>;
80template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<2>, 2>;
81template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<3>, 3>;
82template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<4>, 4>;
83template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<5>, 5>;
84template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<6>, 6>;
85template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<7>, 7>;
86template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<8>, 8>;
87template class MANTID_DATAOBJECTS_DLL MDBox<MDLeanEvent<9>, 9>;
88template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<1>, 1>;
89template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<2>, 2>;
90template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<3>, 3>;
91template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<4>, 4>;
92template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<5>, 5>;
93template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<6>, 6>;
94template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<7>, 7>;
95template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<8>, 8>;
96template class MANTID_DATAOBJECTS_DLL MDBox<MDEvent<9>, 9>;
97
98// Instantiations for MDEventWorkspace
99template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<1>, 1>;
100template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<2>, 2>;
101template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<3>, 3>;
102template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<4>, 4>;
103template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<5>, 5>;
104template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<6>, 6>;
105template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<7>, 7>;
106template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<8>, 8>;
107template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDLeanEvent<9>, 9>;
108template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<1>, 1>;
109template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<2>, 2>;
110template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<3>, 3>;
111template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<4>, 4>;
112template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<5>, 5>;
113template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<6>, 6>;
114template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<7>, 7>;
115template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<8>, 8>;
116template class MANTID_DATAOBJECTS_DLL MDEventWorkspace<MDEvent<9>, 9>;
117
118// Instantiations for MDGridBox
119template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<1>, 1>;
120template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<2>, 2>;
121template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<3>, 3>;
122template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<4>, 4>;
123template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<5>, 5>;
124template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<6>, 6>;
125template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<7>, 7>;
126template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<8>, 8>;
127template class MANTID_DATAOBJECTS_DLL MDGridBox<MDLeanEvent<9>, 9>;
128template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<1>, 1>;
129template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<2>, 2>;
130template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<3>, 3>;
131template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<4>, 4>;
132template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<5>, 5>;
133template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<6>, 6>;
134template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<7>, 7>;
135template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<8>, 8>;
136template class MANTID_DATAOBJECTS_DLL MDGridBox<MDEvent<9>, 9>;
137
138// Instantiations for MDBoxIterator
139template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<1>, 1>;
140template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<2>, 2>;
141template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<3>, 3>;
142template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<4>, 4>;
143template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<5>, 5>;
144template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<6>, 6>;
145template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<7>, 7>;
146template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<8>, 8>;
147template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDLeanEvent<9>, 9>;
148template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<1>, 1>;
149template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<2>, 2>;
150template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<3>, 3>;
151template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<4>, 4>;
152template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<5>, 5>;
153template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<6>, 6>;
154template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<7>, 7>;
155template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<8>, 8>;
156template class MANTID_DATAOBJECTS_DLL MDBoxIterator<MDEvent<9>, 9>;
157
158/* CODE ABOVE WAS AUTO-GENERATED BY generate_mdevent_declarations.py - DO NOT
159 * EDIT! */
160
161// ### END AUTO-GENERATED CODE
162// ##################################################################
163
164//------------------------------- FACTORY METHODS
165//------------------------------------------------------------------------------------------------------------------
166
178MDEventFactory::CreateMDWorkspace(size_t nd, const std::string &eventType,
179 const Mantid::API::MDNormalization &preferredNormalization,
180 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
181 if (nd > MAX_MD_DIMENSIONS_NUM)
182 throw std::invalid_argument(" there are more dimensions requested then instantiated");
183 API::IMDEventWorkspace *pWs = (*(wsCreatorFP[nd]))(eventType, preferredNormalization, preferredNormalizationHisto);
184 return std::shared_ptr<API::IMDEventWorkspace>(pWs);
185}
186
205 API::BoxController_sptr &splitter,
206 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
207 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
208
209 if (nDimensions > MAX_MD_DIMENSIONS_NUM)
210 throw std::invalid_argument(" there are more dimensions requested then instantiated");
211
212 size_t id = nDimensions * MDEventFactory::NumBoxTypes + Type;
213 if (extentsVector.size() != nDimensions) // set defaults
214 {
215 std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> defaultExtents(nDimensions);
216 for (size_t i = 0; i < nDimensions; i++) {
217 // set to smaller than float max, so the entire range fits in a float.
218 defaultExtents[i].setExtents(-1e30f, 1e30f);
219 }
220 return (*(boxCreatorFP[id]))(splitter.get(), defaultExtents, depth, nBoxEvents, boxID);
221 }
222
223 return (*(boxCreatorFP[id]))(splitter.get(), extentsVector, depth, nBoxEvents, boxID);
224}
225
226//------------------------------- FACTORY METHODS END
227//--------------------------------------------------------------------------------------------------------------
228
230std::vector<MDEventFactory::fpCreateBox>
232// static vector, conaining the pointers to the functions creating MD Workspaces
233std::vector<MDEventFactory::fpCreateMDWS> MDEventFactory::wsCreatorFP(MDEventFactory::MAX_MD_DIMENSIONS_NUM + 1,
234 nullptr);
235
236// ########### Teplate methaprogrammed CODE SOURCE start:
237//-------------------------------------
238
239//-------------------------------------------------------------- MD Workspace
240// constructor wrapper
248template <size_t nd>
250MDEventFactory::createMDWorkspaceND(const std::string &eventType,
251 const Mantid::API::MDNormalization &preferredNormalization,
252 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
253 if (eventType == "MDEvent")
254 return new MDEventWorkspace<MDEvent<nd>, nd>(preferredNormalization, preferredNormalizationHisto);
255 else if (eventType == "MDLeanEvent")
256 return new MDEventWorkspace<MDLeanEvent<nd>, nd>(preferredNormalization, preferredNormalizationHisto);
257 else
258 throw std::invalid_argument("Unknown event type " + eventType + " passed to CreateMDWorkspace.");
259}
269template <>
271MDEventFactory::createMDWorkspaceND<0>(const std::string &eventType,
272 const Mantid::API::MDNormalization &preferredNormalization,
273 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
274 UNUSED_ARG(eventType);
275 UNUSED_ARG(preferredNormalization);
276 UNUSED_ARG(preferredNormalizationHisto);
277 throw std::invalid_argument("Workspace can not have 0 dimensions");
278}
279
280//-------------------------------------------------------------- MD BOX
281// constructor wrapper
286 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> & /*unused*/,
287 const uint32_t /*unused*/, const size_t /*unused*/, const size_t /*unused*/) {
288 throw std::invalid_argument("MDBox/MDGridBox can not have 0 dimensions");
289}
299template <size_t nd>
302 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
303 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
304 return new MDBox<MDLeanEvent<nd>, nd>(splitter, depth, extentsVector, nBoxEvents, boxID);
305}
315template <size_t nd>
318 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
319 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
320 return new MDBox<MDEvent<nd>, nd>(splitter, depth, extentsVector, nBoxEvents, boxID);
321}
331template <size_t nd>
334 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
335 const uint32_t depth, const size_t /*nBoxEvents*/, const size_t /*boxID*/) {
336 return new MDGridBox<MDLeanEvent<nd>, nd>(splitter, depth, extentsVector);
337}
347template <size_t nd>
350 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
351 const uint32_t depth, const size_t /*nBoxEvents*/, const size_t /*boxID*/) {
352 return new MDGridBox<MDEvent<nd>, nd>(splitter, depth, extentsVector);
353}
354//-------------------------------------------------------------- MD BOX
355// constructor wrapper -- END
356
357// the class instantiated by compiler at compilation time and generates the map,
358// between the number of dimensions and the function, which process this number
359// of dimensions
360template <size_t nd> class LOOP {
361public:
362 LOOP() { EXEC(); }
363 static inline void EXEC() {
365 MDEventFactory::wsCreatorFP[nd] = &MDEventFactory::createMDWorkspaceND<nd>;
366
368 &MDEventFactory::createMDBoxLean<nd>;
370 &MDEventFactory::createMDBoxFat<nd>;
372 &MDEventFactory::createMDGridBoxLean<nd>;
374 &MDEventFactory::createMDGridBoxFat<nd>;
375 }
376};
377// the class terminates the compitlation-time metaloop and sets up functions
378// which process 0-dimension workspace operations (throw invalid argument)
390// ########### Teplate methaprogrammed CODE SOURCE END:
391//-------------------------------------
392// statically instantiate the code, defined by the class above and assocoate it
393// with events factory
395
396} // namespace Mantid::DataObjects
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:44
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
Abstract base class for multi-dimension event workspaces (MDEventWorkspace).
MDEventFactory : collection of methods to create MDLeanEvent* instances, by specifying the number of ...
Templated super-class of a multi-dimensional event "box".
Definition MDBoxBase.h:49
MDBoxIterator: iterate through MDBoxBase hierarchy down to a given maximum depth.
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:40
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:64
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