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