Belle II Software  release-08-01-10
b2bii_mdst_input.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2 as b2
12 from ROOT import Belle2
13 
14 b2.set_random_seed("something important")
15 # make sure FATAL messages don't have the function signature as this makes
16 # problems with clang printing namespaces differently
17 b2.logging.set_info(b2.LogLevel.FATAL, b2.logging.get_info(b2.LogLevel.ERROR))
18 
19 main = b2.create_path()
20 input = b2.register_module('B2BIIMdstInput')
21 input.param('inputFileNames', [
22  b2.find_file('b2bii/tests/chaintest_1.mdst'),
23  b2.find_file('b2bii/tests/chaintest_2.mdst')
24  ])
25 main.add_module(input)
26 processed_event_numbers = []
27 
28 
29 class TestingModule(b2.Module):
30  """
31  Test module which writes out the processed event numbers
32  into the global processed_event_numbers list
33  """
34 
35  def event(self):
36  """
37  Called for each event
38  """
39  global processed_event_numbers
40  emd = Belle2.PyStoreObj('EventMetaData')
41  processed_event_numbers.append(emd.obj().getEvent())
42 
43 
44 main.add_module(TestingModule())
45 
46 b2.process(main)
47 
48 expected_event_numbers = [3, 1, 2, 4, 6, 5, 8, 9, 3, 4, 2, 1, 7, 6]
49 assert expected_event_numbers == processed_event_numbers
50 
51 # The first file contains the following event numbers (in this order)
52 # 3, 1, 2, 4, 6, 5, 8, 9
53 # The second file contains the following event numbers (in this order)
54 # 3, 4, 2, 1, 7, 6
55 # We select more event than the file contains, to check if it works anyway
56 main = b2.create_path()
57 input = b2.register_module('B2BIIMdstInput')
58 input.param('inputFileNames', [
59  b2.find_file('b2bii/tests/chaintest_1.mdst'),
60  b2.find_file('b2bii/tests/chaintest_2.mdst')
61  ])
62 input.param('entrySequences', ['1:2,4:6', '0,2:3,5:100'])
63 main.add_module(input)
64 main.add_module(TestingModule())
65 
66 expected_event_numbers = [1, 2, 6, 5, 8, 3, 2, 1, 6]
67 processed_event_numbers = []
68 b2.process(main)
69 
70 assert expected_event_numbers == processed_event_numbers
71 
72 # The first file contains the following event numbers (in this order)
73 # 3, 1, 2, 4, 6, 5, 8, 9
74 # The second file contains the following event numbers (in this order)
75 # 3, 4, 2, 1, 7, 6
76 # We select the complete first file and specific elements of the of the subsequent one.
77 main = b2.create_path()
78 input = b2.register_module('B2BIIMdstInput')
79 input.param('inputFileNames', [
80  b2.find_file('b2bii/tests/chaintest_1.mdst'),
81  b2.find_file('b2bii/tests/chaintest_2.mdst')
82 ])
83 input.param('entrySequences', [':', '2:3,5:100'])
84 main.add_module(input)
85 main.add_module(TestingModule())
86 
87 expected_event_numbers = [3, 1, 2, 4, 6, 5, 8, 9, 2, 1, 6]
88 processed_event_numbers = []
89 b2.process(main)
90 assert expected_event_numbers == processed_event_numbers
91 
92 # The first file contains the following event numbers (in this order)
93 # 3, 1, 2, 4, 6, 5, 8, 9
94 # The second file contains the following event numbers (in this order)
95 # 3, 4, 2, 1, 7, 6
96 # We do not select any element from the first file but specific elements of the subsequent one.
97 main = b2.create_path()
98 input = b2.register_module('B2BIIMdstInput')
99 input.param('inputFileNames', [
100  b2.find_file('b2bii/tests/chaintest_1.mdst'),
101  b2.find_file('b2bii/tests/chaintest_2.mdst')
102 ])
103 input.param('entrySequences', ['', '2:3,5:100'])
104 main.add_module(input)
105 main.add_module(TestingModule())
106 
107 expected_event_numbers = [2, 1, 6]
108 processed_event_numbers = []
109 b2.process(main)
110 assert expected_event_numbers == processed_event_numbers
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67