Belle II Software light-2406-ragdoll
eventlimiter.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from ROOT import Belle2
13
14
15num_events = {}
16
17
18class CountEvents(basf2.Module):
19
20 """
21 Count the number of events passing this module and create a dictionary
22 of {(exp,run): events}
23 """
24
25 def initialize(self):
26 """Not implemented"""
27
28 def beginRun(self):
29 """Creates an entry in the global num_events dictionary"""
30 global num_events
31 evtmetadata = Belle2.PyStoreObj('EventMetaData')
32 run = evtmetadata.obj().getRun()
33 exp = evtmetadata.obj().getExperiment()
34 if (exp, run) not in num_events:
35 num_events[(exp, run)] = 0
36
37 def event(self):
38 """Increments the right (Exp,Run) entry in the num_events dictionary"""
39 global num_events
40 evtmetadata = Belle2.PyStoreObj('EventMetaData')
41 run = evtmetadata.obj().getRun()
42 exp = evtmetadata.obj().getExperiment()
43 num_events[(exp, run)] += 1
44
45
46input_events = 1000
47max_events = 500
48
49main = basf2.Path()
50main.add_module("EventInfoSetter", evtNumList=[input_events] * 3, expList=[0, 0, 1], runList=[0, 1, 0])
51eventlimiter_mod = main.add_module('EventLimiter', maxEventsPerRun=500)
52
53success_path = basf2.Path()
54success_count = success_path.add_module(CountEvents())
55eventlimiter_mod.if_true(success_path)
56
57basf2.process(main)
58
59print(basf2.statistics)
60
61for passing_events in num_events.values():
62 assert passing_events == max_events
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67