Belle II Software  release-05-01-25
conditional_iov.py
1 import basf2
2 from iov_conditional import phase_2_conditional, make_conditional_at
3 
4 
5 class PrinterModule(basf2.Module):
6  """Print the given string on each event"""
7 
8  def __init__(self, print_string):
9  """Remember the given string to print later"""
10  super().__init__()
11 
12  self._print_string = print_string
13 
14  def event(self):
15  """And now would be a good time for printing ..."""
16  print(self._print_string)
17 
18 
19 def simulate_run(run_numbers, exp_numbers):
20  assert len(exp_numbers) == len(run_numbers)
21 
22  path = basf2.create_path()
23 
24  path.add_module("EventInfoSetter", evtNumList=[1] * len(run_numbers), runList=run_numbers, expList=exp_numbers)
25  path.add_module("EventInfoPrinter")
26 
27  # Phase 2 path
28  phase2_path = basf2.create_path()
29  phase2_path.add_module(PrinterModule("Phase 2 is here"))
30 
31  # Phase 3 path
32  phase3_path = basf2.create_path()
33  phase3_path.add_module(PrinterModule("Phase 3 is here"))
34 
35  # No Phase 3 path
36  no_phase3_path = basf2.create_path()
37  no_phase3_path.add_module(PrinterModule("Phase 3 is not here"))
38 
39  # Weird path
40  weird_path = basf2.create_path()
41  weird_path.add_module(PrinterModule("Strange condition"))
42 
43  # Condition for phase2
44  phase_2_conditional(path, phase2_path=phase2_path)
45 
46  # Condition for phase3
47  make_conditional_at(path, iov_list=[(0, 0, 0, -1)], path_when_in_iov=phase3_path, path_when_not_in_iov=no_phase3_path)
48 
49  # Some weird condition
50  make_conditional_at(path, iov_list=[(42, 42, 47, 47)], path_when_in_iov=weird_path)
51 
52  # Finished path
53  path.add_module(PrinterModule("Finish"))
54 
55  basf2.process(path)
56 
57 
58 if __name__ == "__main__":
59  basf2.set_random_seed(1)
60  simulate_run(exp_numbers=[0, 1002], run_numbers=[1, 67])
61  simulate_run(exp_numbers=[42, 43, 47], run_numbers=[41, 1, 48])
conditional_iov.PrinterModule._print_string
_print_string
The string we want to print each event.
Definition: conditional_iov.py:12
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25
conditional_iov.PrinterModule.event
def event(self)
Definition: conditional_iov.py:14
conditional_iov.PrinterModule
Definition: conditional_iov.py:5
conditional_iov.PrinterModule.__init__
def __init__(self, print_string)
Definition: conditional_iov.py:8