forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPartitioner.cpp
53 lines (43 loc) · 2 KB
/
Partitioner.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidIndexing/Partitioner.h"
#include <algorithm>
#include <stdexcept>
namespace Mantid::Indexing {
Partitioner::Partitioner(const int numberOfPartitions, const PartitionIndex partition,
const MonitorStrategy monitorStrategy, std::vector<GlobalSpectrumIndex> monitors)
: m_partitions(numberOfPartitions), m_partition(partition), m_monitorStrategy(monitorStrategy),
m_monitors(std::move(monitors)) {
if (numberOfNonMonitorPartitions() < 1)
throw std::logic_error("Partitioner: Number of non-monitor partitions "
"must be larger than 0.");
}
int Partitioner::numberOfPartitions() const { return m_partitions; }
int Partitioner::numberOfNonMonitorPartitions() const {
if (m_monitorStrategy == MonitorStrategy::DedicatedPartition)
return m_partitions - 1;
return m_partitions;
}
PartitionIndex Partitioner::indexOf(const GlobalSpectrumIndex index) const {
if (isMonitor(index)) {
if (m_monitorStrategy == MonitorStrategy::DedicatedPartition)
return PartitionIndex(numberOfPartitions() - 1);
return m_partition;
}
return doIndexOf(index);
}
bool Partitioner::isValid(const PartitionIndex index) const { return index >= 0 && index < numberOfPartitions(); }
void Partitioner::checkValid(const PartitionIndex index) const {
if (!isValid(index))
throw std::out_of_range("PartitionerIndex is out of range 0...numberOfPartitions-1");
}
bool Partitioner::isMonitor(const GlobalSpectrumIndex index) const {
if (m_monitorStrategy == MonitorStrategy::TreatAsNormalSpectrum)
return false;
return std::find(m_monitors.begin(), m_monitors.end(), index) != m_monitors.end();
}
} // namespace Mantid::Indexing