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 dfec8e5ca687533adfeb1003b70899d5c0486915..5eddc641c771481ab54d0c73814ee9cd21969956 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 +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 onlinexpcsutils import onlinexpcsutils import runningstats @@ -142,6 +142,10 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher): super().__init__(config) self.info.merge(Hash("processingTime", 0)) + + # Periodic_Output + self.periodic_output = Periodic_Output(output_period=10) # default time at 300 sec + # expose the get xpcs settings function self.KARABO_SLOT(self.get_OnlineMIDSettings) self.KARABO_SLOT(self.triggerSampleOutput) @@ -298,16 +302,7 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher): self._reset() super().preDestruction() - def print_data_processing_update(self, numBins, numBunches, trainId): - - date_time = datetime.today().strftime('%d/%m/%Y %H:%M:%S') - - - my_device_id = self.getInstanceId() - now = time.time() - if now-self.timeSinceLastDataPrintUpdate > 300: - print(f'{date_time} : {my_device_id} received data for trainid {trainId} with {numBins} qBins and {numBunches} bunches') - self.timeSinceLastDataPrintUpdate = now + my_generated_train_id = 21249888900 def triggerSampleOutput(self): @@ -353,6 +348,8 @@ class OnlineMIDProcessor(TrainMatcher.TrainMatcher): def handle_detector_data_list(self, train_id, detector_data_list, numPixelPerGainStage=None): + mes = f"handle detector data list of length {len(detector_data_list)} from modules {[pair[0] for pair in detector_data_list]}" + self.periodic_output.log(mes) # time_to_handle_list_0 = time.perf_counter() # self.online_processing_memory, online_output_dict = onlinexpcsutils.compute_xpcs_from_detector_data_list( diff --git a/python_package/src/onlinemid/__init__.py b/python_package/src/onlinemid/__init__.py index 88c7ba3d2d640731be36e8349a794a4fbf34a114..6cf55f1faf87f42c2ce7f9f486818a53a0dbdf5e 100644 --- a/python_package/src/onlinemid/__init__.py +++ b/python_package/src/onlinemid/__init__.py @@ -6,7 +6,8 @@ from .utils.agipd import agipd_module_name_from_agipd_module_number from .utils.agipd import agipd_module_number_from_agipd_module_name from .utils.agipd import generate_test_data -from .utils.hash_and_dict import dict_from_hash -from .utils.hash_and_dict import hash_from_dict +from .utils.karabo import dict_from_hash +from .utils.karabo import hash_from_dict +from .utils.karabo import Periodic_Output from .utils.online_data_structures import NpVec diff --git a/python_package/src/onlinemid/utils/hash_and_dict.py b/python_package/src/onlinemid/utils/karabo.py similarity index 68% rename from python_package/src/onlinemid/utils/hash_and_dict.py rename to python_package/src/onlinemid/utils/karabo.py index 08fe7e1115a7af9db9c01921bb0f5be5c5f7926b..e83df007d778ae009233529df36a54c0c0c26844 100644 --- a/python_package/src/onlinemid/utils/hash_and_dict.py +++ b/python_package/src/onlinemid/utils/karabo.py @@ -1,3 +1,4 @@ +import time def hash_from_dict(dictionary): @@ -33,4 +34,19 @@ def hash_from_dict(dictionary): def dict_from_hash(hash): - pass \ No newline at end of file + pass + + + + +class Periodic_Output: + + def __init__(self, output_period = 300): + self.output_period = output_period + self.last_output_time = time.time() - output_period + + def log(self, fun, string_message): + now = time.time() + if now - self.last_output_time > self.output_period: + fun(string_message) + self.last_output_time = now \ No newline at end of file