Mantid
Loading...
Searching...
No Matches
DataBlockGenerator.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 +
7#include <utility>
8
11
12namespace Mantid::DataHandling {
13
14// -------------------------------------------------------------
15// DataBlock Generator
16// -------------------------------------------------------------
17DataBlockGenerator::DataBlockGenerator(std::vector<SpectrumPair> intervals) : m_intervals(std::move(intervals)) {
18 // We need to sort the data items.
19 auto comparison = [](const SpectrumPair &el1, const SpectrumPair &el2) { return el1.first < el2.first; };
20 std::sort(m_intervals.begin(), m_intervals.end(), comparison);
21
22 // If there is an interval then set the current index to the first interval in
23 // the sorted container
24 if (!m_intervals.empty()) {
27
28 } else {
29 m_currentIntervalIndex = boost::none;
31 }
32}
33
41
42 // If there is no valid interval index then do nothing
44 // We need to check if this index is still in the current interval
45 // If not we need to increment the interval or set the interval index
46 // to a final state
47 auto isinCurrentInterval = m_intervals[m_currentIntervalIndex.get()].first <= m_currentSpectrum &&
49
50 if (!isinCurrentInterval) {
51 ++(*m_currentIntervalIndex);
52
53 // Check if we are past the last interval or else set it to the
54 // first element of the new interval
55 if (m_currentIntervalIndex.get() > (m_intervals.size() - 1)) {
56 m_currentIntervalIndex = boost::none;
57 } else {
59 }
60 }
61 }
62
63 return *this;
64}
65
66// Postincrement version
69 ++(*this);
70 return temp;
71}
72
76void DataBlockGenerator::next() { ++(*this); }
77
79
81} // namespace Mantid::DataHandling
DataBlockGenerator: The DataBlockGenerator class provides increasing int64_t numbers from a collectio...
DataBlockGenerator(std::vector< SpectrumPair > intervals)
void next()
Convenience method for incrementing.
DataBlockGenerator & operator++()
We need to increment through a series of intervals and need to make sure that we skip the gaps.
boost::optional< size_t > m_currentIntervalIndex
std::vector< SpectrumPair > m_intervals
std::pair< specnum_t, specnum_t > SpectrumPair
Definition: DataBlock.h:16
int32_t specnum_t
Typedef for a spectrum Number.
Definition: IDTypes.h:16
STL namespace.