From bcf51b7644ecf260bd83d7e72e85b98968f2db76 Mon Sep 17 00:00:00 2001
From: Raquel Alvarez <raquel.alvarez-banos@stfc.ac.uk>
Date: Wed, 5 Oct 2016 08:15:25 +0100
Subject: [PATCH] Re #17673 Updating Stitch1D

---
 .../inc/MantidAlgorithms/Stitch1D.h           |  9 ++-
 Framework/Algorithms/src/Stitch1D.cpp         | 61 ++++++++++---------
 2 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h b/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
index c866aa8fd33..b1f3be04a83 100644
--- a/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
+++ b/Framework/Algorithms/inc/MantidAlgorithms/Stitch1D.h
@@ -2,7 +2,6 @@
 #define MANTID_ALGORITHMS_STITCH1D_H_
 
 #include "MantidAPI/Algorithm.h"
-#include "MantidKernel/cow_ptr.h"
 
 #include <boost/tuple/tuple.hpp>
 
@@ -63,13 +62,13 @@ private:
                        const double &intesectionMax) const;
 
   /// Get the rebin parameters
-  Mantid::MantidVec getRebinParams(Mantid::API::MatrixWorkspace_sptr &lhsWS,
-                                   Mantid::API::MatrixWorkspace_sptr &rhsWS,
-                                   const bool scaleRHS) const;
+  std::vector<double> getRebinParams(Mantid::API::MatrixWorkspace_sptr &lhsWS,
+                                     Mantid::API::MatrixWorkspace_sptr &rhsWS,
+                                     const bool scaleRHS) const;
   /// Perform rebin
   Mantid::API::MatrixWorkspace_sptr
   rebin(Mantid::API::MatrixWorkspace_sptr &input,
-        const Mantid::MantidVec &params);
+        const std::vector<double> &params);
   /// Perform integration
   Mantid::API::MatrixWorkspace_sptr
   integration(Mantid::API::MatrixWorkspace_sptr &input, const double &start,
diff --git a/Framework/Algorithms/src/Stitch1D.cpp b/Framework/Algorithms/src/Stitch1D.cpp
index 26e770d3557..69f33af439d 100644
--- a/Framework/Algorithms/src/Stitch1D.cpp
+++ b/Framework/Algorithms/src/Stitch1D.cpp
@@ -3,6 +3,9 @@
 #include "MantidAPI/MatrixWorkspace.h"
 #include "MantidAPI/HistogramValidator.h"
 #include "MantidAPI/WorkspaceFactory.h"
+#include "MantidHistogramData/HistogramX.h"
+#include "MantidHistogramData/HistogramY.h"
+#include "MantidHistogramData/HistogramE.h"
 #include "MantidKernel/ArrayProperty.h"
 #include "MantidKernel/PropertyWithValue.h"
 #include "MantidKernel/RebinParamsValidator.h"
@@ -17,16 +20,16 @@
 
 using namespace Mantid::Kernel;
 using namespace Mantid::API;
-using Mantid::MantidVec;
+using Mantid::HistogramData::HistogramX;
+using Mantid::HistogramData::HistogramY;
+using Mantid::HistogramData::HistogramE;
 
 namespace {
 
 typedef boost::tuple<double, double> MinMaxTuple;
 MinMaxTuple calculateXIntersection(MatrixWorkspace_sptr lhsWS,
                                    MatrixWorkspace_sptr rhsWS) {
-  MantidVec lhs_x = lhsWS->readX(0);
-  MantidVec rhs_x = rhsWS->readX(0);
-  return MinMaxTuple(rhs_x.front(), lhs_x.back());
+  return MinMaxTuple(rhsWS->x(0).front(), lhsWS->x(0).back());
 }
 
 bool isNonzero(double i) { return (0 != i); }
@@ -67,17 +70,17 @@ MatrixWorkspace_sptr Stitch1D::maskAllBut(int a1, int a2,
   for (int i = 0; i < histogramCount; ++i) {
     PARALLEL_START_INTERUPT_REGION
     // Copy over the bin boundaries
-    product->setX(i, source->refX(i));
+    product->setSharedX(i, source->sharedX(i));
     // Copy over the data
-    const MantidVec &sourceY = source->readY(i);
-    const MantidVec &sourceE = source->readE(i);
+    const auto &sourceY = source->y(i);
+    const auto &sourceE = source->e(i);
 
     // initially zero - out the data.
-    product->dataY(i) = MantidVec(sourceY.size(), 0);
-    product->dataE(i) = MantidVec(sourceE.size(), 0);
+    product->mutableY(i) = HistogramY(sourceY.size(), 0);
+    product->mutableE(i) = HistogramE(sourceE.size(), 0);
 
-    MantidVec &newY = product->dataY(i);
-    MantidVec &newE = product->dataE(i);
+    auto &newY = product->mutableY(i);
+    auto &newE = product->mutableE(i);
 
     // Copy over the non-zero stuff
     std::copy(sourceY.begin() + a1 + 1, sourceY.begin() + a2,
@@ -105,8 +108,8 @@ void Stitch1D::maskInPlace(int a1, int a2, MatrixWorkspace_sptr source) {
   for (int i = 0; i < histogramCount; ++i) {
     PARALLEL_START_INTERUPT_REGION
     // Copy over the data
-    MantidVec &sourceY = source->dataY(i);
-    MantidVec &sourceE = source->dataE(i);
+    auto &sourceY = source->mutableY(i);
+    auto &sourceE = source->mutableE(i);
 
     for (int i = a1; i < a2; ++i) {
       sourceY[i] = 0;
@@ -234,24 +237,24 @@ double Stitch1D::getEndOverlap(const double &intesectionMin,
  @param scaleRHS :: Scale the right hand side workspace
  @return a vector<double> contianing the rebinning parameters
  */
-MantidVec Stitch1D::getRebinParams(MatrixWorkspace_sptr &lhsWS,
-                                   MatrixWorkspace_sptr &rhsWS,
-                                   const bool scaleRHS) const {
-  MantidVec inputParams = this->getProperty("Params");
+std::vector<double> Stitch1D::getRebinParams(MatrixWorkspace_sptr &lhsWS,
+                                             MatrixWorkspace_sptr &rhsWS,
+                                             const bool scaleRHS) const {
+  std::vector<double> inputParams = this->getProperty("Params");
   Property *prop = this->getProperty("Params");
   const bool areParamsDefault = prop->isDefault();
 
-  const MantidVec &lhsX = lhsWS->readX(0);
+  const auto &lhsX = lhsWS->x(0);
   auto it = std::min_element(lhsX.begin(), lhsX.end());
   const double minLHSX = *it;
 
-  const MantidVec &rhsX = rhsWS->readX(0);
+  const auto &rhsX = rhsWS->x(0);
   it = std::max_element(rhsX.begin(), rhsX.end());
   const double maxRHSX = *it;
 
-  MantidVec result;
+  std::vector<double> result;
   if (areParamsDefault) {
-    MantidVec calculatedParams;
+    std::vector<double> calculatedParams;
 
     // Calculate the step size based on the existing step size of the LHS
     // workspace. That way scale factors should be reasonably maintained.
@@ -272,7 +275,7 @@ MantidVec Stitch1D::getRebinParams(MatrixWorkspace_sptr &lhsWS,
     result = calculatedParams;
   } else {
     if (inputParams.size() == 1) {
-      MantidVec calculatedParams;
+      std::vector<double> calculatedParams;
       calculatedParams.push_back(minLHSX);
       calculatedParams.push_back(inputParams.front()); // Use the step supplied.
       calculatedParams.push_back(maxRHSX);
@@ -290,7 +293,7 @@ MantidVec Stitch1D::getRebinParams(MatrixWorkspace_sptr &lhsWS,
  @return A shared pointer to the resulting MatrixWorkspace
  */
 MatrixWorkspace_sptr Stitch1D::rebin(MatrixWorkspace_sptr &input,
-                                     const MantidVec &params) {
+                                     const std::vector<double> &params) {
   auto rebin = this->createChildAlgorithm("Rebin");
   rebin->setProperty("InputWorkspace", input);
   rebin->setProperty("Params", params);
@@ -312,8 +315,8 @@ MatrixWorkspace_sptr Stitch1D::rebin(MatrixWorkspace_sptr &input,
     std::vector<size_t> &infYIndexes = m_infYIndexes[i];
     std::vector<size_t> &infEIndexes = m_infEIndexes[i];
     // Copy over the data
-    MantidVec &sourceY = outWS->dataY(i);
-    MantidVec &sourceE = outWS->dataE(i);
+    auto &sourceY = outWS->mutableY(i);
+    auto &sourceE = outWS->mutableE(i);
 
     for (size_t j = 0; j < sourceY.size(); ++j) {
       const double &value = sourceY[j];
@@ -470,7 +473,7 @@ bool Stitch1D::hasNonzeroErrors(MatrixWorkspace_sptr ws) {
     PARALLEL_START_INTERUPT_REGION
     if (!hasNonZeroErrors) // Keep checking
     {
-      auto e = ws->readE(i);
+      auto e = ws->e(i);
       auto it = std::find_if(e.begin(), e.end(), isNonzero);
       if (it != e.end()) {
         PARALLEL_CRITICAL(has_non_zero) {
@@ -577,8 +580,8 @@ void Stitch1D::exec() {
       ratio = rhsOverlapIntegrated / lhsOverlapIntegrated;
       rebinnedLHS = rebinnedLHS * ratio;
     }
-    scaleFactor = ratio->readY(0).front();
-    errorScaleFactor = ratio->readE(0).front();
+    scaleFactor = ratio->y(0).front();
+    errorScaleFactor = ratio->e(0).front();
     if (scaleFactor < 1e-2 || scaleFactor > 1e2 ||
         boost::math::isnan(scaleFactor)) {
       std::stringstream messageBuffer;
@@ -634,7 +637,7 @@ void Stitch1D::reinsertSpecialValues(MatrixWorkspace_sptr ws) {
   for (int i = 0; i < histogramCount; ++i) {
     PARALLEL_START_INTERUPT_REGION
     // Copy over the data
-    MantidVec &sourceY = ws->dataY(i);
+    auto &sourceY = ws->mutableY(i);
 
     for (auto j : m_nanYIndexes[i]) {
       sourceY[j] = std::numeric_limits<double>::quiet_NaN();
-- 
GitLab