CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rltinfo.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from ROOT import TFile
3 from PhysicsTools.HeppyCore.statistics.tree import Tree as Tree
4 
5 class MyInteger(object):
6  def __init__(self, integer ):
7  self.integer = integer
8  def __add__(self, other):
9  if hasattr(other, 'integer'):
10  self.integer += other.integer
11  else:
12  self.integer += other
13  return self
14  def __str__(self):
15  return str(self.integer)
16 
17 
18 class RLTInfo( object ):
19  def __init__(self):
20  self.dict = {}
21 
22  def add(self, trigger, run, lumi):
23  nEv = self.dict.setdefault( (trigger, run, lumi), MyInteger(0) )
24  nEv += 1
25 
26  def __str__(self):
27  lines = []
28  for rlt, count in self.dict.items():
29  lines.append( ': '.join( [str(rlt), str(count)] ))
30  return '\n'.join(lines)
31 
32  def write(self, dirName, fileName='RLTInfo.root'):
33  f = TFile('/'.join( [dirName, fileName]), 'RECREATE')
34  t = Tree('RLTInfo','HLT/Run/Lumi information')
35  t.var('run', int )
36  t.var('lumi', int )
37  t.var('counts', int )
38  t.var('trigger', int )
39  for rlt, count in self.dict.items():
40  t.fill('run', rlt[1])
41  t.fill('lumi', rlt[2])
42  t.fill( 'counts', count.integer)
43  t.tree.Fill()
44  f.Write()
45  f.Close()
46 
47 if __name__ == '__main__':
48 
49  rltinfo = RLTInfo()
50  rltinfo.add('HLT1', 128, 1)
51  rltinfo.add('HLT1', 128, 1)
52  rltinfo.add('HLT1', 128, 2)
53  rltinfo.add('HLT1', 129, 2)
54  rltinfo.add('HLT2', 129, 2)
55 
56  for rlt, count in rltinfo.dict.items():
57  print(rlt, count)
58 
59  rltinfo.write('.')
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
#define str(s)