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 // ------------------------------------------------------
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;
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;
156 void
157 splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = nullptr) override { /* Do nothing with a box default. */
158 }
159
160 //---------------------------------------------------------------------------------------------------------------------------------
163 void refreshCache(Kernel::ThreadScheduler * /*ts*/ = nullptr) override;
164 void calculateCentroid(coord_t *centroid) const override;
165 void calculateCentroid(coord_t *centroid, const int expInfoIndex) const override;
166 coord_t *getCentroid() const override;
168 void integrateSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, signal_t &signal,
169 signal_t &errorSquared, const coord_t innerRadiusSquared = 0.0,
170 const bool useOnePercentBackgroundCorrection = true) const override;
171 void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, coord_t *centroid,
172 signal_t &signal) const override;
173 void integrateCylinder(Mantid::API::CoordTransform &radiusTransform, const coord_t radius, const coord_t length,
174 signal_t &signal, signal_t &errorSquared, std::vector<signal_t> &signal_fit) const override;
175
176 //------------------------------------------------------------------------------------------------------------------------------------
177 void getBoxes(std::vector<MDBoxBase<MDE, nd> *> &boxes, size_t /*maxDepth*/, bool /*leafOnly*/);
178 void getBoxes(std::vector<API::IMDNode *> &boxes, size_t /*maxDepth*/, bool /*leafOnly*/) override;
179
180 void getBoxes(std::vector<MDBoxBase<MDE, nd> *> &boxes, size_t maxDepth, bool leafOnly,
182 void getBoxes(std::vector<API::IMDNode *> &boxes, size_t maxDepth, bool leafOnly,
183 Mantid::Geometry::MDImplicitFunction *function) override;
184
185 void getBoxes(std::vector<API::IMDNode *> &outBoxes, const std::function<bool(API::IMDNode *)> &cond) final override;
186 //------------------------------------------------------------------------------------------------------------------------------------
187 void transformDimensions(std::vector<double> &scaling, std::vector<double> &offset) override;
188 //------------------------------------------------------------------------------------------------------------------------------------
189 /* Getter to determine if masking is applied.
190 @return true if masking is applied. */
191 bool getIsMasked() const override { return m_bIsMasked; }
193 void mask() override;
195 void unmask() override;
196
197protected:
198 // the pointer to the class, responsible for saving/restoring this class to
199 // the hdd
200 mutable std::unique_ptr<Kernel::ISaveable> m_Saveable;
202 mutable std::vector<MDE> data;
203
206
207private:
210 MDBox(const MDBox &);
212 void initMDBox(const size_t nBoxEvents);
214 std::vector<coord_t> m_tableData;
215
216public:
218 using sptr = std::shared_ptr<MDBox<MDE, nd>>;
219
221 using vec_t = std::vector<MDE>;
222};
223
224#ifndef __INTEL_COMPILER
225#pragma pack(pop) // Return to default packing size
226#endif
227
228//------------------------------------------------------------------------------------------------------------------------------------------------------------
229/* Internal TMP class to simplify adding events to the box for events and lean
230 * events using single interface*/
231template <typename MDE, size_t nd> struct IF {
232public:
233 // create generic events from array of events data and add them to the grid
234 // box
235 static inline void EXEC(std::vector<MDE> &data, const std::vector<signal_t> &sigErrSq,
236 const std::vector<coord_t> &Coord, const std::vector<uint16_t> &expInfoIndex,
237 const std::vector<uint16_t> &goniometerIndex, const std::vector<uint32_t> &detectorId,
238 size_t nEvents) {
239 for (size_t i = 0; i < nEvents; i++) {
240 data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], expInfoIndex[i], goniometerIndex[i], detectorId[i],
241 &Coord[i * nd]);
242 }
243 }
244 // create single generic event from event's data
245 static inline MDE BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,
246 const uint16_t expInfoIndex, const uint16_t goniometerIndex,
247 const uint32_t detectorId) {
248 return MDE(Signal, Error, expInfoIndex, goniometerIndex, detectorId, Coord);
249 }
250};
251/* Specialize for the case of LeanEvent */
252template <size_t nd> struct IF<MDLeanEvent<nd>, nd> {
253public:
254 // create lean events from array of events data and add them to the box
255 static inline void EXEC(std::vector<MDLeanEvent<nd>> &data, const std::vector<signal_t> &sigErrSq,
256 const std::vector<coord_t> &Coord, const std::vector<uint16_t> & /*expInfoIndex*/,
257 const std::vector<uint16_t> & /*goniometerIndex*/,
258 const std::vector<uint32_t> & /*detectorId*/, size_t nEvents) {
259 for (size_t i = 0; i < nEvents; i++) {
260 data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], &Coord[i * nd]);
261 }
262 }
263 // create single lean event from event's data
264 static inline MDLeanEvent<nd> BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,
265 const uint16_t /*expInfoIndex*/, const uint16_t /*goniometerIndex*/,
266 const uint32_t /*detectorId*/) {
267 return MDLeanEvent<nd>(Signal, Error, Coord);
268 }
269};
270} // namespace DataObjects
271
272} // namespace Mantid
#define UNDEF_SIZET
Definition: MDTypes.h:60
#define TMDE_CLASS
Macro to make declaring template classes faster.
Definition: MDTypes.h:58
double radius
Definition: Rasterize.cpp:31
This class is used by MDBox and MDGridBox in order to intelligently determine optimal behavior.
Definition: BoxController.h:33
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
void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t, std::vector< coord_t > &) override
void generalBin(MDBin< MDE, nd > &bin, Mantid::Geometry::MDImplicitFunction &function) const override
General binning method for any shape.
void setEventsData(const std::vector< coord_t > &coordTable) override
void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t) override
std::vector< MDE > vec_t
Typedef for a vector of the conatined events.
Definition: MDBox.h:221
void saveAt(API::IBoxControllerIO *const, uint64_t) const override
Kernel::ISaveable * getISaveable() override
bool getIsMasked() const override
Definition: MDBox.h:191
bool m_bIsMasked
Flag indicating that masking has been applied.
Definition: MDBox.h:205
void calculateCentroid(coord_t *centroid, const int expInfoIndex) const override
size_t getNumChildren() const override
Get the # of children MDBoxBase'es (non-recursive)
Definition: MDBox.h:94
void mask() override
Setter for masking the box.
void unmask() override
Setter for unmasking the box.
API::IMDNode * getChild(size_t) override
Return the indexth child MDBoxBase.
Definition: MDBox.h:100
const std::vector< MDE > & getConstEvents() const
Get vector of constant events to use.
coord_t * getCentroid() const override
void getBoxes(std::vector< MDBoxBase< MDE, nd > * > &boxes, size_t, bool)
void reserveMemoryForLoad(uint64_t) override
size_t buildAndAddEvents(const std::vector< signal_t > &sigErrSq, const std::vector< coord_t > &Coord, const std::vector< uint16_t > &expInfoIndex, const std::vector< uint16_t > &goniometernIndex, const std::vector< uint32_t > &detectorId) override
void calculateCentroid(coord_t *centroid) const override
const std::vector< MDE > & getEvents() const
bool isBox() const override
Definition: MDBox.h:97
MDBox(Mantid::API::BoxController *const bc, const uint32_t depth, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, EventIterator begin, EventIterator end)
size_t addEvent(const MDE &Evnt) override
Add a single event.
size_t getNumDims() const override
void transformDimensions(std::vector< double > &scaling, std::vector< double > &offset) override
MDBox(Mantid::API::BoxController *const splitter, const uint32_t depth=0, const size_t nBoxEvents=UNDEF_SIZET, const size_t boxID=UNDEF_SIZET)
MDBox(Mantid::API::BoxController *const splitter, const uint32_t depth, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, const size_t nBoxEvents=UNDEF_SIZET, const size_t boxID=UNDEF_SIZET)
MDBox(Mantid::API::BoxController_sptr &splitter, const uint32_t depth, const std::vector< Mantid::Geometry::MDDimensionExtents< coord_t > > &extentsVector, const size_t nBoxEvents=UNDEF_SIZET, const size_t boxID=UNDEF_SIZET)
void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler *=nullptr) override
Definition: MDBox.h:157
std::unique_ptr< Kernel::ISaveable > m_Saveable
Definition: MDBox.h:200
size_t addEventUnsafe(const MDE &Evnt) override
Add a single event, with no mutex locking.
size_t addEvents(const std::vector< MDE > &events) override
uint64_t getNPoints() const override
void getEventsData(std::vector< coord_t > &coordTable, size_t &nColumns) const override
void getBoxes(std::vector< API::IMDNode * > &boxes, size_t maxDepth, bool leafOnly, Mantid::Geometry::MDImplicitFunction *function) override
MDBox(const MDBox< MDE, nd > &other, Mantid::API::BoxController *const otherBC)
void getBoxes(std::vector< API::IMDNode * > &boxes, size_t, bool) override
std::vector< MDE > & getEvents()
Get vector of events to change.
size_t addEventsUnsafe(const std::vector< MDE > &events) override
void getBoxes(std::vector< API::IMDNode * > &outBoxes, const std::function< bool(API::IMDNode *)> &cond) final override
void integrateSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, signal_t &signal, signal_t &errorSquared, const coord_t innerRadiusSquared=0.0, const bool useOnePercentBackgroundCorrection=true) const override
Sphere (peak) integration.
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:218
void initMDBox(const size_t nBoxEvents)
common part of mdBox constructor
Kernel::ISaveable * getISaveable() const override
std::vector< MDE > * getEventsCopy() override
Return a copy of contained events.
MDBox(Mantid::API::BoxController_sptr &splitter, const uint32_t depth=0, const size_t nBoxEvents=UNDEF_SIZET, const size_t boxID=UNDEF_SIZET)
void setFileBacked(const uint64_t, const size_t, const bool) override
void centerpointBin(MDBin< MDE, nd > &bin, bool *fullyContained) const override
Perform centerpoint binning of events.
void clearFileBacked(bool loadDiskBackedData) override
void buildAndAddEventUnsafe(const signal_t Signal, const signal_t errorSq, const std::vector< coord_t > &point, uint16_t expInfoIndex, uint16_t goniometernIndex, uint32_t detectorId) override
void refreshCache(Kernel::ThreadScheduler *=nullptr) override
Recalculate signal and various averages dependent on signal and the signal coordinates.
std::vector< coord_t > m_tableData
member to avoid reallocation
Definition: MDBox.h:214
void clearDataFromMemory() override
drop events data from memory but keep averages (and file-backed info)
void calculateDimensionStats(MDDimensionStats *stats) const
void getBoxes(std::vector< MDBoxBase< MDE, nd > * > &boxes, size_t maxDepth, bool leafOnly, Mantid::Geometry::MDImplicitFunction *function)
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
void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, coord_t *centroid, signal_t &signal) const override
Find the centroid around a sphere.
void integrateCylinder(Mantid::API::CoordTransform &radiusTransform, const coord_t radius, const coord_t length, signal_t &signal, signal_t &errorSquared, std::vector< signal_t > &signal_fit) const override
Cylinder (peak) integration.
void buildAndAddEvent(const signal_t Signal, const signal_t errorSq, const std::vector< coord_t > &point, uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId) override
std::vector< MDE > data
Vector of MDEvent's, in no particular order.
Definition: MDBox.h:202
size_t getNumMDBoxes() const override
typename std::vector< MDE >::const_iterator EventIterator
Definition: MDBox.h:60
void setFileBacked() override
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:264
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:255
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:245
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:235