14#include "MantidIndexing/Extract.h"
15#include "MantidIndexing/Scatter.h"
16#include "MantidIndexing/SpectrumIndexSet.h"
17#include "MantidIndexing/SpectrumNumber.h"
18#include "MantidTypes/SpectrumDefinition.h"
28void setupConsistentSpectrumNumbers(IndexInfo &filtered,
const std::vector<detid_t> &detIDs) {
29 std::vector<Indexing::SpectrumNumber> spectrumNumbers;
35 for (int32_t i = 0; i < static_cast<int32_t>(detIDs.size()); ++i) {
36 if (filtered.spectrumNumber(spectrumNumbers.size()) == detIDs[i])
37 spectrumNumbers.emplace_back(i + 1);
38 if (filtered.size() == spectrumNumbers.size())
41 filtered.setSpectrumNumbers(std::move(spectrumNumbers));
46 const int32_t max, std::vector<int32_t> range,
47 Parallel::Communicator communicator)
48 : m_instrumentWorkspace(
std::move(instrumentWorkspace)),
m_min(min),
m_max(max), m_range(
std::move(range)),
49 m_communicator(
std::move(communicator)) {}
58 std::vector<SpectrumDefinition> specDefs;
59 specDefs.reserve(detIDs.size());
60 std::transform(detIDs.cbegin(), detIDs.cend(), std::back_inserter(specDefs),
61 [&detectorInfo](
const auto detID) { return SpectrumDefinition(detectorInfo.indexOf(detID)); });
65 IndexInfo indexInfo(std::vector<SpectrumNumber>(detIDs.begin(), detIDs.end()), Parallel::StorageMode::Cloned,
67 indexInfo.setSpectrumDefinitions(specDefs);
73 if (filtered.size() == indexInfo.size()) {
74 filtered.setSpectrumNumbers(1,
static_cast<int32_t
>(filtered.size()));
76 setupConsistentSpectrumNumbers(filtered, detIDs);
79 return scatter(filtered);
85 std::vector<SpectrumDefinition> spectrumDefinitions;
88 std::vector<SpectrumNumber> spectrumNumbers;
90 for (
const auto &bankName : bankNames) {
91 const auto &bank = instrument->getComponentByName(bankName);
92 std::vector<size_t> dets;
94 const auto bankIndex = componentInfo.indexOf(bank->getComponentID());
95 dets = componentInfo.detectorsInSubtree(bankIndex);
96 for (
const auto detIndex : dets) {
97 spectrumDefinitions.emplace_back(detIndex);
98 spectrumNumbers.emplace_back(detectorInfo.detectorIDs()[detIndex]);
102 throw std::runtime_error(
"Could not find the bank named '" + bankName +
103 "' as a component assembly in the instrument "
104 "tree; or it did not contain any detectors. Try "
105 "unchecking SingleBankPixelsOnly.");
107 Indexing::IndexInfo indexInfo(std::move(spectrumNumbers), Parallel::StorageMode::Cloned,
m_communicator);
108 indexInfo.setSpectrumDefinitions(std::move(spectrumDefinitions));
109 setupConsistentSpectrumNumbers(indexInfo, instrument->getDetectorIDs(
true));
114 return scatter(indexInfo);
118 const std::pair<std::vector<int32_t>, std::vector<int32_t>> &spectrumDetectorMapping,
const bool monitorsOnly) {
119 const auto &spec = spectrumDetectorMapping.first;
120 const auto &udet = spectrumDetectorMapping.second;
125 std::vector<Indexing::SpectrumNumber> spectrumNumbers;
126 std::vector<SpectrumDefinition> spectrumDefinitions;
128 for (
const auto id : monitors) {
130 auto it = std::find(udet.begin(), udet.end(),
id);
131 if (it != udet.end()) {
132 const specnum_t &specNo = spec[it - udet.begin()];
133 spectrumNumbers.emplace_back(specNo);
134 spectrumDefinitions.emplace_back(detectorInfo.indexOf(
id));
137 Indexing::IndexInfo indexInfo(spectrumNumbers, Parallel::StorageMode::Cloned,
m_communicator);
138 indexInfo.setSpectrumDefinitions(std::move(spectrumDefinitions));
139 return scatter(indexInfo);
143 std::vector<SpectrumDefinition> spectrumDefinitions;
144 for (
const auto specNo : uniqueSpectra) {
145 spectrumDefinitions.emplace_back();
148 spectrumDefinitions.back().add(detectorInfo.indexOf(detID));
149 }
catch (std::out_of_range &) {
154 Indexing::IndexInfo indexInfo(std::vector<Indexing::SpectrumNumber>(uniqueSpectra.begin(), uniqueSpectra.end()),
156 indexInfo.setSpectrumDefinitions(std::move(spectrumDefinitions));
170 m_max =
static_cast<int32_t
>(indexInfo.spectrumNumber(indexInfo.size() - 1));
172 m_min =
static_cast<int32_t
>(indexInfo.spectrumNumber(0));
175 const auto indices = indexInfo.makeIndexSet(
static_cast<SpectrumNumber
>(
m_min),
static_cast<SpectrumNumber
>(
m_max));
176 std::transform(indices.begin(), indices.end(), std::back_inserter(
m_range),
177 [indexInfo](
const auto index) { return static_cast<int32_t>(indexInfo.spectrumNumber(index)); });
182 const auto indices = indexInfo.makeIndexSet(std::vector<SpectrumNumber>(
m_range.begin(),
m_range.end()));
183 m_min =
static_cast<int32_t
>(indexInfo.spectrumNumber(*indices.begin()));
184 m_max =
static_cast<int32_t
>(indexInfo.spectrumNumber(*(indices.end() - 1)));
185 return extract(indexInfo, indices);
std::map< DeltaEMode::Type, std::string > index
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
const std::set< detid_t > & getDetectorIDsForSpectrumNo(const specnum_t spectrumNo) const
std::set< specnum_t > getSpectrumNumbers() const
LoadEventNexusIndexSetup(API::MatrixWorkspace_const_sptr instrumentWorkspace, const int32_t min, const int32_t max, std::vector< int32_t > range, Parallel::Communicator communicator=Parallel::Communicator())
std::vector< int32_t > m_range
const API::MatrixWorkspace_const_sptr m_instrumentWorkspace
Indexing::IndexInfo makeIndexInfo()
Indexing::IndexInfo filterIndexInfo(const Indexing::IndexInfo &indexInfo)
Filter IndexInfo based on optional spectrum range/list provided.
const Parallel::Communicator m_communicator
std::pair< int32_t, int32_t > eventIDLimits() const
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
int32_t specnum_t
Typedef for a spectrum Number.