CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Attributes
DQMIO2histo.DQMIO Class Reference

Public Member Functions

def __init__ (self, input_filename, output_filename)
 defined DQMIO types More...
 
def print_index (self)
 
def write_to_file (self, hist_type, index_range, run)
 

Public Attributes

 already_defined
 
 f
 

Private Attributes

 _canvas
 
 _filename
 
 _root_file
 

Detailed Description

Class responsible for browsing the content of a DQM file produced
with the DQMIO I/O framework of CMSSW

Definition at line 17 of file DQMIO2histo.py.

Constructor & Destructor Documentation

def DQMIO2histo.DQMIO.__init__ (   self,
  input_filename,
  output_filename 
)

defined DQMIO types

Definition at line 27 of file DQMIO2histo.py.

27  def __init__(self, input_filename, output_filename):
28  self._filename = input_filename
29  self._canvas = None
30  self.f = R.TFile(output_filename, "RECREATE")
31  self.already_defined = {"TProfiles" : False, "TProfile2Ds" : False,
32  "TH2Fs" : False, "TH2Ds" : False}
33 
34  if os.path.exists(self._filename): #we try to open input file if fail
35  self._root_file = R.TFile.Open(self._filename) #-> close script
36  if args.debug:
37  print "## DEBUG ##:"
38  print " Input: %s\n Output: %s" % (input_filename,
39  output_filename)
40 
41  else:
42  print "File %s does not exists" % self._filename
43  sys.exit(1)
44 
def __init__(self, input_filename, output_filename)
defined DQMIO types
Definition: DQMIO2histo.py:27

Member Function Documentation

def DQMIO2histo.DQMIO.print_index (   self)
Loop over the complete index and dump it on the screen.

Definition at line 45 of file DQMIO2histo.py.

References str, GenObject.GenObject.types, SimHitsValidationHcal.types, and DQMIO2histo.DQMIO.write_to_file().

45  def print_index(self):
46  """
47  Loop over the complete index and dump it on the screen.
48  """
49  indices = self._root_file.Get("Indices")
50  if args.debug:
51  print "## DEBUG ##:"
52  print "Run,\tLumi,\tType,\t\tFirstIndex,\tLastIndex"
53  for i in xrange(indices.GetEntries()):
54  indices.GetEntry(i)
55  print '{0:4d}\t{1:4d}\t{2:4d}({3:s})\t\t{4:4d}\t{5:4d}'.format(
56  indices.Run, indices.Lumi, indices.Type,
57  DQMIO.types[indices.Type], indices.FirstIndex, indices.LastIndex)
58 
59  for i in xrange(indices.GetEntries()):
60  indices.GetEntry(i)
61  if indices.Type < len(DQMIO.types):
62  self.write_to_file(self.types[indices.Type],
63  [indices.FirstIndex,indices.LastIndex], str(indices.Run))
64 
65  else:
66  print "Unknown histogram type. Type numer: %s" % (indices.Type)
67  self.f.Close()
68 
def print_index(self)
Definition: DQMIO2histo.py:45
def write_to_file(self, hist_type, index_range, run)
Definition: DQMIO2histo.py:69
#define str(s)
def DQMIO2histo.DQMIO.write_to_file (   self,
  hist_type,
  index_range,
  run 
)
Method looping over entries for specified histogram type and 
writing to FullName path to output ROOT File

Definition at line 69 of file DQMIO2histo.py.

References DQMIO2histo.DQMIO.already_defined, join(), and str.

Referenced by DQMIO2histo.DQMIO.print_index().

