Belle II Software  release-08-01-10
EventCountLimiter.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # Purpose:
12 # basf module to return false if the event counter equals or exceeds the user-defined limit
13 #
14 import basf2
15 
16 # =========================================================================
17 #
18 # EventCountLimiter
19 #
20 # =========================================================================
21 
22 
23 class EventCountLimiter(basf2.Module):
24  """Report when the event counter has reached or exceeded its limit"""
25 
26  def __init__(self, maxCount):
27  """Constructor
28 
29  Argument:
30  maxCount (int): number of events to be processed
31  """
32  super().__init__()
33 
34  self.maxCountmaxCount = maxCount if (maxCount >= 0) else (1 << 31)
35 
36  self.eventCountereventCounter = 0
37 
38  def initialize(self):
39  """Handle job initialization (nothing to do here)"""
40 
41  def terminate(self):
42  """Handle job termination (nothing to do here)"""
43 
44  def beginRun(self):
45  """Handle begin of run (nothing to do here)"""
46 
47  def endRun(self):
48  """Handle end of run (nothing to do here)"""
49 
50  def event(self):
51  """Process one event: has eventCounter reached or exceeded its limit?"""
52  self.eventCounter += 1
53  super().return_value(self.eventCounter < self.maxCount)
maxCount
internal copy of the event-counter upper limit