diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index 669c77270827d0bdd8ced9560c4bd83ab3be6a70..9811b4feed75986f10557e758e5828cc97c9d3e1 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -89,7 +89,7 @@ const Indexing::IndexInfo &MatrixWorkspace::indexInfo() const { spectrumInfo().sharedSpectrumDefinitions()) { // Changed SpectrumDefinitions implies that detector IDs in ISpectrum have // changed. - std::vector<std::vector<detid_t>> detIDs; + std::vector<std::vector<Indexing::DetectorID>> detIDs; for (size_t i = 0; i < getNumberHistograms(); ++i) { const auto &set = getSpectrum(i).getDetectorIDs(); detIDs.emplace_back(set.begin(), set.end()); @@ -106,7 +106,7 @@ const Indexing::IndexInfo &MatrixWorkspace::indexInfo() const { if (m_indexInfoNeedsUpdate) { std::lock_guard<std::mutex> lock(m_indexInfoMutex); if (m_indexInfoNeedsUpdate) { - std::vector<specnum_t> spectrumNumbers; + std::vector<Indexing::SpectrumNumber> spectrumNumbers; for (size_t i = 0; i < getNumberHistograms(); ++i) spectrumNumbers.push_back(getSpectrum(i).getSpectrumNo()); m_indexInfo->setSpectrumNumbers(std::move(spectrumNumbers)); @@ -128,9 +128,11 @@ void MatrixWorkspace::setIndexInfo(const Indexing::IndexInfo &indexInfo) { for (size_t i = 0; i < getNumberHistograms(); ++i) { auto &spectrum = getSpectrum(i); - spectrum.setSpectrumNo(indexInfo.spectrumNumber(i)); - auto ids = indexInfo.detectorIDs(i); - spectrum.setDetectorIDs(std::set<detid_t>(ids.begin(), ids.end())); + spectrum.setSpectrumNo(static_cast<specnum_t>(indexInfo.spectrumNumber(i))); + std::set<detid_t> ids; + for (const auto id : indexInfo.detectorIDs(i)) + ids.insert(static_cast<detid_t>(id)); + spectrum.setDetectorIDs(std::move(ids)); } *m_indexInfo = indexInfo; m_indexInfoNeedsUpdate = false; diff --git a/Framework/API/test/MatrixWorkspaceTest.h b/Framework/API/test/MatrixWorkspaceTest.h index cb1a40ce63507207a9427d0449643c15dcbde614..b2f869f2958c9231b256bddcd15b691d8748bf42 100644 --- a/Framework/API/test/MatrixWorkspaceTest.h +++ b/Framework/API/test/MatrixWorkspaceTest.h @@ -100,9 +100,12 @@ public: TS_ASSERT_EQUALS(indexInfo.spectrumNumber(0), 2); TS_ASSERT_EQUALS(indexInfo.spectrumNumber(1), 4); TS_ASSERT_EQUALS(indexInfo.spectrumNumber(2), 6); - TS_ASSERT_EQUALS(indexInfo.detectorIDs(0), (std::vector<detid_t>{0})); - TS_ASSERT_EQUALS(indexInfo.detectorIDs(1), (std::vector<detid_t>{1})); - TS_ASSERT_EQUALS(indexInfo.detectorIDs(2), (std::vector<detid_t>{2, 3})); + TS_ASSERT_EQUALS(indexInfo.detectorIDs(0), + (std::vector<Indexing::DetectorID>{0})); + TS_ASSERT_EQUALS(indexInfo.detectorIDs(1), + (std::vector<Indexing::DetectorID>{1})); + TS_ASSERT_EQUALS(indexInfo.detectorIDs(2), + (std::vector<Indexing::DetectorID>{2, 3})); } void test_setIndexInfo() { @@ -136,16 +139,19 @@ public: ws.initialize(1, 1, 1); const auto &indexInfo = ws.indexInfo(); TS_ASSERT_EQUALS(indexInfo.spectrumNumber(0), 1); - TS_ASSERT_EQUALS(indexInfo.detectorIDs(0), std::vector<detid_t>({0})); + TS_ASSERT_EQUALS(indexInfo.detectorIDs(0), + std::vector<Indexing::DetectorID>({0})); ws.getSpectrum(0).setSpectrumNo(7); ws.getSpectrum(0).addDetectorID(7); // No changes -- old and new interface should not be mixed! TS_ASSERT_EQUALS(indexInfo.spectrumNumber(0), 1); - TS_ASSERT_EQUALS(indexInfo.detectorIDs(0), std::vector<detid_t>({0})); + TS_ASSERT_EQUALS(indexInfo.detectorIDs(0), + std::vector<Indexing::DetectorID>({0})); // After getting a new reference we should see the changes. const auto &indexInfo2 = ws.indexInfo(); TS_ASSERT_EQUALS(indexInfo2.spectrumNumber(0), 7); - TS_ASSERT_EQUALS(indexInfo2.detectorIDs(0), std::vector<detid_t>({0, 7})); + TS_ASSERT_EQUALS(indexInfo2.detectorIDs(0), + std::vector<Indexing::DetectorID>({0, 7})); } void test_IndexInfo_copy() { @@ -165,17 +171,22 @@ public: TS_ASSERT_EQUALS(copy.spectrumNumber(0), 2); TS_ASSERT_EQUALS(copy.spectrumNumber(1), 4); TS_ASSERT_EQUALS(copy.spectrumNumber(2), 6); - TS_ASSERT_EQUALS(copy.detectorIDs(0), (std::vector<detid_t>{0})); - TS_ASSERT_EQUALS(copy.detectorIDs(1), (std::vector<detid_t>{1})); - TS_ASSERT_EQUALS(copy.detectorIDs(2), (std::vector<detid_t>{2, 3})); + TS_ASSERT_EQUALS(copy.detectorIDs(0), + (std::vector<Indexing::DetectorID>{0})); + TS_ASSERT_EQUALS(copy.detectorIDs(1), + (std::vector<Indexing::DetectorID>{1})); + TS_ASSERT_EQUALS(copy.detectorIDs(2), + (std::vector<Indexing::DetectorID>{2, 3})); // Changing data in workspace affects indexInfo, but not copy ws.getSpectrum(0).setSpectrumNo(7); ws.getSpectrum(0).addDetectorID(7); const auto &indexInfo2 = ws.indexInfo(); TS_ASSERT_EQUALS(indexInfo2.spectrumNumber(0), 7); - TS_ASSERT_EQUALS(indexInfo2.detectorIDs(0), (std::vector<detid_t>{0, 7})); + TS_ASSERT_EQUALS(indexInfo2.detectorIDs(0), + (std::vector<Indexing::DetectorID>{0, 7})); TS_ASSERT_EQUALS(copy.spectrumNumber(0), 2); - TS_ASSERT_EQUALS(copy.detectorIDs(0), (std::vector<detid_t>{0})); + TS_ASSERT_EQUALS(copy.detectorIDs(0), + (std::vector<Indexing::DetectorID>{0})); } void test_setIndexInfo_shares_spectrumDefinition() { diff --git a/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h b/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h index 967762d40cafe3dec1abe2abc6a75c1189f1dc5f..c9e5a2bf34210d3f5bfa5bda88a33fd1f6dbaf48 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/CalMuonDetectorPhases.h @@ -8,6 +8,9 @@ #include "MantidGeometry/IDTypes.h" namespace Mantid { +namespace Indexing { +class SpectrumNumber; +} namespace Algorithms { /** CalMuonDetectorPhases : Calculates asymmetry and phase for each spectra in a @@ -73,7 +76,7 @@ private: /// Extract asymmetry and phase from fitting results void extractDetectorInfo(const API::ITableWorkspace_sptr ¶mTab, const API::ITableWorkspace_sptr &resultsTab, - const Mantid::specnum_t spectrumNumber); + const Indexing::SpectrumNumber spectrumNumber); /// Find frequency to use in sequential fit double getFrequency(const API::MatrixWorkspace_sptr &ws); /// Get frequency hint to use when finding frequency diff --git a/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h b/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h index cbe4dd83a97f7f113d5655099de51ad9b5e16973..8b4bab6882c13c1fe6d7bbb2546a72281fea63c9 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/DiffractionFocussing2.h @@ -1,12 +1,10 @@ #ifndef MANTID_ALGORITHMS_DIFFRACTIONFOCUSSING2_H_ #define MANTID_ALGORITHMS_DIFFRACTIONFOCUSSING2_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidAPI/Algorithm.h" #include "MantidDataObjects/EventWorkspace.h" #include "MantidDataObjects/GroupingWorkspace.h" +#include "MantidIndexing/SpectrumNumber.h" #include "MantidKernel/System.h" namespace Mantid { @@ -147,7 +145,7 @@ private: /// Mapping of group number to vector of inputworkspace indices. std::vector<std::vector<std::size_t>> m_wsIndices; /// List of valid group numbers - std::vector<int> m_validGroups; + std::vector<Indexing::SpectrumNumber> m_validGroups; }; } // namespace Algorithm diff --git a/Framework/Algorithms/src/AppendSpectra.cpp b/Framework/Algorithms/src/AppendSpectra.cpp index fd6986a3d3dded2ecd05fdca9ec3af80a6a4caaf..f155a2822413329d6e6bc5a6f4599adf48952056 100644 --- a/Framework/Algorithms/src/AppendSpectra.cpp +++ b/Framework/Algorithms/src/AppendSpectra.cpp @@ -8,7 +8,6 @@ #include "MantidKernel/BoundedValidator.h" #include "MantidKernel/SingletonHolder.h" #include "MantidIndexing/IndexInfo.h" -#include "MantidIndexing/MakeRange.h" using namespace Mantid::Indexing; using namespace Mantid::Kernel; @@ -138,7 +137,7 @@ void AppendSpectra::fixSpectrumNumbers(const MatrixWorkspace &ws1, auto indexInfo = output.indexInfo(); indexInfo.setSpectrumNumbers( - makeRange(0, static_cast<specnum_t>(output.getNumberHistograms() - 1))); + 0, static_cast<int32_t>(output.getNumberHistograms() - 1)); output.setIndexInfo(indexInfo); const int yAxisNum = 1; diff --git a/Framework/Algorithms/src/CalMuonDetectorPhases.cpp b/Framework/Algorithms/src/CalMuonDetectorPhases.cpp index 869e2d8b5a71d98ea6fbdc3408f3b0aabc168448..639a7949eb50f30d602c0cbacbca941c5f44a67b 100644 --- a/Framework/Algorithms/src/CalMuonDetectorPhases.cpp +++ b/Framework/Algorithms/src/CalMuonDetectorPhases.cpp @@ -198,7 +198,7 @@ void CalMuonDetectorPhases::fitWorkspace(const API::MatrixWorkspace_sptr &ws, void CalMuonDetectorPhases::extractDetectorInfo( const API::ITableWorkspace_sptr ¶mTab, const API::ITableWorkspace_sptr &resultsTab, - const specnum_t spectrumNumber) { + const Indexing::SpectrumNumber spectrumNumber) { double asym = paramTab->Double(0, 1); double phase = paramTab->Double(2, 1); diff --git a/Framework/Algorithms/src/CreateSampleWorkspace.cpp b/Framework/Algorithms/src/CreateSampleWorkspace.cpp index 8a8bf4524705b76a875d6f13e40385d2126ecea3..75634dbf13936ede12ea8f1605a3ff914eb917e4 100644 --- a/Framework/Algorithms/src/CreateSampleWorkspace.cpp +++ b/Framework/Algorithms/src/CreateSampleWorkspace.cpp @@ -303,7 +303,7 @@ MatrixWorkspace_sptr CreateSampleWorkspace::createHistogramWorkspace( Counts y(evalFunction(functionString, xValues, isRandom ? 1 : 0)); CountStandardDeviations e(CountVariances(y.cbegin(), y.cend())); - std::vector<detid_t> detIDs; + std::vector<Indexing::DetectorID> detIDs; for (int wi = 0; wi < numMonitors + numPixels; wi++) detIDs.push_back(wi < numMonitors ? start_at_pixelID + numPixels + wi : start_at_pixelID + wi - numMonitors); @@ -323,7 +323,7 @@ EventWorkspace_sptr CreateSampleWorkspace::createEventWorkspace( const std::string &functionString, bool isRandom) { DateAndTime run_start("2010-01-01T00:00:00"); - std::vector<detid_t> detIDs; + std::vector<Indexing::DetectorID> detIDs; for (int wi = 0; wi < numPixels + numMonitors; wi++) detIDs.push_back(wi < numMonitors ? start_at_pixelID + numPixels + wi : start_at_pixelID + wi - numMonitors); diff --git a/Framework/Algorithms/src/DiffractionFocussing.cpp b/Framework/Algorithms/src/DiffractionFocussing.cpp index efd56eaa0add57f6f1fe95e5aede719d262ce227..b4cac6232c9d4fa8ee992438e889ef0fdd733c72 100644 --- a/Framework/Algorithms/src/DiffractionFocussing.cpp +++ b/Framework/Algorithms/src/DiffractionFocussing.cpp @@ -131,7 +131,7 @@ void DiffractionFocussing::exec() { API::MatrixWorkspace_sptr outputW = API::WorkspaceFactory::Instance().create( tmpW, resultIndeces.size(), newSize + 1, newSize); - std::vector<specnum_t> specNums; + std::vector<Indexing::SpectrumNumber> specNums; const auto &tmpIndices = tmpW->indexInfo(); for (int64_t hist = 0; hist < static_cast<int64_t>(resultIndeces.size()); hist++) { diff --git a/Framework/Algorithms/src/DiffractionFocussing2.cpp b/Framework/Algorithms/src/DiffractionFocussing2.cpp index 9c53f1b3a87754e930bfd2cef0dbb6f73638afad..1685ab1df6eb815017fbb5a6ca29f69713ae6ba7 100644 --- a/Framework/Algorithms/src/DiffractionFocussing2.cpp +++ b/Framework/Algorithms/src/DiffractionFocussing2.cpp @@ -180,7 +180,7 @@ void DiffractionFocussing2::exec() { outWorkspaceIndex < static_cast<int>(m_validGroups.size()); outWorkspaceIndex++) { PARALLEL_START_INTERUPT_REGION - int group = m_validGroups[outWorkspaceIndex]; + int group = static_cast<int>(m_validGroups[outWorkspaceIndex]); // Get the group auto it = group2xvector.find(group); @@ -370,7 +370,7 @@ void DiffractionFocussing2::execEvent() { // This creates and reserves the space required for (size_t iGroup = 0; iGroup < this->m_validGroups.size(); iGroup++) { - const int group = this->m_validGroups[iGroup]; + const int group = static_cast<int>(m_validGroups[iGroup]); EventList &groupEL = out->getSpectrum(iGroup); groupEL.switchTo(eventWtype); groupEL.reserve(size_required[iGroup]); @@ -455,7 +455,7 @@ void DiffractionFocussing2::execEvent() { prog = new Progress(this, 0.9, 1.0, nGroups); for (size_t workspaceIndex = 0; workspaceIndex < this->m_validGroups.size(); workspaceIndex++) { - const int group = this->m_validGroups[workspaceIndex]; + const int group = static_cast<int>(m_validGroups[workspaceIndex]); // Now this is the workspace index of that group; simply 1 offset prog->reportIncrement(1, "Setting X"); diff --git a/Framework/Algorithms/src/EditInstrumentGeometry.cpp b/Framework/Algorithms/src/EditInstrumentGeometry.cpp index fb7b9a82722fa9b0f84e89c937166dbfe9eefa36..efec359b9fc56d9ddc80dfad8c2f87483f49d33d 100644 --- a/Framework/Algorithms/src/EditInstrumentGeometry.cpp +++ b/Framework/Algorithms/src/EditInstrumentGeometry.cpp @@ -302,7 +302,7 @@ void EditInstrumentGeometry::exec() { // Add/copy detector information auto indexInfo = workspace->indexInfo(); - std::vector<detid_t> detIDs; + std::vector<Indexing::DetectorID> detIDs; for (size_t i = 0; i < workspace->getNumberHistograms(); i++) { // Create a new detector. // (Instrument will take ownership of pointer so no need to delete.) @@ -325,9 +325,9 @@ void EditInstrumentGeometry::exec() { // Add new detector to spectrum and instrument // Good and do some debug output - g_log.debug() << "Orignal spectrum " << indexInfo.spectrumNumber(i) - << "has " << indexInfo.detectorIDs(i).size() - << " detectors. \n"; + g_log.debug() << "Orignal spectrum " + << static_cast<int32_t>(indexInfo.spectrumNumber(i)) << "has " + << indexInfo.detectorIDs(i).size() << " detectors. \n"; detIDs.push_back(newdetid); instrument->add(detector); diff --git a/Framework/Algorithms/src/FindDeadDetectors.cpp b/Framework/Algorithms/src/FindDeadDetectors.cpp index 32a2d88eb5a214e8fa6068999ab4e4a5869992b6..63343c2e47cba189f5ff6f95406edbbc0b4702b3 100644 --- a/Framework/Algorithms/src/FindDeadDetectors.cpp +++ b/Framework/Algorithms/src/FindDeadDetectors.cpp @@ -99,12 +99,13 @@ void FindDeadDetectors::exec() { } else { ++countSpec; y = deadValue; - const specnum_t specNo = indexInfo.spectrumNumber(i); + const auto specNo = indexInfo.spectrumNumber(i); // Write the spectrum number to file - file << i << " " << specNo; + file << i << " " << static_cast<int32_t>(specNo); // Get the list of detectors for this spectrum and iterate over const auto &dets = indexInfo.detectorIDs(i); - for (const auto &det : dets) { + for (const auto &id : dets) { + const auto det = static_cast<detid_t>(id); // Write the detector ID to file, log & the FoundDead output property file << " " << det; // we could write dead detectors to the log but if they are viewing the diff --git a/Framework/Algorithms/src/GeneratePeaks.cpp b/Framework/Algorithms/src/GeneratePeaks.cpp index b132b81487dd8f8c2a86a5193eff8bb832ad3935..116c626573b318ad1b39ceda38144c663a192bb8 100644 --- a/Framework/Algorithms/src/GeneratePeaks.cpp +++ b/Framework/Algorithms/src/GeneratePeaks.cpp @@ -760,7 +760,7 @@ GeneratePeaks::createDataWorkspace(std::vector<double> binparameters) { xvalue += fabs(dx) * xvalue; } - std::vector<specnum_t> specNums; + std::vector<Indexing::SpectrumNumber> specNums; for (const auto &item : m_SpectrumMap) { specnum_t specid = item.first; g_log.debug() << "Build WorkspaceIndex-Spectrum " << specNums.size() diff --git a/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp b/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp index f48ec4225a508478c76fe69fc72e4bf787e1bd91..6956b515aff6bc40f1ce634cb17cfd1d59c2a6b0 100644 --- a/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp +++ b/Framework/Algorithms/src/SofQWNormalisedPolygon.cpp @@ -79,7 +79,7 @@ void SofQWNormalisedPolygon::exec() { const size_t nHistos = inputWS->getNumberHistograms(); // Holds the spectrum-detector mapping - std::vector<std::vector<detid_t>> detIDMapping( + std::vector<std::vector<Indexing::DetectorID>> detIDMapping( outputWS->getNumberHistograms()); // Progress reports & cancellation @@ -133,7 +133,7 @@ void SofQWNormalisedPolygon::exec() { const double phiUpper = phi + phiHalfWidth; const double efixed = m_EmodeProperties.getEFixed(spectrumInfo.detector(i)); - const specnum_t specNo = inputIndices.spectrumNumber(i); + const auto specNo = static_cast<specnum_t>(inputIndices.spectrumNumber(i)); std::stringstream logStream; for (size_t j = 0; j < nEnergyBins; ++j) { m_progress->report("Computing polygon intersections"); diff --git a/Framework/CurveFitting/test/Functions/ComptonProfileTestHelpers.h b/Framework/CurveFitting/test/Functions/ComptonProfileTestHelpers.h index aa906275735d36cf835d4c6d6a71ad494cb37044..d910b5ddbe4dda129370f5bb0c012f6cd2e15aa5 100644 --- a/Framework/CurveFitting/test/Functions/ComptonProfileTestHelpers.h +++ b/Framework/CurveFitting/test/Functions/ComptonProfileTestHelpers.h @@ -88,7 +88,8 @@ createTestWorkspace(const size_t nhist, const double x0, const double x1, // Link workspace with detector Mantid::Indexing::IndexInfo indexInfo(nhist); - indexInfo.setDetectorIDs(std::vector<Mantid::detid_t>(nhist, id)); + indexInfo.setDetectorIDs( + std::vector<Mantid::Indexing::DetectorID>(nhist, id)); ws2d->setIndexInfo(indexInfo); return ws2d; diff --git a/Framework/Indexing/CMakeLists.txt b/Framework/Indexing/CMakeLists.txt index 32fc9dc7a3917a06f9c806ff9e1951c6cd195359..3f7b57b0d65076a167fbefb51857ca723b80916d 100644 --- a/Framework/Indexing/CMakeLists.txt +++ b/Framework/Indexing/CMakeLists.txt @@ -8,6 +8,7 @@ set ( SRC_FILES ) set ( INC_FILES + inc/MantidIndexing/DetectorID.h inc/MantidIndexing/DllConfig.h inc/MantidIndexing/Extract.h inc/MantidIndexing/GlobalSpectrumIndex.h @@ -25,6 +26,7 @@ set ( INC_FILES ) set ( TEST_FILES + DetectorIDTest.h ExtractTest.h GlobalSpectrumIndexTest.h GroupTest.h diff --git a/Framework/Indexing/inc/MantidIndexing/DetectorID.h b/Framework/Indexing/inc/MantidIndexing/DetectorID.h new file mode 100644 index 0000000000000000000000000000000000000000..75fddfca2e026dc818e9b05e38ab3d1df5f719e4 --- /dev/null +++ b/Framework/Indexing/inc/MantidIndexing/DetectorID.h @@ -0,0 +1,45 @@ +#ifndef MANTID_INDEXING_DETECTORID_H_ +#define MANTID_INDEXING_DETECTORID_H_ + +#include "MantidIndexing/DllConfig.h" +#include "MantidIndexing/IndexType.h" + +namespace Mantid { +namespace Indexing { + +/** DetectorID : TODO: DESCRIPTION + + @author Simon Heybrock + @date 2017 + + Copyright © 2017 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + Mantid is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +struct MANTID_INDEXING_DLL DetectorID + : public detail::IndexType<DetectorID, int32_t> { + using detail::IndexType<DetectorID, int32_t>::IndexType; + using detail::IndexType<DetectorID, int32_t>::operator=; +}; + +} // namespace Indexing +} // namespace Mantid + +#endif /* MANTID_INDEXING_DETECTORID_H_ */ diff --git a/Framework/Indexing/inc/MantidIndexing/Group.h b/Framework/Indexing/inc/MantidIndexing/Group.h index 1210c7dda63cc2d1cca7f14f3bb87d8a400e890f..1bce5a44054e63591603d8d7ff143052468060ba 100644 --- a/Framework/Indexing/inc/MantidIndexing/Group.h +++ b/Framework/Indexing/inc/MantidIndexing/Group.h @@ -2,11 +2,11 @@ #define MANTID_INDEXING_GROUP_H_ #include "MantidIndexing/DllConfig.h" +#include "MantidIndexing/SpectrumNumber.h" #include <vector> namespace Mantid { -using specnum_t = int32_t; namespace Indexing { class IndexInfo; @@ -38,7 +38,7 @@ class IndexInfo; Code Documentation is available at: <http://doxygen.mantidproject.org> */ MANTID_INDEXING_DLL IndexInfo -group(const IndexInfo &source, std::vector<specnum_t> &&specNums, +group(const IndexInfo &source, std::vector<SpectrumNumber> &&specNums, const std::vector<std::vector<size_t>> &grouping); } // namespace Indexing diff --git a/Framework/Indexing/inc/MantidIndexing/IndexInfo.h b/Framework/Indexing/inc/MantidIndexing/IndexInfo.h index 7fb245b405ac956d20fc48db8acdab64d3859b9f..ddb262de02d26925d3f85acefec1e826960c2597 100644 --- a/Framework/Indexing/inc/MantidIndexing/IndexInfo.h +++ b/Framework/Indexing/inc/MantidIndexing/IndexInfo.h @@ -2,6 +2,8 @@ #define MANTID_INDEXING_INDEXINFO_H_ #include "MantidIndexing/DllConfig.h" +#include "MantidIndexing/DetectorID.h" +#include "MantidIndexing/SpectrumNumber.h" #include "MantidKernel/cow_ptr.h" #include <functional> @@ -10,8 +12,12 @@ namespace Mantid { +<<<<<<< 208a5dde8dfafc5b56bfdaa2c35baa69748103b0 using specnum_t = int32_t; using detid_t = int32_t; +======= +namespace Beamline { +>>>>>>> Re #18522. Use new type-safe detector IDs in spectrum numbers. class SpectrumDefinition; namespace Indexing { @@ -58,18 +64,20 @@ class SpectrumNumberTranslator; class MANTID_INDEXING_DLL IndexInfo { public: explicit IndexInfo(const size_t globalSize); - IndexInfo(std::vector<specnum_t> &&spectrumNumbers, - std::vector<std::vector<detid_t>> &&detectorIDs); + IndexInfo(std::vector<SpectrumNumber> &&spectrumNumbers, + std::vector<std::vector<DetectorID>> &&detectorIDs); ~IndexInfo(); size_t size() const; - specnum_t spectrumNumber(const size_t index) const; - const std::vector<detid_t> &detectorIDs(const size_t index) const; + SpectrumNumber spectrumNumber(const size_t index) const; + const std::vector<DetectorID> &detectorIDs(const size_t index) const; - void setSpectrumNumbers(std::vector<specnum_t> &&spectrumNumbers) & ; - void setDetectorIDs(const std::vector<detid_t> &detectorIDs) & ; - void setDetectorIDs(std::vector<std::vector<detid_t>> &&detectorIDs) & ; + void setSpectrumNumbers(std::vector<SpectrumNumber> &&spectrumNumbers) & ; + void setSpectrumNumbers(const SpectrumNumber min, const SpectrumNumber max) & + ; + void setDetectorIDs(const std::vector<DetectorID> &detectorIDs) & ; + void setDetectorIDs(std::vector<std::vector<DetectorID>> &&detectorIDs) & ; void setSpectrumDefinitions( Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinitions); @@ -78,11 +86,10 @@ public: private: size_t m_size; - Kernel::cow_ptr<std::vector<specnum_t>> m_spectrumNumbers; - Kernel::cow_ptr<std::vector<std::vector<detid_t>>> m_detectorIDs; - - Kernel::cow_ptr<std::vector<SpectrumDefinition>> m_spectrumDefinitions{ - nullptr}; + Kernel::cow_ptr<std::vector<SpectrumNumber>> m_spectrumNumbers; + Kernel::cow_ptr<std::vector<std::vector<DetectorID>>> m_detectorIDs; + Kernel::cow_ptr<std::vector<SpectrumDefinition>> + m_spectrumDefinitions{nullptr}; std::unique_ptr<SpectrumNumberTranslator> m_spectrumNumberTranslator; }; diff --git a/Framework/Indexing/inc/MantidIndexing/IndexType.h b/Framework/Indexing/inc/MantidIndexing/IndexType.h index f408afa8538bfb36f26e46dd88ece3caeccb93f0..984d913c621e83d6141ca44eae6df39d5f58b3b9 100644 --- a/Framework/Indexing/inc/MantidIndexing/IndexType.h +++ b/Framework/Indexing/inc/MantidIndexing/IndexType.h @@ -37,7 +37,8 @@ template <class Derived, class Int, class = typename std::enable_if<std::is_integral<Int>::value>::type> class IndexType { public: - explicit IndexType(Int data) noexcept : m_data(data) {} + IndexType() noexcept : m_data(0) {} + IndexType(Int data) noexcept : m_data(data) {} explicit operator Int() const noexcept { return m_data; } template <class T> IndexType &operator=(const T &other) noexcept { m_data = IndexType(other).m_data; diff --git a/Framework/Indexing/src/Extract.cpp b/Framework/Indexing/src/Extract.cpp index 20529f9ea794ddcde81c91f9d1a3509478f18088..142006b3a3dfa4fc0c967e70915d6431de64a4e6 100644 --- a/Framework/Indexing/src/Extract.cpp +++ b/Framework/Indexing/src/Extract.cpp @@ -1,3 +1,4 @@ +#include "MantidIndexing/DetectorID.h" #include "MantidIndexing/Extract.h" #include "MantidIndexing/IndexInfo.h" @@ -7,8 +8,8 @@ namespace Indexing { /// Extracts IndexInfo from source IndexInfo, extracting data for all indices /// specified by vector. IndexInfo extract(const IndexInfo &source, const std::vector<size_t> &indices) { - std::vector<specnum_t> specNums; - std::vector<std::vector<detid_t>> detIDs; + std::vector<SpectrumNumber> specNums; + std::vector<std::vector<DetectorID>> detIDs; for (const auto &i : indices) { specNums.emplace_back(source.spectrumNumber(i)); detIDs.emplace_back(source.detectorIDs(i)); @@ -20,8 +21,8 @@ IndexInfo extract(const IndexInfo &source, const std::vector<size_t> &indices) { /// specified by range. IndexInfo extract(const IndexInfo &source, const size_t minIndex, const size_t maxIndex) { - std::vector<specnum_t> specNums; - std::vector<std::vector<detid_t>> detIDs; + std::vector<SpectrumNumber> specNums; + std::vector<std::vector<DetectorID>> detIDs; for (size_t i = minIndex; i <= maxIndex; ++i) { specNums.emplace_back(source.spectrumNumber(i)); detIDs.emplace_back(source.detectorIDs(i)); diff --git a/Framework/Indexing/src/Group.cpp b/Framework/Indexing/src/Group.cpp index 1503a1eb49c9dd2b8a2202ccb137c30b051db09a..61963587bba78aac79f2fa69f3808fea006d405f 100644 --- a/Framework/Indexing/src/Group.cpp +++ b/Framework/Indexing/src/Group.cpp @@ -1,3 +1,4 @@ +#include "MantidIndexing/DetectorID.h" #include "MantidIndexing/Group.h" #include "MantidIndexing/IndexInfo.h" @@ -12,14 +13,14 @@ namespace Indexing { * vector describes the group for the i-th entry in 'specNums'. Each entry is a * vector of indices of spectra in 'source' that are to be grouped. */ -IndexInfo group(const IndexInfo &source, std::vector<specnum_t> &&specNums, +IndexInfo group(const IndexInfo &source, std::vector<SpectrumNumber> &&specNums, const std::vector<std::vector<size_t>> &grouping) { if (specNums.size() != grouping.size()) throw std::runtime_error("Indexing::group: Size mismatch between spectrum " "number and grouping vectors"); - std::vector<std::vector<detid_t>> detIDs; + std::vector<std::vector<DetectorID>> detIDs; for (const auto &group : grouping) { - detIDs.emplace_back(std::vector<detid_t>()); + detIDs.emplace_back(std::vector<DetectorID>()); for (const auto &i : group) { const auto &IDs = source.detectorIDs(i); auto &newIDs = detIDs.back(); diff --git a/Framework/Indexing/src/IndexInfo.cpp b/Framework/Indexing/src/IndexInfo.cpp index 54ed5b31baac501b63fa0bffdcd2fcb2841cb701..3c9ce50b348bbcd430d15f3195cf478c852a9b2b 100644 --- a/Framework/Indexing/src/IndexInfo.cpp +++ b/Framework/Indexing/src/IndexInfo.cpp @@ -14,9 +14,10 @@ namespace Indexing { /// 1 and no detector IDs. IndexInfo::IndexInfo(const size_t globalSize) : m_size(globalSize), - m_spectrumNumbers(Kernel::make_cow<std::vector<specnum_t>>(globalSize)), + m_spectrumNumbers( + Kernel::make_cow<std::vector<SpectrumNumber>>(globalSize)), m_detectorIDs( - Kernel::make_cow<std::vector<std::vector<detid_t>>>(globalSize)) { + Kernel::make_cow<std::vector<std::vector<DetectorID>>>(globalSize)) { // Default to spectrum numbers 1...globalSize auto &specNums = m_spectrumNumbers.access(); std::iota(specNums.begin(), specNums.end(), 1); @@ -24,8 +25,8 @@ IndexInfo::IndexInfo(const size_t globalSize) /// Construct with given spectrum number and vector of detector IDs for each /// index. -IndexInfo::IndexInfo(std::vector<specnum_t> &&spectrumNumbers, - std::vector<std::vector<detid_t>> &&detectorIDs) +IndexInfo::IndexInfo(std::vector<SpectrumNumber> &&spectrumNumbers, + std::vector<std::vector<DetectorID>> &&detectorIDs) : m_size(spectrumNumbers.size()) { if (spectrumNumbers.size() != detectorIDs.size()) throw std::runtime_error("IndexInfo: Size mismatch between spectrum number " @@ -41,25 +42,37 @@ IndexInfo::~IndexInfo() = default; size_t IndexInfo::size() const { return m_size; } /// Returns the spectrum number for given index. -specnum_t IndexInfo::spectrumNumber(const size_t index) const { +SpectrumNumber IndexInfo::spectrumNumber(const size_t index) const { return (*m_spectrumNumbers)[index]; } /// Return a vector of the detector IDs for given index. -const std::vector<detid_t> &IndexInfo::detectorIDs(const size_t index) const { +const std::vector<DetectorID> & +IndexInfo::detectorIDs(const size_t index) const { return (*m_detectorIDs)[index]; } /// Set a spectrum number for each index. -void IndexInfo::setSpectrumNumbers(std::vector<specnum_t> &&spectrumNumbers) & { +void IndexInfo::setSpectrumNumbers( + std::vector<SpectrumNumber> &&spectrumNumbers) & { if (size() != spectrumNumbers.size()) throw std::runtime_error( "IndexInfo: Size mismatch when setting new spectrum numbers"); m_spectrumNumbers.access() = std::move(spectrumNumbers); } +void IndexInfo::setSpectrumNumbers(const SpectrumNumber min, + const SpectrumNumber max) & { + if (static_cast<int64_t>(size()) != + static_cast<int32_t>(max) - static_cast<int32_t>(min) + 1) + throw std::runtime_error( + "IndexInfo: Size mismatch when setting new spectrum numbers"); + auto &data = m_spectrumNumbers.access(); + std::iota(data.begin(), data.end(), static_cast<int32_t>(min)); +} + /// Set a single detector ID for each index. -void IndexInfo::setDetectorIDs(const std::vector<detid_t> &detectorIDs) & { +void IndexInfo::setDetectorIDs(const std::vector<DetectorID> &detectorIDs) & { if (size() != detectorIDs.size()) throw std::runtime_error( "IndexInfo: Size mismatch when setting new detector IDs"); @@ -74,7 +87,7 @@ void IndexInfo::setDetectorIDs(const std::vector<detid_t> &detectorIDs) & { /// Set a vector of detector IDs for each index. void IndexInfo::setDetectorIDs( - std::vector<std::vector<detid_t>> &&detectorIDs) & { + std::vector<std::vector<DetectorID>> &&detectorIDs) & { if (size() != detectorIDs.size()) throw std::runtime_error( "IndexInfo: Size mismatch when setting new detector IDs"); diff --git a/Framework/Indexing/test/DetectorIDTest.h b/Framework/Indexing/test/DetectorIDTest.h new file mode 100644 index 0000000000000000000000000000000000000000..eadba5f43553be783846db81baf7a967732c48ac --- /dev/null +++ b/Framework/Indexing/test/DetectorIDTest.h @@ -0,0 +1,33 @@ +#ifndef MANTID_INDEXING_DETECTORIDTEST_H_ +#define MANTID_INDEXING_DETECTORIDTEST_H_ + +#include <cxxtest/TestSuite.h> + +#include "MantidIndexing/DetectorID.h" + +using namespace Mantid; +using namespace Indexing; + +class DetectorIDTest : public CxxTest::TestSuite { +public: + // This pair of boilerplate methods prevent the suite being created statically + // This means the constructor isn't called when running other tests + static DetectorIDTest *createSuite() { return new DetectorIDTest(); } + static void destroySuite(DetectorIDTest *suite) { delete suite; } + + void test_has_correct_mixins() { + DetectorID data(0); +// AppleClang gives warning if the result is unused. +#if __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-value" +#endif + TS_ASSERT_THROWS_NOTHING( + (dynamic_cast<detail::IndexType<DetectorID, int32_t> &>(data))); +#if __clang__ +#pragma clang diagnostic pop +#endif + } +}; + +#endif /* MANTID_INDEXING_DETECTORIDTEST_H_ */ diff --git a/Framework/Indexing/test/ExtractTest.h b/Framework/Indexing/test/ExtractTest.h index 462157faceb8e62f6cf0fc2178c52241fcf091a5..0bb38976877176edb9230282777130ab9e2eb693 100644 --- a/Framework/Indexing/test/ExtractTest.h +++ b/Framework/Indexing/test/ExtractTest.h @@ -3,6 +3,7 @@ #include <cxxtest/TestSuite.h> +#include "MantidIndexing/DetectorID.h" #include "MantidIndexing/Extract.h" #include "MantidIndexing/IndexInfo.h" @@ -23,8 +24,8 @@ public: TS_ASSERT_EQUALS(result.size(), 2); TS_ASSERT_EQUALS(result.spectrumNumber(0), 1); TS_ASSERT_EQUALS(result.spectrumNumber(1), 3); - TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<detid_t>{10}); - TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<detid_t>{30}); + TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<DetectorID>{10}); + TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<DetectorID>{30}); } void test_reorder() { @@ -35,9 +36,9 @@ public: TS_ASSERT_EQUALS(result.spectrumNumber(0), 3); TS_ASSERT_EQUALS(result.spectrumNumber(1), 2); TS_ASSERT_EQUALS(result.spectrumNumber(2), 1); - TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<detid_t>{30}); - TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<detid_t>{20}); - TS_ASSERT_EQUALS(result.detectorIDs(2), std::vector<detid_t>{10}); + TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<DetectorID>{30}); + TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<DetectorID>{20}); + TS_ASSERT_EQUALS(result.detectorIDs(2), std::vector<DetectorID>{10}); } }; diff --git a/Framework/Indexing/test/GroupTest.h b/Framework/Indexing/test/GroupTest.h index 5c5c272d96123e493f34031c43237f40232be93e..05ba7c0af793c446d202d7a6c025072c8466c369 100644 --- a/Framework/Indexing/test/GroupTest.h +++ b/Framework/Indexing/test/GroupTest.h @@ -3,6 +3,7 @@ #include <cxxtest/TestSuite.h> +#include "MantidIndexing/DetectorID.h" #include "MantidIndexing/Group.h" #include "MantidIndexing/IndexInfo.h" @@ -19,7 +20,7 @@ public: void test_size_mismatch_fail() { IndexInfo source({1, 2, 3}, {{10}, {20}, {30}}); std::vector<std::vector<size_t>> grouping{{0}, {1}, {2}}; - std::vector<specnum_t> specNums{4, 5}; + std::vector<SpectrumNumber> specNums{4, 5}; TS_ASSERT_THROWS(group(source, std::move(specNums), grouping), std::runtime_error); TS_ASSERT_EQUALS(specNums.size(), 2); @@ -33,9 +34,9 @@ public: TS_ASSERT_EQUALS(result.spectrumNumber(0), 4); TS_ASSERT_EQUALS(result.spectrumNumber(1), 5); TS_ASSERT_EQUALS(result.spectrumNumber(2), 6); - TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<detid_t>{10}); - TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<detid_t>{20}); - TS_ASSERT_EQUALS(result.detectorIDs(2), std::vector<detid_t>{30}); + TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<DetectorID>{10}); + TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<DetectorID>{20}); + TS_ASSERT_EQUALS(result.detectorIDs(2), std::vector<DetectorID>{30}); } void test_swap_ids() { @@ -46,9 +47,9 @@ public: TS_ASSERT_EQUALS(result.spectrumNumber(0), 1); TS_ASSERT_EQUALS(result.spectrumNumber(1), 2); TS_ASSERT_EQUALS(result.spectrumNumber(2), 3); - TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<detid_t>{20}); - TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<detid_t>{10}); - TS_ASSERT_EQUALS(result.detectorIDs(2), std::vector<detid_t>{30}); + TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<DetectorID>{20}); + TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<DetectorID>{10}); + TS_ASSERT_EQUALS(result.detectorIDs(2), std::vector<DetectorID>{30}); } void test_extract() { @@ -57,7 +58,7 @@ public: auto result = group(source, {1}, grouping); TS_ASSERT_EQUALS(result.size(), 1); TS_ASSERT_EQUALS(result.spectrumNumber(0), 1); - TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<detid_t>{20}); + TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<DetectorID>{20}); } void test_group() { @@ -67,8 +68,8 @@ public: TS_ASSERT_EQUALS(result.size(), 2); TS_ASSERT_EQUALS(result.spectrumNumber(0), 1); TS_ASSERT_EQUALS(result.spectrumNumber(1), 2); - TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<detid_t>({10, 30})); - TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<detid_t>{20}); + TS_ASSERT_EQUALS(result.detectorIDs(0), std::vector<DetectorID>({10, 30})); + TS_ASSERT_EQUALS(result.detectorIDs(1), std::vector<DetectorID>{20}); } }; diff --git a/Framework/Indexing/test/IndexInfoTest.h b/Framework/Indexing/test/IndexInfoTest.h index b5fc2fa245787856000fb201fab64b182f02b038..e8e14aa512a374e090720c2837efc240ecd069d0 100644 --- a/Framework/Indexing/test/IndexInfoTest.h +++ b/Framework/Indexing/test/IndexInfoTest.h @@ -38,9 +38,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.detectorIDs(0), (std::vector<detid_t>{})); - TS_ASSERT_EQUALS(info.detectorIDs(1), (std::vector<detid_t>{10})); - TS_ASSERT_EQUALS(info.detectorIDs(2), (std::vector<detid_t>{20, 30})); + TS_ASSERT_EQUALS(info.detectorIDs(0), (std::vector<DetectorID>{})); + TS_ASSERT_EQUALS(info.detectorIDs(1), (std::vector<DetectorID>{10})); + TS_ASSERT_EQUALS(info.detectorIDs(2), (std::vector<DetectorID>{20, 30})); } void test_size() { TS_ASSERT_EQUALS(IndexInfo(3).size(), 3); } @@ -66,9 +66,9 @@ public: void test_setDetectorIDs() { IndexInfo t(3); TS_ASSERT_THROWS_NOTHING(t.setDetectorIDs({6, 7, 8})); - TS_ASSERT_EQUALS(t.detectorIDs(0), std::vector<detid_t>{6}); - TS_ASSERT_EQUALS(t.detectorIDs(1), std::vector<detid_t>{7}); - TS_ASSERT_EQUALS(t.detectorIDs(2), std::vector<detid_t>{8}); + TS_ASSERT_EQUALS(t.detectorIDs(0), std::vector<DetectorID>{6}); + TS_ASSERT_EQUALS(t.detectorIDs(1), std::vector<DetectorID>{7}); + TS_ASSERT_EQUALS(t.detectorIDs(2), std::vector<DetectorID>{8}); } void test_setSpectrumDefinitions_setting_nullptr_fails() {