Mantid
Loading...
Searching...
No Matches
Histogram1D.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10
11namespace Mantid::DataObjects {
12
14Histogram1D::Histogram1D(HistogramData::Histogram::XMode xmode, HistogramData::Histogram::YMode ymode)
15 : API::ISpectrum(), m_histogram(xmode, ymode) {
16 if (ymode == HistogramData::Histogram::YMode::Counts) {
18 m_histogram.setCountStandardDeviations(0);
19 } else if (ymode == HistogramData::Histogram::YMode::Frequencies) {
20 m_histogram.setFrequencies(0);
21 m_histogram.setFrequencyStandardDeviations(0);
22 } else {
23 throw std::logic_error("Histogram1D: YMode must be Counts or Frequencies");
24 }
25}
26
28Histogram1D::Histogram1D(const ISpectrum &other) : ISpectrum(other), m_histogram(other.histogram()) {}
29
33 m_histogram = rhs.histogram();
34 return *this;
35}
36
38void Histogram1D::copyDataFrom(const ISpectrum &source) { source.copyDataInto(*this); }
39
42
44 auto &yValues = this->mutableY();
45 std::fill(yValues.begin(), yValues.end(), 0.0);
46 auto &eValues = this->mutableE();
47 std::fill(eValues.begin(), eValues.end(), 0.0);
48}
49
53
54// The mutable legacy accessors below can only be expressed in terms of Histogram's own legacy
55// interface: handing out a mutable MantidVec would allow the length to be changed, so
56// FixedLengthVector::mutableRawData() is protected and Histogram is its only friend.
57GNU_DIAG_OFF("deprecated-declarations")
58MSVC_DIAG_OFF(4996)
59
61MantidVec &Histogram1D::dataX() { return m_histogram.dataX(); }
62
63MSVC_DIAG_ON(4996)
64GNU_DIAG_ON("deprecated-declarations")
65
67const MantidVec &Histogram1D::dataX() const { return m_histogram.x().rawData(); }
68
70const MantidVec &Histogram1D::readX() const { return m_histogram.x().rawData(); }
71
74
75GNU_DIAG_OFF("deprecated-declarations")
76MSVC_DIAG_OFF(4996)
78MantidVec &Histogram1D::dataDx() { return m_histogram.dataDx(); }
79MSVC_DIAG_ON(4996)
80GNU_DIAG_ON("deprecated-declarations")
82const MantidVec &Histogram1D::dataDx() const { return m_histogram.dx().rawData(); }
84const MantidVec &Histogram1D::readDx() const { return m_histogram.dx().rawData(); }
85
91void Histogram1D::checkAndSanitizeHistogram(HistogramData::Histogram &histogram) {
92 if (!histogram.sharedY()) {
93 throw std::invalid_argument("Histogram1D: invalid input: Y data set to nullptr");
94 }
95 if (!histogram.sharedE()) {
96 throw std::invalid_argument("Histogram1D: invalid input: E data set to nullptr");
97 }
98}
99
100} // namespace Mantid::DataObjects
const std::vector< double > & rhs
#define MSVC_DIAG_ON(x)
#define MSVC_DIAG_OFF(x)
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
A "spectrum" is an object that holds the data for a particular spectrum, in particular:
Definition ISpectrum.h:38
HistogramData::HistogramY & mutableY() &
Definition ISpectrum.h:191
const HistogramData::HistogramX & x() const
Definition ISpectrum.h:185
const HistogramData::HistogramDx & dx() const
Definition ISpectrum.h:188
virtual HistogramData::Histogram histogram() const
Returns the Histogram associated with this spectrum.
Definition ISpectrum.h:108
void setCounts(T &&...data) &
Definition ISpectrum.h:160
virtual void copyDataInto(DataObjects::EventList &) const
Override in child classes for polymorphic copying of data.
ISpectrum & operator=(const ISpectrum &other)
Copy assignment.
HistogramData::HistogramE & mutableE() &
Definition ISpectrum.h:195
1D histogram implementation.
Definition Histogram1D.h:19
void checkAndSanitizeHistogram(HistogramData::Histogram &histogram) override
Makes sure a histogram has valid Y and E data.
Kernel::cow_ptr< HistogramData::HistogramX > ptrX() const override
Deprecated, use sharedX() instead. Returns a pointer to the x data.
const MantidVec & readDx() const override
Deprecated, use dx() instead.
HistogramData::Histogram m_histogram
Histogram object holding the histogram data.
Definition Histogram1D.h:22
void copyDataInto(Histogram1D &sink) const override
Used by copyDataFrom for dynamic dispatch for its source.
void setX(const Kernel::cow_ptr< HistogramData::HistogramX > &X) override
Deprecated, use setSharedX() instead.
MantidVec & dataX() override
Deprecated, use mutableX() instead. Returns the x data.
const MantidVec & readX() const override
Deprecated, use x() instead. Returns the x data const.
Histogram1D & operator=(const Histogram1D &)=default
MantidVec & dataDx() override
Deprecated, use mutableDx() instead.
void clearData() override
Zero the data (Y&E) in this spectrum.
Histogram1D(HistogramData::Histogram::XMode xmode, HistogramData::Histogram::YMode ymode)
Construct empty.
void copyDataFrom(const ISpectrum &source) override
Copy data from a Histogram1D or EventList, via ISpectrum reference.
Implements a copy on write data template.
Definition cow_ptr.h:41
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
Definition cow_ptr.h:172