From 935cd3380ebc9df1d99fd003a8c65b82ed8dfc96 Mon Sep 17 00:00:00 2001 From: Neil Vaytet <neil.vaytet@esss.se> Date: Tue, 9 Oct 2018 16:28:06 +0200 Subject: [PATCH] Refs #23238 : Addressing Simons comments --- Framework/API/test/MatrixWorkspaceTest.h | 4 +--- Framework/Algorithms/test/NormaliseToMonitorTest.h | 10 +++++----- Framework/Beamline/inc/MantidBeamline/ComponentInfo.h | 3 ++- Framework/Beamline/inc/MantidBeamline/DetectorInfo.h | 9 ++++++++- Framework/Beamline/src/ComponentInfo.cpp | 6 +++--- Framework/Beamline/src/DetectorInfo.cpp | 6 +++--- Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp | 8 ++------ .../DataObjects/test/ScanningWorkspaceBuilderTest.h | 8 +++----- .../inc/MantidGeometry/Instrument/ComponentInfo.h | 3 ++- Framework/Geometry/src/Instrument/ComponentInfo.cpp | 4 ++-- 10 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Framework/API/test/MatrixWorkspaceTest.h b/Framework/API/test/MatrixWorkspaceTest.h index 9c326664c29..f297cd30d9d 100644 --- a/Framework/API/test/MatrixWorkspaceTest.h +++ b/Framework/API/test/MatrixWorkspaceTest.h @@ -1653,14 +1653,12 @@ public: detInfo1.setPosition(0, {1, 0, 0}); detInfo2.setPosition(0, {2, 0, 0}); - detInfo1.setScanInterval({10, 20}); - detInfo2.setScanInterval({20, 30}); compInfo1.setScanInterval({10, 20}); compInfo2.setScanInterval({20, 30}); // Merge auto merged = WorkspaceFactory::Instance().create(ws1, 2); - merged->mutableComponentInfo().merge(ws2->mutableComponentInfo()); + merged->mutableComponentInfo().merge(ws2->componentInfo()); // Setting IndexInfo without spectrum definitions will set up a 1:1 mapping // such that each spectrum corresponds to 1 time index of a detector. diff --git a/Framework/Algorithms/test/NormaliseToMonitorTest.h b/Framework/Algorithms/test/NormaliseToMonitorTest.h index 13a27140978..d28a02baa5c 100644 --- a/Framework/Algorithms/test/NormaliseToMonitorTest.h +++ b/Framework/Algorithms/test/NormaliseToMonitorTest.h @@ -510,14 +510,14 @@ public: N_DET, N_BINS, true); auto ws2 = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument( N_DET, N_BINS, true); - auto &detInfo1 = ws1->mutableDetectorInfo(); - auto &detInfo2 = ws2->mutableDetectorInfo(); - detInfo1.setScanInterval({10, 20}); - detInfo2.setScanInterval({20, 30}); + auto &cmpInfo1 = ws1->mutableComponentInfo(); + auto &cmpInfo2 = ws2->mutableComponentInfo(); + cmpInfo1.setScanInterval({10, 20}); + cmpInfo2.setScanInterval({20, 30}); // Merge auto merged = WorkspaceFactory::Instance().create(ws1, 2 * N_DET); auto &cmpInfo = merged->mutableComponentInfo(); - cmpInfo.merge(ws2->mutableComponentInfo()); + cmpInfo.merge(ws2->ComponentInfo()); merged->setIndexInfo(Indexing::IndexInfo(merged->getNumberHistograms())); NormaliseToMonitor alg; diff --git a/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h b/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h index 0ff7898f7c7..58c6e39cb75 100644 --- a/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h @@ -66,6 +66,7 @@ private: 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 Kernel::cow_ptr<std::vector<std::vector<size_t>>> m_indexMap{nullptr}; @@ -75,7 +76,7 @@ private: size_t linearIndex(const std::pair<size_t, size_t> &index) const; void initScanIntervals(); void checkNoTimeDependence() const; - std::vector<bool> buildMergeIndicesSync(const ComponentInfo &other) const; + std::vector<bool> buildMergeIndices(const ComponentInfo &other) const; void checkSizes(const ComponentInfo &other) const; void initIndices(); void checkIdenticalIntervals(const ComponentInfo &other, diff --git a/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h b/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h index 4e7fdad7b61..211f2846825 100644 --- a/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h @@ -102,13 +102,20 @@ public: Eigen::Vector3d sourcePosition() const; Eigen::Vector3d samplePosition() const; + /** The merge() operation was made private in DetectorInfo, and only + * accessible through ComponentInfo (via this friend declaration) + * because we need to avoid merging DetectorInfo without merging + * ComponentInfo, since that would effectively let us create a non-sync + * scan. Otherwise we cannot provide scanning-related methods in + * ComponentInfo without component index. + */ friend class ComponentInfo; 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> buildMergeSyncScanIndices(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; diff --git a/Framework/Beamline/src/ComponentInfo.cpp b/Framework/Beamline/src/ComponentInfo.cpp index c3daebcd015..eee2b6a07f8 100644 --- a/Framework/Beamline/src/ComponentInfo.cpp +++ b/Framework/Beamline/src/ComponentInfo.cpp @@ -620,7 +620,7 @@ this has no time dependence prior to this operation. * ignored, i.e., no time index is added. **/ void ComponentInfo::merge(const ComponentInfo &other) { - const auto &toMerge = buildMergeIndicesSync(other); + const auto &toMerge = buildMergeIndices(other); for (size_t timeIndex = 0; timeIndex < other.m_scanIntervals.size(); ++timeIndex) { if (!toMerge[timeIndex]) @@ -641,7 +641,7 @@ void ComponentInfo::merge(const ComponentInfo &other) { } std::vector<bool> -ComponentInfo::buildMergeIndicesSync(const ComponentInfo &other) const { +ComponentInfo::buildMergeIndices(const ComponentInfo &other) const { checkSizes(other); std::vector<bool> merge(other.m_scanIntervals.size(), true); @@ -658,7 +658,7 @@ ComponentInfo::buildMergeIndicesSync(const ComponentInfo &other) const { merge[t1] = false; } else if ((interval1.first < interval2.second) && (interval1.second > interval2.first)) { - failMerge("sync scan intervals overlap but not identical"); + failMerge("scan intervals overlap but not identical"); } } } diff --git a/Framework/Beamline/src/DetectorInfo.cpp b/Framework/Beamline/src/DetectorInfo.cpp index d50572a8f55..530c5a10102 100644 --- a/Framework/Beamline/src/DetectorInfo.cpp +++ b/Framework/Beamline/src/DetectorInfo.cpp @@ -170,7 +170,7 @@ void failMerge(const std::string &what) { * 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 = buildMergeSyncScanIndices(other); + const auto &merge = buildMergeScanIndices(other); for (size_t timeIndex = 0; timeIndex < other.scanCount(); ++timeIndex) { if (!merge[timeIndex]) @@ -227,7 +227,7 @@ Eigen::Vector3d DetectorInfo::samplePosition() const { // Indices returned here are the list of time indexes not to merge std::vector<bool> -DetectorInfo::buildMergeSyncScanIndices(const DetectorInfo &other) const { +DetectorInfo::buildMergeScanIndices(const DetectorInfo &other) const { checkSizes(other); std::vector<bool> merge(other.scanCount(), true); @@ -244,7 +244,7 @@ DetectorInfo::buildMergeSyncScanIndices(const DetectorInfo &other) const { merge[t1] = false; } else if ((interval1.first < interval2.second) && (interval1.second > interval2.first)) { - failMerge("sync scan intervals overlap but not identical"); + failMerge("scan intervals overlap but not identical"); } } } diff --git a/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp b/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp index 3edd6cd6d5c..87873fd5751 100644 --- a/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp +++ b/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp @@ -196,9 +196,7 @@ MatrixWorkspace_sptr ScanningWorkspaceBuilder::buildWorkspace() const { m_instrument, m_nDetectors * m_nTimeIndexes, m_histogram); auto &outputComponentInfo = outputWorkspace->mutableComponentInfo(); - outputComponentInfo.setScanInterval( - {m_timeRanges[0].first.totalNanoseconds(), - m_timeRanges[0].second.totalNanoseconds()}); + outputComponentInfo.setScanInterval(m_timeRanges[0]); buildOutputComponentInfo(outputComponentInfo); @@ -235,9 +233,7 @@ void ScanningWorkspaceBuilder::buildOutputComponentInfo( create<Workspace2D>(m_instrument, m_nDetectors, m_histogram.binEdges()); for (size_t i = 1; i < m_nTimeIndexes; ++i) { auto &mergeComponentInfo = mergeWorkspace->mutableComponentInfo(); - mergeComponentInfo.setScanInterval( - {m_timeRanges[i].first.totalNanoseconds(), - m_timeRanges[i].second.totalNanoseconds()}); + mergeComponentInfo.setScanInterval(m_timeRanges[i]); outputComponentInfo.merge(mergeComponentInfo); } } diff --git a/Framework/DataObjects/test/ScanningWorkspaceBuilderTest.h b/Framework/DataObjects/test/ScanningWorkspaceBuilderTest.h index 742f0718ba0..08d6b3b1176 100644 --- a/Framework/DataObjects/test/ScanningWorkspaceBuilderTest.h +++ b/Framework/DataObjects/test/ScanningWorkspaceBuilderTest.h @@ -1,4 +1,4 @@ -#ifndef MANTID_DATAOBJECTS_SCANNINGWORKSPACEBUILDERTEST_H_ +// #ifndef MANTID_DATAOBJECTS_SCANNINGWORKSPACEBUILDERTEST_H_ #define MANTID_DATAOBJECTS_SCANNINGWORKSPACEBUILDERTEST_H_ #include <cxxtest/TestSuite.h> @@ -591,10 +591,8 @@ private: } void checkTimeRanges(const DetectorInfo &detectorInfo) { - for (size_t i = 0; i < nDetectors; ++i) { - for (size_t j = 0; j < nTimeIndexes; ++j) { - TS_ASSERT_EQUALS(detectorInfo.scanIntervals()[j], timeRanges[j]); - } + for (size_t i = 0; i < nTimeIndexes; ++i) { + TS_ASSERT_EQUALS(detectorInfo.scanIntervals()[i], timeRanges[i]); } } }; diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/ComponentInfo.h b/Framework/Geometry/inc/MantidGeometry/Instrument/ComponentInfo.h index fe7e75dbf48..aaa7d8e6b3b 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/ComponentInfo.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/ComponentInfo.h @@ -4,6 +4,7 @@ #include "MantidBeamline/ComponentType.h" #include "MantidGeometry/DllConfig.h" #include "MantidGeometry/Objects/BoundingBox.h" +#include "MantidKernel/DateAndTime.h" #include <boost/shared_ptr.hpp> #include <unordered_map> #include <vector> @@ -149,7 +150,7 @@ public: BoundingBox boundingBox(const size_t componentIndex, const BoundingBox *reference = nullptr) const; Beamline::ComponentType componentType(const size_t componentIndex) const; - void setScanInterval(const std::pair<int64_t, int64_t> &interval); + void setScanInterval(const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> &interval); size_t scanCount() const; void merge(const ComponentInfo &other); friend class Instrument; diff --git a/Framework/Geometry/src/Instrument/ComponentInfo.cpp b/Framework/Geometry/src/Instrument/ComponentInfo.cpp index 64e10b00922..e4207b03879 100644 --- a/Framework/Geometry/src/Instrument/ComponentInfo.cpp +++ b/Framework/Geometry/src/Instrument/ComponentInfo.cpp @@ -420,8 +420,8 @@ ComponentInfo::componentType(const size_t componentIndex) const { } void ComponentInfo::setScanInterval( - const std::pair<int64_t, int64_t> &interval) { - m_componentInfo->setScanInterval(interval); + const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> &interval) { + m_componentInfo->setScanInterval({interval.first.totalNanoseconds(),interval.second.totalNanoseconds()}); } size_t ComponentInfo::scanCount() const { -- GitLab