Mantid
Loading...
Searching...
No Matches
IMDNode.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2009 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
10#include "MantidKernel/VMD.h"
11#include <algorithm>
12#include <functional>
13#include <memory>
14#include <string>
15#include <vector>
16
17namespace Mantid {
18namespace Kernel {
19class ISaveable;
20class ThreadScheduler;
21} // namespace Kernel
22
23namespace Geometry {
24template <typename T> class MDDimensionExtents;
25class MDImplicitFunction;
26} // namespace Geometry
27
28namespace API {
29
30class BoxController;
31class IBoxControllerIO;
32class CoordTransform;
33
34class IMDNode {
40public:
41 virtual ~IMDNode() = default;
42 //---------------- ISAVABLE
48 virtual Kernel::ISaveable *getISaveable() const = 0;
51 virtual void setFileBacked(const uint64_t /*fileLocation*/, const size_t /*fileSize*/, const bool /*markSaved*/) = 0;
55 virtual void setFileBacked() = 0;
61 virtual void clearFileBacked(bool loadFileData) = 0;
62 virtual void reserveMemoryForLoad(uint64_t) = 0;
63
66 virtual void saveAt(API::IBoxControllerIO *const /*saver */, uint64_t /*position*/) const = 0;
67
71 virtual void loadAndAddFrom(API::IBoxControllerIO *const /*saver */, uint64_t /*position*/, size_t /* Size */,
72 std::vector<coord_t> &) = 0;
76 virtual void loadAndAddFrom(API::IBoxControllerIO *const /*saver */, uint64_t /*position*/, size_t /* Size */) = 0;
78 virtual void clearDataFromMemory() = 0;
79 //-------------------------------------------------------------
81 virtual void clear() = 0;
82
84 virtual std::string getEventType() const = 0;
87 virtual unsigned int getCoordType() const = 0;
88 //-------------------------------------------------------------
91 virtual size_t getID() const = 0;
94 virtual void setID(const size_t &newID) = 0;
95
97 virtual size_t getNumDims() const = 0;
98
100 virtual bool getIsMasked() const = 0;
102 virtual void mask() = 0;
104 virtual void unmask() = 0;
105
109
110 // -------------------------------- Parents/Children-Related
111 // -------------------------------------------
113 virtual bool isLeaf() const = 0;
115 virtual size_t getNumMDBoxes() const = 0;
117 virtual size_t getNumChildren() const = 0;
119 virtual IMDNode *getChild(size_t index) = 0;
121 virtual void setChildren(const std::vector<IMDNode *> &boxes, const size_t indexStart, const size_t indexEnd) = 0;
123 virtual void setParent(IMDNode *parent) = 0;
125 virtual IMDNode *getParent() = 0;
127 virtual const IMDNode *getParent() const = 0;
128 // -------------------------------------------------------------------------------------------
129 // box-related
132 virtual void getBoxes(std::vector<IMDNode *> &boxes, size_t maxDepth, bool leafOnly) = 0;
135 virtual void getBoxes(std::vector<IMDNode *> &boxes, size_t maxDepth, bool leafOnly,
137
139 virtual void getBoxes(std::vector<IMDNode *> &outBoxes, const std::function<bool(IMDNode *)> &cond) = 0;
140
141 // -------------------------------- Events-Related
142 // -------------------------------------------
144 virtual uint64_t getNPoints() const = 0;
147 virtual size_t getDataInMemorySize() const = 0;
149 virtual uint64_t getTotalDataSize() const = 0;
150
157 virtual void getEventsData(std::vector<coord_t> &coordTable, size_t &nColumns) const = 0;
163 virtual void setEventsData(const std::vector<coord_t> &coordTable) = 0;
164
166 virtual void buildAndAddEvent(const signal_t Signal, const signal_t errorSq, const std::vector<coord_t> &point,
167 uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId) = 0;
169 virtual void buildAndAddEventUnsafe(const signal_t Signal, const signal_t errorSq, const std::vector<coord_t> &point,
170 uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId) = 0;
172 virtual size_t buildAndAddEvents(const std::vector<signal_t> &sigErrSq, const std::vector<coord_t> &Coord,
173 const std::vector<uint16_t> &expInfoIndex,
174 const std::vector<uint16_t> &goniometerIndex,
175 const std::vector<uint32_t> &detectorId) = 0;
176
177 // -------------------------------------------------------------------------------------------
178
194 virtual void integrateSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared,
195 signal_t &signal, signal_t &errorSquared, const coord_t innerRadiusSquared = 0.0,
196 const bool useOnePercentBackgroundCorrection = true) const = 0;
208 virtual void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared,
209 coord_t *centroid, signal_t &signal) const = 0;
223 virtual void integrateCylinder(Mantid::API::CoordTransform &radiusTransform, const coord_t radius,
224 const coord_t length, signal_t &signal, signal_t &errorSquared,
225 std::vector<signal_t> &signal_fit) const = 0;
226
228 virtual void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler * /*ts*/ = nullptr) = 0;
230 virtual void refreshCache(Kernel::ThreadScheduler * /*ts*/ = nullptr) = 0;
232 virtual void calculateCentroid(coord_t * /*centroid*/) const = 0;
234 virtual void calculateCentroid(coord_t * /*centroid*/, const int /*expInfoIndex*/) const = 0;
236 virtual coord_t *getCentroid() const = 0;
237 //----------------------------------------------------------------------------------------------------------------------------------
238 // MDBoxBase interface, related to average signals/error box parameters
239 virtual signal_t getSignal() const = 0;
240 virtual signal_t getError() const = 0;
241 virtual signal_t getErrorSquared() const = 0;
242 virtual coord_t getInverseVolume() const = 0;
244 virtual const IMDNode *getBoxAtCoord(const coord_t * /*coords*/) = 0;
245 virtual void getCenter(coord_t *const /*boxCenter*/) const = 0;
246 virtual uint32_t getDepth() const = 0;
247 virtual signal_t getSignalNormalized() const = 0;
248
249 virtual void calcVolume() = 0;
250 virtual void setInverseVolume(const coord_t) = 0;
251 virtual void setSignal(const signal_t) = 0;
252 virtual void setErrorSquared(const signal_t) = 0;
253
254 // -------------------------------- Geometry/vertexes-Related
255 // -------------------------------------------
256 virtual std::vector<Mantid::Kernel::VMD> getVertexes() const = 0;
257 virtual std::unique_ptr<coord_t[]> getVertexesArray(size_t &numVertices) const = 0;
258 virtual std::unique_ptr<coord_t[]> getVertexesArray(size_t &numVertices, const size_t outDimensions,
259 const bool *maskDim) const = 0;
260 virtual void transformDimensions(std::vector<double> &scaling, std::vector<double> &offset) = 0;
261
262 // to avoid casting (which need also the number of dimensions) method say if
263 // Node is a box. if not, it is gridbox
264 virtual bool isBox() const = 0;
265
266 virtual signal_t getSignalByNEvents() const { return this->getSignal() / static_cast<signal_t>(this->getNPoints()); }
267
268 // ----------------------------- Helper Methods
269 // --------------------------------------------------------
270 //-----------------------------------------------------------------------------------------------
279 static inline bool CompareFilePosition(const IMDNode *const a, const IMDNode *const b) {
280
281 return (a->getID() < b->getID());
282 }
283
284 //-----------------------------------------------------------------------------------------------
292 static void sortObjByID(std::vector<IMDNode *> &boxes) { std::sort(boxes.begin(), boxes.end(), CompareFilePosition); }
293};
294} // namespace API
295} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
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...
virtual signal_t getSignalNormalized() const =0
virtual void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t, std::vector< coord_t > &)=0
Load the additional box data of specified size from the disk location provided using the class,...
virtual size_t getNumMDBoxes() const =0
Get the total # of unsplit MDBoxes contained.
virtual void setSignal(const signal_t)=0
virtual IMDNode * getParent()=0
Return a pointer to the parent box.
virtual const IMDNode * getParent() const =0
Return a pointer to the parent box (const)
virtual void clear()=0
Clear all contained data including precalculated averages.
virtual bool isBox() const =0
virtual void calculateCentroid(coord_t *) const =0
Calculate the centroid of this box and all sub-boxes.
virtual void mask()=0
Setter for masking the box.
virtual 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 =0
Cylinder (peak) integration The CoordTransform object could be used for more cylinder reduces the dim...
virtual void getBoxes(std::vector< IMDNode * > &boxes, size_t maxDepth, bool leafOnly)=0
Fill a vector with all the boxes who are the childred of this one up to a certain depth.
static bool CompareFilePosition(const IMDNode *const a, const IMDNode *const b)
Helper method for sorting MDBoxBasees by file position.
Definition: IMDNode.h:279
virtual signal_t getSignalByNEvents() const
Definition: IMDNode.h:266
virtual size_t getNumChildren() const =0
Get the # of children MDBoxBase'es (non-recursive)
virtual coord_t getInverseVolume() const =0
virtual Kernel::ISaveable * getISaveable() const =0
Return the pointer to the sconst tructure responsible for saving the box on disk if the workspace occ...
virtual void clearDataFromMemory()=0
drop event data from memory but keep averages
virtual void refreshCache(Kernel::ThreadScheduler *=nullptr)=0
Recalculate signal etc.
virtual void centroidSphere(Mantid::API::CoordTransform &radiusTransform, const coord_t radiusSquared, coord_t *centroid, signal_t &signal) const =0
Find the centroid of all events contained within by doing a weighted average of their coordinates.
virtual 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 =0
Sphere (peak) integration The CoordTransform object could be used for more complex shapes,...
virtual std::string getEventType() const =0
virtual void splitAllIfNeeded(Mantid::Kernel::ThreadScheduler *=nullptr)=0
Split sub-boxes, if this is possible and neede for this box.
virtual void saveAt(API::IBoxControllerIO *const, uint64_t) const =0
Save the box at specific disk position using the class, respoinsible for the file IO.
virtual std::unique_ptr< coord_t[]> getVertexesArray(size_t &numVertices) const =0
virtual unsigned int getCoordType() const =0
virtual bool getIsMasked() const =0
Getter for the masking.
virtual std::vector< Mantid::Kernel::VMD > getVertexes() const =0
virtual void calculateCentroid(coord_t *, const int) const =0
Calculate the centroid of this box and all sub-boxes.
virtual 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 > &goniometerIndex, const std::vector< uint32_t > &detectorId)=0
Add several events from the vector of event parameters.
virtual void calcVolume()=0
virtual void loadAndAddFrom(API::IBoxControllerIO *const, uint64_t, size_t)=0
Load the additional box data of specified size from the disk location provided using the class,...
virtual void setErrorSquared(const signal_t)=0
virtual signal_t getErrorSquared() const =0
virtual void getEventsData(std::vector< coord_t > &coordTable, size_t &nColumns) const =0
The method to convert events in a box into a table of coodrinates/signal/errors casted into coord_t t...
virtual void transformDimensions(std::vector< double > &scaling, std::vector< double > &offset)=0
virtual void getCenter(coord_t *const) const =0
virtual 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)=0
Add a single event defined by its components.
virtual coord_t * getCentroid() const =0
Get the centroid of this box and all sub-boxes.
virtual size_t getID() const =0
virtual ~IMDNode()=default
This is an interface to MDBox or MDGridBox of an MDWorkspace.
virtual uint64_t getNPoints() const =0
Get total number of points both in memory and on file if present;.
virtual void buildAndAddEventUnsafe(const signal_t Signal, const signal_t errorSq, const std::vector< coord_t > &point, uint16_t expInfoIndex, uint16_t goniometerIndex, uint32_t detectorId)=0
Add a single event, with no mutex locking.
virtual Mantid::API::BoxController * getBoxController()=0
virtual size_t getNumDims() const =0
Get number of dimensions, the box with this interface has.
virtual void clearFileBacked(bool loadFileData)=0
if node was fileBacked, the method clears file-backed information
virtual void setChildren(const std::vector< IMDNode * > &boxes, const size_t indexStart, const size_t indexEnd)=0
Sets the children from a vector of children.
virtual void unmask()=0
Setter for unmasking the box.
virtual Mantid::Geometry::MDDimensionExtents< coord_t > & getExtents(size_t dim)=0
virtual void setID(const size_t &newID)=0
sets the special id, which specify the position of this node in the chain linearly ordered nodes
virtual void getBoxes(std::vector< IMDNode * > &boxes, size_t maxDepth, bool leafOnly, Mantid::Geometry::MDImplicitFunction *function)=0
Fill a vector with all the boxes who are the childred of this one up to a certain depth and selected ...
virtual Kernel::ISaveable * getISaveable()=0
Return the pointer to the structure responsible for saving the box on disk if the workspace occupies ...
virtual size_t getDataInMemorySize() const =0
get size of the data located in memory, it is equivalent to getNPoints above for memory based workspa...
virtual uint32_t getDepth() const =0
virtual Mantid::API::BoxController * getBoxController() const =0
get box controller
virtual signal_t getError() const =0
virtual void setParent(IMDNode *parent)=0
Return a pointer to the parent box.
virtual uint64_t getTotalDataSize() const =0
virtual void setFileBacked(const uint64_t, const size_t, const bool)=0
initiate the structure responsible for swapping the box on HDD if out of memory.
virtual std::unique_ptr< coord_t[]> getVertexesArray(size_t &numVertices, const size_t outDimensions, const bool *maskDim) const =0
virtual const IMDNode * getBoxAtCoord(const coord_t *)=0
virtual void getBoxes(std::vector< IMDNode * > &outBoxes, const std::function< bool(IMDNode *)> &cond)=0
Fill a vector with all the boxes who are satisfying the condition.
virtual void setEventsData(const std::vector< coord_t > &coordTable)=0
The method to convert the table of data into vector of events Used to load events from plain binary f...
virtual bool isLeaf() const =0
Is this node a leaf: getNumChildren() == 0.
static void sortObjByID(std::vector< IMDNode * > &boxes)
Static method for sorting a list of MDBoxBase pointers by their file position, ascending.
Definition: IMDNode.h:292
virtual signal_t getSignal() const =0
virtual void reserveMemoryForLoad(uint64_t)=0
virtual IMDNode * getChild(size_t index)=0
Return the indexth child MDBoxBase.
virtual void setInverseVolume(const coord_t)=0
virtual void setFileBacked()=0
initiate the structure responsible for swapping the box on HDD if out of memory with default paramete...
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.
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