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
155 splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = nullptr) override { /* Do nothing with a box default. */ }
156
157 //---------------------------------------------------------------------------------------------------------------------------------
160 void refreshCache(Kernel::ThreadScheduler * /*ts*/ = nullptr) override;
161 void calculateCentroid(coord_t *centroid) const override;
162 void calculateCentroid(coord_t *centroid, const int expInfoIndex) const override;
163 coord_t *getCentroid() const override;
164 void calculateDimensionStats(MDDimensionStats *stats) const;
165 void integrateSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, signal_t &signal,
166 signal_t &errorSquared, const coord_t innerRadiusSquared = 0.0,
167 const bool useOnePercentBackgroundCorrection = true) const override;
168 void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, coord_t *centroid,
169 signal_t &signal) const override;
170 void integrateCylinder(Mantid::API::CoordTransform &radiusTransform, const coord_t radius, const coord_t length,
171 signal_t &signal, signal_t &errorSquared, std::vector<signal_t> &signal_fit) const override;
172
173 //------------------------------------------------------------------------------------------------------------------------------------
174 void getBoxes(std::vector<MDBoxBase<MDE, nd> *> &boxes, size_t /*maxDepth*/, bool /*leafOnly*/);
175 void getBoxes(std::vector<API::IMDNode *> &boxes, size_t /*maxDepth*/, bool /*leafOnly*/) override;
176
177 void getBoxes(std::vector<MDBoxBase<MDE, nd> *> &boxes, size_t maxDepth, bool leafOnly,
179 void getBoxes(std::vector<API::IMDNode *> &boxes, size_t maxDepth, bool leafOnly,
180 Mantid::Geometry::MDImplicitFunction *function) override;
181
182 //------------------------------------------------------------------------------------------------------------------------------------
183 void transformDimensions(std::vector<double> &scaling, std::vector<double> &offset) override;
184 //------------------------------------------------------------------------------------------------------------------------------------
185 /* Getter to determine if masking is applied.
186 @return true if masking is applied. */
187 bool getIsMasked() const override { return m_bIsMasked; }
189 void mask() override;
191 void unmask() override;
192
193protected:
194 // the pointer to the class, responsible for saving/restoring this class to
195 // the hdd
196 mutable std::unique_ptr<Kernel::ISaveable> m_Saveable;
198 mutable std::vector<MDE> data;
199
202
203private:
206 MDBox(const MDBox &);
208 void initMDBox(const size_t nBoxEvents);
210 std::vector<coord_t> m_tableData;
211
212public:
214 using sptr = std::shared_ptr<MDBox<MDE, nd>>;
215
217 using vec_t = std::vector<MDE>;
218};
219
220#ifndef __INTEL_COMPILER
221#pragma pack(pop) // Return to default packing size
222#endif
223
224//------------------------------------------------------------------------------------------------------------------------------------------------------------
225/* Internal TMP class to simplify adding events to the box for events and lean
226 * events using single interface*/
227template <typename MDE, size_t nd> struct IF {
228public:
229 // create generic events from array of events data and add them to the grid
230 // box
231 static inline void EXEC(std::vector<MDE> &data, const std::vector<signal_t> &sigErrSq,
232 const std::vector<coord_t> &Coord, const std::vector<uint16_t> &expInfoIndex,
233 const std::vector<uint16_t> &goniometerIndex, const std::vector<uint32_t> &detectorId,
234 size_t nEvents) {
235 for (size_t i = 0; i < nEvents; i++) {
236 data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], expInfoIndex[i], goniometerIndex[i], detectorId[i],
237 &Coord[i * nd]);
238 }
239 }
240 // create single generic event from event's data
241 static inline MDE BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,
242 const uint16_t expInfoIndex, const uint16_t goniometerIndex,
243 const uint32_t detectorId) {
244 return MDE(Signal, Error, expInfoIndex, goniometerIndex, detectorId, Coord);
245 }
246};
247/* Specialize for the case of LeanEvent */
248template <size_t nd> struct IF<MDLeanEvent<nd>, nd> {
249public:
250 // create lean events from array of events data and add them to the box
251 static inline void EXEC(std::vector<MDLeanEvent<nd>> &data, const std::vector<signal_t> &sigErrSq,
252 const std::vector<coord_t> &Coord, const std::vector<uint16_t> & /*expInfoIndex*/,
253 const std::vector<uint16_t> & /*goniometerIndex*/,
254 const std::vector<uint32_t> & /*detectorId*/, size_t nEvents) {
255 for (size_t i = 0; i < nEvents; i++) {
256 data.emplace_back(sigErrSq[2 * i], sigErrSq[2 * i + 1], &Coord[i * nd]);
257 }
258 }
259 // create single lean event from event's data
260 static inline MDLeanEvent<nd> BUILD_EVENT(const signal_t Signal, const signal_t Error, const coord_t *Coord,
261 const uint16_t /*expInfoIndex*/, const uint16_t /*goniometerIndex*/,
262 const uint32_t /*detectorId*/) {
263 return MDLeanEvent<nd>(Signal, Error, Coord);
264 }
265};
266} // namespace DataObjects
267
268} // 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...
Templated super-class of a multi-dimensional event "box".
Definition MDBoxBase.h:49
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:217
bool getIsMasked() const override
Definition MDBox.h:187
bool m_bIsMasked
Flag indicating that masking has been applied.
Definition MDBox.h:201
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:155
std::unique_ptr< Kernel::ISaveable > m_Saveable
Definition MDBox.h:196
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:214
std::vector< coord_t > m_tableData
member to avoid reallocation
Definition MDBox.h:210
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:198
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:64
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.
@ Error
Background thread reported an exception.
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:260
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:251
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:241
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:231