From b0b854ccbf8dc552e143b741faf94858b103f339 Mon Sep 17 00:00:00 2001
From: Pete Peterson <petersonpf@ornl.gov>
Date: Tue, 14 Nov 2017 14:13:30 -0500
Subject: [PATCH] Not compress empty event lists

---
 Framework/DataObjects/src/EventList.cpp | 47 ++++++++++++++-----------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/Framework/DataObjects/src/EventList.cpp b/Framework/DataObjects/src/EventList.cpp
index 381196aaa25..78859e08dbf 100644
--- a/Framework/DataObjects/src/EventList.cpp
+++ b/Framework/DataObjects/src/EventList.cpp
@@ -1784,29 +1784,34 @@ void EventList::compressEvents(double tolerance, EventList *destination) {
 void EventList::compressFatEvents(
     const double tolerance, const Mantid::Types::Core::DateAndTime &timeStart,
     const double seconds, EventList *destination) {
-  switch (eventType) {
-  case WEIGHTED_NOTIME:
-    throw std::invalid_argument(
-        "Cannot compress events that do not have pulsetime");
-  case TOF:
-    this->sortPulseTimeTOFDelta(timeStart, seconds);
-    compressFatEventsHelper(this->events, destination->weightedEvents,
-                            tolerance, timeStart, seconds);
-    break;
-  case WEIGHTED:
-    this->sortPulseTimeTOFDelta(timeStart, seconds);
-    if (destination == this) {
-      // Put results in a temp output
-      std::vector<WeightedEvent> out;
-      compressFatEventsHelper(this->weightedEvents, out, tolerance, timeStart,
-                              seconds);
-      // Put it back
-      this->weightedEvents.swap(out);
-    } else {
-      compressFatEventsHelper(this->weightedEvents, destination->weightedEvents,
+
+  // only worry about non-empty EventLists
+  if (this->getNumberEvents() > 0) {
+    switch (eventType) {
+    case WEIGHTED_NOTIME:
+      throw std::invalid_argument(
+          "Cannot compress events that do not have pulsetime");
+    case TOF:
+      this->sortPulseTimeTOFDelta(timeStart, seconds);
+      compressFatEventsHelper(this->events, destination->weightedEvents,
                               tolerance, timeStart, seconds);
+      break;
+    case WEIGHTED:
+      this->sortPulseTimeTOFDelta(timeStart, seconds);
+      if (destination == this) {
+        // Put results in a temp output
+        std::vector<WeightedEvent> out;
+        compressFatEventsHelper(this->weightedEvents, out, tolerance, timeStart,
+                                seconds);
+        // Put it back
+        this->weightedEvents.swap(out);
+      } else {
+        compressFatEventsHelper(this->weightedEvents,
+                                destination->weightedEvents, tolerance,
+                                timeStart, seconds);
+      }
+      break;
     }
-    break;
   }
   // In all cases, you end up WEIGHTED_NOTIME.
   destination->eventType = WEIGHTED;
-- 
GitLab