69  def write_to_file(self, hist_type, index_range, run):
70  """
71  Method looping over entries for specified histogram type and
72  writing to FullName path to output ROOT File
73  """
74  print "Working on: %s indexes: %s..%s" % (hist_type ,index_range[0],
75  index_range[1])
76  t_tree = self._root_file.Get(hist_type)
77  __run_dir = "Run %s" % (run)
78  ###we set Branch for the needed type
79  if hist_type == "TProfiles":
80  if not self.already_defined["TProfiles"]:
81  R.gROOT.ProcessLine("TProfile* _tprof;")
82  self.already_defined["TProfiles"] = True
83  t_tree.SetBranchAddress("Value", R._tprof)
84  t_tree.GetEntry(index_range[0])
85  elif hist_type == "TProfile2Ds":
86  if not self.already_defined["TProfile2Ds"]:
87  R.gROOT.ProcessLine("TProfile2D* _tprof2d;")
88  self.already_defined["TProfile2Ds"] = True
89  t_tree.SetBranchAddress("Value", R._tprof2d)
90  t_tree.GetEntry(index_range[0])
91  elif hist_type == "TH2Fs":
92  if not self.already_defined["TH2Fs"]:
93  R.gROOT.ProcessLine("TH2F* _th2f;")
94  self.already_defined["TH2Fs"] = True
95  t_tree.SetBranchAddress("Value", R._th2f)
96  t_tree.GetEntry(index_range[0])
97  elif hist_type == "TH2Ds":
98  if not self.already_defined["TH2Ds"]:
99  R.gROOT.ProcessLine("TH2D* _th2d;")
100  self.already_defined["TH2Ds"] = True
101  t_tree.SetBranchAddress("Value", R._th2d)
102  t_tree.GetEntry(index_range[0])
103 
104  for i in range(0,t_tree.GetEntries()+1): ##iterate on entries for specified type
105  if i >= index_range[0] and i <= index_range[1]: ##if entries as in range:
106  t_tree.GetEntry(i)
107  name = str(t_tree.FullName)
108  # print " %s: %s" % (i, name)
109  file_path = name.split("/")[:-1] ## same run/lumi histograms
110  __directory = "%s/%s" % (os.path.join("DQMData", __run_dir),
111  "/".join(file_path))
112  directory_ret = self.f.GetDirectory(__directory)
113  if not directory_ret:
114  self.f.mkdir(os.path.join(__directory))
115  self.f.cd(os.path.join(__directory))
116  if hist_type == "Strings":
117  construct_str = '<%s>s=%s</%s>' % (name.split("/")[-1:][0],
118  t_tree.Value, name.split("/")[-1:][0])
119  tmp_str = R.TObjString(construct_str)
120  tmp_str.Write()
121  elif hist_type == "Ints":
122  construct_str = '<%s>i=%s</%s>' % (name.split("/")[-1:][0],
123  t_tree.Value, name.split("/")[-1:][0])
124  tmp_str = R.TObjString(construct_str)
125  tmp_str.Write()
126  elif hist_type == "Floats":
127  construct_str = '<%s>f=%s</%s>' % (name.split("/")[-1:][0],
128  t_tree.Value, name.split("/")[-1:][0])
129  tmp_str = R.TObjString(construct_str)
130  tmp_str.Write()
131  else:
132  if hist_type in ["TProfiles", "TProfile2Ds", "TH2Fs", "TH2Ds"]:
133  if hist_type == "TProfiles": #if type is specific we write it.
134  R._tprof.Write()
135  elif hist_type == "TProfile2Ds":
136  R._tprof2d.Write()
137  elif hist_type == "TH2Fs":
138  R._th2f.Write()
139  elif hist_type == "TH2Ds":
140  R._th2d.Write()
141  else: #else we wirte Leafs Value which is a histogram
142  t_tree.Value.Write()
143 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def write_to_file(self, hist_type, index_range, run)
Definition: DQMIO2histo.py:69
#define str(s)

Member Data Documentation

DQMIO2histo.DQMIO._canvas
private

Definition at line 29 of file DQMIO2histo.py.

DQMIO2histo.DQMIO._filename
private
DQMIO2histo.DQMIO._root_file
private

Definition at line 35 of file DQMIO2histo.py.

DQMIO2histo.DQMIO.already_defined

Definition at line 31 of file DQMIO2histo.py.

Referenced by DQMIO2histo.DQMIO.write_to_file().

DQMIO2histo.DQMIO.f