From c45cc2e9eb958be700eaf19458419db5d6385e8c Mon Sep 17 00:00:00 2001
From: Neil Vaytet <neil.vaytet@esss.se>
Date: Fri, 17 Aug 2018 15:14:53 +0200
Subject: [PATCH] Refs #23238 : fixing more compilation errors. Not finished

---
 Framework/Algorithms/src/MergeRuns.cpp        | 42 +++++++++++++++----
 .../ScanningWorkspaceBuilder.h                |  2 +-
 .../src/ScanningWorkspaceBuilder.cpp          |  3 +-
 .../MantidGeometry/Instrument/ComponentInfo.h |  3 ++
 .../Geometry/src/Instrument/ComponentInfo.cpp |  9 ++++
 5 files changed, 50 insertions(+), 9 deletions(-)

diff --git a/Framework/Algorithms/src/MergeRuns.cpp b/Framework/Algorithms/src/MergeRuns.cpp
index bbd4eabd2c3..df70e3c88c5 100644
--- a/Framework/Algorithms/src/MergeRuns.cpp
+++ b/Framework/Algorithms/src/MergeRuns.cpp
@@ -10,6 +10,7 @@
 #include "MantidDataObjects/Workspace2D.h"
 #include "MantidDataObjects/WorkspaceCreation.h"
 #include "MantidGeometry/Instrument.h"
+#include "MantidGeometry/Instrument/ComponentInfo.h"
 #include "MantidGeometry/Instrument/DetectorInfo.h"
 #include "MantidIndexing/IndexInfo.h"
 #include "MantidKernel/ArrayProperty.h"
