Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:50

0001 from ROOT import TFile
0002 from PhysicsTools.HeppyCore.statistics.tree import Tree as Tree
0003 
0004 class MyInteger(object):
0005     def __init__(self, integer ):
0006         self.integer = integer
0007     def __add__(self, other):
0008         if hasattr(other, 'integer'):
0009             self.integer += other.integer
0010         else:
0011             self.integer += other 
0012         return self
0013     def __str__(self):
0014         return str(self.integer)
0015     
0016 
0017 class RLTInfo( object ):
0018     def __init__(self):
0019         self.dict = {}
0020 
0021     def add(self, trigger, run, lumi):
0022         nEv = self.dict.setdefault( (trigger, run, lumi), MyInteger(0) )
0023         nEv += 1
0024 
0025     def __str__(self):
0026         lines = []
0027         for rlt, count in self.dict.items():
0028             lines.append( ': '.join( [str(rlt), str(count)] ))
0029         return '\n'.join(lines)
0030 
0031     def write(self, dirName, fileName='RLTInfo.root'):
0032         f = TFile('/'.join( [dirName, fileName]), 'RECREATE')
0033         t = Tree('RLTInfo','HLT/Run/Lumi information')
0034         t.var('run', int )
0035         t.var('lumi', int )
0036         t.var('counts', int )
0037         t.var('trigger', int )
0038         for rlt, count in self.dict.items():
0039             t.fill('run', rlt[1])
0040             t.fill('lumi', rlt[2])
0041             t.fill( 'counts', count.integer)
0042             t.tree.Fill()
0043         f.Write()
0044         f.Close()
0045         
0046 if __name__ == '__main__':
0047 
0048     rltinfo = RLTInfo()
0049     rltinfo.add('HLT1', 128, 1)
0050     rltinfo.add('HLT1', 128, 1)
0051     rltinfo.add('HLT1', 128, 2)
0052     rltinfo.add('HLT1', 129, 2)
0053     rltinfo.add('HLT2', 129, 2)
0054 
0055     for rlt, count in rltinfo.dict.items():
0056         print(rlt, count)
0057 
0058     rltinfo.write('.')