Belle II Software light-2406-ragdoll
python_modules.py
1#!/usr/bin/env python3
2
3
10
11import basf2.core as _basf2
12from ROOT import Belle2
13
14from hep_ipython_tools.entities import StoreContentList, StoreContent
15
16
17class PrintCollections(_basf2.Module):
18
19 """
20 A small module to catch the content of the store array for some events and store them in the queue.
21 """
22
23 def __init__(self, queue):
24 """
25 Create the module with the given queue.
26 """
27 super().__init__()
28
29 self.queue = queue
30
32
33 self.event_number = 0
34
36
37 def initialize(self):
38 """
39 Get the total number of events from C++
40 """
41 self.total_number_of_events = Belle2.Environment.Instance().getNumberOfEvents()
42
43 def store_content(self):
44 """
45 Store the current content of the store array into the internal list.
46 """
47 registered_store_arrays = Belle2.PyStoreArray.list()
48 registered_store_objects = Belle2.PyStoreObj.list()
49
50 event_store_content_list = []
51
52 for store_array_name in registered_store_arrays:
53 store_array = Belle2.PyStoreArray(store_array_name)
54 event_store_content_list.append(StoreContent(store_array_name, len(store_array)))
55
56 for store_array_name in registered_store_objects:
57 event_store_content_list.append(StoreContent(store_array_name, 0))
58
59 event_store_content = StoreContentList(content=event_store_content_list, event_number=self.event_number)
60 self.store_content_list.append(event_store_content)
61
62 def event(self):
63 """
64 Write the store array content into a list for later.
65 """
66 if self.total_number_of_events == 0:
67 if self.event_number % 1000 == 0:
68 self.store_content()
69
70 else:
71 current_percentage = 1.0 * self.event_number / self.total_number_of_events
72
73 if 100 * current_percentage % 10 == 0:
74 self.store_content()
75
76 self.event_number += 1
77
78 def terminate(self):
79 """
80 Write the store array contents from the events to the queue.
81 """
82 self.queue.put("ipython.store_content", self.store_content_list)
83
84
85class ProgressPython(_basf2.Module):
86
87 """
88 A small module that prints every now and then the event number to the given connection.
89 It is used for status viewers. Do not call it by yourself.
90 """
91
92 def __init__(self, queue):
93 """ Init the module """
94 super().__init__()
95
96 self.queue = queue
97
98 self.event_number = 0
99
101 self.queue.send("init")
102
103 def initialize(self):
104 """ Send start to the connection """
105 self.queue.send("start")
106
107 # Receive the total number of events
108
109 self.total_number_of_events = Belle2.Environment.Instance().getNumberOfEvents()
110
111 def event(self):
112 """ Send the event number to the connection """
113 if self.total_number_of_events == 0:
114 return
115
116 current_percentage = 1.0 * self.event_number / self.total_number_of_events
117
118 if 100 * current_percentage % 5 == 0:
119 self.queue.send(current_percentage)
120
121 self.event_number += 1
122
123 def terminate(self):
124 """ Send stop to the connection """
125 self.queue.send(1)
126 self.queue.send("end")
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
static std::vector< std::string > list(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Return list of available arrays for given durability.
Definition: PyStoreArray.cc:28
static std::vector< std::string > list(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Return list of available objects for given durability.
Definition: PyStoreObj.cc:28
basf2 (Belle II Analysis Software Framework) # Author: The Belle II Collaboration # # See git log for...
Definition: entities.py:8
store_content_list
The contents of the store arrays for some events.