From b7cda726f5829f0fa3c18e7b924873058e5d676c Mon Sep 17 00:00:00 2001
From: Simon Heybrock <simon.heybrock@esss.se>
Date: Thu, 15 Sep 2016 08:42:06 +0200
Subject: [PATCH] Re #0. Sharing Y and E data in ExtractSpectra when possible.

---
 Framework/Algorithms/src/ExtractSpectra.cpp | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/Framework/Algorithms/src/ExtractSpectra.cpp b/Framework/Algorithms/src/ExtractSpectra.cpp
index d151a6a4330..f0792c1e0a8 100644
--- a/Framework/Algorithms/src/ExtractSpectra.cpp
+++ b/Framework/Algorithms/src/ExtractSpectra.cpp
@@ -140,6 +140,8 @@ void ExtractSpectra::execHistogram() {
                                                oldX.begin() + m_maxX);
   }
 
+  bool doCrop = ((m_minX != 0) || (m_maxX != m_inputWorkspace->x(0).size()));
+
   Progress prog(this, 0.0, 1.0, (m_workspaceIndexList.size()));
   // Loop over the required workspace indices, copying in the desired bins
   for (int j = 0; j < static_cast<int>(m_workspaceIndexList.size()); ++j) {
@@ -163,12 +165,17 @@ void ExtractSpectra::execHistogram() {
       outputWorkspace->setSharedDx(j, m_inputWorkspace->sharedDx(i));
     }
 
-    auto &oldY = m_inputWorkspace->y(i);
-    outputWorkspace->mutableY(j)
-        .assign(oldY.begin() + m_minX, oldY.begin() + (m_maxX - m_histogram));
-    auto &oldE = m_inputWorkspace->e(i);
-    outputWorkspace->mutableE(j)
-        .assign(oldE.begin() + m_minX, oldE.begin() + (m_maxX - m_histogram));
+    if (doCrop) {
+      auto &oldY = m_inputWorkspace->y(i);
+      outputWorkspace->mutableY(j)
+          .assign(oldY.begin() + m_minX, oldY.begin() + (m_maxX - m_histogram));
+      auto &oldE = m_inputWorkspace->e(i);
+      outputWorkspace->mutableE(j)
+          .assign(oldE.begin() + m_minX, oldE.begin() + (m_maxX - m_histogram));
+    } else {
+      outputWorkspace->setSharedY(j, m_inputWorkspace->sharedY(i));
+      outputWorkspace->setSharedE(j, m_inputWorkspace->sharedE(i));
+    }
 
     // copy over the axis entry for each spectrum, regardless of the type of
     // axes present
-- 
GitLab