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
50 virtual MantidVec &dataX() = 0;
51 virtual const MantidVec &dataX() const = 0;
52 virtual const MantidVec &readX() const = 0;
54
55 virtual MantidVec &dataDx() = 0;
56 virtual const MantidVec &dataDx() const = 0;
57 virtual const MantidVec &readDx() const = 0;
58
59 virtual void clearData() = 0;
60
61 virtual MantidVec &dataY() = 0;
62 virtual MantidVec &dataE() = 0;
63
64 virtual const MantidVec &dataY() const = 0;
65 virtual const MantidVec &dataE() const = 0;
66 virtual const MantidVec &readY() const;
67 virtual const MantidVec &readE() const;
68
69 virtual size_t getMemorySize() const = 0;
70
71 virtual std::pair<double, double> getXDataRange() const;
72 // ---------------------------------------------------------
73 void addDetectorID(const detid_t detID);
74 void addDetectorIDs(const std::set<detid_t> &detIDs);
75 void addDetectorIDs(const std::vector<detid_t> &detIDs);
76 void setDetectorID(const detid_t detID);
77 void setDetectorIDs(const std::set<detid_t> &detIDs);
78 void setDetectorIDs(std::set<detid_t> &&detIDs);
79
80 bool hasDetectorID(const detid_t detID) const;
81 const std::set<detid_t> &getDetectorIDs() const;
82
83 void clearDetectorIDs();
84
85 // ---------------------------------------------------------
86 specnum_t getSpectrumNo() const;
87
88 void setSpectrumNo(specnum_t num);
89
90 bool hasDx() const;
91 void resetHasDx();
92
94 virtual HistogramData::Histogram histogram() const { return histogramRef(); }
96 template <typename... T> void setHistogram(T &&...data) {
97 HistogramData::Histogram hist(std::forward<T>(data)...);
98 // Check for the special case EventList, it only accepts histograms without
99 // Y and E data.
100 checkAndSanitizeHistogram(hist);
101 mutableHistogramRef() = std::move(hist);
102 }
103
104 HistogramData::Histogram::YMode yMode() const { return histogramRef().yMode(); }
105 void setYMode(HistogramData::Histogram::YMode ymode) { mutableHistogramRef().setYMode(ymode); }
107 checkIsYAndEWritable();
108 mutableHistogramRef().convertToCounts();
109 }
111 checkIsYAndEWritable();
112 mutableHistogramRef().convertToFrequencies();
113 }
114
115 HistogramData::BinEdges binEdges() const { return histogramRef().binEdges(); }
116 HistogramData::Points points() const { return histogramRef().points(); }
117 HistogramData::PointStandardDeviations pointStandardDeviations() const {
118 return histogramRef().pointStandardDeviations();
119 }
120 template <typename... T> void setBinEdges(T &&...data) & {
121 mutableHistogramRef().setBinEdges(std::forward<T>(data)...);
122 }
123 template <typename... T> void setPoints(T &&...data) & {
124 // Check for the special case EventList, it only works with BinEdges.
125 checkWorksWithPoints();
126 mutableHistogramRef().setPoints(std::forward<T>(data)...);
127 }
128 template <typename... T> void setPointVariances(T &&...data) & {
129 // Note that we can set point variances even if storage mode is BinEdges, Dx
130 // is *always* one value *per bin*.
131 mutableHistogramRef().setPointVariances(std::forward<T>(data)...);
132 }
133 template <typename... T> void setPointStandardDeviations(T &&...data) & {
134 mutableHistogramRef().setPointStandardDeviations(std::forward<T>(data)...);
135 }
136 virtual HistogramData::Counts counts() const { return histogramRef().counts(); }
137 virtual HistogramData::CountVariances countVariances() const { return histogramRef().countVariances(); }
138 virtual HistogramData::CountStandardDeviations countStandardDeviations() const {
139 return histogramRef().countStandardDeviations();
140 }
141 virtual HistogramData::Frequencies frequencies() const { return histogramRef().frequencies(); }
142 virtual HistogramData::FrequencyVariances frequencyVariances() const { return histogramRef().frequencyVariances(); }
143 virtual HistogramData::FrequencyStandardDeviations frequencyStandardDeviations() const {
144 return histogramRef().frequencyStandardDeviations();
145 }
146 template <typename... T> void setCounts(T &&...data) & {
147 // Check for the special case EventList, cannot set Y and E there.
148 checkIsYAndEWritable();
149 mutableHistogramRef().setCounts(std::forward<T>(data)...);
150 }
151 template <typename... T> void setCountVariances(T &&...data) & {
152 checkIsYAndEWritable();
153 mutableHistogramRef().setCountVariances(std::forward<T>(data)...);
154 }
155 template <typename... T> void setCountStandardDeviations(T &&...data) & {
156 checkIsYAndEWritable();
157 mutableHistogramRef().setCountStandardDeviations(std::forward<T>(data)...);
158 }
159 template <typename... T> void setFrequencies(T &&...data) & {
160 checkIsYAndEWritable();
161 mutableHistogramRef().setFrequencies(std::forward<T>(data)...);
162 }
163 template <typename... T> void setFrequencyVariances(T &&...data) & {
164 checkIsYAndEWritable();
165 mutableHistogramRef().setFrequencyVariances(std::forward<T>(data)...);
166 }
167 template <typename... T> void setFrequencyStandardDeviations(T &&...data) & {
168 checkIsYAndEWritable();
169 mutableHistogramRef().setFrequencyStandardDeviations(std::forward<T>(data)...);
170 }
171 const HistogramData::HistogramX &x() const { return histogramRef().x(); }
172 virtual const HistogramData::HistogramY &y() const { return histogramRef().y(); }
173 virtual const HistogramData::HistogramE &e() const { return histogramRef().e(); }
174 const HistogramData::HistogramDx &dx() const { return histogramRef().dx(); }
175 HistogramData::HistogramX &mutableX() & { return mutableHistogramRef().mutableX(); }
176 HistogramData::HistogramDx &mutableDx() & { return mutableHistogramRef().mutableDx(); }
177 HistogramData::HistogramY &mutableY() & {
178 checkIsYAndEWritable();
179 return mutableHistogramRef().mutableY();
180 }
181 HistogramData::HistogramE &mutableE() & {
182 checkIsYAndEWritable();
183 return mutableHistogramRef().mutableE();
184 }
185 Kernel::cow_ptr<HistogramData::HistogramX> sharedX() const { return histogramRef().sharedX(); }
186 virtual Kernel::cow_ptr<HistogramData::HistogramY> sharedY() const { return histogramRef().sharedY(); }
187 virtual Kernel::cow_ptr<HistogramData::HistogramE> sharedE() const { return histogramRef().sharedE(); }
188 Kernel::cow_ptr<HistogramData::HistogramDx> sharedDx() const { return histogramRef().sharedDx(); }
189 void setSharedX(const Kernel::cow_ptr<HistogramData::HistogramX> &x) & { mutableHistogramRef().setSharedX(x); }
190 void setSharedDx(const Kernel::cow_ptr<HistogramData::HistogramDx> &dx) & { mutableHistogramRef().setSharedDx(dx); }
192 checkIsYAndEWritable();
193 mutableHistogramRef().setSharedY(y);
194 }
196 checkIsYAndEWritable();
197 mutableHistogramRef().setSharedE(e);
198 }
199
200 void resize(size_t n) { mutableHistogramRef().resize(n); }
201 size_t size() const { return histogramRef().size(); }
202
203 void setMatrixWorkspace(MatrixWorkspace *matrixWorkspace, const size_t index);
204
205 virtual void copyDataInto(DataObjects::EventList &) const;
206 virtual void copyDataInto(DataObjects::Histogram1D &) const;
207 virtual void copyDataInto(SpectrumTester &) const;
208
209protected:
210 virtual void checkAndSanitizeHistogram(HistogramData::Histogram &) {};
211 virtual void checkWorksWithPoints() const {}
212 virtual void checkIsYAndEWritable() const {}
213
214 // Copy and move are not public since this is an abstract class, but protected
215 // such that derived classes can implement copy and move.
216 ISpectrum(const ISpectrum &other);
217 ISpectrum(ISpectrum &&other);
218 ISpectrum &operator=(const ISpectrum &other);
219 ISpectrum &operator=(ISpectrum &&other);
220
221private:
222 virtual const HistogramData::Histogram &histogramRef() const = 0;
223 virtual HistogramData::Histogram &mutableHistogramRef() = 0;
224
225 void invalidateCachedSpectrumNumbers() const;
226 void invalidateSpectrumDefinition() const;
227 MatrixWorkspace *m_matrixWorkspace{nullptr};
228 // The default value is meaningless. This will always be set before use.
229 size_t m_index{0};
230
232 specnum_t m_specNo{0};
233
235 std::set<detid_t> detectorIDs;
236};
237
238} // namespace API
239} // 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:96
virtual HistogramData::FrequencyVariances frequencyVariances() const
Definition ISpectrum.h:142
void setFrequencyVariances(T &&...data) &
Definition ISpectrum.h:163
HistogramData::Histogram::YMode yMode() const
Definition ISpectrum.h:104
virtual HistogramData::FrequencyStandardDeviations frequencyStandardDeviations() const
Definition ISpectrum.h:143
HistogramData::HistogramY & mutableY() &
Definition ISpectrum.h:177
HistogramData::Points points() const
Definition ISpectrum.h:116
virtual const MantidVec & dataX() const =0
const HistogramData::HistogramX & x() const
Definition ISpectrum.h:171
virtual const HistogramData::HistogramE & e() const
Definition ISpectrum.h:173
void setSharedDx(const Kernel::cow_ptr< HistogramData::HistogramDx > &dx) &
Definition ISpectrum.h:190
virtual MantidVec & dataY()=0
virtual const MantidVec & readX() const =0
void setPointStandardDeviations(T &&...data) &
Definition ISpectrum.h:133
void setCountVariances(T &&...data) &
Definition ISpectrum.h:151
virtual MantidVec & dataE()=0
std::set< detid_t > detectorIDs
Set of the detector IDs associated with this spectrum.
Definition ISpectrum.h:235
void setSharedY(const Kernel::cow_ptr< HistogramData::HistogramY > &y) &
Definition ISpectrum.h:191
void setCountStandardDeviations(T &&...data) &
Definition ISpectrum.h:155
virtual const MantidVec & dataDx() const =0
virtual HistogramData::Frequencies frequencies() const
Definition ISpectrum.h:141
void setPointVariances(T &&...data) &
Definition ISpectrum.h:128
virtual void setX(const Kernel::cow_ptr< HistogramData::HistogramX > &X)=0
void setBinEdges(T &&...data) &
Definition ISpectrum.h:120
virtual HistogramData::Histogram & mutableHistogramRef()=0
virtual size_t getMemorySize() const =0
const HistogramData::HistogramDx & dx() const
Definition ISpectrum.h:174
HistogramData::HistogramDx & mutableDx() &
Definition ISpectrum.h:176
virtual void checkWorksWithPoints() const
Definition ISpectrum.h:211
virtual const MantidVec & readDx() const =0
virtual ~ISpectrum()=default
virtual HistogramData::Histogram histogram() const
Returns the Histogram associated with this spectrum.
Definition ISpectrum.h:94
virtual HistogramData::Counts counts() const
Definition ISpectrum.h:136
void setYMode(HistogramData::Histogram::YMode ymode)
Definition ISpectrum.h:105
Kernel::cow_ptr< HistogramData::HistogramX > sharedX() const
Definition ISpectrum.h:185
void setFrequencies(T &&...data) &
Definition ISpectrum.h:159
virtual const HistogramData::HistogramY & y() const
Definition ISpectrum.h:172
virtual HistogramData::CountStandardDeviations countStandardDeviations() const
Definition ISpectrum.h:138
void setSharedE(const Kernel::cow_ptr< HistogramData::HistogramE > &e) &
Definition ISpectrum.h:195
HistogramData::BinEdges binEdges() const
Definition ISpectrum.h:115
void setCounts(T &&...data) &
Definition ISpectrum.h:146
virtual MantidVec & dataDx()=0
virtual void clearData()=0
size_t size() const
Definition ISpectrum.h:201
virtual const HistogramData::Histogram & histogramRef() const =0
virtual Kernel::cow_ptr< HistogramData::HistogramY > sharedY() const
Definition ISpectrum.h:186
virtual Kernel::cow_ptr< HistogramData::HistogramE > sharedE() const
Definition ISpectrum.h:187
void resize(size_t n)
Definition ISpectrum.h:200
virtual void checkAndSanitizeHistogram(HistogramData::Histogram &)
Definition ISpectrum.h:210
virtual HistogramData::CountVariances countVariances() const
Definition ISpectrum.h:137
void setPoints(T &&...data) &
Definition ISpectrum.h:123
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:188
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:189
HistogramData::HistogramX & mutableX() &
Definition ISpectrum.h:175
HistogramData::HistogramE & mutableE() &
Definition ISpectrum.h:181
void setFrequencyStandardDeviations(T &&...data) &
Definition ISpectrum.h:167
virtual MantidVec & dataX()=0
virtual void checkIsYAndEWritable() const
Definition ISpectrum.h:212
virtual const MantidVec & dataY() const =0
HistogramData::PointStandardDeviations pointStandardDeviations() const
Definition ISpectrum.h:117
Base MatrixWorkspace Abstract Class.
A class for holding :
Definition EventList.h:57
1D histogram implementation.
Definition Histogram1D.h:18
Implements a copy on write data template.
Definition cow_ptr.h:41
Helper class that implements ISpectrum.
Definition FakeObjects.h:55
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