From 68d63495d65a92cdfe4f42121bf90aecb1af9234 Mon Sep 17 00:00:00 2001
From: Mads Jakobsen <mads.jakobsen@xfel.eu>
Date: Wed, 12 Mar 2025 14:19:33 +0100
Subject: [PATCH] adding debug info

---
 .../src/onlinemid_karabo/processor.py         | 32 +++++++++++--------
 .../onlinemid/dataplotters/agipd_module.py    |  7 ++--
 .../src/onlinemid/utils/image_plotting.py     |  8 +++--
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/karabo_devices/shared_mem_processor/src/onlinemid_karabo/processor.py b/karabo_devices/shared_mem_processor/src/onlinemid_karabo/processor.py
index 031aeb8..4538c67 100644
--- a/karabo_devices/shared_mem_processor/src/onlinemid_karabo/processor.py
+++ b/karabo_devices/shared_mem_processor/src/onlinemid_karabo/processor.py
@@ -33,7 +33,7 @@ from TrainMatcher import TrainMatcher
 
 from calngUtils import shmem_utils, trackers
 
-from onlinemid import agipd_module_name_from_mid_agipd_source, agipd_module_name_from_agipd_module_number, hash_from_dict, generate_test_data, Periodic_Output
+from onlinemid import agipd_module_name_from_mid_agipd_source, agipd_module_name_from_agipd_module_number, hash_from_dict, generate_test_data, Periodic_Output, AgipdModulePlotter
 
 from onlinexpcsutils import onlinexpcsutils
 import runningstats
@@ -144,7 +144,9 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher):
         
 
         # Periodic_Output
-        self.periodic_output = Periodic_Output(output_period=10) # default time at 300 sec
+        self.periodic_output = Periodic_Output() # default time at 300 sec
+
+        self.onlineImagePlotter = AgipdModulePlotter()
 
         # expose the get xpcs settings function
         self.KARABO_SLOT(self.get_OnlineMIDSettings)
@@ -350,6 +352,11 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher):
         
         message = f"processing detector data from modules {[pair[0] for pair in detector_data_list]} of shape {[pair[1].shape for pair in detector_data_list]}"
         self.periodic_output.log(self.log.INFO, message)
+
+        print("asking to plot")
+        current_img = self.onlineImagePlotter.plot(train_id, detector_data_list[0][1])
+        
+
         # time_to_handle_list_0 = time.perf_counter()
         
         # self.online_processing_memory, online_output_dict = onlinexpcsutils.compute_xpcs_from_detector_data_list(
@@ -394,7 +401,7 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher):
         # plot accumulating sum and lit pixel counter for panel data
         # time_to_handle_list_3 = time.perf_counter()
         
-        #plot_hash = Hash()
+        plot_hash = Hash()
         
         #        npArray_sum = onlinexpcsutils.get_accumulating_sum(self.xpcs_processing_memory, selected_module_key)
         #        if npArray_sum is not None:
@@ -405,8 +412,8 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher):
         #            plot_hash['data.accumulating_lit_bunch'] = ImageData(npArray_lit_pixel_counter)
 
         #npArray_currentImage = onlinexpcsutils.get_current_Image(self.online_processing_memory, selected_module_key)
-        #if npArray_currentImage is not None:
-        #    plot_hash['data.current_det_image'] = ImageData(npArray_currentImage)
+        if current_img is not None:
+            plot_hash['data.current_det_image'] = ImageData(current_img)
 
 
 
@@ -419,19 +426,18 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher):
 
         # time_to_handle_list_4 = time.perf_counter()
 
-        #        my_timestamp = Timestamp(Epochstamp(), Trainstamp(train_id))
-        #        myname = self.get('deviceId')
-        #        if self.assembled_output is not None:
-        #            self.assembled_output.write(
-        #                    plot_hash, ChannelMetaData(f'{myname}:plots', my_timestamp), copyAllData=False
-        #                )
-        #            self.assembled_output.update(safeNDArray=True)
+        my_timestamp = Timestamp(Epochstamp(), Trainstamp(train_id))
+        myname = self.get('deviceId')
+        if self.assembled_output is not None:
+            self.assembled_output.write(
+                plot_hash, ChannelMetaData(f'{myname}:plots', my_timestamp), copyAllData=False
+                )
+        self.assembled_output.update(safeNDArray=True)
 
 
         # print("time_to_handle_list _ 4", time.perf_counter() - time_to_handle_list_4)        
         
         #             time_to_handle_list_5 = time.perf_counter()
-        output_hash = Hash() 
         
         '''
                         if runningstats_output_dict is not None:
diff --git a/python_package/src/onlinemid/dataplotters/agipd_module.py b/python_package/src/onlinemid/dataplotters/agipd_module.py
index 55dbf5b..c0d6d31 100644
--- a/python_package/src/onlinemid/dataplotters/agipd_module.py
+++ b/python_package/src/onlinemid/dataplotters/agipd_module.py
@@ -10,6 +10,7 @@ import numpy as np
 
 def plot_data(data):
 
+    print("AGIPD MODULE PLOTE FUNCTION CALLED! suing pyplot to plot...")
     plt.switch_backend("agg")
     fig = plt.figure(figsize=(15,10))
 
@@ -25,23 +26,25 @@ def plot_data(data):
         canvas.get_width_height()[::-1] + (4,))
             
     plt.close(fig)
-
+    print("AGIPD MODULE PLOTE FUNCTION CALLED! ... DONE")
     return image_buffer
 
 
 class AgipdModulePlotter():
 
     def __init__(self):
+        print("AGIPD PLOTTER INIT")
         self.onlineImagePlotter = OnlineImagePlotter(figsize=(15,10))
 
 
     
     def plot(self, train_id, module_data):
-
+        print("AGIPD PLOTTER PLOT")
         if module_data.shape != (512, 128):
             print(f"Error, AgipdModulePlotter.plot received data must be of shape (512, 128), and not {module_data.shape}")
             return
         
+        print("AGIPD PLOTTER call get image buffer")
         img = self.onlineImagePlotter.get_image_buffer_if_ready_and_make_new_image(train_id, plot_data, module_data)
 
         return img
diff --git a/python_package/src/onlinemid/utils/image_plotting.py b/python_package/src/onlinemid/utils/image_plotting.py
index 66c8592..caf0aea 100644
--- a/python_package/src/onlinemid/utils/image_plotting.py
+++ b/python_package/src/onlinemid/utils/image_plotting.py
@@ -27,9 +27,10 @@ def plot_receiver(connection, shared_mem_for_plot, shared_mem_trainId):
 
         if item is None:
             break
-           
-        output = item['fun'](item['arg']) 
         
+        print("PLOT RECEIVER RECEIVED DATA, CALLONG FUN")
+        output = item['fun'](item['arg']) 
+        print("PLOT RECEIVER RECEIVED DATA, FUN EXECUTED, YAY!")
         npArray = tonumpyarray(shared_mem_for_plot)
         npArray[:] = output.reshape(-1)
         shared_mem_trainId.value = item['train_id']
@@ -68,9 +69,10 @@ class OnlineImagePlotter():
 
         def is_new_image_ready():
             return self.prev_train_id != self.train_id.value
-    
+
         if is_new_image_ready():
             
+            print("NEW IMAGE READY", "from tid", self.prev_train_id, "asking new for tid", train_id)
             # get the previously computed image
 
             def get_plot_as_np_array(shared_mem_array):
-- 
GitLab