Commit 9e060007 authored by Robert Applin's avatar Robert Applin
Browse files

Refs #29855. Add method for checking if workspace is ragged.

parent 455e46ae
......@@ -121,6 +121,9 @@ public:
bool hasGroupedDetectors() const;
/// Returns true if the workspace is ragged (has differently sized spectra).
virtual bool isRaggedWorkspace() const = 0;
/// Get the footprint in memory in bytes.
size_t getMemorySize() const override;
virtual size_t getMemorySizeForXAxes() const;
......
......@@ -60,6 +60,9 @@ public:
//------------------------------------------------------------
/// Returns true if the workspace is ragged (has differently sized spectra).
bool isRaggedWorkspace() const override;
// Returns the number of single indexable items in the workspace
std::size_t size() const override;
......
......@@ -48,6 +48,9 @@ public:
return std::unique_ptr<Workspace2D>(doCloneEmpty());
}
/// Returns true if the workspace is ragged (has differently sized spectra).
bool isRaggedWorkspace() const override;
/// Returns the histogram number
std::size_t getNumberHistograms() const override;
......
......@@ -38,6 +38,10 @@ public:
return std::unique_ptr<WorkspaceSingleValue>(doCloneEmpty());
}
WorkspaceSingleValue &operator=(const WorkspaceSingleValue &other) = delete;
/// Returns true if the workspace is ragged (has differently sized spectra).
bool isRaggedWorkspace() const override { return false; }
/// Returns the number of single indexable items in the workspace
std::size_t size() const override { return 1; }
......
......@@ -136,6 +136,21 @@ void EventWorkspace::init(const HistogramData::Histogram &histogram) {
m_axes[1] = std::make_unique<API::SpectraAxis>(this);
}
/// Returns true if the workspace is ragged (has differently sized spectra).
/// @returns true if the workspace is ragged.
bool EventWorkspace::isRaggedWorkspace() const {
if (data.empty()) {
throw std::runtime_error("There are no pixels in the event workspace, "
"therefore cannot determine if it is ragged.");
} else {
const auto numberOfBins = data[0]->histogram_size();
for (const auto &eventList : data)
if (numberOfBins != eventList->histogram_size())
return true;
return false;
}
}
/// The total size of the workspace
/// @returns the number of single indexable items in the workspace
size_t EventWorkspace::size() const {
......
......@@ -104,6 +104,21 @@ void Workspace2D::init(const HistogramData::Histogram &histogram) {
m_axes[1] = std::make_unique<API::SpectraAxis>(this);
}
/// Returns true if the workspace is ragged (has differently sized spectra).
/// @returns true if the workspace is ragged.
bool Workspace2D::isRaggedWorkspace() const {
if (data.empty()) {
throw std::runtime_error("There is no data in the Workspace2D, "
"therefore cannot determine if it is ragged.");
} else {
const auto numberOfBins = data[0]->size();
for (const auto &histogram : data)
if (numberOfBins != histogram->size())
return true;
return false;
}
}
/** Gets the number of histograms
@return Integer
*/
......
......@@ -130,6 +130,19 @@ public:
Mantid::Parallel::StorageMode::Cloned)
: MatrixWorkspace(storageMode), m_spec(0) {}
bool isRaggedWorkspace() const override {
if (m_vec.empty()) {
throw std::runtime_error(
"Vector data is empty, cannot check for ragged workspace.");
} else {
auto numberOfBins = m_vec[0].dataY().size();
for (const auto &spectrum : m_vec)
if (spectrum.dataY().size() != numberOfBins)
return true;
return false;
}
}
// Empty overrides of virtual methods
size_t getNumberHistograms() const override { return m_spec; }
const std::string id() const override { return "AxeslessWorkspaceTester"; }
......@@ -754,4 +767,4 @@ class VariableBinThrowingTester : public AxeslessWorkspaceTester {
return 0;
}
};
\ No newline at end of file
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment