Belle II Software  release-08-01-10
multiple_module_conditions.py
1 
8 import basf2
9 
10 # @cond internal_test
11 
12 
13 class 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 
25 class 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 
36 counter_0 = Counter()
37 counter_1 = Counter()
38 counter_2 = Counter()
39 counter_end = Counter()
40 
41 counter_path_0 = basf2.create_path()
42 counter_path_0.add_module(counter_0)
43 counter_path_1 = basf2.create_path()
44 counter_path_1.add_module(counter_1)
45 counter_path_2 = basf2.create_path()
46 counter_path_2.add_module(counter_2)
47 
48 path = basf2.create_path()
49 path.add_module("EventInfoSetter", evtNumList=[3])
50 
51 module_with_conditions = path.add_module(ReturnTrueFalse())
52 module_with_conditions.if_value("=0", counter_path_0)
53 module_with_conditions.if_value("=1", counter_path_1)
54 module_with_conditions.if_value("=2", counter_path_2, basf2.AfterConditionPath.CONTINUE)
55 
56 path.add_module(counter_end)
57 
58 basf2.process(path)
59 
60 assert counter_0.counter == 1
61 assert counter_1.counter == 1
62 assert counter_2.counter == 1
63 assert counter_end.counter == 1
64 
65 # @endcond