Mantid
Loading...
Searching...
No Matches
MDBox.h
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 +
7#pragma once
8
17
18namespace Mantid {
19namespace DataObjects {
20
21#ifndef __INTEL_COMPILER // As of July 13, the packing has no effect for the
22 // Intel compiler and produces a warning
23#pragma pack(push, 4) // Ensure the structure is no larger than it needs to
24#endif
25
26//===============================================================================================
45class MANTID_DATAOBJECTS_DLL MDBox : public MDBoxBase<MDE, nd> {
46public:
47 MDBox(Mantid::API::BoxController_sptr &splitter, const uint32_t depth = 0, const size_t nBoxEvents = UNDEF_SIZET,
48 const size_t boxID = UNDEF_SIZET);
49
50 MDBox(Mantid::API::BoxController *const splitter, const uint32_t depth = 0, const size_t nBoxEvents = UNDEF_SIZET,
51 const size_t boxID = UNDEF_SIZET);
52
53 MDBox(Mantid::API::BoxController_sptr &splitter, const uint32_t depth,
54 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
55 const size_t nBoxEvents = UNDEF_SIZET, const size_t boxID = UNDEF_SIZET);
56 MDBox(Mantid::API::BoxController *const splitter, const uint32_t depth,
57 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector,
58 const size_t nBoxEvents = UNDEF_SIZET, const size_t boxID = UNDEF_SIZET);
59
60 using EventIterator = typename std::vector<MDE>::const_iterator;
61 MDBox(Mantid::API::BoxController *const bc, const uint32_t depth,
62 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector, EventIterator begin,
63 EventIterator end);
64
65 MDBox(const MDBox<MDE, nd> &other, Mantid::API::BoxController *const otherBC);
66
67 ~MDBox() override;
68
69 // ----------------------------- ISaveable Methods
70 // ------------------------------------------------------
71 Kernel::ISaveable *getISaveable() override;
72 Kernel::ISaveable *getISaveable() const override;
73 void setFileBacked(const uint64_t /*fileLocation*/, const size_t /*fileSize*/, const bool /*markSaved*/) override;
74 void setFileBacked() override;
75 void clearFileBacked(bool loadDiskBackedData) override;
76 //-----------------------------------------------------------------------------------------------
77 void saveAt(API::IBoxControllerIO *const, uint64_t /*position*/) const override;
78 void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t, std::vector<coord_t> &) override;
79 void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t /*position*/, size_t /* Size */) override;
80 void reserveMemoryForLoad(uint64_t /* Size */) override;
82 void clearDataFromMemory() override;
83
84 void clear() override;
85
86 uint64_t getNPoints() const override;
87 size_t getDataInMemorySize() const override { return data.size(); }
88 uint64_t getTotalDataSize() const override { return getNPoints(); }
89
90 size_t getNumDims() const override;
91 size_t getNumMDBoxes() const override;
92
94 size_t getNumChildren() const override { return 0; }
95 // to avoid casting (which need also the number of dimensions) method say if
96 // Node is a box. if not, it is gridbox
97 bool isBox() const override { return true; }
98
100 API::IMDNode *getChild(size_t /*index*/) override { throw std::runtime_error("MDBox does not have children."); }
101
103 void setChildren(const std::vector<API::IMDNode *> & /*boxes*/, const size_t /*indexStart*/,
104 const size_t /*indexEnd*/) override {
105 throw std::runtime_error("MDBox cannot have children.");
106 }
107
110 bool isDataAdded() const;
111
118 std::vector<MDE> &getEvents();
125 const std::vector<MDE> &getConstEvents() const;
126 // the same as getConstEvents above,
127 const std::vector<MDE> &getEvents() const;
128 void releaseEvents();
129
130 std::vector<MDE> *getEventsCopy() override;
131
132 void getEventsData(std::vector<coord_t> &coordTable, size_t &nColumns) const override;
133 void setEventsData(const std::vector<coord_t> &coordTable) override;
134
135 size_t addEvent(const MDE &Evnt) override;
136 size_t addEventUnsafe(const MDE &Evnt) override;
137
138 // add range of events
139 size_t addEvents(const std::vector<MDE> &events) override;
140 // unhide MDBoxBase methods
141 size_t addEventsUnsafe(const std::vector<MDE> &events) override;
142
143 /*---------------> EVENTS from event data
144 * <-------------------------------------------------------------*/
145 void buildAndAddEvent(const signal_t Signal, const signal_t errorSq, const std::vector<coord_t> &point,
146 uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId) override;
147 void buildAndAddEventUnsafe(const signal_t Signal, const signal_t errorSq, const std::vector<coord_t> &point,
148 uint16_t expInfoIndex, uint16_t goniometernIndex, uint32_t detectorId) override;
149 size_t buildAndAddEvents(const std::vector<signal_t> &sigErrSq, const std::vector<coord_t> &Coord,
150 const std::vector<uint16_t> &expInfoIndex, const std::vector<uint16_t> &goniometernIndex,
151 const std::vector<uint32_t> &detectorId) override;
152
153 //---------------------------------------------------------------------------------------------------------------------------------
154 void centerpointBin(MDBin<MDE, nd> &bin, bool *fullyContained) const override;
155 void generalBin(MDBin<MDE, nd> &bin, Mantid::Geometry::MDImplicitFunction &function) const override;
156 void
157 splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = nullptr) override { /* Do nothing with a box default. */ }
158
159 //---------------------------------------------------------------------------------------------------------------------------------
162 void refreshCache(Kernel::ThreadScheduler * /*ts*/ = nullptr) override;
163 void calculateCentroid(coord_t *centroid) const override;
164 void calculateCentroid(coord_t *centroid, const int expInfoIndex) const override;
165 coord_t *getCentroid() const override;
166 void calculateDimensionStats(MDDimensionStats *stats) const;
167 void integrateSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, signal_t &signal,
168 signal_t &errorSquared, const coord_t innerRadiusSquared = 0.0,
169 const bool useOnePercentBackgroundCorrection = true) const override;
170 void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, coord_t *centroid,
171 signal_t &signal) const override;
172 void integrateCylinder(Mantid::API::CoordTransform &radiusTransform, const coord_t radius, const coord_t length,
173 signal_t &signal, signal_t &errorSquared, std::vector<signal_t> &signal_fit) const override;
174
175 //------------------------------------------------------------------------------------------------------------------------------------
176 void getBoxes(std::vector<MDBoxBase<MDE, nd> *> &boxes, size_t /*maxDepth*/, bool /*leafOnly*/);
177 void getBoxes(std::vector<API::IMDNode *> &boxes, size_t /*maxDepth*/, bool /*leafOnly*/) override;
178
179 void getBoxes(std::vector<MDBoxBase<MDE, nd> *> &boxes, size_t maxDepth, bool leafOnly,
181 void getBoxes(std::vector<API::IMDNode *> &boxes, size_t maxDepth, bool leafOnly,
182 Mantid::Geometry::MDImplicitFunction *function) override;
183
184 void getBoxes(std::vector<API::IMDNode *> &outBoxes, const std::function<bool(API::IMDNode *)> &cond) final override;
185 //------------------------------------------------------------------------------------------------------------------------------------
186 void transformDimensions(std::vector<double> &scaling, std::vector<double> &offset) override;
187 //------------------------------------------------------------------------------------------------------------------------------------
188 /* Getter to determine if masking is applied.
189 @return true if masking is applied. */
190 bool getIsMasked() const override { return m_bIsMasked; }
192 void mask() override;
194 void unmask() override;
195
196protected:
197 // the pointer to the class, responsible for saving/restoring this class to
198 // the hdd
199 mutable std::unique_ptr<Kernel::ISaveable> m_Saveable;
201 mutable std::vector<MDE> data;
202
205
206private:
209 MDBox(const MDBox &);
211 void initMDBox(const size_t nBoxEvents);
213 std::vector<coord_t> m_tableData;
214
215public:
217 using sptr = std::shared_ptr<MDBox<MDE, nd>>;
218
220 using vec_t = std::vector<MDE>;
221};
222
223#ifndef __INTEL_COMPILER
224#pragma pack(pop) // Return to default packing size
225#endif
226
227//------------------------------------------------------------------------------------------------------------------------------------------------------------
228/* Internal TMP class to simplify adding events to the box for events and lean
229 * events using single interface*/
230template <typename MDE, size_t nd> struct IF {
231public:
232 // create generic events from array of events data and add them to the grid
233 // box
234 static inline void EXEC(std::vector<MDE> &data, const std::vector<signal_t> &sigErrSq,
235 const std::vector<coord_t> &Coord, const std::vector<uint16_t> &expInfoIndex,
236 const std::vector<uint16_t> &goniometerIndex, const std::vector<uint32_t> &detectorId,
237 size_t nEvents) {
238 for (size_t i = 0; i < nEvents; i++) {
239 data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], expInfoIndex[i], goniometerIndex[i], detectorId[i],
240 &Coord[i * nd]);
241 }
242 }
243 // create single generic event from event's data
244 static inline MDE BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,
245 const uint16_t expInfoIndex, const uint16_t goniometerIndex,
246 const uint32_t detectorId) {
247 return MDE(Signal, Error, expInfoIndex, goniometerIndex, detectorId, Coord);
248 }
249};
250/* Specialize for the case of LeanEvent */
251template <size_t nd> struct IF<MDLeanEvent<nd>, nd> {
252public:
253 // create lean events from array of events data and add them to the box
254 static inline void EXEC(std::vector<MDLeanEvent<nd>> &data, const std::vector<signal_t> &sigErrSq,
255 const std::vector<coord_t> &Coord, const std::vector<uint16_t> & /*expInfoIndex*/,
256 const std::vector<uint16_t> & /*goniometerIndex*/,
257 const std::vector<uint32_t> & /*detectorId*/, size_t nEvents) {
258 for (size_t i = 0; i < nEvents; i++) {
259 data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], &Coord[i * nd]);
260 }
261 }
262 // create single lean event from event's data
263 static inline MDLeanEvent<nd> BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,
264 const uint16_t /*expInfoIndex*/, const uint16_t /*goniometerIndex*/,
265 const uint32_t /*detectorId*/) {
266 return MDLeanEvent<nd>(Signal, Error, Coord);
267 }
268};
269} // namespace DataObjects
270
271} // namespace Mantid
#define UNDEF_SIZET
Definition MDTypes.h:61
#define TMDE_CLASS
Macro to make declaring template classes faster.
Definition MDTypes.h:59
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
Unique SingleValueParameter Declaration for InputNDimensions.
The header describes interface to IO Operations perfomed by the box controller May be replaced by a b...
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
Templated class for a multi-dimensional event "box".
Definition MDBox.h:45
std::vector< MDE > vec_t
Typedef for a vector of the conatined events.
Definition MDBox.h:220
bool getIsMasked() const override
Definition MDBox.h:190
bool m_bIsMasked
Flag indicating that masking has been applied.
Definition MDBox.h:204
size_t getNumChildren() const override
Get the # of children MDBoxBase'es (non-recursive)
Definition MDBox.h:94
API::IMDNode * getChild(size_t) override
Return the indexth child MDBoxBase.
Definition MDBox.h:100
bool isBox() const override
Definition MDBox.h:97
void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler *=nullptr) override
Definition MDBox.h:157
std::unique_ptr< Kernel::ISaveable > m_Saveable
Definition MDBox.h:199
uint64_t getTotalDataSize() const override
Definition MDBox.h:88
std::shared_ptr< MDBox< MDE, nd > > sptr
Typedef for a shared pointer to a MDBox.
Definition MDBox.h:217
std::vector< coord_t > m_tableData
member to avoid reallocation
Definition MDBox.h:213
void setChildren(const std::vector< API::IMDNode * > &, const size_t, const size_t) override
Sets the children from a vector of children.
Definition MDBox.h:103
std::vector< MDE > data
Vector of MDEvent's, in no particular order.
Definition MDBox.h:201
typename std::vector< MDE >::const_iterator EventIterator
Definition MDBox.h:60
size_t getDataInMemorySize() const override
Definition MDBox.h:87
MDBox(const MDBox &)
private default copy constructor as the only correct constructor is the one with the boxController;
A simple class holding some statistics on the distribution of events in a particular dimension.
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.
An "ImplicitFunction" defining a hyper-cuboid-shaped region in N dimensions.
An interface for objects that can be cached or saved to disk.
Definition ISaveable.h:28
The ThreadScheduler object defines how tasks are allocated to threads and in what order.
std::shared_ptr< BoxController > BoxController_sptr
Shared ptr to BoxController.
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,...
Definition MDTypes.h:27
double signal_t
Typedef for the signal recorded in a MDBox, etc.
Definition MDTypes.h:36
static MDLeanEvent< nd > BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord, const uint16_t, const uint16_t, const uint32_t)
Definition MDBox.h:263
static void EXEC(std::vector< MDLeanEvent< nd > > &data, const std::vector< signal_t > &sigErrSq, const std::vector< coord_t > &Coord, const std::vector< uint16_t > &, const std::vector< uint16_t > &, const std::vector< uint32_t > &, size_t nEvents)
Definition MDBox.h:254
static MDE BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord, const uint16_t expInfoIndex, const uint16_t goniometerIndex, const uint32_t detectorId)
Definition MDBox.h:244
static void EXEC(std::vector< MDE > &data, const std::vector< signal_t > &sigErrSq, const std::vector< coord_t > &Coord, const std::vector< uint16_t > &expInfoIndex, const std::vector< uint16_t > &goniometerIndex, const std::vector< uint32_t > &detectorId, size_t nEvents)
Definition MDBox.h:234