From 81d95bfbc48914d55c1257b2f679e5b5fe0d5136 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Tue, 27 Jun 2023 10:36:18 +0200
Subject: [PATCH] Move preview generation before addons to avoid interference

---
 src/calng/corrections/AgipdCorrection.py | 26 ++++++++++++------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/calng/corrections/AgipdCorrection.py b/src/calng/corrections/AgipdCorrection.py
index 2765209a..0bd3daf3 100644
--- a/src/calng/corrections/AgipdCorrection.py
+++ b/src/calng/corrections/AgipdCorrection.py
@@ -776,19 +776,7 @@ class AgipdCorrection(base_correction.BaseCorrection):
 
         buffer_handle, buffer_array = self._shmem_buffer.next_slot()
         self.kernel_runner.correct(self._correction_flag_enabled)
-        for addon in self._enabled_addons:
-            addon.post_correction(
-                self.kernel_runner.processed_data, cell_table, pulse_table, data_hash
-            )
-        self.kernel_runner.reshape(
-            output_order=self.unsafe_get("dataFormat.outputAxisOrder"),
-            out=buffer_array,
-        )
-        for addon in self._enabled_addons:
-            addon.post_reshape(
-                buffer_array, cell_table, pulse_table, data_hash
-            )
-        # after reshape, data for dataOutput is now safe in its own buffer
+        # previews are generated before any addons are run
         with self.warning_context(
             "processingState", base_correction.WarningLampType.PREVIEW_SETTINGS
         ) as warn:
@@ -812,6 +800,18 @@ class AgipdCorrection(base_correction.BaseCorrection):
             preview_raw_gain,
             preview_gain_map,
         ) = self.kernel_runner.compute_previews(preview_slice_index)
+        for addon in self._enabled_addons:
+            addon.post_correction(
+                self.kernel_runner.processed_data, cell_table, pulse_table, data_hash
+            )
+        self.kernel_runner.reshape(
+            output_order=self.unsafe_get("dataFormat.outputAxisOrder"),
+            out=buffer_array,
+        )
+        for addon in self._enabled_addons:
+            addon.post_reshape(
+                buffer_array, cell_table, pulse_table, data_hash
+            )
 
         # reusing input data hash for sending
         if self._use_shmem_handles:
-- 
GitLab