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