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('.')
rltinfo.RLTInfo.write
def write(self, dirName, fileName='RLTInfo.root')
Definition: rltinfo.py:33
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
rltinfo.RLTInfo
Definition: rltinfo.py:19
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
rltinfo.MyInteger
Definition: rltinfo.py:6
rltinfo.MyInteger.integer
integer
Definition: rltinfo.py:8
str
#define str(s)
Definition: TestProcessor.cc:51
rltinfo.MyInteger.__add__
def __add__(self, other)
Definition: rltinfo.py:9
rltinfo.MyInteger.__str__
def __str__(self)
Definition: rltinfo.py:15
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
rltinfo.MyInteger.__init__
def __init__(self, integer)
Definition: rltinfo.py:7
rltinfo.RLTInfo.dict
dict
Definition: rltinfo.py:21
rltinfo.RLTInfo.__init__
def __init__(self)
Definition: rltinfo.py:20
rltinfo.RLTInfo.__str__
def __str__(self)
Definition: rltinfo.py:27
rltinfo.RLTInfo.add
def add(self, trigger, run, lumi)
Definition: rltinfo.py:23