Belle II Software  release-05-01-25
multiple_module_conditions.py
1 import basf2
2 
3 # @cond internal_test
4 
5 
6 class ReturnTrueFalse(basf2.Module):
7 
8  def __init__(self):
9  super().__init__()
10 
11  self.event_counter = 0
12 
13  def event(self):
14  self.return_value(int(self.event_counter % 3))
15  self.event_counter += 1
16 
17 
18 class Counter(basf2.Module):
19 
20  def __init__(self):
21  super().__init__()
22 
23  self.counter = 0
24 
25  def event(self):
26  self.counter += 1
27 
28 
29 counter_0 = Counter()
30 counter_1 = Counter()
31 counter_2 = Counter()
32 counter_end = Counter()
33 
34 counter_path_0 = basf2.create_path()
35 counter_path_0.add_module(counter_0)
36 counter_path_1 = basf2.create_path()
37 counter_path_1.add_module(counter_1)
38 counter_path_2 = basf2.create_path()
39 counter_path_2.add_module(counter_2)
40 
41 path = basf2.create_path()
42 path.add_module("EventInfoSetter", evtNumList=[3])
43 
44 module_with_conditions = path.add_module(ReturnTrueFalse())
45 module_with_conditions.if_value("=0", counter_path_0)
46 module_with_conditions.if_value("=1", counter_path_1)
47 module_with_conditions.if_value("=2", counter_path_2, basf2.AfterConditionPath.CONTINUE)
48 
49 path.add_module(counter_end)
50 
51 basf2.process(path)
52 
53 assert counter_0.counter == 1
54 assert counter_1.counter == 1
55 assert counter_2.counter == 1
56 assert counter_end.counter == 1
57 
58 # @endcond
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25