9#include "MantidAPI/DllConfig.h"
37class SpectrumDetectorMapping;
55 using ExperimentInfo::toString;
62 void initialize(
const std::size_t &NVectors,
const std::size_t &XLength,
const std::size_t &YLength);
63 void initialize(
const std::size_t &NVectors,
const HistogramData::Histogram &histogram);
64 void initialize(
const Indexing::IndexInfo &indexInfo,
const HistogramData::Histogram &histogram);
76 const Indexing::IndexInfo &indexInfo()
const;
77 void setIndexInfo(
const Indexing::IndexInfo &indexInfo);
79 using IMDWorkspace::toString;
81 const std::string toString()
const override;
85 std::shared_ptr<const Geometry::IDetector> getDetector(
const size_t workspaceIndex)
const;
94 void rebuildSpectraMapping(
const bool includeMonitors =
true,
const specnum_t specNumOffset = 1);
98 detid2index_map getDetectorIDToWorkspaceIndexMap(
bool throwIfMultipleDets =
false,
99 bool ignoreIfNoValidDets =
false)
const;
100 virtual std::vector<size_t> getDetectorIDToWorkspaceIndexVector(detid_t &offset,
101 bool throwIfMultipleDets =
false)
const;
103 virtual std::vector<size_t> getSpectrumToWorkspaceIndexVector(
specnum_t &offset)
const;
104 std::vector<size_t> getIndicesFromSpectra(
const std::vector<specnum_t> &spectraList)
const;
105 size_t getIndexFromSpectrumNumber(
const specnum_t specNo)
const;
106 std::vector<size_t> getIndicesFromDetectorIDs(
const std::vector<detid_t> &detIdList)
const;
107 std::vector<specnum_t> getSpectraFromDetectorIDs(
const std::vector<detid_t> &detIdList)
const;
109 bool hasGroupedDetectors()
const;
115 size_t getMemorySize()
const override;
116 virtual size_t getMemorySizeForXAxes()
const;
120 virtual std::size_t
size()
const = 0;
133 void setTitle(
const std::string &)
override;
135 const std::string getTitle()
const override;
137 virtual Types::Core::DateAndTime getFirstPulseTime()
const;
138 Types::Core::DateAndTime getLastPulseTime()
const;
141 std::size_t yIndexOfX(
const double xValue,
const std::size_t &
index = 0,
142 [[maybe_unused]]
const double tolerance = 0.0)
const;
157 getSpectrum(
index).setHistogram(std::forward<T>(data)...);
162 HistogramData::Points
points(
const size_t index)
const {
return getSpectrum(
index).points(); }
164 return getSpectrum(
index).pointStandardDeviations();
167 getSpectrum(
index).setBinEdges(std::forward<T>(data)...);
170 getSpectrum(
index).setPoints(std::forward<T>(data)...);
173 getSpectrumWithoutInvalidation(
index).setPointVariances(std::forward<T>(data)...);
176 getSpectrumWithoutInvalidation(
index).setPointStandardDeviations(std::forward<T>(data)...);
178 HistogramData::Counts
counts(
const size_t index)
const {
return getSpectrum(
index).counts(); }
181 return getSpectrum(
index).countStandardDeviations();
185 return getSpectrum(
index).frequencyVariances();
188 return getSpectrum(
index).frequencyStandardDeviations();
191 getSpectrumWithoutInvalidation(
index).setCounts(std::forward<T>(data)...);
194 getSpectrumWithoutInvalidation(
index).setCountVariances(std::forward<T>(data)...);
197 getSpectrumWithoutInvalidation(
index).setCountStandardDeviations(std::forward<T>(data)...);
200 getSpectrumWithoutInvalidation(
index).setFrequencies(std::forward<T>(data)...);
203 getSpectrumWithoutInvalidation(
index).setFrequencyVariances(std::forward<T>(data)...);
206 getSpectrumWithoutInvalidation(
index).setFrequencyStandardDeviations(std::forward<T>(data)...);
208 const HistogramData::HistogramX &
x(
const size_t index)
const {
return getSpectrum(
index).x(); }
209 const HistogramData::HistogramY &
y(
const size_t index)
const {
return getSpectrum(
index).y(); }
210 const HistogramData::HistogramE &
e(
const size_t index)
const {
return getSpectrum(
index).e(); }
211 const HistogramData::HistogramDx &
dx(
const size_t index)
const {
return getSpectrum(
index).dx(); }
214 return getSpectrumWithoutInvalidation(
index).mutableDx();
216 HistogramData::HistogramY &
mutableY(
const size_t index) & {
return getSpectrumWithoutInvalidation(
index).mutableY(); }
217 HistogramData::HistogramE &
mutableE(
const size_t index) & {
return getSpectrumWithoutInvalidation(
index).mutableE(); }
222 return getSpectrum(
index).sharedDx();
225 getSpectrum(
index).setSharedX(
x);
228 getSpectrumWithoutInvalidation(
index).setSharedDx(dx);
231 getSpectrumWithoutInvalidation(
index).setSharedY(
y);
234 getSpectrumWithoutInvalidation(
index).setSharedE(e);
273 virtual double getXMin()
const;
274 virtual double getXMax()
const;
275 virtual void getXMinMax(
double &xmin,
double &xmax)
const;
279 return getSpectrum(
index).ptrX();
285 getSpectrum(
index).setX(
X);
290 virtual void setX(
const std::size_t
index,
const std::shared_ptr<HistogramData::HistogramX> &X) {
291 getSpectrum(
index).setX(
X);
298 virtual bool hasDx(
const std::size_t
index)
const {
return getSpectrum(
index).hasDx(); }
302 bool skipError =
false)
const = 0;
306 virtual void getIntegratedSpectra(std::vector<double> &out,
const double minX,
const double maxX,
307 const bool entireRange)
const;
310 std::pair<size_t, double> getXIndex(
size_t i,
double x,
bool isLeft =
true,
size_t start = 0)
const;
315 virtual Axis *getAxis(
const std::size_t &axisIndex)
const;
316 void replaceAxis(
const std::size_t &axisIndex, std::unique_ptr<Axis> newAxis);
320 size_t numberOfAxis()
const;
323 virtual bool isCommonLogBins()
const;
327 virtual bool isHistogramData()
const;
330 virtual bool isCommonBins()
const;
333 virtual bool isIntegerBins()
const;
335 std::string YUnit()
const;
336 void setYUnit(
const std::string &newUnit);
337 std::string YUnitLabel(
bool useLatex =
false,
bool plotAsDistribution =
false)
const;
338 void setYUnitLabel(
const std::string &newLabel);
341 bool isDistribution()
const;
342 void setDistribution(
bool newValue);
345 void maskBin(
const size_t &workspaceIndex,
const size_t &binIndex,
const double &weight = 1.0);
346 void flagMasked(
const size_t &
index,
const size_t &binIndex,
const double &weight = 1.0);
347 bool hasMaskedBins(
const size_t &workspaceIndex)
const;
348 bool hasAnyMaskedBins()
const;
352 const MaskList &maskedBins(
const size_t &workspaceIndex)
const;
353 std::vector<size_t> maskedBinsIndices(
const size_t &workspaceIndex)
const;
354 void setMaskedBins(
const size_t workspaceIndex,
const MaskList &maskedBins);
355 void setUnmaskedBins(
const size_t workspaceIndex);
358 virtual void setMonitorWorkspace(
const std::shared_ptr<MatrixWorkspace> &monitorWS);
359 std::shared_ptr<MatrixWorkspace> monitorWorkspace()
const;
366 size_t getNumDims()
const override;
367 std::shared_ptr<const Mantid::Geometry::IMDDimension> getDimension(
size_t index)
const override;
368 std::shared_ptr<const Mantid::Geometry::IMDDimension> getDimensionWithId(std::string
id)
const override;
378 uint64_t getNPoints()
const override;
380 uint64_t
getNEvents()
const override {
return this->getNPoints(); }
395 std::vector<std::unique_ptr<IMDIterator>>
396 createIterators(
size_t suggestedNumCores = 1,
400 void setMDMasking(std::unique_ptr<Mantid::Geometry::MDImplicitFunction> maskingRegion)
override;
402 void clearMDMasking()
override;
408 virtual bool hasOrientedLattice()
const override;
414 virtual std::pair<int64_t, int64_t> findY(
double value,
const std::pair<int64_t, int64_t> &idx = {0, 0})
const;
425 std::pair<size_t, size_t> getImageStartEndXIndices(
size_t i,
double startX,
double endX)
const;
433 virtual void setImageY(
const MantidImage &image,
size_t start = 0,
bool parallelExecution =
true);
435 virtual void setImageE(
const MantidImage &image,
size_t start = 0,
bool parallelExecution =
true);
441 void invalidateCachedSpectrumNumbers();
451 MatrixWorkspace(
const Parallel::StorageMode storageMode = Parallel::StorageMode::Cloned);
455 virtual void init(
const std::size_t &NVectors,
const std::size_t &XLength,
const std::size_t &YLength) = 0;
456 virtual void init(
const HistogramData::Histogram &histogram) = 0;
460 void updateCachedDetectorGrouping(
const size_t index)
const override;
463 std::vector<std::unique_ptr<Axis>>
m_axes;
466 std::size_t binIndexOfValue(Mantid::HistogramData::HistogramX
const &xValues,
const double xValue,
467 const bool ascendingOrder)
const;
468 std::size_t xIndexOfValue(
const Mantid::HistogramData::HistogramX &xValues,
const double xValue,
476 size_t stop,
size_t width,
size_t indexStart,
size_t indexEnd)
const;
479 [[maybe_unused]]
bool parallelExecution);
481 void setIndexInfoWithoutISpectrumUpdate(
const Indexing::IndexInfo &indexInfo);
482 void buildDefaultSpectrumDefinitions();
483 void rebuildDetectorIDGroupings();
485 virtual bool isHistogramDataByIndex(std::size_t
index = 0)
const;
490 bool m_isInitialized{
false};
498 mutable std::atomic<bool> m_isCommonBinsFlagValid{
false};
500 mutable bool m_isCommonBinsFlag{
false};
511 mutable std::atomic<bool> m_indexInfoNeedsUpdate{
true};
516 std::string getDimensionIdFromAxis(
const int &axisIndex)
const;
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
Class to represent the axis of a workspace.
This class is shared by a few Workspace types and holds information related to a particular experimen...
Basic MD Workspace Abstract Class.
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Base MatrixWorkspace Abstract Class.
HistogramData::CountVariances countVariances(const size_t index) const
void convertToFrequencies(const size_t index)
uint64_t getNEvents() const override
Get the number of points available on the workspace.
MatrixWorkspace_uptr clone() const
Returns a clone of the workspace.
void setFrequencyStandardDeviations(const size_t index, T &&...data) &
MatrixWorkspace & operator=(const MatrixWorkspace &other)=delete
const MantidVec & readE(std::size_t const index) const
Deprecated, use e() instead.
void setSharedDx(const size_t index, const Kernel::cow_ptr< HistogramData::HistogramDx > &dx) &
virtual ISpectrum & getSpectrum(const size_t index)=0
Return the underlying ISpectrum ptr at the given workspace index.
std::vector< std::unique_ptr< Axis > > m_axes
A vector of pointers to the axes for this workspace.
const HistogramData::HistogramE & e(const size_t index) const
virtual const MantidVec & dataX(const std::size_t index) const
Deprecated, use x() instead. Returns the x data const.
void setSharedX(const size_t index, const Kernel::cow_ptr< HistogramData::HistogramX > &x) &
HistogramData::CountStandardDeviations countStandardDeviations(const size_t index) const
const MantidVec & readDx(size_t const index) const
Deprecated, use dx() instead.
virtual MantidVec & dataDx(const std::size_t index)
Deprecated, use mutableDx() instead. Returns the x error data.
HistogramData::BinEdges binEdges(const size_t index) const
std::unique_ptr< Indexing::IndexInfo > m_indexInfo
void setPoints(const size_t index, T &&...data) &
static const std::string xDimensionId
Dimension id for x-dimension.
HistogramData::Points points(const size_t index) const
virtual const MantidVec & dataY(const std::size_t index) const
Deprecated, use y() instead. Returns the y data const.
HistogramData::HistogramX & mutableX(const size_t index) &
std::string m_YUnit
The unit for the data values (e.g. Counts)
const HistogramData::HistogramDx & dx(const size_t index) const
virtual std::size_t blocksize() const =0
Returns the size of each block of data returned by the dataY accessors.
MatrixWorkspace_uptr cloneEmpty() const
Returns a default-initialized clone of the workspace.
virtual const ISpectrum & getSpectrum(const size_t index) const =0
Return the underlying ISpectrum ptr (const version) at the given workspace index.
std::shared_ptr< MatrixWorkspace > m_monitorWorkspace
A workspace holding monitor data relating to the main data in the containing workspace (null if none)...
virtual MantidVec & dataX(const std::size_t index)
Deprecated, use mutableX() instead. Returns the x data.
virtual std::size_t getNumberHistograms() const =0
Returns the number of histograms in the workspace.
void setCounts(const size_t index, T &&...data) &
HistogramData::FrequencyStandardDeviations frequencyStandardDeviations(const size_t index) const
virtual const MantidVec & dataDx(const std::size_t index) const
Deprecated, use dx() instead. Returns the error const.
void setHistogram(const size_t index, T &&...data) &
void setSharedE(const size_t index, const Kernel::cow_ptr< HistogramData::HistogramE > &e) &
Kernel::cow_ptr< HistogramData::HistogramY > sharedY(const size_t index) const
std::map< size_t, double > MaskList
Masked bins for each spectrum are stored as a set of pairs containing <bin index, weight>
std::mutex m_isCommonBinsMutex
A mutex protecting the update of m_isCommonBinsFlag.
MatrixWorkspace * doCloneEmpty() const override=0
Virtual cloneEmpty method.
const HistogramData::HistogramX & x(const size_t index) const
void setSharedY(const size_t index, const Kernel::cow_ptr< HistogramData::HistogramY > &y) &
~MatrixWorkspace() override
Delete.
std::map< int64_t, MaskList > m_masks
The set of masked bins in a map keyed on workspace index.
virtual MantidVec & dataE(const std::size_t index)
Deprecated, use mutableE() instead. Returns the error data.
virtual Kernel::cow_ptr< HistogramData::HistogramX > refX(const std::size_t index) const
Deprecated, use sharedX() instead. Returns a pointer to the x data.
void setFrequencyVariances(const size_t index, T &&...data) &
Kernel::cow_ptr< HistogramData::HistogramX > sharedX(const size_t index) const
HistogramData::Counts counts(const size_t index) const
void loadInstrumentNexus(::NeXus::File *file)
virtual bool isRaggedWorkspace() const =0
Returns true if the workspace is ragged (has differently sized spectra).
void invalidateCommonBinsFlag()
Invalidates the commons bins flag.
void convertToCounts(const size_t index)
HistogramData::Histogram histogram(const size_t index) const
Returns the Histogram at the given workspace index.
void setPointVariances(const size_t index, T &&...data) &
Kernel::cow_ptr< HistogramData::HistogramDx > sharedDx(const size_t index) const
void setCountStandardDeviations(const size_t index, T &&...data) &
virtual bool hasDx(const std::size_t index) const
Probes if DX (X Error) values were set on a particular spectrum.
virtual std::size_t getMaxNumberBins() const =0
Returns the maximum number of bins in a workspace (works on ragged data).
const MantidVec & readY(std::size_t const index) const
Deprecated, use y() instead.
HistogramData::PointStandardDeviations pointStandardDeviations(const size_t index) const
HistogramData::FrequencyVariances frequencyVariances(const size_t index) const
virtual std::size_t getNumberBins(const std::size_t &index) const =0
Returns the number of bins for a given histogram index.
HistogramData::HistogramE & mutableE(const size_t index) &
std::mutex m_indexInfoMutex
static const std::string yDimensionId
Dimensin id for y-dimension.
virtual void setX(const std::size_t index, const std::shared_ptr< HistogramData::HistogramX > &X)
Deprecated, use setSharedX() instead.
HistogramData::Frequencies frequencies(const size_t index) const
void setPointStandardDeviations(const size_t index, T &&...data) &
Kernel::cow_ptr< HistogramData::HistogramE > sharedE(const size_t index) const
HistogramData::HistogramDx & mutableDx(const size_t index) &
const MantidVec & readX(std::size_t const index) const
Deprecated, use x() instead.
virtual void generateHistogram(const std::size_t index, const MantidVec &X, MantidVec &Y, MantidVec &E, bool skipError=false) const =0
Generate the histogram or rebin the existing histogram.
virtual std::size_t size() const =0
Returns the number of single indexable items in the workspace.
virtual void init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength)=0
Initialises the workspace.
MatrixWorkspace * doClone() const override=0
Virtual clone method. Not implemented to force implementation in children.
virtual MantidVec & dataY(const std::size_t index)
Deprecated, use mutableY() instead. Returns the y data.
HistogramData::HistogramY & mutableY(const size_t index) &
virtual ISpectrum & getSpectrumWithoutInvalidation(const size_t index)=0
void setFrequencies(const size_t index, T &&...data) &
virtual const MantidVec & dataE(const std::size_t index) const
Deprecated, use e() instead. Returns the error const.
virtual void init(const HistogramData::Histogram &histogram)=0
const HistogramData::HistogramY & y(const size_t index) const
std::string m_YUnitLabel
A text label for use when plotting spectra.
void setBinEdges(const size_t index, T &&...data) &
void setCountVariances(const size_t index, T &&...data) &
virtual void setX(const std::size_t index, const Kernel::cow_ptr< HistogramData::HistogramX > &X)
Deprecated, use setSharedX() instead.
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
The WorkspaceFactory class is in charge of the creation of all types of workspaces.
Interface class for detector objects.
An "ImplicitFunction" defining a hyper-cuboid-shaped region in N dimensions.
Implements a copy on write data template.
std::shared_ptr< const MantidImage > MantidImage_const_sptr
shared pointer to const MantidImage
std::unique_ptr< MatrixWorkspace > MatrixWorkspace_uptr
unique pointer to Mantid::API::MatrixWorkspace
std::vector< std::vector< double > > MantidImage
typedef for the image type
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
MDNormalization
Enum describing different ways to normalize the signal in a MDWorkspace.
std::shared_ptr< MantidImage > MantidImage_sptr
shared pointer to MantidImage
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
SpecialCoordinateSystem
Special coordinate systems for Q3D.
Helper class which provides the Collimation Length for SANS instruments.
std::unordered_map< specnum_t, size_t > spec2index_map
Map with key = spectrum number, value = workspace index.
float coord_t
Typedef for the data type to use for coordinate axes in MD objects such as MDBox, MDEventWorkspace,...
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
double signal_t
Typedef for the signal recorded in a MDBox, etc.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
int32_t specnum_t
Typedef for a spectrum Number.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Holds X, Y, E for a line plot.