CMS 3D CMS Logo

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