from __future__ import absolute_import from __future__ import division from __future__ import print_function from ratproc.base import Processor class Count(Processor): ''' Counts events and prints updates at a specified interval. Similar to the C++ RAT processor. Not particularly useful on its own, but serves as a good example. ''' def __init__(self, interval=1): Processor.__init__(self) self.count = 0 self.triggers = 0 self.interval = interval def dsevent(self, run, ds): self.count += 1 self.triggers += ds.GetEVCount() if self.count % self.interval == 0: print('PyCountProc: Event {} ({} triggered events)'.format(self.count, self.triggers)) return 0 def finish(self): print('PyCountProc: Total # of events {} ({} triggers)'.format(self.count, self.triggers))