diff --git a/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Framework/API/inc/MantidAPI/MatrixWorkspace.h index d32afacfefdd55aa7a855a94881420d892f64a7f..088ddf2bf105b2114741a63ac57da2463b2095e8 100644 --- a/Framework/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Framework/API/inc/MantidAPI/MatrixWorkspace.h @@ -585,7 +585,6 @@ private: /// A text label for use when plotting spectra std::string m_YUnitLabel; -protected: /// Flag indicating whether the m_isCommonBinsFlag has been set. False by /// default mutable bool m_isCommonBinsFlagSet{false}; diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index fd6bb81feafb94be6bf06c7e3d368ec9ddf0b354..17dbc481480382d04a671c9b98143f9af066d604 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -963,47 +963,67 @@ bool MatrixWorkspace::isHistogramData() const { * @return whether the workspace contains common X bins */ bool MatrixWorkspace::isCommonBins() const { - if (!m_isCommonBinsFlagSet) { - m_isCommonBinsFlag = true; - - const size_t numHist = getNumberHistograms(); - // there being only one or zero histograms is accepted as not being an error - if (numHist > 1) { - const size_t numBins = x(0).size(); - for (size_t i = 1; i < numHist; ++i) { - if (x(i).size() != numBins) { + if (m_isCommonBinsFlagSet) { + return m_isCommonBinsFlag; + } + + m_isCommonBinsFlag = true; + const size_t numHist = this->getNumberHistograms(); + // there being only one or zero histograms is accepted as not being an error + if (numHist <= 1) { + m_isCommonBinsFlagSet = true; + return m_isCommonBinsFlag; + } + + // First check if the x-axis shares a common ptr. + const HistogramData::HistogramX *first = &x(0); + for (size_t i = 1; i < numHist; ++i) { + if (&x(i) != first) { + m_isCommonBinsFlag = false; + break; + } + } + + // If true, we may return here. + if (m_isCommonBinsFlag) { + m_isCommonBinsFlagSet = true; + return m_isCommonBinsFlag; + } + + m_isCommonBinsFlag = true; + // Check that that size of each histogram is identical. + const size_t numBins = x(0).size(); + for (size_t i = 1; i < numHist; ++i) { + if (x(i).size() != numBins) { + m_isCommonBinsFlag = false; + break; + } + } + + // Check that the values of each histogram are identical. + if (m_isCommonBinsFlag) { + const size_t numBins = x(0).size(); + const size_t lastSpec = numHist - 1; + for (size_t i = 0; i < lastSpec; ++i) { + const auto &xi = x(i); + const auto &xip1 = x(i + 1); + for (size_t j = 0; j < numBins; ++j) { + const double first = xi[j]; + const double next = xip1[j]; + if (std::abs(first - next) / std::abs(first + next) > 1.0E-9) { m_isCommonBinsFlag = false; break; } - } - - // there being only one or zero histograms is accepted as not being an - // error - if (m_isCommonBinsFlag) { - const size_t numBins = x(0).size(); - const size_t lastSpec = numHist - 1; - for (size_t i = 0; i < lastSpec; ++i) { - const auto &xi = x(i); - const auto &xip1 = x(i + 1); - for (size_t j = 0; j < numBins; ++j) { - const double first = xi[j]; - const double next = xip1[j]; - if (std::abs(first - next) / std::abs(first + next) > 1.0E-9) { - m_isCommonBinsFlag = false; - break; - } - // handle Nan's and inf's - if ((std::isinf(first) != std::isinf(next)) || - (std::isnan(first) != std::isnan(next))) { - m_isCommonBinsFlag = false; - break; - } - } + // handle Nan's and inf's + if ((std::isinf(first) != std::isinf(next)) || + (std::isnan(first) != std::isnan(next))) { + m_isCommonBinsFlag = false; + break; } } } - m_isCommonBinsFlagSet = true; } + m_isCommonBinsFlagSet = true; return m_isCommonBinsFlag; } diff --git a/Framework/DataObjects/inc/MantidDataObjects/EventWorkspace.h b/Framework/DataObjects/inc/MantidDataObjects/EventWorkspace.h index 4c3daf5d0e467a7fe02eac66729439a80b003245..f531ab34e85e01f2c0571338cd9e3b99072850cc 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/EventWorkspace.h +++ b/Framework/DataObjects/inc/MantidDataObjects/EventWorkspace.h @@ -151,9 +151,6 @@ public: const bool entireRange) const override; EventWorkspace &operator=(const EventWorkspace &other) = delete; - /// Returns true if the workspace contains has common X bins - bool isCommonBins() const override; - protected: /// Protected copy constructor. May be used by childs for cloning. EventWorkspace(const EventWorkspace &other); diff --git a/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h b/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h index 34082b267c8ee9281e7b228f9f8997ce2e4d7f80..acc8dddc9f7f6e71426ad9a450112ac586d86cc3 100644 --- a/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h +++ b/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h @@ -80,9 +80,6 @@ public: bool loadAsRectImg = false, double scale_1 = 1.0, bool parallelExecution = true); - /// Returns true if the workspace contains has common X bins - bool isCommonBins() const override; - protected: /// Protected copy constructor. May be used by childs for cloning. Workspace2D(const Workspace2D &other); diff --git a/Framework/DataObjects/src/EventWorkspace.cpp b/Framework/DataObjects/src/EventWorkspace.cpp index b151573b39ce91b8c1fe46939a9cbf5c73ec4d77..d9ac64c79e879063051fea5a684b7d38f6b4495a 100644 --- a/Framework/DataObjects/src/EventWorkspace.cpp +++ b/Framework/DataObjects/src/EventWorkspace.cpp @@ -605,30 +605,6 @@ void EventWorkspace::resetAllXToSingleBin() { setAllX({tofmin, tofmax}); } -bool EventWorkspace::isCommonBins() const { - if (!m_isCommonBinsFlagSet) { - m_isCommonBinsFlag = true; - const size_t numHist = this->getNumberHistograms(); - // there being only one or zero histograms is accepted as not being an error - if (numHist > 1) { - // First check if the x-axis shares a common cow_ptr. - auto first = data[0]->ptrX(); - for (const auto &el : data) { - if (el->ptrX() != first) { - m_isCommonBinsFlag = false; - break; - } - } - // If false, we need to check more carefully. - if (!m_isCommonBinsFlag) { - return MatrixWorkspace::isCommonBins(); - } - } - m_isCommonBinsFlagSet = true; - } - return m_isCommonBinsFlag; -} - /** Task for sorting an event list */ class EventSortingTask { public: diff --git a/Framework/DataObjects/src/Workspace2D.cpp b/Framework/DataObjects/src/Workspace2D.cpp index ef01141f435715ab313c3c5c6773ffe251cb475a..2a016c9c954b039470fb972a59d0aa83d12dec1e 100644 --- a/Framework/DataObjects/src/Workspace2D.cpp +++ b/Framework/DataObjects/src/Workspace2D.cpp @@ -362,30 +362,6 @@ Workspace2D *Workspace2D::doClone() const { return new Workspace2D(*this); } Workspace2D *Workspace2D::doCloneEmpty() const { return new Workspace2D(storageMode()); } - -bool Workspace2D::isCommonBins() const { - if (!m_isCommonBinsFlagSet) { - m_isCommonBinsFlag = true; - const size_t numHist = this->getNumberHistograms(); - // there being only one or zero histograms is accepted as not being an error - if (numHist > 1) { - // First check if the x-axis shares a common cow_ptr. - auto first = data[0]->ptrX(); - for (const auto &histogram : data) { - if (histogram->ptrX() != first) { - m_isCommonBinsFlag = false; - break; - } - } - // If false, we need to check more carefully. - if (!m_isCommonBinsFlag) { - return MatrixWorkspace::isCommonBins(); - } - } - m_isCommonBinsFlagSet = true; - } - return m_isCommonBinsFlag; -} } // namespace DataObjects } // namespace Mantid diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/FakeObjects.h b/Framework/TestHelpers/inc/MantidTestHelpers/FakeObjects.h index 69c47b0dba790b3428028bf1326b084a7f5c34e3..e961c55ef803ea274a14369d0330e4199a9bf1a3 100644 --- a/Framework/TestHelpers/inc/MantidTestHelpers/FakeObjects.h +++ b/Framework/TestHelpers/inc/MantidTestHelpers/FakeObjects.h @@ -199,31 +199,6 @@ protected: throw std::runtime_error( "Cloning of AxeslessWorkspaceTester is not implemented."); } -public: - bool isCommonBins() const override { - if (!m_isCommonBinsFlagSet) { - m_isCommonBinsFlag = true; - const size_t numHist = this->getNumberHistograms(); - // there being only one or zero histograms is accepted as not being an - // error - if (numHist > 1) { - // First check if the x-axis shares a common cow_ptr. - auto first = m_vec[0].ptrX(); - for (const auto &st : m_vec) { - if (st.ptrX() != first) { - m_isCommonBinsFlag = false; - break; - } - } - // If false, we need to check more carefully. - if (!m_isCommonBinsFlag) { - return MatrixWorkspace::isCommonBins(); - } - } - m_isCommonBinsFlagSet = true; - } - return m_isCommonBinsFlag; - } private: std::vector<SpectrumTester> m_vec;