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
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67