diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index bf1f9f059370321c8e05b134a5b87449fa50c9fc..8589a7bde7487763ee3d043145550addabfb3f07 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -1964,13 +1964,14 @@ void MatrixWorkspace::buildDefaultSpectrumDefinitions() { std::vector<SpectrumDefinition>(m_indexInfo->size())); return; } - size_t numberOfSpectra{0}; - if (detInfo.isScanning()) { - for (size_t i = 0; i < numberOfDetectors; ++i) - numberOfSpectra += detInfo.scanCount(i); - } else { - numberOfSpectra = numberOfDetectors; - } + // size_t numberOfSpectra{0}; + // if (detInfo.isScanning()) { + // for (size_t i = 0; i < numberOfDetectors; ++i) + // numberOfSpectra += detInfo.scanCount(i); + // } else { + // numberOfSpectra = numberOfDetectors; + // } + size_t numberOfSpectra = numberOfDetectors * detInfo.scanCount(); if (numberOfSpectra != m_indexInfo->globalSize()) throw std::invalid_argument( "MatrixWorkspace: IndexInfo does not contain spectrum definitions so " @@ -1985,7 +1986,7 @@ void MatrixWorkspace::buildDefaultSpectrumDefinitions() { size_t specIndex = 0; size_t globalSpecIndex = 0; for (size_t detIndex = 0; detIndex < detInfo.size(); ++detIndex) { - for (size_t time = 0; time < detInfo.scanCount(detIndex); ++time) { + for (size_t time = 0; time < detInfo.scanCount(); ++time) { if (m_indexInfo->isOnThisPartition( Indexing::GlobalSpectrumIndex(globalSpecIndex++))) specDefs[specIndex++].add(detIndex, time); @@ -2014,7 +2015,7 @@ void MatrixWorkspace::rebuildDetectorIDGroupings() { const size_t timeIndex = index.second; if (detIndex >= allDetIDs.size()) { errorValue = ErrorCode::InvalidDetIndex; - } else if (timeIndex >= detInfo.scanCount(detIndex)) { + } else if (timeIndex >= detInfo.scanCount()) { errorValue = ErrorCode::InvalidTimeIndex; } else { detIDs.insert(allDetIDs[detIndex]); diff --git a/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h b/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h index a8883732d2d26155b18d85df9c08f5eb57da20b8..d3f0e88fc529066feb6ada16859a9e5f287d3288 100644 --- a/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/ComponentInfo.h @@ -66,8 +66,9 @@ private: const int64_t m_sampleIndex = -1; DetectorInfo *m_detectorInfo; // Geometry::DetectorInfo is the owner. size_t m_scanCounts = 1; - Kernel::cow_ptr<std::vector<std::pair<int64_t, int64_t>>> m_scanIntervals{ - nullptr}; + std::vector<std::pair<int64_t, int64_t>> m_scanIntervals{{0, 0}}; + // Kernel::cow_ptr<std::vector<std::pair<int64_t, int64_t>>> m_scanIntervals{ + // nullptr}; /// For (component index, time index) -> linear index conversions Kernel::cow_ptr<std::vector<std::vector<size_t>>> m_indexMap{nullptr}; /// For linear index -> (detector index, time index) conversions @@ -158,11 +159,13 @@ public: const Eigen::Vector3d &scaleFactor); ComponentType componentType(const size_t componentIndex) const; - size_t scanCount(const size_t index) const; +// size_t scanCount(const size_t index) const; + size_t scanCount() const; size_t scanSize() const; bool isScanning() const; - std::pair<int64_t, int64_t> - scanInterval(const std::pair<size_t, size_t> &index) const; +// std::pair<int64_t, int64_t> +// scanInterval(const std::pair<size_t, size_t> &index) const; + const std::vector<std::pair<int64_t, int64_t>> &scanIntervals() const; void setScanInterval(const std::pair<int64_t, int64_t> &interval); void merge(const ComponentInfo &other); diff --git a/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h b/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h index 94ee3cf8ff00a1813729dd23dff696903e81e5cc..326cfeb7e316ca584ac8b35332c13acf46ea9068 100644 --- a/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h +++ b/Framework/Beamline/inc/MantidBeamline/DetectorInfo.h @@ -76,7 +76,7 @@ public: size_t size() const; size_t scanSize() const; bool isScanning() const; - bool isSyncScan() const; +// bool isSyncScan() const; bool isMonitor(const size_t index) const; bool isMonitor(const std::pair<size_t, size_t> &index) const; @@ -95,32 +95,39 @@ public: void setRotation(const std::pair<size_t, size_t> &index, const Eigen::Quaterniond &rotation); - size_t scanCount(const size_t index) const; - std::pair<int64_t, int64_t> - scanInterval(const std::pair<size_t, size_t> &index) const; - void setScanInterval(const size_t index, - const std::pair<int64_t, int64_t> &interval); + size_t scanCount() const; + const std::vector<std::pair<int64_t, int64_t>> &scanIntervals() const; +// std::vector<std::pair<int64_t, int64_t>> &scanIntervals() const; + +// std::pair<int64_t, int64_t> +// scanInterval(const std::pair<size_t, size_t> &index) const; +// void setScanInterval(const size_t index, +// const std::pair<int64_t, int64_t> &interval); void setScanInterval(const std::pair<int64_t, int64_t> &interval); - void merge(const DetectorInfo &other); +// void merge(const DetectorInfo &other); void setComponentInfo(ComponentInfo *componentInfo); bool hasComponentInfo() const; double l1() const; Eigen::Vector3d sourcePosition() const; Eigen::Vector3d samplePosition() const; + friend class ComponentInfo; +// friend class Geometry::DetectorInfo; + private: size_t linearIndex(const std::pair<size_t, size_t> &index) const; void checkNoTimeDependence() const; - void initScanCounts(); - void initScanIntervals(); - void initIndices(); +// void initScanCounts(); +// void initScanIntervals(); +// void initIndices(); std::vector<bool> buildMergeIndices(const DetectorInfo &other) const; std::vector<bool> buildMergeSyncScanIndices(const DetectorInfo &other) const; void checkSizes(const DetectorInfo &other) const; void checkIdenticalIntervals(const DetectorInfo &other, const size_t index1, const size_t index2) const; - bool m_isSyncScan{true}; +// bool m_isSyncScan{true}; + void merge(const DetectorInfo &other); Kernel::cow_ptr<std::vector<bool>> m_isMonitor{nullptr}; Kernel::cow_ptr<std::vector<bool>> m_isMasked{nullptr}; @@ -129,13 +136,15 @@ private: Eigen::aligned_allocator<Eigen::Quaterniond>>> m_rotations{nullptr}; - Kernel::cow_ptr<std::vector<size_t>> m_scanCounts{nullptr}; - Kernel::cow_ptr<std::vector<std::pair<int64_t, int64_t>>> m_scanIntervals{ - nullptr}; +// Kernel::cow_ptr<std::vector<size_t>> m_scanCounts{nullptr}; + size_t m_scanCounts = 1; + std::vector<std::pair<int64_t, int64_t>> m_scanIntervals{{0, 0}}; + // Kernel::cow_ptr<std::vector<std::pair<int64_t, int64_t>>> m_scanIntervals{ + // nullptr}; /// For (detector index, time index) -> linear index conversions - Kernel::cow_ptr<std::vector<std::vector<size_t>>> m_indexMap{nullptr}; +// Kernel::cow_ptr<std::vector<std::vector<size_t>>> m_indexMap{nullptr}; /// For linear index -> (detector index, time index) conversions - Kernel::cow_ptr<std::vector<std::pair<size_t, size_t>>> m_indices{nullptr}; +// Kernel::cow_ptr<std::vector<std::pair<size_t, size_t>>> m_indices{nullptr}; ComponentInfo *m_componentInfo = nullptr; // Geometry::ComponentInfo owner }; @@ -234,9 +243,10 @@ DetectorInfo::linearIndex(const std::pair<size_t, size_t> &index) const { // so even in the time dependent case no translation is necessary. if (index.second == 0) return index.first; - if (m_isSyncScan) + else +// if (m_isSyncScan) return index.first + size() * index.second; - return (*m_indexMap)[index.first][index.second]; +// return (*m_indexMap)[index.first][index.second]; } } // namespace Beamline diff --git a/Framework/Beamline/src/ComponentInfo.cpp b/Framework/Beamline/src/ComponentInfo.cpp index 6baef33046eb9e3973cd0eee83ee5f21f78b384c..da08cfdba2b5bb0c6b040b97be53b9d79bdcf663 100644 --- a/Framework/Beamline/src/ComponentInfo.cpp +++ b/Framework/Beamline/src/ComponentInfo.cpp @@ -566,13 +566,16 @@ ComponentType ComponentInfo::componentType(const size_t componentIndex) const { * @param index : Component Index * @return Number of scans for component index */ -size_t ComponentInfo::scanCount(const size_t index) const { - if (m_detectorInfo && isDetector(index)) - return m_detectorInfo->scanCount(index); - else { - return m_scanCounts; - } +size_t ComponentInfo::scanCount() const { + return m_scanCounts; } +// size_t ComponentInfo::scanCount(const size_t index) const { +// if (m_detectorInfo && isDetector(index)) +// return m_detectorInfo->scanCount(index); +// else { +// return m_scanCounts; +// } +// } size_t ComponentInfo::scanSize() const { const auto detectorScanSize = m_detectorInfo ? m_detectorInfo->scanSize() : 0; @@ -603,14 +606,28 @@ void ComponentInfo::checkNoTimeDependence() const { * @param index component index, time index pair * @return offset interval times since epoch */ -std::pair<int64_t, int64_t> -ComponentInfo::scanInterval(const std::pair<size_t, size_t> &index) const { - if (m_detectorInfo && isDetector(index.first)) - return m_detectorInfo->scanInterval(index); - if (!m_scanIntervals) - return {0, 0}; - return (*m_scanIntervals)[index.second]; -} +const std::vector<std::pair<int64_t, int64_t>> &ComponentInfo::scanIntervals() const { +// if (!m_scanIntervals) { +// // // return &{0, 0}; +// std::vector<std::pair<int64_t, int64_t>>* dummy_vec = new std::vector<std::pair<int64_t, int64_t>> (1); +// // std::pair<int64_t, int64_t> dummy_pair = {0,0}; +// // dummy_vec[0] = dummy_pair; +// dummy_vec->push_back({0, 0}); +// return *dummy_vec; +// // return new std::vector<std::pair<int64_t, int64_t>> {{0,0}}; +// } else { + return m_scanIntervals; + // } +} + +// std::pair<int64_t, int64_t> +// ComponentInfo::scanInterval(const std::pair<size_t, size_t> &index) const { +// if (m_detectorInfo && isDetector(index.first)) +// return m_detectorInfo->scanInterval(index); +// if (!m_scanIntervals) +// return {0, 0}; +// return (*m_scanIntervals)[index.second]; +// } void ComponentInfo::checkSpecialIndices(size_t componentIndex) const { if (!isDetector(componentIndex)) { @@ -628,10 +645,10 @@ void ComponentInfo::setScanInterval( // Enforces setting scan intervals BEFORE time indexed positions and rotations checkNoTimeDependence(); checkScanInterval(interval); - if (!m_scanIntervals) { - initScanIntervals(); - } - m_scanIntervals.access()[0] = interval; + // if (!m_scanIntervals) { + // initScanIntervals(); + // } + m_scanIntervals[0] = interval; if (m_detectorInfo) { m_detectorInfo->setScanInterval(interval); } @@ -654,14 +671,15 @@ this has no time dependence prior to this operation. void ComponentInfo::merge(const ComponentInfo &other) { checkNoTimeDependence(); const auto &toMerge = buildMergeIndicesSync(other); - for (size_t timeIndex = 0; timeIndex < other.m_scanIntervals->size(); + for (size_t timeIndex = 0; timeIndex < other.m_scanIntervals.size(); ++timeIndex) { if (!toMerge[timeIndex]) continue; - auto &scanIntervals = m_scanIntervals.access(); + // auto &scanIntervals = m_scanIntervals.access(); auto &positions = m_positions.access(); auto &rotations = m_rotations.access(); - scanIntervals.push_back((*other.m_scanIntervals)[timeIndex]); + // scanIntervals.push_back((*other.m_scanIntervals)[timeIndex]); + m_scanIntervals.push_back(other.m_scanIntervals[timeIndex]); const size_t indexStart = other.linearIndex({0, timeIndex}); size_t indexEnd = indexStart + nonDetectorSize(); positions.insert(positions.end(), other.m_positions->begin() + indexStart, @@ -677,12 +695,12 @@ void ComponentInfo::merge(const ComponentInfo &other) { std::vector<bool> ComponentInfo::buildMergeIndicesSync(const ComponentInfo &other) const { checkSizes(other); - std::vector<bool> merge(other.m_scanIntervals->size(), true); + std::vector<bool> merge(other.m_scanIntervals.size(), true); - for (size_t t1 = 0; t1 < other.m_scanIntervals->size(); ++t1) { - for (size_t t2 = 0; t2 < m_scanIntervals->size(); ++t2) { - const auto &interval1 = (*other.m_scanIntervals)[t1]; - const auto &interval2 = (*m_scanIntervals)[t2]; + for (size_t t1 = 0; t1 < other.m_scanIntervals.size(); ++t1) { + for (size_t t2 = 0; t2 < m_scanIntervals.size(); ++t2) { + const auto &interval1 = other.m_scanIntervals[t1]; + const auto &interval2 = m_scanIntervals[t2]; if (interval1 == interval2) { for (size_t compIndex = 0; compIndex < nonDetectorSize(); ++compIndex) { const size_t linearIndex1 = other.linearIndex({compIndex, t1}); @@ -702,8 +720,8 @@ ComponentInfo::buildMergeIndicesSync(const ComponentInfo &other) const { void ComponentInfo::checkSizes(const ComponentInfo &other) const { if (size() != other.size()) failMerge("size mismatch"); - if (!m_scanIntervals || !other.m_scanIntervals) - failMerge("scan intervals not defined"); + // if (!m_scanIntervals || !other.m_scanIntervals) + // failMerge("scan intervals not defined"); } void ComponentInfo::checkIdenticalIntervals( @@ -730,11 +748,11 @@ size_t ComponentInfo::nonDetectorSize() const { return 0; } -void ComponentInfo::initScanIntervals() { - checkNoTimeDependence(); - m_scanIntervals = Kernel::make_cow<std::vector<std::pair<int64_t, int64_t>>>( - 1, std::pair<int64_t, int64_t>{0, 1}); -} +// void ComponentInfo::initScanIntervals() { +// checkNoTimeDependence(); +// m_scanIntervals = Kernel::make_cow<std::vector<std::pair<int64_t, int64_t>>>( +// 1, std::pair<int64_t, int64_t>{0, 1}); +// } } // namespace Beamline } // namespace Mantid diff --git a/Framework/Beamline/src/DetectorInfo.cpp b/Framework/Beamline/src/DetectorInfo.cpp index e284ddaa58fd34b37085fdcc02d495edff73c2c8..cc791cb6175f2e38cd967f6633fda6069aedbf7b 100644 --- a/Framework/Beamline/src/DetectorInfo.cpp +++ b/Framework/Beamline/src/DetectorInfo.cpp @@ -61,12 +61,15 @@ bool DetectorInfo::isEquivalent(const DetectorInfo &other) const { // Scanning related fields. Not testing m_scanCounts and m_indexMap since // those just are internally derived from m_indices. - if (m_scanIntervals && other.m_scanIntervals && - !(m_scanIntervals == other.m_scanIntervals) && - (*m_scanIntervals != *other.m_scanIntervals)) + // if (m_scanIntervals && other.m_scanIntervals && + // !(m_scanIntervals == other.m_scanIntervals) && + // (*m_scanIntervals != *other.m_scanIntervals)) + // return false; + if (m_scanIntervals != other.m_scanIntervals) return false; - if (m_indices && other.m_indices && !(m_indices == other.m_indices) && - (*m_indices != *other.m_indices)) +// if (m_indices && other.m_indices && !(m_indices == other.m_indices) && +// (*m_indices != *other.m_indices)) + if (m_scanCounts && other.m_scanCounts && !(m_scanCounts == other.m_scanCounts)) return false; // Positions: Absolute difference matter, so comparison is not relative. @@ -114,7 +117,7 @@ size_t DetectorInfo::scanSize() const { * Returns true if all of the detectors all have the same scan interval. Will * return false if DetectorInfo is not scanning. */ -bool DetectorInfo::isSyncScan() const { return isScanning() && m_isSyncScan; } +// bool DetectorInfo::isSyncScan() const { return isScanning() && m_isSyncScan; } /// Returns true if the detector with given detector index is a monitor. bool DetectorInfo::isMonitor(const size_t index) const { @@ -162,27 +165,45 @@ void DetectorInfo::setMasked(const std::pair<size_t, size_t> &index, } /// Returns the scan count of the detector with given detector index. -size_t DetectorInfo::scanCount(const size_t index) const { +// size_t DetectorInfo::scanCount(const size_t index) const { +size_t DetectorInfo::scanCount() const { if (!m_scanCounts) return 1; - if (m_isSyncScan) - return (*m_scanCounts)[0]; - return (*m_scanCounts)[index]; +// if (m_isSyncScan) + else + return m_scanCounts; +// return (*m_scanCounts)[0]; +// return m_scanCounts.access()[0]; //? +// return (*m_scanCounts)[index]; } /** Returns the scan interval of the detector with given index. * * The interval start and end values would typically correspond to nanoseconds * since 1990, as in Types::Core::DateAndTime. */ -std::pair<int64_t, int64_t> -DetectorInfo::scanInterval(const std::pair<size_t, size_t> &index) const { - if (!m_scanIntervals) - return {0, 0}; - if (m_isSyncScan) - return (*m_scanIntervals)[index.second]; - return (*m_scanIntervals)[linearIndex(index)]; +const std::vector<std::pair<int64_t, int64_t>> &DetectorInfo::scanIntervals() const { +// if (!m_scanIntervals) { +// // // return &{0, 0}; +// std::vector<std::pair<int64_t, int64_t>>* dummy_vec = new std::vector<std::pair<int64_t, int64_t>> (1); +// // std::pair<int64_t, int64_t> dummy_pair = {0,0}; +// // dummy_vec[0] = dummy_pair; +// dummy_vec->push_back({0, 0}); +// return *dummy_vec; +// // return new std::vector<std::pair<int64_t, int64_t>> {{0,0}}; +// } else { + return m_scanIntervals; + // } } +// std::pair<int64_t, int64_t> +// DetectorInfo::scanInterval(const std::pair<size_t, size_t> &index) const { +// if (!m_scanIntervals) +// return {0, 0}; +// if (m_isSyncScan) +// return (*m_scanIntervals)[index.second]; +// return (*m_scanIntervals)[linearIndex(index)]; +// } + namespace { void checkScanInterval(const std::pair<int64_t, int64_t> &interval) { if (interval.first >= interval.second) @@ -199,20 +220,20 @@ void checkScanInterval(const std::pair<int64_t, int64_t> &interval) { * to modify scan intervals for a DetectorInfo with time-dependent detectors, * i.e., time intervals must be set with this method before merging individual * scans. */ -void DetectorInfo::setScanInterval( - const size_t index, const std::pair<int64_t, int64_t> &interval) { - // Time intervals must be set up before adding time sensitive - // positions/rotations hence check below. - checkNoTimeDependence(); - checkScanInterval(interval); - if (!m_scanIntervals) - initScanIntervals(); - if (m_isSyncScan) - throw std::runtime_error("DetectorInfo has been initialized with a " - "synchonous scan, cannot set scan interval for " - "individual detector."); - m_scanIntervals.access()[index] = interval; -} +// void DetectorInfo::setScanInterval( +// const size_t index, const std::pair<int64_t, int64_t> &interval) { +// // Time intervals must be set up before adding time sensitive +// // positions/rotations hence check below. +// checkNoTimeDependence(); +// checkScanInterval(interval); +// if (!m_scanIntervals) +// initScanIntervals(); +// if (m_isSyncScan) +// throw std::runtime_error("DetectorInfo has been initialized with a " +// "synchonous scan, cannot set scan interval for " +// "individual detector."); +// m_scanIntervals.access()[index] = interval; +// } /** Set the scan interval for all detectors. * @@ -222,17 +243,17 @@ void DetectorInfo::setScanInterval( const std::pair<int64_t, int64_t> &interval) { checkNoTimeDependence(); checkScanInterval(interval); - if (!m_scanIntervals) { - m_scanIntervals = - Kernel::make_cow<std::vector<std::pair<int64_t, int64_t>>>( - 1, std::pair<int64_t, int64_t>{0, 1}); - } - if (!m_isSyncScan) { - throw std::runtime_error( - "DetectorInfo has been initialized with a " - "asynchonous scan, cannot set synchronous scan interval."); - } - m_scanIntervals.access()[0] = interval; + // if (!m_scanIntervals) { + // m_scanIntervals = + // Kernel::make_cow<std::vector<std::pair<int64_t, int64_t>>>( + // 1, std::pair<int64_t, int64_t>{0, 1}); + // } +// if (!m_isSyncScan) { +// throw std::runtime_error( +// "DetectorInfo has been initialized with a " +// "asynchonous scan, cannot set synchronous scan interval."); +// } + m_scanIntervals[0] = interval; } namespace { @@ -240,13 +261,13 @@ void failMerge(const std::string &what) { throw std::runtime_error(std::string("Cannot merge DetectorInfo: ") + what); } -std::pair<size_t, size_t> -getIndex(const Kernel::cow_ptr<std::vector<std::pair<size_t, size_t>>> &indices, - const size_t index) { - if (!indices) - return {index, 0}; - return (*indices)[index]; -} +// std::pair<size_t, size_t> +// getIndex(const Kernel::cow_ptr<std::vector<std::pair<size_t, size_t>>> &indices, +// const size_t index) { +// if (!indices) +// return {index, 0}; +// return (*indices)[index]; +// } } // namespace /** Merges the contents of other into this. @@ -261,52 +282,54 @@ getIndex(const Kernel::cow_ptr<std::vector<std::pair<size_t, size_t>>> &indices, * 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) { - if (!m_scanCounts) - initScanCounts(); - if (m_isSyncScan) { - const auto &merge = buildMergeSyncScanIndices(other); - for (size_t timeIndex = 0; timeIndex < other.m_scanIntervals->size(); - ++timeIndex) { - if (!merge[timeIndex]) - continue; - auto &scanIntervals = m_scanIntervals.access(); - auto &isMasked = m_isMasked.access(); - auto &positions = m_positions.access(); - auto &rotations = m_rotations.access(); - m_scanCounts.access()[0]++; - scanIntervals.push_back((*other.m_scanIntervals)[timeIndex]); - const size_t indexStart = other.linearIndex({0, timeIndex}); - size_t indexEnd = indexStart + size(); - isMasked.insert(isMasked.end(), other.m_isMasked->begin() + indexStart, - other.m_isMasked->begin() + indexEnd); - positions.insert(positions.end(), other.m_positions->begin() + indexStart, - other.m_positions->begin() + indexEnd); - rotations.insert(rotations.end(), other.m_rotations->begin() + indexStart, - other.m_rotations->begin() + indexEnd); - } - return; - } - const auto &merge = buildMergeIndices(other); - if (!m_indexMap) - initIndices(); - // Temporary to accumulate scan counts (need original for index offset). - auto scanCounts(m_scanCounts); - for (size_t linearIndex = 0; linearIndex < other.m_positions->size(); - ++linearIndex) { - if (!merge[linearIndex]) +// if (!m_scanCounts) +// initScanCounts(); +// if (m_isSyncScan) { + const auto &merge = buildMergeSyncScanIndices(other); + for (size_t timeIndex = 0; timeIndex < other.m_scanIntervals.size(); + ++timeIndex) { + if (!merge[timeIndex]) continue; - auto newIndex = getIndex(other.m_indices, linearIndex); - const size_t detIndex = newIndex.first; - newIndex.second += scanCount(detIndex); - scanCounts.access()[detIndex]++; - m_indexMap.access()[detIndex].push_back((*m_indices).size()); - m_indices.access().push_back(newIndex); - m_isMasked.access().push_back((*other.m_isMasked)[linearIndex]); - m_positions.access().push_back((*other.m_positions)[linearIndex]); - m_rotations.access().push_back((*other.m_rotations)[linearIndex]); - m_scanIntervals.access().push_back((*other.m_scanIntervals)[linearIndex]); + // auto &scanIntervals = m_scanIntervals.access(); + auto &isMasked = m_isMasked.access(); + auto &positions = m_positions.access(); + auto &rotations = m_rotations.access(); +// m_scanCounts.access()[0]++; + m_scanCounts++; + // scanIntervals.push_back((*other.m_scanIntervals)[timeIndex]); + m_scanIntervals.push_back(other.m_scanIntervals[timeIndex]); + const size_t indexStart = other.linearIndex({0, timeIndex}); + size_t indexEnd = indexStart + size(); + isMasked.insert(isMasked.end(), other.m_isMasked->begin() + indexStart, + other.m_isMasked->begin() + indexEnd); + positions.insert(positions.end(), other.m_positions->begin() + indexStart, + other.m_positions->begin() + indexEnd); + rotations.insert(rotations.end(), other.m_rotations->begin() + indexStart, + other.m_rotations->begin() + indexEnd); } - m_scanCounts = std::move(scanCounts); + return; +// } +// const auto &merge = buildMergeIndices(other); +// if (!m_indexMap) +// initIndices(); +// // Temporary to accumulate scan counts (need original for index offset). +// auto scanCounts(m_scanCounts); +// for (size_t linearIndex = 0; linearIndex < other.m_positions->size(); +// ++linearIndex) { +// if (!merge[linearIndex]) +// continue; +// auto newIndex = getIndex(other.m_indices, linearIndex); +// const size_t detIndex = newIndex.first; +// newIndex.second += scanCount(detIndex); +// scanCounts.access()[detIndex]++; +// m_indexMap.access()[detIndex].push_back((*m_indices).size()); +// m_indices.access().push_back(newIndex); +// m_isMasked.access().push_back((*other.m_isMasked)[linearIndex]); +// m_positions.access().push_back((*other.m_positions)[linearIndex]); +// m_rotations.access().push_back((*other.m_rotations)[linearIndex]); +// m_scanIntervals.access().push_back((*other.m_scanIntervals)[linearIndex]); +// } +// m_scanCounts = std::move(scanCounts); } void DetectorInfo::setComponentInfo(ComponentInfo *componentInfo) { @@ -344,71 +367,71 @@ Eigen::Vector3d DetectorInfo::samplePosition() const { return m_componentInfo->samplePosition(); } -void DetectorInfo::initScanCounts() { - checkNoTimeDependence(); - if (m_isSyncScan) - m_scanCounts = Kernel::make_cow<std::vector<size_t>>(1, 1); - else - m_scanCounts = Kernel::make_cow<std::vector<size_t>>(size(), 1); -} - -void DetectorInfo::initScanIntervals() { - checkNoTimeDependence(); - m_isSyncScan = false; - m_scanIntervals = Kernel::make_cow<std::vector<std::pair<int64_t, int64_t>>>( - size(), std::pair<int64_t, int64_t>{0, 1}); -} - -void DetectorInfo::initIndices() { - checkNoTimeDependence(); - m_indexMap = Kernel::make_cow<std::vector<std::vector<size_t>>>(); - m_indices = Kernel::make_cow<std::vector<std::pair<size_t, size_t>>>(); - auto &indexMap = m_indexMap.access(); - auto &indices = m_indices.access(); - indexMap.reserve(size()); - indices.reserve(size()); - // No time dependence, so both the detector index and the linear index are i. - for (size_t i = 0; i < size(); ++i) { - indexMap.emplace_back(1, i); - indices.emplace_back(i, 0); - } -} - -// Indices returned here are the list of linear indexes not to merge -std::vector<bool> -DetectorInfo::buildMergeIndices(const DetectorInfo &other) const { - checkSizes(other); - std::vector<bool> merge(other.m_positions->size(), true); - - for (size_t linearIndex1 = 0; linearIndex1 < other.m_positions->size(); - ++linearIndex1) { - const size_t detIndex = getIndex(other.m_indices, linearIndex1).first; - const auto &interval1 = (*other.m_scanIntervals)[linearIndex1]; - for (size_t timeIndex = 0; timeIndex < scanCount(detIndex); ++timeIndex) { - const auto linearIndex2 = linearIndex({detIndex, timeIndex}); - const auto &interval2 = (*m_scanIntervals)[linearIndex2]; - if (interval1 == interval2) { - checkIdenticalIntervals(other, linearIndex1, linearIndex2); - merge[linearIndex1] = false; - } else if ((interval1.first < interval2.second) && - (interval1.second > interval2.first)) { - failMerge("scan intervals overlap but not identical"); - } - } - } - return merge; -} +// void DetectorInfo::initScanCounts() { +// checkNoTimeDependence(); +// // if (m_isSyncScan) +// m_scanCounts = Kernel::make_cow<std::vector<size_t>>(1, 1); +// // else +// // m_scanCounts = Kernel::make_cow<std::vector<size_t>>(size(), 1); +// } + +// void DetectorInfo::initScanIntervals() { +// checkNoTimeDependence(); +// m_isSyncScan = false; +// m_scanIntervals = Kernel::make_cow<std::vector<std::pair<int64_t, int64_t>>>( +// size(), std::pair<int64_t, int64_t>{0, 1}); +// } + +// void DetectorInfo::initIndices() { +// checkNoTimeDependence(); +// m_indexMap = Kernel::make_cow<std::vector<std::vector<size_t>>>(); +// m_indices = Kernel::make_cow<std::vector<std::pair<size_t, size_t>>>(); +// auto &indexMap = m_indexMap.access(); +// auto &indices = m_indices.access(); +// indexMap.reserve(size()); +// indices.reserve(size()); +// // No time dependence, so both the detector index and the linear index are i. +// for (size_t i = 0; i < size(); ++i) { +// indexMap.emplace_back(1, i); +// indices.emplace_back(i, 0); +// } +// } + +// // Indices returned here are the list of linear indexes not to merge +// std::vector<bool> +// DetectorInfo::buildMergeIndices(const DetectorInfo &other) const { +// checkSizes(other); +// std::vector<bool> merge(other.m_positions->size(), true); +// +// for (size_t linearIndex1 = 0; linearIndex1 < other.m_positions->size(); +// ++linearIndex1) { +// const size_t detIndex = getIndex(other.m_indices, linearIndex1).first; +// const auto &interval1 = (*other.m_scanIntervals)[linearIndex1]; +// for (size_t timeIndex = 0; timeIndex < scanCount(detIndex); ++timeIndex) { +// const auto linearIndex2 = linearIndex({detIndex, timeIndex}); +// const auto &interval2 = (*m_scanIntervals)[linearIndex2]; +// if (interval1 == interval2) { +// checkIdenticalIntervals(other, linearIndex1, linearIndex2); +// merge[linearIndex1] = false; +// } else if ((interval1.first < interval2.second) && +// (interval1.second > interval2.first)) { +// failMerge("scan intervals overlap but not identical"); +// } +// } +// } +// return merge; +// } // Indices returned here are the list of time indexes not to merge std::vector<bool> DetectorInfo::buildMergeSyncScanIndices(const DetectorInfo &other) const { checkSizes(other); - std::vector<bool> merge(other.m_scanIntervals->size(), true); + std::vector<bool> merge(other.m_scanIntervals.size(), true); - for (size_t t1 = 0; t1 < other.m_scanIntervals->size(); ++t1) { - for (size_t t2 = 0; t2 < m_scanIntervals->size(); ++t2) { - const auto &interval1 = (*other.m_scanIntervals)[t1]; - const auto &interval2 = (*m_scanIntervals)[t2]; + for (size_t t1 = 0; t1 < other.m_scanIntervals.size(); ++t1) { + for (size_t t2 = 0; t2 < m_scanIntervals.size(); ++t2) { + const auto &interval1 = other.m_scanIntervals[t1]; + const auto &interval2 = m_scanIntervals[t2]; if (interval1 == interval2) { for (size_t detIndex = 0; detIndex < size(); ++detIndex) { const size_t linearIndex1 = other.linearIndex({detIndex, t1}); @@ -428,10 +451,10 @@ DetectorInfo::buildMergeSyncScanIndices(const DetectorInfo &other) const { void DetectorInfo::checkSizes(const DetectorInfo &other) const { if (size() != other.size()) failMerge("size mismatch"); - if (!m_scanIntervals || !other.m_scanIntervals) - failMerge("scan intervals not defined"); - if (m_isSyncScan != other.m_isSyncScan) - failMerge("both or none of the scans must be synchronous"); + // if (!m_scanIntervals || !other.m_scanIntervals) + // failMerge("scan intervals not defined"); +// if (m_isSyncScan != other.m_isSyncScan) +// failMerge("both or none of the scans must be synchronous"); if (!(m_isMonitor == other.m_isMonitor) && (*m_isMonitor != *other.m_isMonitor)) failMerge("monitor flags mismatch"); diff --git a/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp b/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp index 9d8a9df2e58f01c75002b0e0dc9094b8b2ebee18..393268d0c4e570efe6f52a2f3a781363196e33b0 100644 --- a/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp +++ b/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp @@ -194,11 +194,14 @@ MatrixWorkspace_sptr ScanningWorkspaceBuilder::buildWorkspace() const { auto outputWorkspace = create<Workspace2D>( m_instrument, m_nDetectors * m_nTimeIndexes, m_histogram); + auto &outputComponentInfo = outputWorkspace->mutableComponentInfo(); + outputComponentInfo.setScanInterval(m_timeRanges[0]); + + buildOutputComponentInfo(outputComponentInfo); + auto &outputDetectorInfo = outputWorkspace->mutableDetectorInfo(); outputDetectorInfo.setScanInterval(m_timeRanges[0]); - buildOutputDetectorInfo(outputDetectorInfo); - if (!m_positions.empty()) buildPositions(outputDetectorInfo); @@ -224,14 +227,14 @@ MatrixWorkspace_sptr ScanningWorkspaceBuilder::buildWorkspace() const { return boost::shared_ptr<MatrixWorkspace>(std::move(outputWorkspace)); } -void ScanningWorkspaceBuilder::buildOutputDetectorInfo( - Geometry::DetectorInfo &outputDetectorInfo) const { +void ScanningWorkspaceBuilder::buildOutputComponentInfo( + Geometry::ComponentInfo &outputComponentInfo) const { auto mergeWorkspace = create<Workspace2D>(m_instrument, m_nDetectors, m_histogram.binEdges()); for (size_t i = 1; i < m_nTimeIndexes; ++i) { - auto &mergeDetectorInfo = mergeWorkspace->mutableDetectorInfo(); - mergeDetectorInfo.setScanInterval(m_timeRanges[i]); - outputDetectorInfo.merge(mergeDetectorInfo); + auto &mergeComponentInfo = mergeWorkspace->mutableComponentInfo(); + mergeComponentInfo.setScanInterval(m_timeRanges[i]); + outputComponentInfo.merge(mergeComponentInfoInfo); } } @@ -256,7 +259,7 @@ void ScanningWorkspaceBuilder::buildPositions( void ScanningWorkspaceBuilder::buildRelativeRotationsForScans( Geometry::DetectorInfo &outputDetectorInfo) const { for (size_t i = 0; i < outputDetectorInfo.size(); ++i) { - for (size_t j = 0; j < outputDetectorInfo.scanCount(i); ++j) { + for (size_t j = 0; j < outputDetectorInfo.scanCount(); ++j) { if (outputDetectorInfo.isMonitor({i, j})) continue; auto position = outputDetectorInfo.position({i, j}); diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h index 18924dc6f9c4c58bd5cfba333c228106e53d708f..0fb3ac5db9beb19af557317f6b3738a41e960647 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h @@ -78,7 +78,7 @@ public: size_t size() const; size_t scanSize() const; bool isScanning() const; - bool isSyncScan() const; +// bool isSyncScan() const; bool isMonitor(const size_t index) const; bool isMonitor(const std::pair<size_t, size_t> &index) const; @@ -119,16 +119,18 @@ public: /// This will throw an out of range exception if the detector does not exist. size_t indexOf(const detid_t id) const { return m_detIDToIndex->at(id); } - size_t scanCount(const size_t index) const; - std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> - scanInterval(const std::pair<size_t, size_t> &index) const; - void setScanInterval(const size_t index, - const std::pair<Types::Core::DateAndTime, - Types::Core::DateAndTime> &interval); +// size_t scanCount(const size_t index) const; + size_t scanCount() const; + const std::vector<std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>> &scanIntervals() const; +// std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> +// scanInterval(const std::pair<size_t, size_t> &index) const; +// void setScanInterval(const size_t index, +// const std::pair<Types::Core::DateAndTime, +// Types::Core::DateAndTime> &interval); void setScanInterval(const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> &interval); - void merge(const DetectorInfo &other); +// void merge(const DetectorInfo &other); friend class API::SpectrumInfo; friend class Instrument; @@ -138,6 +140,8 @@ private: boost::shared_ptr<const Geometry::IDetector> getDetectorPtr(const size_t index) const; + // void merge(const DetectorInfo &other); + /// Pointer to the actual DetectorInfo object (non-wrapping part). std::unique_ptr<Beamline::DetectorInfo> m_detectorInfo; diff --git a/Framework/Geometry/src/Instrument/DetectorInfo.cpp b/Framework/Geometry/src/Instrument/DetectorInfo.cpp index 11b9d095149d3cee38dd3637522d77eab102da75..786cd1dc34629dc4e3b7234a6327fdf0e6c81fb6 100644 --- a/Framework/Geometry/src/Instrument/DetectorInfo.cpp +++ b/Framework/Geometry/src/Instrument/DetectorInfo.cpp @@ -92,7 +92,7 @@ bool DetectorInfo::isScanning() const { return m_detectorInfo->isScanning(); } /// Returns true if the beamline has scanning detectors and they have all the /// same scan intervals. -bool DetectorInfo::isSyncScan() const { return m_detectorInfo->isSyncScan(); } +// bool DetectorInfo::isSyncScan() const { return m_detectorInfo->isSyncScan(); } /// Returns true if the detector is a monitor. bool DetectorInfo::isMonitor(const size_t index) const { @@ -321,20 +321,29 @@ const std::vector<detid_t> &DetectorInfo::detectorIDs() const { } /// Returns the scan count of the detector with given detector index. -size_t DetectorInfo::scanCount(const size_t index) const { - return m_detectorInfo->scanCount(index); +size_t DetectorInfo::scanCount() const { + return m_detectorInfo->scanCount(); } /** Returns the scan interval of the detector with given index. * * The interval start and end values would typically correspond to nanoseconds * since 1990, as in Types::Core::DateAndTime. */ -std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> -DetectorInfo::scanInterval(const std::pair<size_t, size_t> &index) const { - const auto &interval = m_detectorInfo->scanInterval(index); - return {interval.first, interval.second}; +const std::vector<std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>> &DetectorInfo::scanIntervals() const { + std::vector<std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>> *intervals_vector = new std::vector<std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>> ((m_detectorInfo->scanIntervals()).size()); + for (auto it = m_detectorInfo->scanIntervals().begin(); it != m_detectorInfo->scanIntervals().end(); ++it) { + intervals_vector->push_back({(*it).first, (*it).second}); + } + return *intervals_vector; +// return m_detectorInfo->scanIntervals(); } +// std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> +// DetectorInfo::scanInterval(const std::pair<size_t, size_t> &index) const { +// const auto &interval = m_detectorInfo->scanInterval(index); +// return {interval.first, interval.second}; +// } + /** Set the scan interval of the detector with given detector index. * * The interval start and end values would typically correspond to nanoseconds @@ -343,13 +352,13 @@ DetectorInfo::scanInterval(const std::pair<size_t, size_t> &index) const { * to modify scan intervals for a DetectorInfo with time-dependent detectors, * i.e., time intervals must be set with this method before merging individual * scans. */ -void DetectorInfo::setScanInterval( - const size_t index, - const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> - &interval) { - m_detectorInfo->setScanInterval(index, {interval.first.totalNanoseconds(), - interval.second.totalNanoseconds()}); -} +// void DetectorInfo::setScanInterval( +// const size_t index, +// const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> +// &interval) { +// m_detectorInfo->setScanInterval(index, {interval.first.totalNanoseconds(), +// interval.second.totalNanoseconds()}); +// } /** Set the scan interval for all detectors. * @@ -367,9 +376,9 @@ void DetectorInfo::setScanInterval( * Scan intervals in both other and this must be set. Intervals must be * identical or non-overlapping. If they are identical all other parameters (for * that index) must match. */ -void DetectorInfo::merge(const DetectorInfo &other) { - m_detectorInfo->merge(*other.m_detectorInfo); -} +// void DetectorInfo::merge(const DetectorInfo &other) { +// m_detectorInfo->merge(*other.m_detectorInfo); +// } const Geometry::IDetector &DetectorInfo::getDetector(const size_t index) const { size_t thread = static_cast<size_t>(PARALLEL_THREAD_NUMBER);