From cc61d846240a7232861a55482984336d9f3f693a Mon Sep 17 00:00:00 2001
From: Jose Borreguero <borreguero@gmail.com>
Date: Mon, 6 Aug 2018 11:43:56 -0400
Subject: [PATCH] Refs #23175 Add Number to Events workspaces

---
 Framework/Algorithms/src/AppendSpectra.cpp    | 19 ++++++++++---------
 Framework/Algorithms/test/AppendSpectraTest.h |  7 +++++--
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/Framework/Algorithms/src/AppendSpectra.cpp b/Framework/Algorithms/src/AppendSpectra.cpp
index 8b76af15f72..ba58b76499d 100644
--- a/Framework/Algorithms/src/AppendSpectra.cpp
+++ b/Framework/Algorithms/src/AppendSpectra.cpp
@@ -86,15 +86,16 @@ void AppendSpectra::exec() {
   const int number = getProperty("Number");
 
   if (event_ws1 && event_ws2) {
-    // Both are event workspaces. Use the special method
-    MatrixWorkspace_sptr output = this->execEvent(*event_ws1, *event_ws2);
-    if (number > 1)
-      g_log.warning("Number property is ignored for event workspaces");
-    if (mergeLogs)
-      combineLogs(ws1->run(), ws2->run(), output->mutableRun());
-    // Set the output workspace
-    setProperty("OutputWorkspace", output);
-    return;
+      // Both are event workspaces. Use the special method
+      DataObjects::EventWorkspace_sptr output = this->execEvent(*event_ws1, *event_ws2);
+      for (int i = 1; i < number; i++) {
+          output = this->execEvent(*output, *event_ws2);
+      }
+      if (mergeLogs)
+          combineLogs(ws1->run(), ws2->run(), output->mutableRun());
+      // Set the output workspace
+      setProperty("OutputWorkspace", boost::dynamic_pointer_cast<MatrixWorkspace>(output));
+      return;
   }
   // So it is a workspace 2D.
 
diff --git a/Framework/Algorithms/test/AppendSpectraTest.h b/Framework/Algorithms/test/AppendSpectraTest.h
index bdf76d8bb24..271e43d8225 100644
--- a/Framework/Algorithms/test/AppendSpectraTest.h
+++ b/Framework/Algorithms/test/AppendSpectraTest.h
@@ -178,7 +178,7 @@ public:
   }
 
   //----------------------------------------------------------------------------------------------
-  void doTest(bool event, bool combineLogs = false) {
+  void doTest(bool event, bool combineLogs=false, int number=1) {
     MatrixWorkspace_sptr ws1, ws2, out;
     int numBins = 20;
 
@@ -212,6 +212,7 @@ public:
     TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace1", ws1Name));
     TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace2", ws2Name));
     TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", ws1Name));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("Number", number));
     if (combineLogs)
       alg.setProperty("MergeLogs", true);
     TS_ASSERT_THROWS_NOTHING(alg.execute();)
@@ -224,7 +225,7 @@ public:
     if (!out)
       return;
 
-    TS_ASSERT_EQUALS(out->getNumberHistograms(), 15);
+    TS_ASSERT_EQUALS(out->getNumberHistograms(), 10 + 5 * number);
     TS_ASSERT_EQUALS(out->blocksize(), numBins);
 
     for (size_t wi = 0; wi < out->getNumberHistograms(); wi++) {
@@ -246,6 +247,8 @@ public:
 
   void test_events() { doTest(true); }
 
+  void test_number_events() {doTest(true, true, 3);}
+
   void test_2D() { doTest(false); }
 
   void test_events_mergeLogs() { doTest(true, true); }
-- 
GitLab