Mantid
Loading...
Searching...
No Matches
MDGridBox.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
15#include "MantidKernel/Task.h"
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//===============================================================================================
42class MANTID_DATAOBJECTS_DLL MDGridBox : public MDBoxBase<MDE, nd> {
43public:
44 MDGridBox(std::shared_ptr<API::BoxController> &bc, const uint32_t depth,
45 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector);
46 MDGridBox(Mantid::API::BoxController *const bc, const uint32_t depth,
47 const std::vector<Mantid::Geometry::MDDimensionExtents<coord_t>> &extentsVector);
48
50
51 MDGridBox(const MDGridBox<MDE, nd> &other, Mantid::API::BoxController *const otherBC);
52
53 ~MDGridBox() override;
54 // ----------------------------- ISaveable Methods
55 // ------------------------------------------------------
59 Kernel::ISaveable *getISaveable() override { return nullptr; }
63 Kernel::ISaveable *getISaveable() const override { return nullptr; }
65 void setFileBacked(const uint64_t /*fileLocation*/, const size_t /*fileSize*/, const bool /*markSaved*/) override;
66 void setFileBacked() override;
67 void clearFileBacked(bool loadDiskBackedData) override;
68 void clear() override;
69 void clearDataFromMemory() override { /*it seems works on boxes only though recursive
70 clearing makes sence, not yet implemented*/
71 }
74 void saveAt(API::IBoxControllerIO *const, uint64_t /*position*/) const override { /*Not saveable */ }
75
78 void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t /*position*/, size_t /* Size */,
79 std::vector<coord_t> & /*memory*/) override { /*Not directly loadable */ }
80
83 void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t /*position*/,
84 size_t /* Size */) override { /*Not directly loadable */ }
85 void reserveMemoryForLoad(uint64_t /* Size */) override { /*Not directly loadable */ }
86 //-------------------------------------------------------------------------------------------------------
87 // Setters for cached values
88 void setNPoints(const uint64_t &n) { nPoints = n; }
89 //-------------------------------------------------------------------------------------------------------
93 uint64_t getNPoints() const override { return nPoints; }
96 uint64_t getTotalDataSize() const override { return nPoints; }
100 size_t getDataInMemorySize() const override;
101
102 size_t getNumDims() const override;
103 size_t getNumMDBoxes() const override;
104 size_t getNumChildren() const override;
107 bool isBox() const override { return false; }
108
109 size_t getChildIndexFromID(size_t childId) const;
110 API::IMDNode *getChild(size_t index) override;
111 void setChild(size_t index, MDGridBox<MDE, nd> *newChild);
112
113 void setChildren(const std::vector<API::IMDNode *> &otherBoxes, const size_t indexStart,
114 const size_t indexEnd) override;
115
116 void getBoxes(std::vector<API::IMDNode *> &outBoxes, size_t maxDepth, bool leafOnly) override;
117 void getBoxes(std::vector<API::IMDNode *> &outBoxes, size_t maxDepth, bool leafOnly,
118 Mantid::Geometry::MDImplicitFunction *function) override;
119
120 void getBoxes(std::vector<API::IMDNode *> &outBoxes, const std::function<bool(API::IMDNode *)> &cond) final override;
121
122 const API::IMDNode *getBoxAtCoord(const coord_t *coords) override;
123
124 void transformDimensions(std::vector<double> &scaling, std::vector<double> &offset) override;
125 //----------------------------------------------------------------------------
126
127 std::vector<MDE> *getEventsCopy() override;
128
129 //----------------------------------------------------------------------------------------------------------------------
130 size_t addEvent(const MDE &event) override;
131 size_t addEventUnsafe(const MDE &event) override;
132
133 /*---------------> EVENTS from event data
134 * <-------------------------------------------------------------*/
135 void buildAndAddEvent(const signal_t Signal, const signal_t errorSq, const std::vector<coord_t> &point,
136 uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId) override;
137 void buildAndAddEventUnsafe(const signal_t Signal, const signal_t errorSq, const std::vector<coord_t> &point,
138 uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId) override;
139 size_t buildAndAddEvents(const std::vector<signal_t> &sigErrSq, const std::vector<coord_t> &Coord,
140 const std::vector<uint16_t> &expInfoIndex, const std::vector<uint16_t> &goniometerIndex,
141 const std::vector<uint32_t> &detectorId) override;
142 //----------------------------------------------------------------------------------------------------------------------
143
144 void centerpointBin(MDBin<MDE, nd> &bin, bool *fullyContained) const override;
145
146 void generalBin(MDBin<MDE, nd> & /*bin*/, Mantid::Geometry::MDImplicitFunction & /*function*/) const override {}
147
148 void integrateSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, signal_t &signal,
149 signal_t &errorSquared, const coord_t innerRadiusSquared = 0.0,
150 const bool useOnePercentBackgroundCorrection = true) const override;
151
152 void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, coord_t *centroid,
153 signal_t &signal) const override;
154
155 void integrateCylinder(Mantid::API::CoordTransform &radiusTransform, const coord_t radius, const coord_t length,
156 signal_t &signal, signal_t &errorSquared, std::vector<signal_t> &signal_fit) const override;
157
158 void splitContents(size_t index, Kernel::ThreadScheduler *ts = nullptr);
159
160 void splitAllIfNeeded(Kernel::ThreadScheduler *ts = nullptr) override;
161
162 void refreshCache(Kernel::ThreadScheduler *ts = nullptr) override;
163
164 void calculateGridCaches() override final;
165
166 bool getIsMasked() const override;
168 void mask() override;
170 void unmask() override;
171 // ======================= Testing/Debugging Methods =================
173 std::vector<MDBoxBase<MDE, nd> *> &getBoxes() { return m_Children; }
174
175 //-------------------------------------------------------------------------
178 void calculateCentroid(coord_t * /*centroid*/) const override {
179 throw(std::runtime_error("This function should not be called on MDGridBox "
180 "(as its meaning for MDbox is dubious too)"));
181 }
182 //-------------------------------------------------------------------------
185 void calculateCentroid(coord_t * /*centroid*/, const int /*expInfoIndex*/) const override {
186 throw(std::runtime_error("This function should not be called on MDGridBox "
187 "(as its meaning for MDbox is dubious too)"));
188 }
189 //-------------------------------------------------------------------------
192 coord_t *getCentroid() const override {
193 throw(std::runtime_error("This function should not be called on MDGridBox "
194 "(as its meaning for MDbox is dubious too)"));
195 }
196
197public:
199 using sptr = std::shared_ptr<MDGridBox<MDE, nd>>;
200
202 using boxVector_t = std::vector<MDBoxBase<MDE, nd> *>;
203
204private:
206 size_t calculateChildIndex(const MDE &event) const;
207
209 size_t split[nd];
212 size_t splitCumul[nd];
215 double m_SubBoxSize[nd];
216
219 size_t numBoxes;
220
223 std::vector<MDBoxBase<MDE, nd> *> m_Children;
224
229
231 size_t nPoints;
232
233 //=================== PRIVATE METHODS =======================================
234
235 size_t getLinearIndex(size_t *indices) const;
236
237 size_t computeSizesFromSplit();
238 void fillBoxShell(const size_t tot, const coord_t ChildInverseVolume);
243 MDGridBox() = default;
245 size_t initGridBox();
246};
247
248#ifndef __INTEL_COMPILER
249#pragma pack(pop) // Return to default packing size
250#endif
251
252} // namespace DataObjects
253} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
#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
Templated class for a GRIDDED multi-dimensional event "box".
Definition MDGridBox.h:42
std::vector< MDBoxBase< MDE, nd > * > m_Children
1D array of boxes contained within.
Definition MDGridBox.h:223
void saveAt(API::IBoxControllerIO *const, uint64_t) const override
Save the box at specific disk position using the class, respoinsible for the file IO.
Definition MDGridBox.h:74
void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t, std::vector< coord_t > &) override
Load the box data of specified size from the disk location provided using the class,...
Definition MDGridBox.h:78
MDGridBox()=default
Private constructor as it does not work without box controller.
coord_t diagonalSquared
Length (squared) of the diagonal through every dimension = sum( boxSize[i]^2 ) Used in some calculati...
Definition MDGridBox.h:228
Kernel::ISaveable * getISaveable() override
get object responsible for saving the box to a file.
Definition MDGridBox.h:59
void setNPoints(const uint64_t &n)
Definition MDGridBox.h:88
std::shared_ptr< MDGridBox< MDE, nd > > sptr
Typedef for a shared pointer to a MDGridBox.
Definition MDGridBox.h:199
void generalBin(MDBin< MDE, nd > &, Mantid::Geometry::MDImplicitFunction &) const override
General binning method for any shape.
Definition MDGridBox.h:146
void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t) override
Load the box data of specified size from the disk location provided using the class,...
Definition MDGridBox.h:83
size_t nPoints
Cached number of points contained (including all sub-boxes)
Definition MDGridBox.h:231
coord_t * getCentroid() const override
The function used to satisfy IMDNode interface but the physical meaning is unclear.
Definition MDGridBox.h:192
bool isBox() const override
to avoid casting (which need also the number of dimensions) method say if Node is a box.
Definition MDGridBox.h:107
void reserveMemoryForLoad(uint64_t) override
Definition MDGridBox.h:85
MDGridBox(const MDGridBox< MDE, nd > &box)
private default copy constructor as the only correct constructor is the one with box controller
uint64_t getTotalDataSize() const override
Definition MDGridBox.h:96
void calculateCentroid(coord_t *, const int) const override
The function used to satisfy IMDNode interface but the physical meaning is unclear.
Definition MDGridBox.h:185
Kernel::ISaveable * getISaveable() const override
get const object responsible for saving the box to a file.
Definition MDGridBox.h:63
size_t numBoxes
How many boxes in the boxes vector? This is just to avoid boxes.size() calls.
Definition MDGridBox.h:219
void calculateCentroid(coord_t *) const override
The function used to satisfy IMDNode interface but the physical meaning is unclear.
Definition MDGridBox.h:178
std::vector< MDBoxBase< MDE, nd > * > boxVector_t
Typedef for a vector of MDBoxBase pointers.
Definition MDGridBox.h:202
void clearDataFromMemory() override
Definition MDGridBox.h:69
uint64_t getNPoints() const override
Uses the cached value of points stored in the grid box.
Definition MDGridBox.h:93
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.
void split(const int A, int &S, int &V)
Split a number into the sign and positive value.
Definition Acomp.cpp:42
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
STL namespace.