From 0b5e9cb989705d28ccda0cc3fdd6f302de05a27a Mon Sep 17 00:00:00 2001 From: Simon Heybrock <simon.heybrock@esss.se> Date: Tue, 23 Jan 2018 07:39:50 +0100 Subject: [PATCH] Re #21608. Getter for global vector of spectrum numbers in IndexInfo. --- Framework/Indexing/inc/MantidIndexing/IndexInfo.h | 1 + .../inc/MantidIndexing/SpectrumNumberTranslator.h | 1 + Framework/Indexing/src/IndexInfo.cpp | 9 ++++++++- Framework/Indexing/src/SpectrumNumberTranslator.cpp | 5 +++++ Framework/Indexing/test/IndexInfoTest.h | 9 +++++++-- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Framework/Indexing/inc/MantidIndexing/IndexInfo.h b/Framework/Indexing/inc/MantidIndexing/IndexInfo.h index b96a988ca0a..73db808d8e3 100644 --- a/Framework/Indexing/inc/MantidIndexing/IndexInfo.h +++ b/Framework/Indexing/inc/MantidIndexing/IndexInfo.h @@ -96,6 +96,7 @@ public: size_t globalSize() const; SpectrumNumber spectrumNumber(const size_t index) const; + const std::vector<SpectrumNumber> &spectrumNumbers() const; void setSpectrumNumbers(std::vector<SpectrumNumber> &&spectrumNumbers); void setSpectrumNumbers(const SpectrumNumber min, const SpectrumNumber max); diff --git a/Framework/Indexing/inc/MantidIndexing/SpectrumNumberTranslator.h b/Framework/Indexing/inc/MantidIndexing/SpectrumNumberTranslator.h index 486e19ed5fc..0002ebaf0dd 100644 --- a/Framework/Indexing/inc/MantidIndexing/SpectrumNumberTranslator.h +++ b/Framework/Indexing/inc/MantidIndexing/SpectrumNumberTranslator.h @@ -60,6 +60,7 @@ public: size_t localSize() const; SpectrumNumber spectrumNumber(const size_t index) const; + const std::vector<SpectrumNumber> &globalSpectrumNumbers() const; SpectrumIndexSet makeIndexSet() const; SpectrumIndexSet makeIndexSet(SpectrumNumber min, SpectrumNumber max) const; diff --git a/Framework/Indexing/src/IndexInfo.cpp b/Framework/Indexing/src/IndexInfo.cpp index a9ac6b11c00..f226f2136ef 100644 --- a/Framework/Indexing/src/IndexInfo.cpp +++ b/Framework/Indexing/src/IndexInfo.cpp @@ -109,11 +109,18 @@ size_t IndexInfo::globalSize() const { return m_spectrumNumberTranslator->globalSize(); } -/// Returns the spectrum number for given index. +/// Returns the spectrum number for given *local* index, i.e., spectrum numbers +/// for spectra in this partition. SpectrumNumber IndexInfo::spectrumNumber(const size_t index) const { return m_spectrumNumberTranslator->spectrumNumber(index); } +/// Returns a reference to the *global* vector of spectrum numbers, i.e., the +/// spectrum numbers of spectra across all partitions. +const std::vector<SpectrumNumber> &IndexInfo::spectrumNumbers() const { + return m_spectrumNumberTranslator->globalSpectrumNumbers(); +} + /// Set a spectrum number for each index. void IndexInfo::setSpectrumNumbers( std::vector<SpectrumNumber> &&spectrumNumbers) { diff --git a/Framework/Indexing/src/SpectrumNumberTranslator.cpp b/Framework/Indexing/src/SpectrumNumberTranslator.cpp index 8802e2212e1..30ff5101a1b 100644 --- a/Framework/Indexing/src/SpectrumNumberTranslator.cpp +++ b/Framework/Indexing/src/SpectrumNumberTranslator.cpp @@ -83,6 +83,11 @@ SpectrumNumberTranslator::SpectrumNumberTranslator( } } +const std::vector<SpectrumNumber> & +SpectrumNumberTranslator::globalSpectrumNumbers() const { + return m_globalSpectrumNumbers; +} + SpectrumNumberTranslator::SpectrumNumberTranslator( const std::vector<GlobalSpectrumIndex> &globalIndices, const SpectrumNumberTranslator &parent) diff --git a/Framework/Indexing/test/IndexInfoTest.h b/Framework/Indexing/test/IndexInfoTest.h index 7c48bfb57a2..b93e0660da5 100644 --- a/Framework/Indexing/test/IndexInfoTest.h +++ b/Framework/Indexing/test/IndexInfoTest.h @@ -31,12 +31,14 @@ void run_StorageMode_Cloned(const Parallel::Communicator &comm) { void run_StorageMode_Distributed(const Parallel::Communicator &comm) { IndexInfo i(47, Parallel::StorageMode::Distributed, comm); TS_ASSERT_EQUALS(i.globalSize(), 47); + TS_ASSERT_EQUALS(i.spectrumNumbers().size(), 47); size_t expectedSize = 0; for (size_t globalIndex = 0; globalIndex < i.globalSize(); ++globalIndex) { + SpectrumNumber specNum = static_cast<int>(globalIndex) + 1; + TS_ASSERT_EQUALS(i.spectrumNumbers()[globalIndex], specNum); // Current default is RoundRobinPartitioner if (static_cast<int>(globalIndex) % comm.size() == comm.rank()) { - TS_ASSERT_EQUALS(i.spectrumNumber(expectedSize), - static_cast<int>(globalIndex) + 1); + TS_ASSERT_EQUALS(i.spectrumNumber(expectedSize), specNum); ++expectedSize; } } @@ -163,6 +165,9 @@ public: TS_ASSERT_EQUALS(info.spectrumNumber(0), 3); TS_ASSERT_EQUALS(info.spectrumNumber(1), 2); TS_ASSERT_EQUALS(info.spectrumNumber(2), 1); + TS_ASSERT_EQUALS(info.spectrumNumbers()[0], 3); + TS_ASSERT_EQUALS(info.spectrumNumbers()[1], 2); + TS_ASSERT_EQUALS(info.spectrumNumbers()[2], 1); } void test_construct_from_parent_reorder() { -- GitLab