00001
00002 '''
00003 Add an alg that holds on to readout headers for a little while
00004 '''
00005
00006 from DybPython.DybPythonAlg import DybPythonAlg, gbl, SUCCESS, FAILURE, irange, units
00007
00008 class QueueueueUp(DybPythonAlg):
00009
00010 def __init__(self, name = None):
00011 DybPythonAlg.__init__(self,name)
00012 self.queue = []
00013 self.size = 4
00014 self.oldho = None
00015 self.execNum = 0
00016 return
00017
00018
00019 def _newhos(self,hos):
00020 'Return any new hos not yet seen'
00021
00022 if not hos: return []
00023
00024 if self.oldho is None:
00025 self.oldho = hos[0]
00026 return list(hos)
00027
00028 try:
00029 ind = hos.index(self.oldho)
00030 except ValueError:
00031 self.oldho = hos[0]
00032 return list(hos)
00033
00034 self.oldho = hos[0]
00035 return hos[:ind]
00036
00037 def execute(self):
00038 self.execNum += 1
00039 rohs = self.getAES('/Event/Readout/ReadoutHeader')
00040
00041 print 'Execution# %d %s' % (self.execNum,'-'*70)
00042 print 'AES holds %d RoHs' % len(rohs)
00043
00044 rohs = self._newhos(rohs)
00045
00046 def rohstr(roh): return '%s [%d]' % (roh.context().AsString(), id(roh))
00047
00048 print 'New RoHs: (%d)' % len(rohs)
00049 for roh in rohs: print '\t%s'%rohstr(roh)
00050
00051 self.queue = rohs + self.queue
00052 loss = self.queue[self.size:]
00053
00054 print 'Lost RoHs: (%d)' % len(loss)
00055 for roh in loss: print '\t%s'%rohstr(roh)
00056
00057 self.queue = self.queue[:self.size]
00058
00059 print 'Queued RoHs: (%d)' % len(self.queue)
00060 for roh in self.queue: print '\t%s'%rohstr(roh)
00061
00062 print 'Execution# %d %s' % (self.execNum,'-'*70)
00063 return SUCCESS
00064
00065 pass
00066
00067 def run(app):
00068 alg = QueueueueUp()
00069 app.addAlgorithm(alg)