Belle II Software light-2406-ragdoll
evtmetadata.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from ROOT import Belle2
13from b2test_utils import safe_process
14
15basf2.set_random_seed("something important")
16
17
18class NoopModule(basf2.Module):
19
20 """Doesn't do anything."""
21
22
23class EvtMetaDataTest(basf2.Module):
24
25 """Prints EventMetaData objects and stops event processing in event 3."""
26
27 def __init__(self):
28 """constructor."""
29
30 # need to call super() _if_ we reimplement the constructor
31 super().__init__()
32 basf2.B2INFO('event\trun\texp')
33
34 def initialize(self):
35 """reimplementation of Module::initialize()."""
36
37 basf2.B2INFO('EvtMetaDataTest::initialize()')
38
39 def beginRun(self):
40 """reimplementation of Module::beginRun()."""
41
42 basf2.B2INFO('EvtMetaDataTest::beginRun()')
43
44 def event(self):
45 """reimplementation of Module::event()."""
46
47 evtmetadata = Belle2.PyStoreObj('EventMetaData')
48
49 if not evtmetadata:
50 basf2.B2ERROR('No EventMetaData found')
51 else:
52 event = evtmetadata.obj().getEvent()
53 run = evtmetadata.obj().getRun()
54 exp = evtmetadata.obj().getExperiment()
55 basf2.B2INFO(f"{event}\t{run}\t{exp}")
56 if event == 4:
57 # stop event processing.
58 evtmetadata.obj().setEndOfData()
59
60 def endRun(self):
61 """reimplementation of Module::endRun()."""
62
63 basf2.B2INFO('EvtMetaDataTest::endRun()')
64
65 def terminate(self):
66 """reimplementation of Module::terminate()."""
67
68 basf2.B2INFO('EvtMetaDataTest::terminate()')
69
70
71# Normal steering file part begins here
72
73for skipNEvents in range(10):
74 # Create main path
75 main = basf2.Path()
76
77 # not used for anything, just checking wether the master module
78 # can be found if it's not the first module in the path.
79 main.add_module(NoopModule())
80
81 # exp 0 has only 2 events, so cannot trigger the test module
82 # also tests for a problem where beginRun() wasn't called
83 # exp 1 has only 2 events, so cannot trigger the test module,
84 # exp 2 has no events and will be skipped
85 # exp 3 will be stopped in event 3 by EvtMetaDataTest
86 main.add_module('EventInfoSetter',
87 expList=[0, 1, 2, 3],
88 runList=[0, 1, 2, 3],
89 evtNumList=[2, 2, 0, 5],
90 skipNEvents=skipNEvents)
91
92 main.add_module(EvtMetaDataTest())
93
94 safe_process(main)
95
96# test skipping to specific events
97skipToEvents = [
98 [0, 0, 1],
99 [0, 0, 3],
100 [0, 1, 1],
101 [0, 1, 6],
102 [0, 2, 3],
103 [1, 0, 1],
104 [2, 0, 1],
105]
106
107for event in skipToEvents:
108 basf2.B2INFO("skipping to exp={}, run={}, evt={}".format(*event))
109 main = basf2.Path()
110 main.add_module("EventInfoSetter", evtNumList=[3, 3, 3, 3], expList=[0, 0, 0, 1],
111 runList=[0, 1, 2, 0], skipToEvent=event)
112 main.add_module(EvtMetaDataTest())
113 safe_process(main)
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67