CMS 3D CMS Logo

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 import six
5 
7  def __init__(self, integer ):
8  self.integer = integer
9  def __add__(self, other):
10  if hasattr(other, 'integer'):
11  self.integer += other.integer
12  else:
13  self.integer += other
14  return self
15  def __str__(self):
16  return str(self.integer)
17 
18 
19 class RLTInfo( object ):
20  def __init__(self):
21  self.dict = {}
22 
23  def add(self, trigger, run, lumi):
24  nEv = self.dict.setdefault( (trigger, run, lumi), MyInteger(0) )
25  nEv += 1
26 
27  def __str__(self):
28  lines = []
29  for rlt, count in six.iteritems(self.dict):
30  lines.append( ': '.join( [str(rlt), str(count)] ))
31  return '\n'.join(lines)
32 
33  def write(self, dirName, fileName='RLTInfo.root'):
34  f = TFile('/'.join( [dirName, fileName]), 'RECREATE')
35  t = Tree('RLTInfo','HLT/Run/Lumi information')
36  t.var('run', int )
37  t.var('lumi', int )
38  t.var('counts', int )
39  t.var('trigger', int )
40  for rlt, count in six.iteritems(self.dict):
41  t.fill('run', rlt[1])
42  t.fill('lumi', rlt[2])
43  t.fill( 'counts', count.integer)
44  t.tree.Fill()
45  f.Write()
46  f.Close()
47 
48 if __name__ == '__main__':
49 
50  rltinfo = RLTInfo()
51  rltinfo.add('HLT1', 128, 1)
52  rltinfo.add('HLT1', 128, 1)
53  rltinfo.add('HLT1', 128, 2)
54  rltinfo.add('HLT1', 129, 2)
55  rltinfo.add('HLT2', 129, 2)
56 
57  for rlt, count in six.iteritems(rltinfo.dict):
58  print(rlt, count)
59 
60  rltinfo.write('.')
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def __init__(self, integer)
Definition: rltinfo.py:7
def __add__(self, other)
Definition: rltinfo.py:9
def __str__(self)
Definition: rltinfo.py:15
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
def __init__(self)
Definition: rltinfo.py:20
def write(self, dirName, fileName='RLTInfo.root')
Definition: rltinfo.py:33
def __str__(self)
Definition: rltinfo.py:27
def add(self, trigger, run, lumi)
Definition: rltinfo.py:23
#define str(s)