Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:52

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