diff --git a/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h b/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h index 58c6e39cb75018acf14705db9a3fa04bf2c85540..de53cb31f0a595068264e167e38ae6120027dd16 100644 --- a/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h @@ -65,7 +65,6 @@ private: const int64_t m_sourceIndex = -1; const int64_t m_sampleIndex = -1; DetectorInfo *m_detectorInfo; // Geometry::DetectorInfo is the owner. - size_t m_scanCounts = 1; /// The default initialisation is a single interval, i.e. no scan std::vector<std::pair<int64_t, int64_t>> m_scanIntervals{{0, 1}}; /// For (component index, time index) -> linear index conversions diff --git a/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h b/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h index eedeee1da6fd0976827b675629d848648d4729b3..3dc213b02e8c6b6d4b136f704620ac95c30791bb 100644 --- a/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h @@ -114,12 +114,10 @@ public: private: size_t linearIndex(const std::pair<size_t, size_t> &index) const; void checkNoTimeDependence() const; - std::vector<bool> buildMergeIndices(const DetectorInfo &other) const; - std::vector<bool> buildMergeScanIndices(const DetectorInfo &other) const; void checkSizes(const DetectorInfo &other) const; void checkIdenticalIntervals(const DetectorInfo &other, const size_t index1, const size_t index2) const; - void merge(const DetectorInfo &other); + void merge(const DetectorInfo &other, const std::vector<bool> &merge); Kernel::cow_ptr<std::vector<bool>> m_isMonitor{nullptr}; Kernel::cow_ptr<std::vector<bool>> m_isMasked{nullptr}; diff --git a/Framework/Beamline/src/ComponentInfo.cpp b/Framework/Beamline/src/ComponentInfo.cpp index a0bd74667e006d3be2cdbff3fc41128fa383f746..a812701b77ba2a831649b3e8ff363d49550d1016 100644 --- a/Framework/Beamline/src/ComponentInfo.cpp +++ b/Framework/Beamline/src/ComponentInfo.cpp @@ -464,6 +464,8 @@ void ComponentInfo::setDetectorInfo(DetectorInfo *detectorInfo) { "input of same size as size of DetectorInfo"); } m_detectorInfo = detectorInfo; + if (m_detectorInfo) + m_detectorInfo->setComponentInfo(this); } bool ComponentInfo::hasSource() const { return m_sourceIndex >= 0; } @@ -622,6 +624,8 @@ this has no time dependence prior to this operation. **/ void ComponentInfo::merge(const ComponentInfo &other) { const auto &toMerge = buildMergeIndices(other); + // Merging the detectorInfo has to be done before we update scanIntervals + m_detectorInfo->merge(*other.m_detectorInfo, toMerge); for (size_t timeIndex = 0; timeIndex < other.m_scanIntervals.size(); ++timeIndex) { if (!toMerge[timeIndex]) @@ -635,10 +639,7 @@ void ComponentInfo::merge(const ComponentInfo &other) { other.m_positions->begin() + indexEnd); rotations.insert(rotations.end(), other.m_rotations->begin() + indexStart, other.m_rotations->begin() + indexEnd); - ++m_scanCounts; } - - m_detectorInfo->merge(*other.m_detectorInfo); } std::vector<bool> diff --git a/Framework/Beamline/src/DetectorInfo.cpp b/Framework/Beamline/src/DetectorInfo.cpp index 68c9652965b509bfc13b047e66b4abcc3b5215c3..ae8d672feeb309a8e0b9ebeaabd16f01ad46dee3 100644 --- a/Framework/Beamline/src/DetectorInfo.cpp +++ b/Framework/Beamline/src/DetectorInfo.cpp @@ -59,9 +59,9 @@ bool DetectorInfo::isEquivalent(const DetectorInfo &other) const { if (!(m_isMasked == other.m_isMasked) && (*m_isMasked != *other.m_isMasked)) return false; - // Scanning related fields. Not testing m_scanCounts and m_indexMap since + // Scanning related fields. Not testing m_indexMap since // those just are internally derived from m_indices. - if (scanIntervals() != other.scanIntervals()) + if (this->scanIntervals() != other.scanIntervals()) return false; // Positions: Absolute difference matter, so comparison is not relative. @@ -168,8 +168,8 @@ void failMerge(const std::string &what) { * of time indices added from `other` is preserved. If the interval for a time * index in `other` is identical to a corresponding interval in `this`, it is * ignored, i.e., no time index is added. */ -void DetectorInfo::merge(const DetectorInfo &other) { - const auto &merge = buildMergeScanIndices(other); +void DetectorInfo::merge(const DetectorInfo &other, + const std::vector<bool> &merge) { for (size_t timeIndex = 0; timeIndex < other.scanCount(); ++timeIndex) { if (!merge[timeIndex]) continue; @@ -185,7 +185,6 @@ void DetectorInfo::merge(const DetectorInfo &other) { rotations.insert(rotations.end(), other.m_rotations->begin() + indexStart, other.m_rotations->begin() + indexEnd); } - return; } void DetectorInfo::setComponentInfo(ComponentInfo *componentInfo) { @@ -223,32 +222,6 @@ Eigen::Vector3d DetectorInfo::samplePosition() const { return m_componentInfo->samplePosition(); } -// Indices returned here are the list of time indexes not to merge -std::vector<bool> -DetectorInfo::buildMergeScanIndices(const DetectorInfo &other) const { - checkSizes(other); - std::vector<bool> merge(other.scanCount(), true); - - for (size_t t1 = 0; t1 < other.scanCount(); ++t1) { - for (size_t t2 = 0; t2 < scanCount(); ++t2) { - const auto &interval1 = other.scanIntervals()[t1]; - const auto &interval2 = scanIntervals()[t2]; - if (interval1 == interval2) { - for (size_t detIndex = 0; detIndex < size(); ++detIndex) { - const size_t linearIndex1 = other.linearIndex({detIndex, t1}); - const size_t linearIndex2 = linearIndex({detIndex, t2}); - checkIdenticalIntervals(other, linearIndex1, linearIndex2); - } - merge[t1] = false; - } else if ((interval1.first < interval2.second) && - (interval1.second > interval2.first)) { - failMerge("scan intervals overlap but not identical"); - } - } - } - return merge; -} - void DetectorInfo::checkSizes(const DetectorInfo &other) const { if (size() != other.size()) failMerge("size mismatch"); diff --git a/Framework/Beamline/test/ComponentInfoTest.h b/Framework/Beamline/test/ComponentInfoTest.h index ff1988b1f432bbca358e84c2be0ded3ac9070e5f..39ba3bef527dfcb7024c83f1260cc70ed6cfbe13 100644 --- a/Framework/Beamline/test/ComponentInfoTest.h +++ b/Framework/Beamline/test/ComponentInfoTest.h @@ -241,7 +241,6 @@ cloneInfos(const std::tuple<boost::shared_ptr<ComponentInfo>, std::get<0>(in)->cloneWithoutDetectorInfo()); auto detInfo = boost::make_shared<DetectorInfo>(*std::get<1>(in)); compInfo->setDetectorInfo(detInfo.get()); - detInfo->setComponentInfo(compInfo.get()); return std::make_tuple(compInfo, detInfo); } @@ -1005,17 +1004,17 @@ public: b.setScanInterval({-1, 5}); TS_ASSERT_THROWS_EQUALS(b.merge(a), const std::runtime_error &e, std::string(e.what()), - "Cannot merge ComponentInfo: sync scan intervals " + "Cannot merge ComponentInfo: scan intervals " "overlap but not identical"); b.setScanInterval({1, 5}); TS_ASSERT_THROWS_EQUALS(b.merge(a), const std::runtime_error &e, std::string(e.what()), - "Cannot merge ComponentInfo: sync scan intervals " + "Cannot merge ComponentInfo: scan intervals " "overlap but not identical"); b.setScanInterval({1, 11}); TS_ASSERT_THROWS_EQUALS(b.merge(a), const std::runtime_error &e, std::string(e.what()), - "Cannot merge ComponentInfo: sync scan intervals " + "Cannot merge ComponentInfo: scan intervals " "overlap but not identical"); }