Belle II Software development
b2bii_mdst_input.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12from ROOT import Belle2
13
14b2.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
17b2.logging.set_info(b2.LogLevel.FATAL, b2.logging.get_info(b2.LogLevel.ERROR))
18
19main = b2.create_path()
20input = b2.register_module('B2BIIMdstInput')
21input.param('inputFileNames', [
22 b2.find_file('b2bii/tests/chaintest_1.mdst'),
23 b2.find_file('b2bii/tests/chaintest_2.mdst')
24 ])
25main.add_module(input)
26processed_event_numbers = []
27
28
29class 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
44main.add_module(TestingModule())
45
46b2.process(main)
47
48expected_event_numbers = [3, 1, 2, 4, 6, 5, 8, 9, 3, 4, 2, 1, 7, 6]
49assert 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
56main = b2.create_path()
57input = b2.register_module('B2BIIMdstInput')
58input.param('inputFileNames', [
59 b2.find_file('b2bii/tests/chaintest_1.mdst'),
60 b2.find_file('b2bii/tests/chaintest_2.mdst')
61 ])
62input.param('entrySequences', ['1:2,4:6', '0,2:3,5:100'])
63main.add_module(input)
64main.add_module(TestingModule())
65
66expected_event_numbers = [1, 2, 6, 5, 8, 3, 2, 1, 6]
67processed_event_numbers = []
68b2.process(main)
69
70assert 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.
77main = b2.create_path()
78input = b2.register_module('B2BIIMdstInput')
79input.param('inputFileNames', [
80 b2.find_file('b2bii/tests/chaintest_1.mdst'),
81 b2.find_file('b2bii/tests/chaintest_2.mdst')
82])
83input.param('entrySequences', [':', '2:3,5:100'])
84main.add_module(input)
85main.add_module(TestingModule())
86
87expected_event_numbers = [3, 1, 2, 4, 6, 5, 8, 9, 2, 1, 6]
88processed_event_numbers = []
89b2.process(main)
90assert 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.
97main = b2.create_path()
98input = b2.register_module('B2BIIMdstInput')
99input.param('inputFileNames', [
100 b2.find_file('b2bii/tests/chaintest_1.mdst'),
101 b2.find_file('b2bii/tests/chaintest_2.mdst')
102])
103input.param('entrySequences', ['', '2:3,5:100'])
104main.add_module(input)
105main.add_module(TestingModule())
106
107expected_event_numbers = [2, 1, 6]
108processed_event_numbers = []
109b2.process(main)
110assert expected_event_numbers == processed_event_numbers
111
112# Test the case where the input file is a .gen file
113main = b2.create_path()
114
115input = b2.register_module('B2BIIMdstInput')
116input.param('inputFileNames', [
117 b2.find_file('b2bii/tests/evtgen_BtoJpsiK_Jpsitoll.gen')
118])
119input.param('evtgenProcessing', True)
120main.add_module(input)
121
122convert = b2.register_module('B2BIIConvertMdst')
123convert.param('convertBeamParameters', False)
124convert.param('evtgenProcessing', True)
125main.add_module(convert)
126
127expected_MCParticles_len = [18, 28, 18, 24, 23, 35, 26, 29, 20, 26, 39, 28, 32, 32, 20, 19, 30,
128 26, 27, 18, 34, 27, 33, 39, 25, 20, 23, 17, 17, 18, 24, 31, 31, 23,
129 31, 18, 31, 29, 32, 23, 15, 28, 17, 27, 26, 27, 39]
130processed_MCParticles_len = []
131
132
134 """
135 Test module which writes out the length of the MCParticles' storearray
136 into the global processed_MCParticles_len list
137 """
138
139 def event(self):
140 """
141 Called for each event
142 """
143 global processed_MCParticles_len
144 emd = Belle2.PyStoreArray('MCParticles')
145 processed_MCParticles_len.append(emd.getEntries())
146
147
148main.add_module(MCParticlesTestingModule())
149b2.process(main)
150assert expected_MCParticles_len == processed_MCParticles_len
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
Definition PyStoreObj.h:67