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