From f6d60ea9cb69bc3ab460db80559d17017132e150 Mon Sep 17 00:00:00 2001
From: David Hammer <dhammer@mailbox.org>
Date: Thu, 13 Feb 2025 17:00:05 +0100
Subject: [PATCH] WIP: make hook to do what Mads wants

---
 src/calng/base_correction.py             | 6 ++++++
 src/calng/base_kernel_runner.py          | 9 +++++++++
 src/calng/corrections/AgipdCorrection.py | 5 +++++
 3 files changed, 20 insertions(+)

diff --git a/src/calng/base_correction.py b/src/calng/base_correction.py
index aed5cba3..51d6f5cd 100644
--- a/src/calng/base_correction.py
+++ b/src/calng/base_correction.py
@@ -907,6 +907,12 @@ class BaseCorrection(PythonDevice):
                     warn_fun=warn,
                 )
 
+            # extra hook: should be refactored away
+            # maybe it's time the runner learns about hashes
+            self.kernel_runner.extra_processing(
+                data_hash, processed_buffer, cell_table, pulse_table, *additional_data
+            )
+
             for addon in self._enabled_addons:
                 addon.post_correction(
                     timestamp.getTrainId(),
diff --git a/src/calng/base_kernel_runner.py b/src/calng/base_kernel_runner.py
index a5ba784b..c6cbc368 100644
--- a/src/calng/base_kernel_runner.py
+++ b/src/calng/base_kernel_runner.py
@@ -389,6 +389,15 @@ class BaseKernelRunner:
             )
         return self._correction_applied_hash, processed_buffers[0], preview_buffers
 
+    def extra_processing(
+        self, out_hash, processed_data, cell_table, pulse_table, *additional_data
+    ):
+        """Temporary hook for doing naughty things not yet possible with addons. For
+        example, counting number of pixels in different gain stages for AGIPD. We should
+        either start passing more stuff around so addons can do this or refactor the
+        device-runner interface."""
+        pass
+
 
 kernel_dir = pathlib.Path(__file__).absolute().parent / "kernels"
 
diff --git a/src/calng/corrections/AgipdCorrection.py b/src/calng/corrections/AgipdCorrection.py
index 75a2032c..02a502d3 100644
--- a/src/calng/corrections/AgipdCorrection.py
+++ b/src/calng/corrections/AgipdCorrection.py
@@ -343,6 +343,11 @@ class AgipdBaseRunner(base_kernel_runner.BaseKernelRunner):
             self.num_pixels_fs,
         )
 
+    def extra_processing(
+        self, out_hash, processed_dat,a cell_table, pulse_table, gain_map
+    ):
+        out_hash["numPixelsPerGainStage"] = ...
+
     @property
     def _gm_map_shape(self):
         return self._map_shape + (3,)  # for gain-mapped constants
-- 
GitLab