Belle II Software  release-08-01-10
eventlimiter.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import basf2
12 from ROOT import Belle2
13 
14 
15 num_events = {}
16 
17 
18 class 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 
46 input_events = 1000
47 max_events = 500
48 
49 main = basf2.Path()
50 main.add_module("EventInfoSetter", evtNumList=[input_events] * 3, expList=[0, 0, 1], runList=[0, 1, 0])
51 eventlimiter_mod = main.add_module('EventLimiter', maxEventsPerRun=500)
52 
53 success_path = basf2.Path()
54 success_count = success_path.add_module(CountEvents())
55 eventlimiter_mod.if_true(success_path)
56 
57 basf2.process(main)
58 
59 print(basf2.statistics)
60 
61 for passing_events in num_events.values():
62  assert passing_events == max_events
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
static ExpRun getRun(std::map< ExpRun, std::pair< double, double >> runs, double t)
Get exp number + run number from time.
Definition: Splitter.cc:262