From 03010533b333b720f669adeef5b40857c3cbd6e7 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Wed, 16 Oct 2024 18:03:03 +0200
Subject: [PATCH] Compute preview reductions before running addons

---
 src/calng/base_correction.py | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py
index 6d56b2d2..35486688 100644
--- a/src/calng/base_correction.py
+++ b/src/calng/base_correction.py
@@ -884,6 +884,19 @@ class BaseCorrection(PythonDevice):
                 image_data, cell_table, *additional_data
             )
             data_hash["corrections"] = corrections
+
+            # write previews first so addons cannot mess with them
+            with self.warning_context(
+                "processingState", WarningLampType.PREVIEW_SETTINGS
+            ) as warn:
+                self.preview_friend.write_outputs(
+                    *previews,
+                    timestamp=timestamp,
+                    cell_table=cell_table,
+                    pulse_table=pulse_table,
+                    warn_fun=warn,
+                )
+
             for addon in self._enabled_addons:
                 addon.post_correction(
                     timestamp.getTrainId(),
@@ -894,17 +907,6 @@ class BaseCorrection(PythonDevice):
                 )
             self.kernel_runner.reshape(processed_buffer, out=buffer_array)
 
-        with self.warning_context(
-            "processingState", WarningLampType.PREVIEW_SETTINGS
-        ) as warn:
-            self.preview_friend.write_outputs(
-                *previews,
-                timestamp=timestamp,
-                cell_table=cell_table,
-                pulse_table=pulse_table,
-                warn_fun=warn,
-            )
-
         for addon in self._enabled_addons:
             addon.post_reshape(
                 timestamp.getTrainId(), buffer_array, cell_table, pulse_table, data_hash
-- 
GitLab