diff --git a/Framework/API/inc/MantidAPI/SpectrumInfo.h b/Framework/API/inc/MantidAPI/SpectrumInfo.h index e8ce651bd3492e29d913ba88806af30c0bc9e132..fc4c9bffede5a5a78483e024b32d072cb4ea619a 100644 --- a/Framework/API/inc/MantidAPI/SpectrumInfo.h +++ b/Framework/API/inc/MantidAPI/SpectrumInfo.h @@ -56,6 +56,7 @@ public: ~SpectrumInfo(); size_t size() const; + size_t detectorCount() const; const SpectrumDefinition &spectrumDefinition(const size_t index) const; const Kernel::cow_ptr<std::vector<SpectrumDefinition>> & diff --git a/Framework/API/inc/MantidAPI/SpectrumInfoItem.h b/Framework/API/inc/MantidAPI/SpectrumInfoItem.h index e98df300bdd949b486aad469a8eb64e51edeb972..15062d08639c7d74565ea733b617ff93efb156e2 100644 --- a/Framework/API/inc/MantidAPI/SpectrumInfoItem.h +++ b/Framework/API/inc/MantidAPI/SpectrumInfoItem.h @@ -59,6 +59,8 @@ public: return m_spectrumInfo->hasUniqueDetector(m_index); } + bool hasDetectors() const { return m_spectrumInfo->hasDetectors(m_index); } + const Mantid::SpectrumDefinition &spectrumDefinition() const { return m_spectrumInfo->spectrumDefinition(m_index); } diff --git a/Framework/API/src/SpectrumInfo.cpp b/Framework/API/src/SpectrumInfo.cpp index f487795992ab037ed3b570a337ae154424f2a929..8ca2b71c33da18fb765e09ccc5607c3225e4369b 100644 --- a/Framework/API/src/SpectrumInfo.cpp +++ b/Framework/API/src/SpectrumInfo.cpp @@ -33,6 +33,10 @@ SpectrumInfo::~SpectrumInfo() = default; /// Returns the size of the SpectrumInfo, i.e., the number of spectra. size_t SpectrumInfo::size() const { return m_spectrumInfo.size(); } +size_t SpectrumInfo::detectorCount() const { + return m_spectrumInfo.detectorCount(); +} + /// Returns a const reference to the SpectrumDefinition of the spectrum. const SpectrumDefinition & SpectrumInfo::spectrumDefinition(const size_t index) const { diff --git a/Framework/Beamline/inc/MantidBeamline/SpectrumInfo.h b/Framework/Beamline/inc/MantidBeamline/SpectrumInfo.h index 67e3b70e76dd3ba21e9f72f111670e0c4709c952..5b6c22de7ee0066fbf7c64d318a91362b2d77ab9 100644 --- a/Framework/Beamline/inc/MantidBeamline/SpectrumInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/SpectrumInfo.h @@ -46,6 +46,7 @@ public: Kernel::cow_ptr<std::vector<SpectrumDefinition>> spectrumDefinition); size_t size() const; + size_t detectorCount() const; const SpectrumDefinition &spectrumDefinition(const size_t index) const; void setSpectrumDefinition(const size_t index, SpectrumDefinition def); diff --git a/Framework/Beamline/src/SpectrumInfo.cpp b/Framework/Beamline/src/SpectrumInfo.cpp index ceac56034cb36f6f255decefaa998c85772c11af..5906a4f48e9a92d04376ea9acf2dccf15621ffbc 100644 --- a/Framework/Beamline/src/SpectrumInfo.cpp +++ b/Framework/Beamline/src/SpectrumInfo.cpp @@ -26,6 +26,15 @@ size_t SpectrumInfo::size() const { return m_spectrumDefinition->size(); } +/// Return count of all detectors used within spectrum +size_t SpectrumInfo::detectorCount() const { + size_t count = 0; + for (const auto &spec : *m_spectrumDefinition) { + count += spec.size(); + } + return count; +} + /// Returns a const reference to the SpectrumDefinition of the spectrum. const SpectrumDefinition & SpectrumInfo::spectrumDefinition(const size_t index) const { diff --git a/Framework/Beamline/test/SpectrumInfoTest.h b/Framework/Beamline/test/SpectrumInfoTest.h index e619efa83203703b252f8ac05c21bb33d760b7b3..e4bb67fefa47e9fc79a65083f903d58e3af85452 100644 --- a/Framework/Beamline/test/SpectrumInfoTest.h +++ b/Framework/Beamline/test/SpectrumInfoTest.h @@ -107,4 +107,17 @@ public: (std::pair<size_t, size_t>(i, 0))); } } + + void test_detectorCount() { + SpectrumDefinition def1; + def1.add(1); + def1.add(2); + SpectrumDefinition def2; + def2.add(1); + SpectrumInfo info{2}; + info.setSpectrumDefinition(0, def1); + info.setSpectrumDefinition(1, def2); + TS_ASSERT_EQUALS(info.size(), 2); + TS_ASSERT_EQUALS(info.detectorCount(), 3); + } }; diff --git a/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfo.cpp b/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfo.cpp index 2191b63476bdea9805b258c28c4103754d39473c..1c23af6e39416ca7d1dae00963e6e48bddd50144 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfo.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfo.cpp @@ -76,5 +76,7 @@ void export_SpectrumInfo() { .def("getSpectrumDefinition", &SpectrumInfo::spectrumDefinition, return_value_policy<return_by_value>(), (arg("self"), arg("index")), "Returns the SpectrumDefinition of the spectrum with the given " - "index."); + "index.") + .def("detectorCount", &SpectrumInfo::detectorCount, arg("self"), + "Returns the total number of detectors used across spectrum info."); } diff --git a/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfoItem.cpp b/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfoItem.cpp index bb294ed960006533d1759c7a71cb72bd195da917..2b2dd604232966c98631a55b655c92b599dab0b9 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfoItem.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/SpectrumInfoItem.cpp @@ -27,6 +27,8 @@ void export_SpectrumInfoItem() { .add_property("signedTwoTheta", &SpectrumInfoItem<SpectrumInfo>::signedTwoTheta) .add_property("l2", &SpectrumInfoItem<SpectrumInfo>::l2) + .add_property("hasDetectors", + &SpectrumInfoItem<SpectrumInfo>::hasDetectors) .add_property("hasUniqueDetector", &SpectrumInfoItem<SpectrumInfo>::hasUniqueDetector) .add_property( diff --git a/Framework/PythonInterface/test/python/mantid/api/SpectrumInfoTest.py b/Framework/PythonInterface/test/python/mantid/api/SpectrumInfoTest.py index 4dcd6cf7638815092678d28b67bb946b255006e5..bcaee8d1ab35ec74ff46275f60457a9a5e5723c7 100644 --- a/Framework/PythonInterface/test/python/mantid/api/SpectrumInfoTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/SpectrumInfoTest.py @@ -40,6 +40,13 @@ class SpectrumInfoTest(unittest.TestCase): info = self._ws.spectrumInfo() self.assertEqual(info.size(), 3) + def test_detectorCount(self): + """ Check total detector count """ + info = self._ws.spectrumInfo() + # One detector cleared. So not counted. + self.assertEqual(info.detectorCount(), 2) + + def test_isMonitor(self): """ Check if a monitor is present. """ info = self._ws.spectrumInfo()