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 
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('.')
def __init__(self, integer)
Definition: rltinfo.py:6
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def __add__(self, other)
Definition: rltinfo.py:8
def __str__(self)
Definition: rltinfo.py:14
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def __init__(self)
Definition: rltinfo.py:19
def write(self, dirName, fileName='RLTInfo.root')
Definition: rltinfo.py:32
def __str__(self)
Definition: rltinfo.py:26
def add(self, trigger, run, lumi)
Definition: rltinfo.py:22
#define str(s)