forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExtract.cpp
60 lines (54 loc) · 2.27 KB
/
Extract.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
54
55
56
57
58
59
60
// 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/Extract.h"
#include "MantidIndexing/IndexInfo.h"
#include "MantidIndexing/SpectrumIndexSet.h"
#include "MantidTypes/SpectrumDefinition.h"
namespace Mantid::Indexing {
namespace {
void checkStorageMode(const IndexInfo &indexInfo) {
using namespace Parallel;
if (indexInfo.storageMode() == StorageMode::Distributed)
throw std::runtime_error("extract() does not support " + Parallel::toString(StorageMode::Distributed));
}
} // namespace
/// Extracts IndexInfo from source IndexInfo, extracting data for all indices
/// specified by index set.
IndexInfo extract(const IndexInfo &source, const SpectrumIndexSet &indices) {
return extract(source, std::vector<size_t>(indices.begin(), indices.end()));
}
/// Extracts IndexInfo from source IndexInfo, extracting data for all indices
/// specified by vector.
IndexInfo extract(const IndexInfo &source, const std::vector<size_t> &indices) {
checkStorageMode(source);
std::vector<SpectrumNumber> specNums;
std::vector<SpectrumDefinition> specDefs;
const auto &sourceDefs = source.spectrumDefinitions();
for (const auto &i : indices) {
specNums.emplace_back(source.spectrumNumber(i));
specDefs.emplace_back((*sourceDefs)[i]);
}
IndexInfo result(std::move(specNums));
result.setSpectrumDefinitions(std::move(specDefs));
return result;
}
/// Extracts IndexInfo from source IndexInfo, extracting data for all indices
/// specified by range.
IndexInfo extract(const IndexInfo &source, const size_t minIndex, const size_t maxIndex) {
checkStorageMode(source);
std::vector<SpectrumNumber> specNums;
std::vector<SpectrumDefinition> specDefs;
const auto &sourceDefs = source.spectrumDefinitions();
for (size_t i = minIndex; i <= maxIndex; ++i) {
specNums.emplace_back(source.spectrumNumber(i));
specDefs.emplace_back((*sourceDefs)[i]);
}
IndexInfo result(std::move(specNums));
result.setSpectrumDefinitions(std::move(specDefs));
return result;
}
} // namespace Mantid::Indexing