From f7d09427f427afbadca854f7c42fa8045570ca70 Mon Sep 17 00:00:00 2001
From: meschi <emilio.meschi@cern.ch>
Date: Wed, 26 Oct 2022 12:57:51 +0200
Subject: [PATCH] fix closing of file at end of run

---
 src/OutputByOrbit.cc | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/OutputByOrbit.cc b/src/OutputByOrbit.cc
index ab8b40c7..02d046e5 100644
--- a/src/OutputByOrbit.cc
+++ b/src/OutputByOrbit.cc
@@ -29,11 +29,18 @@ void OutputByOrbitStream::OutputFixedOrbits(Slice &out) {
         control.output_force_write) { // i.e should be writing data
       n = fwrite(out.begin(), 1, out.size(),
                  output_file_handler_.getFile(control.run_number, index));
+      current_file_size += n;
+    } else if (output_file_handler_.hasFile()) {
+      // the run has been stopped so drop but first check if there is a last
+      // file to close
+      LOG(TRACE) << "the run was stopped. queueing the last file for close and "
+                    "rename ";
+      output_file_handler_.enqueue_current_file_for_close_and_move_maybe();
     }
-    current_file_size += n;
+
   } else { // i.e should not currently be writing data - but then we should
            // never get here in the first place
-    output_file_handler_.enqueue_current_file_for_close_and_move_maybe();
+    LOG(TRACE) << "got an empty slice ";
   }
 }
 
-- 
GitLab