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