Mantid
Loading...
Searching...
No Matches
ISpectrum.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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
9#include "MantidAPI/DllConfig.h"
11#include "MantidHistogramData/Histogram.h"
13
14#include <set>
15
16class SpectrumTester;
17namespace Mantid {
18namespace DataObjects {
19class Histogram1D;
20class EventList;
21} // namespace DataObjects
22namespace API {
23class MatrixWorkspace;
24
38class MANTID_API_DLL ISpectrum {
39public:
40 ISpectrum() = default;
41 ISpectrum(const specnum_t specNo);
42 virtual ~ISpectrum() = default;
43
44 void copyInfoFrom(const ISpectrum &other);
45
47 virtual void copyDataFrom(const ISpectrum &source) = 0;
48
49 [[deprecated("use setSharedX() instead")]]
51 [[deprecated("use mutableX() instead")]]
52 virtual MantidVec &dataX() = 0;
53 [[deprecated("use x() instead")]]
54 virtual const MantidVec &dataX() const = 0;
55 [[deprecated("use x() instead")]]
56 virtual const MantidVec &readX() const = 0;
57 [[deprecated("use sharedX() instead")]]
59
60 [[deprecated("use mutableDx() instead")]]
61 virtual MantidVec &dataDx() = 0;
62 [[deprecated("use dx() instead")]]
63 virtual const MantidVec &dataDx() const = 0;
64 [[deprecated("use dx() instead")]]
65 virtual const MantidVec &readDx() const = 0;
66
67 virtual void clearData() = 0;
68
69 [[deprecated("use mutableY() instead")]]
70 virtual MantidVec &dataY() = 0;
71 [[deprecated("use mutableE() instead")]]
72 virtual MantidVec &dataE() = 0;
73
74 [[deprecated("use y() instead")]]
75 virtual const MantidVec &dataY() const = 0;
76 [[deprecated("use e() instead")]]
77 virtual const MantidVec &dataE() const = 0;
78 [[deprecated("use y() instead")]]
79 virtual const MantidVec &readY() const;
80 [[deprecated("use e() instead")]]
81 virtual const MantidVec &readE() const;
82
83 virtual size_t getMemorySize() const = 0;
84
85 virtual std::pair<double, double> getXDataRange() const;
86 // ---------------------------------------------------------
87 void addDetectorID(const detid_t detID);
88 void addDetectorIDs(const std::set<detid_t> &detIDs);
89 void addDetectorIDs(const std::vector<detid_t> &detIDs);
90 void setDetectorID(const detid_t detID);
91 void setDetectorIDs(const std::set<detid_t> &detIDs);
92 void setDetectorIDs(std::set<detid_t> &&detIDs);
93
94 bool hasDetectorID(const detid_t detID) const;
95 const std::set<detid_t> &getDetectorIDs() const;
96
97 void clearDetectorIDs();
98
99 // ---------------------------------------------------------
100 specnum_t getSpectrumNo() const;
101
102 void setSpectrumNo(specnum_t num);
103
104 bool hasDx() const;
105 void resetHasDx();
106
108 virtual HistogramData::Histogram histogram() const { return histogramRef(); }
110 template <typename... T> void setHistogram(T &&...data) {
111 HistogramData::Histogram hist(std::forward<T>(data)...);
112 // Check for the special case EventList, it only accepts histograms without
113 // Y and E data.
114 checkAndSanitizeHistogram(hist);
115 mutableHistogramRef() = std::move(hist);
116 }
117
118 HistogramData::Histogram::YMode yMode() const { return histogramRef().yMode(); }
119 void setYMode(HistogramData::Histogram::YMode ymode) { mutableHistogramRef().setYMode(ymode); }
121 checkIsYAndEWritable();
122 mutableHistogramRef().convertToCounts();
123 }
125 checkIsYAndEWritable();
126 mutableHistogramRef().convertToFrequencies();
127 }
128
129 HistogramData::BinEdges binEdges() const { return histogramRef().binEdges(); }
130 HistogramData::Points points() const { return histogramRef().points(); }
131 HistogramData::PointStandardDeviations pointStandardDeviations() const {
132 return histogramRef().pointStandardDeviations();
133 }
134 template <typename... T> void setBinEdges(T &&...data) & {
135 mutableHistogramRef().setBinEdges(std::forward<T>(data)...);
136 }
137 template <typename... T> void setPoints(T &&...data) & {
138 // Check for the special case EventList, it only works with BinEdges.
139 checkWorksWithPoints();
140 mutableHistogramRef().setPoints(std::forward<T>(data)...);
141 }
142 template <typename... T> void setPointVariances(T &&...data) & {
143 // Note that we can set point variances even if storage mode is BinEdges, Dx
144 // is *always* one value *per bin*.
145 mutableHistogramRef().setPointVariances(std::forward<T>(data)...);
146 }
147 template <typename... T> void setPointStandardDeviations(T &&...data) & {
148 mutableHistogramRef().setPointStandardDeviations(std::forward<T>(data)...);
149 }
150 virtual HistogramData::Counts counts() const { return histogramRef().counts(); }
151 virtual HistogramData::CountVariances countVariances() const { return histogramRef().countVariances(); }
152 virtual HistogramData::CountStandardDeviations countStandardDeviations() const {
153 return histogramRef().countStandardDeviations();
154 }
155 virtual HistogramData::Frequencies frequencies() const { return histogramRef().frequencies(); }
156 virtual HistogramData::FrequencyVariances frequencyVariances() const { return histogramRef().frequencyVariances(); }
157 virtual HistogramData::FrequencyStandardDeviations frequencyStandardDeviations() const {
158 return histogramRef().frequencyStandardDeviations();
159 }
160 template <typename... T> void setCounts(T &&...data) & {
161 // Check for the special case EventList, cannot set Y and E there.
162 checkIsYAndEWritable();
163 mutableHistogramRef().setCounts(std::forward<T>(data)...);
164 }
165 template <typename... T> void setCountVariances(T &&...data) & {
166 checkIsYAndEWritable();
167 mutableHistogramRef().setCountVariances(std::forward<T>(data)...);
168 }
169 template <typename... T> void setCountStandardDeviations(T &&...data) & {
170 checkIsYAndEWritable();
171 mutableHistogramRef().setCountStandardDeviations(std::forward<T>(data)...);
172 }
173 template <typename... T> void setFrequencies(T &&...data) & {
174 checkIsYAndEWritable();
175 mutableHistogramRef().setFrequencies(std::forward<T>(data)...);
176 }
177 template <typename... T> void setFrequencyVariances(T &&...data) & {
178 checkIsYAndEWritable();
179 mutableHistogramRef().setFrequencyVariances(std::forward<T>(data)...);
180 }
181 template <typename... T> void setFrequencyStandardDeviations(T &&...data) & {
182 checkIsYAndEWritable();
183 mutableHistogramRef().setFrequencyStandardDeviations(std::forward<T>(data)...);
184 }
185 const HistogramData::HistogramX &x() const { return histogramRef().x(); }
186 virtual const HistogramData::HistogramY &y() const { return histogramRef().y(); }
187 virtual const HistogramData::HistogramE &e() const { return histogramRef().e(); }
188 const HistogramData::HistogramDx &dx() const { return histogramRef().dx(); }
189 HistogramData::HistogramX &mutableX() & { return mutableHistogramRef().mutableX(); }
190 HistogramData::HistogramDx &mutableDx() & { return mutableHistogramRef().mutableDx(); }
191 HistogramData::HistogramY &mutableY() & {
192 checkIsYAndEWritable();
193 return mutableHistogramRef().mutableY();
194 }
195 HistogramData::HistogramE &mutableE() & {
196 checkIsYAndEWritable();
197 return mutableHistogramRef().mutableE();
198 }
199 Kernel::cow_ptr<HistogramData::HistogramX> sharedX() const { return histogramRef().sharedX(); }
200 virtual Kernel::cow_ptr<HistogramData::HistogramY> sharedY() const { return histogramRef().sharedY(); }
201 virtual Kernel::cow_ptr<HistogramData::HistogramE> sharedE() const { return histogramRef().sharedE(); }
202 Kernel::cow_ptr<HistogramData::HistogramDx> sharedDx() const { return histogramRef().sharedDx(); }
203 void setSharedX(const Kernel::cow_ptr<HistogramData::HistogramX> &x) & { mutableHistogramRef().setSharedX(x); }
204 void setSharedDx(const Kernel::cow_ptr<HistogramData::HistogramDx> &dx) & { mutableHistogramRef().setSharedDx(dx); }
206 checkIsYAndEWritable();
207 mutableHistogramRef().setSharedY(y);
208 }
210 checkIsYAndEWritable();
211 mutableHistogramRef().setSharedE(e);
212 }
213
214 void resize(size_t n) { mutableHistogramRef().resize(n); }
215 size_t size() const { return histogramRef().size(); }
216
217 void setMatrixWorkspace(MatrixWorkspace *matrixWorkspace, const size_t index);
218
219 virtual void copyDataInto(DataObjects::EventList &) const;
220 virtual void copyDataInto(DataObjects::Histogram1D &) const;
221 virtual void copyDataInto(SpectrumTester &) const;
222
223protected:
224 virtual void checkAndSanitizeHistogram(HistogramData::Histogram &) {};
225 virtual void checkWorksWithPoints() const {}
226 virtual void checkIsYAndEWritable() const {}
227
228 // Copy and move are not public since this is an abstract class, but protected
229 // such that derived classes can implement copy and move.
230 ISpectrum(const ISpectrum &other);
231 ISpectrum(ISpectrum &&other);
232 ISpectrum &operator=(const ISpectrum &other);
233 ISpectrum &operator=(ISpectrum &&other);
234
235private:
236 virtual const HistogramData::Histogram &histogramRef() const = 0;
237 virtual HistogramData::Histogram &mutableHistogramRef() = 0;
238
239 void invalidateCachedSpectrumNumbers() const;
240 void invalidateSpectrumDefinition() const;
241 MatrixWorkspace *m_matrixWorkspace{nullptr};
242 // The default value is meaningless. This will always be set before use.
243 size_t m_index{0};
244
246 specnum_t m_specNo{0};
247
249 std::set<detid_t> detectorIDs;
250};
251
252} // namespace API
253} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Definition ISpectrum.h:38
void setHistogram(T &&...data)
Sets the Histogram associated with this spectrum.
Definition ISpectrum.h:110
virtual HistogramData::FrequencyVariances frequencyVariances() const
Definition ISpectrum.h:156
void setFrequencyVariances(T &&...data) &
Definition ISpectrum.h:177
HistogramData::Histogram::YMode yMode() const
Definition ISpectrum.h:118
virtual HistogramData::FrequencyStandardDeviations frequencyStandardDeviations() const
Definition ISpectrum.h:157
HistogramData::HistogramY & mutableY() &
Definition ISpectrum.h:191
HistogramData::Points points() const
Definition ISpectrum.h:130
virtual const MantidVec & dataX() const =0
const HistogramData::HistogramX & x() const
Definition ISpectrum.h:185
virtual const HistogramData::HistogramE & e() const
Definition ISpectrum.h:187
void setSharedDx(const Kernel::cow_ptr< HistogramData::HistogramDx > &dx) &
Definition ISpectrum.h:204
virtual MantidVec & dataY()=0
virtual const MantidVec & readX() const =0
void setPointStandardDeviations(T &&...data) &
Definition ISpectrum.h:147
void setCountVariances(T &&...data) &
Definition ISpectrum.h:165
virtual MantidVec & dataE()=0
std::set< detid_t > detectorIDs
Set of the detector IDs associated with this spectrum.
Definition ISpectrum.h:249
void setSharedY(const Kernel::cow_ptr< HistogramData::HistogramY > &y) &
Definition ISpectrum.h:205
void setCountStandardDeviations(T &&...data) &
Definition ISpectrum.h:169
virtual const MantidVec & dataDx() const =0
virtual HistogramData::Frequencies frequencies() const
Definition ISpectrum.h:155
void setPointVariances(T &&...data) &
Definition ISpectrum.h:142
virtual void setX(const Kernel::cow_ptr< HistogramData::HistogramX > &X)=0
void setBinEdges(T &&...data) &
Definition ISpectrum.h:134
virtual HistogramData::Histogram & mutableHistogramRef()=0
virtual size_t getMemorySize() const =0
const HistogramData::HistogramDx & dx() const
Definition ISpectrum.h:188
HistogramData::HistogramDx & mutableDx() &
Definition ISpectrum.h:190
virtual void checkWorksWithPoints() const
Definition ISpectrum.h:225
virtual const MantidVec & readDx() const =0
virtual ~ISpectrum()=default
virtual HistogramData::Histogram histogram() const
Returns the Histogram associated with this spectrum.
Definition ISpectrum.h:108
virtual HistogramData::Counts counts() const
Definition ISpectrum.h:150
void setYMode(HistogramData::Histogram::YMode ymode)
Definition ISpectrum.h:119
Kernel::cow_ptr< HistogramData::HistogramX > sharedX() const
Definition ISpectrum.h:199
void setFrequencies(T &&...data) &
Definition ISpectrum.h:173
virtual const HistogramData::HistogramY & y() const
Definition ISpectrum.h:186
virtual HistogramData::CountStandardDeviations countStandardDeviations() const
Definition ISpectrum.h:152
void setSharedE(const Kernel::cow_ptr< HistogramData::HistogramE > &e) &
Definition ISpectrum.h:209
HistogramData::BinEdges binEdges() const
Definition ISpectrum.h:129
void setCounts(T &&...data) &
Definition ISpectrum.h:160
virtual MantidVec & dataDx()=0
virtual void clearData()=0
size_t size() const
Definition ISpectrum.h:215
virtual const HistogramData::Histogram & histogramRef() const =0
virtual Kernel::cow_ptr< HistogramData::HistogramY > sharedY() const
Definition ISpectrum.h:200
virtual Kernel::cow_ptr< HistogramData::HistogramE > sharedE() const
Definition ISpectrum.h:201
void resize(size_t n)
Definition ISpectrum.h:214
virtual void checkAndSanitizeHistogram(HistogramData::Histogram &)
Definition ISpectrum.h:224
virtual HistogramData::CountVariances countVariances() const
Definition ISpectrum.h:151
void setPoints(T &&...data) &
Definition ISpectrum.h:137
virtual const MantidVec & dataE() const =0
virtual Kernel::cow_ptr< HistogramData::HistogramX > ptrX() const =0
Kernel::cow_ptr< HistogramData::HistogramDx > sharedDx() const
Definition ISpectrum.h:202
virtual void copyDataFrom(const ISpectrum &source)=0
Copy data from another ISpectrum with double-dynamic dispatch.
void setSharedX(const Kernel::cow_ptr< HistogramData::HistogramX > &x) &
Definition ISpectrum.h:203
HistogramData::HistogramX & mutableX() &
Definition ISpectrum.h:189
HistogramData::HistogramE & mutableE() &
Definition ISpectrum.h:195
void setFrequencyStandardDeviations(T &&...data) &
Definition ISpectrum.h:181
virtual MantidVec & dataX()=0
virtual void checkIsYAndEWritable() const
Definition ISpectrum.h:226
virtual const MantidVec & dataY() const =0
HistogramData::PointStandardDeviations pointStandardDeviations() const
Definition ISpectrum.h:131
Base MatrixWorkspace Abstract Class.
A class for holding :
Definition EventList.h:58
1D histogram implementation.
Definition Histogram1D.h:19
Implements a copy on write data template.
Definition cow_ptr.h:41
Helper class that implements ISpectrum.
Definition FakeObjects.h:57
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition cow_ptr.h:172
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14