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#include <algorithm>
12
13namespace Mantid::DataHandling {
14
15// -------------------------------------------------------------
16// DataBlock Generator
17// -------------------------------------------------------------
18DataBlockGenerator::DataBlockGenerator(std::vector<SpectrumPair> intervals) : m_intervals(std::move(intervals)) {
19 // We need to sort the data items.
20 auto comparison = [](const SpectrumPair &el1, const SpectrumPair &el2) { return el1.first < el2.first; };
21 std::sort(m_intervals.begin(), m_intervals.end(), comparison);
22
23 // If there is an interval then set the current index to the first interval in
24 // the sorted container
25 if (!m_intervals.empty()) {
28
29 } else {
30 m_currentIntervalIndex = std::nullopt;
32 }
33}
34
42
43 // If there is no valid interval index then do nothing
45 // We need to check if this index is still in the current interval
46 // If not we need to increment the interval or set the interval index
47 // to a final state
48 auto isinCurrentInterval = m_intervals[m_currentIntervalIndex.value()].first <= m_currentSpectrum &&
50
51 if (!isinCurrentInterval) {
52 ++(*m_currentIntervalIndex);
53
54 // Check if we are past the last interval or else set it to the
55 // first element of the new interval
56 if (m_currentIntervalIndex.value() > (m_intervals.size() - 1)) {
57 m_currentIntervalIndex = std::nullopt;
58 } else {
60 }
61 }
62 }
63
64 return *this;
65}
66
67// Postincrement version
70 ++(*this);
71 return temp;
72}
73
77void DataBlockGenerator::next() { ++(*this); }
78
80
82} // 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.
std::pair< specnum_t, specnum_t > SpectrumPair
Definition DataBlock.h:18
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14
STL namespace.