@@ -118,7 +119,9 @@ MergeRuns::buildScanningOutputWorkspace(const MatrixWorkspace_sptr &outWS,
   MatrixWorkspace_sptr newOutWS = DataObjects::create<MatrixWorkspace>(
       *outWS, numOutputSpectra, outWS->histogram(0).binEdges());
 
-  newOutWS->mutableDetectorInfo().merge(addeeWS->detectorInfo());
+  // newOutWS->mutableDetectorInfo().merge(addeeWS->detectorInfo());
+  newOutWS->mutableComponentInfo().merge(addeeWS->componentInfo());
+
 
   if (newOutWS->detectorInfo().scanSize() == outWS->detectorInfo().scanSize()) {
     // In this case the detector info objects were identical. We just add the
@@ -715,19 +718,24 @@ std::vector<SpectrumDefinition> MergeRuns::buildScanIntervals(
     const DetectorInfo &newOutDetInfo) {
   std::vector<SpectrumDefinition> newAddeeSpecDefs(addeeSpecDefs.size());
 
+  const auto &addeeScanIntervals = addeeDetInfo.scanIntervals();
+  const auto &outScanIntervals = outDetInfo.scanIntervals();
+  const auto &newOutScanIntervals = newOutDetInfo.scanIntervals();
+
   PARALLEL_FOR_NO_WSP_CHECK()
   for (int64_t i = 0; i < int64_t(addeeSpecDefs.size()); ++i) {
     for (auto &index : addeeSpecDefs[i]) {
       SpectrumDefinition newSpecDef;
-      const auto &addeeScanInterval = addeeDetInfo.scanInterval(index);
-      if (addeeScanInterval == outDetInfo.scanInterval(index)) {
+      // const auto &addeeScanInterval = addeeDetInfo.scanInterval(index);
+      // if (addeeScanInterval == outDetInfo.scanInterval(index)) {
+      if (addeeScanIntervals[index] == outScanIntervals[index]) {
         newSpecDef.add(index.first, index.second);
       } else {
         // Find the correct time index for this entry
-        for (size_t i = 0; i < newOutDetInfo.scanCount(index.first); i++) {
-          if (addeeScanInterval ==
-              newOutDetInfo.scanInterval({index.first, i})) {
-            newSpecDef.add(index.first, i);
+        for (size_t j = 0; j < newOutDetInfo.scanCount(); j++) {
+          if (addeeScanIntervals[index] ==
+              newOutScanInterval[{index.first, j}]) {
+            newSpecDef.add(index.first, j);
           }
         }
       }
@@ -735,6 +743,26 @@ std::vector<SpectrumDefinition> MergeRuns::buildScanIntervals(
     }
   }
 
+  // PARALLEL_FOR_NO_WSP_CHECK()
+  // for (int64_t i = 0; i < int64_t(addeeSpecDefs.size()); ++i) {
+  //   for (auto &index : addeeSpecDefs[i]) {
+  //     SpectrumDefinition newSpecDef;
+  //     const auto &addeeScanInterval = addeeDetInfo.scanInterval(index);
+  //     if (addeeScanInterval == outDetInfo.scanInterval(index)) {
+  //       newSpecDef.add(index.first, index.second);
+  //     } else {
+  //       // Find the correct time index for this entry
+  //       for (size_t i = 0; i < newOutDetInfo.scanCount(index.first); i++) {
+  //         if (addeeScanInterval ==
+  //             newOutDetInfo.scanInterval({index.first, i})) {
+  //           newSpecDef.add(index.first, i);
+  //         }
+  //       }
+  //     }
+  //     newAddeeSpecDefs[i] = newSpecDef;
+  //   }
+  // }
+
   return newAddeeSpecDefs;
 }
 
diff --git a/Framework/DataObjects/inc/MantidDataObjects/ScanningWorkspaceBuilder.h b/Framework/DataObjects/inc/MantidDataObjects/ScanningWorkspaceBuilder.h
index cc5b59dc6c2..fc812da2665 100644
--- a/Framework/DataObjects/inc/MantidDataObjects/ScanningWorkspaceBuilder.h
+++ b/Framework/DataObjects/inc/MantidDataObjects/ScanningWorkspaceBuilder.h
@@ -99,7 +99,7 @@ private:
   IndexingType m_indexingType;
 
   void
-  buildOutputDetectorInfo(Geometry::DetectorInfo &outputDetectorInfo) const;
+  buildOutputComponentInfo(Geometry::ComponentInfo &outputComponentInfo) const;
 
   void buildPositions(Geometry::DetectorInfo &outputDetectorInfo) const;
   void buildRotations(Geometry::DetectorInfo &outputDetectorInfo) const;
diff --git a/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp b/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp
index 393268d0c4e..c31f6acdb93 100644
--- a/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp
+++ b/Framework/DataObjects/src/ScanningWorkspaceBuilder.cpp
@@ -5,6 +5,7 @@
 #include "MantidDataObjects/WorkspaceCreation.h"
 #include "MantidGeometry/Instrument.h"
 #include "MantidGeometry/Instrument/DetectorInfo.h"
+#include "MantidGeometry/Instrument/ComponentInfo.h"
 #include "MantidHistogramData/BinEdges.h"
 #include "MantidHistogramData/Histogram.h"
 #include "MantidHistogramData/LinearGenerator.h"
@@ -234,7 +235,7 @@ void ScanningWorkspaceBuilder::buildOutputComponentInfo(
   for (size_t i = 1; i < m_nTimeIndexes; ++i) {
     auto &mergeComponentInfo = mergeWorkspace->mutableComponentInfo();
     mergeComponentInfo.setScanInterval(m_timeRanges[i]);
-    outputComponentInfo.merge(mergeComponentInfoInfo);
+    outputComponentInfo.merge(mergeComponentInfo);
   }
 }
 
diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/ComponentInfo.h b/Framework/Geometry/inc/MantidGeometry/Instrument/ComponentInfo.h
index 5da5f185b4d..9af0f004d79 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>
@@ -150,6 +151,8 @@ public:
                           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);
   void merge(const ComponentInfo &other);
   size_t scanSize() const;
   friend class Instrument;
diff --git a/Framework/Geometry/src/Instrument/ComponentInfo.cpp b/Framework/Geometry/src/Instrument/ComponentInfo.cpp
index 73e92efa2d6..a78088adba5 100644
--- a/Framework/Geometry/src/Instrument/ComponentInfo.cpp
+++ b/Framework/Geometry/src/Instrument/ComponentInfo.cpp
@@ -421,9 +421,18 @@ ComponentInfo::componentType(const size_t componentIndex) const {
 
 void ComponentInfo::setScanInterval(
     const std::pair<int64_t, int64_t> &interval) {
+  // const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>
+        // &interval) {
   m_componentInfo->setScanInterval(interval);
 }
 
+void ComponentInfo::setScanInterval(
+    // const std::pair<int64_t, int64_t> &interval) {
+  const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime>
+        &interval) {
+  m_componentInfo->setScanInterval({interval.first.totalNanoseconds(),interval.second.totalNanoseconds()});
+}
+
 void ComponentInfo::merge(const ComponentInfo &other) {
   m_componentInfo->merge(*other.m_componentInfo);
 }
-- 
GitLab