From 44abfdb92f435a678307636abd284b76a6202227 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Tue, 27 Jun 2023 14:16:57 +0200
Subject: [PATCH] Reorder correct / preview / reshape

---
 src/calng/corrections/AgipdCorrection.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/calng/corrections/AgipdCorrection.py b/src/calng/corrections/AgipdCorrection.py
index 0bd3daf3..212462f8 100644
--- a/src/calng/corrections/AgipdCorrection.py
+++ b/src/calng/corrections/AgipdCorrection.py
@@ -775,13 +775,11 @@ class AgipdCorrection(base_correction.BaseCorrection):
             self.log_status_warn(f"Unknown exception when loading data to GPU: {e}")
 
         buffer_handle, buffer_array = self._shmem_buffer.next_slot()
-        self.kernel_runner.correct(self._correction_flag_enabled)
-        # previews are generated before any addons are run
+        # first prepare previews (not affected by addons)
+        self.kernel_runner.correct(self._correction_flag_preview)
         with self.warning_context(
             "processingState", base_correction.WarningLampType.PREVIEW_SETTINGS
         ) as warn:
-            if self._correction_flag_enabled != self._correction_flag_preview:
-                self.kernel_runner.correct(self._correction_flag_preview)
             (
                 preview_slice_index,
                 preview_cell,
@@ -800,6 +798,11 @@ class AgipdCorrection(base_correction.BaseCorrection):
             preview_raw_gain,
             preview_gain_map,
         ) = self.kernel_runner.compute_previews(preview_slice_index)
+        # TODO: start writing out previews asynchronously in the background
+
+        # then prepare full corrected data
+        if self._correction_flag_enabled != self._correction_flag_preview:
+            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
-- 
GitLab