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
19
20// We need to include the .cpp files so that the declarations are picked up
21// correctly. Weird, I know.
22// See http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13
28
29namespace Mantid::DataObjects {
30// ### BEGIN AUTO-GENERATED CODE
31/* Code below Auto-generated by 'generate_mdevent_declarations.py'
32 * on 2016-06-03 10:28:44.608989
33 *
34 * DO NOT EDIT!
35 */
36
37// Instantiations for MDLeanEvent
47// Instantiations for MDEvent
48template class DLLExport MDEvent<1>;
49template class DLLExport MDEvent<2>;
50template class DLLExport MDEvent<3>;
51template class DLLExport MDEvent<4>;
52template class DLLExport MDEvent<5>;
53template class DLLExport MDEvent<6>;
54template class DLLExport MDEvent<7>;
55template class DLLExport MDEvent<8>;
56template class DLLExport MDEvent<9>;
57// Instantiations for MDBoxBase
76
77// Instantiations for MDBox
87template class DLLExport MDBox<MDEvent<1>, 1>;
88template class DLLExport MDBox<MDEvent<2>, 2>;
89template class DLLExport MDBox<MDEvent<3>, 3>;
90template class DLLExport MDBox<MDEvent<4>, 4>;
91template class DLLExport MDBox<MDEvent<5>, 5>;
92template class DLLExport MDBox<MDEvent<6>, 6>;
93template class DLLExport MDBox<MDEvent<7>, 7>;
94template class DLLExport MDBox<MDEvent<8>, 8>;
95template class DLLExport MDBox<MDEvent<9>, 9>;
96
97// Instantiations for MDEventWorkspace
116
117// Instantiations for MDGridBox
136
137// Instantiations for MDBoxIterator
156
157/* CODE ABOVE WAS AUTO-GENERATED BY generate_mdevent_declarations.py - DO NOT
158 * EDIT! */
159
160// ### END AUTO-GENERATED CODE
161// ##################################################################
162
163//------------------------------- FACTORY METHODS
164//------------------------------------------------------------------------------------------------------------------
165
177MDEventFactory::CreateMDWorkspace(size_t nd, const std::string &eventType,
178 const Mantid::API::MDNormalization &preferredNormalization,
179 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
180 if (nd > MAX_MD_DIMENSIONS_NUM)
181 throw std::invalid_argument(" there are more dimensions requested then instantiated");
182 API::IMDEventWorkspace *pWs = (*(wsCreatorFP[nd]))(eventType, preferredNormalization, preferredNormalizationHisto);
183 return std::shared_ptr<API::IMDEventWorkspace>(pWs);
184}
185
204 API::BoxController_sptr &splitter,
205 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
206 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
207
208 if (nDimensions > MAX_MD_DIMENSIONS_NUM)
209 throw std::invalid_argument(" there are more dimensions requested then instantiated");
210
211 size_t id = nDimensions * MDEventFactory::NumBoxTypes + Type;
212 if (extentsVector.size() != nDimensions) // set defaults
213 {
214 std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> defaultExtents(nDimensions);
215 for (size_t i = 0; i < nDimensions; i++) {
216 // set to smaller than float max, so the entire range fits in a float.
217 defaultExtents[i].setExtents(-1e30f, 1e30f);
218 }
219 return (*(boxCreatorFP[id]))(splitter.get(), defaultExtents, depth, nBoxEvents, boxID);
220 }
221
222 return (*(boxCreatorFP[id]))(splitter.get(), extentsVector, depth, nBoxEvents, boxID);
223}
224
225//------------------------------- FACTORY METHODS END
226//--------------------------------------------------------------------------------------------------------------
227
229std::vector<MDEventFactory::fpCreateBox>
231// static vector, conaining the pointers to the functions creating MD Workspaces
232std::vector<MDEventFactory::fpCreateMDWS> MDEventFactory::wsCreatorFP(MDEventFactory::MAX_MD_DIMENSIONS_NUM + 1,
233 nullptr);
234
235// ########### Teplate methaprogrammed CODE SOURCE start:
236//-------------------------------------
237
238//-------------------------------------------------------------- MD Workspace
239// constructor wrapper
247template <size_t nd>
249MDEventFactory::createMDWorkspaceND(const std::string &eventType,
250 const Mantid::API::MDNormalization &preferredNormalization,
251 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
252 if (eventType == "MDEvent")
253 return new MDEventWorkspace<MDEvent<nd>, nd>(preferredNormalization, preferredNormalizationHisto);
254 else if (eventType == "MDLeanEvent")
255 return new MDEventWorkspace<MDLeanEvent<nd>, nd>(preferredNormalization, preferredNormalizationHisto);
256 else
257 throw std::invalid_argument("Unknown event type " + eventType + " passed to CreateMDWorkspace.");
258}
268template <>
270MDEventFactory::createMDWorkspaceND<0>(const std::string &eventType,
271 const Mantid::API::MDNormalization &preferredNormalization,
272 const Mantid::API::MDNormalization &preferredNormalizationHisto) {
273 UNUSED_ARG(eventType);
274 UNUSED_ARG(preferredNormalization);
275 UNUSED_ARG(preferredNormalizationHisto);
276 throw std::invalid_argument("Workspace can not have 0 dimensions");
277}
278
279//-------------------------------------------------------------- MD BOX
280// constructor wrapper
285 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> & /*unused*/,
286 const uint32_t /*unused*/, const size_t /*unused*/, const size_t /*unused*/) {
287 throw std::invalid_argument("MDBox/MDGridBox can not have 0 dimensions");
288}
298template <size_t nd>
301 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
302 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
303 return new MDBox<MDLeanEvent<nd>, nd>(splitter, depth, extentsVector, nBoxEvents, boxID);
304}
314template <size_t nd>
317 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
318 const uint32_t depth, const size_t nBoxEvents, const size_t boxID) {
319 return new MDBox<MDEvent<nd>, nd>(splitter, depth, extentsVector, nBoxEvents, boxID);
320}
330template <size_t nd>
333 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
334 const uint32_t depth, const size_t /*nBoxEvents*/, const size_t /*boxID*/) {
335 return new MDGridBox<MDLeanEvent<nd>, nd>(splitter, depth, extentsVector);
336}
346template <size_t nd>
349 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
350 const uint32_t depth, const size_t /*nBoxEvents*/, const size_t /*boxID*/) {
351 return new MDGridBox<MDEvent<nd>, nd>(splitter, depth, extentsVector);
352}
353//-------------------------------------------------------------- MD BOX
354// constructor wrapper -- END
355
356// the class instantiated by compiler at compilation time and generates the map,
357// between the number of dimensions and the function, which process this number
358// of dimensions
359template <size_t nd> class LOOP {
360public:
361 LOOP() { EXEC(); }
362 static inline void EXEC() {
364 MDEventFactory::wsCreatorFP[nd] = &MDEventFactory::createMDWorkspaceND<nd>;
365
367 &MDEventFactory::createMDBoxLean<nd>;
369 &MDEventFactory::createMDBoxFat<nd>;
371 &MDEventFactory::createMDGridBoxLean<nd>;
373 &MDEventFactory::createMDGridBoxFat<nd>;
374 }
375};
376// the class terminates the compitlation-time metaloop and sets up functions
377// which process 0-dimension workspace operations (throw invalid argument)
389// ########### Teplate methaprogrammed CODE SOURCE END:
390//-------------------------------------
391// statically instantiate the code, defined by the class above and assocoate it
392// with events factory
394
395} // namespace Mantid::DataObjects
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition System.h:33
#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