CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
DQMIO2histo.DQMIO Class Reference

Public Member Functions

def __init__
 
def print_index
 
def write_to_file
 

Public Attributes

 already_defined
 
 f
 

Static Public Attributes

list types
 

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 19 of file DQMIO2histo.py.

Constructor & Destructor Documentation

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

Definition at line 29 of file DQMIO2histo.py.

29 
30  def __init__(self, input_filename, output_filename):
31  self._filename = input_filename
32  self._canvas = None
33  self.f = R.TFile(output_filename, "RECREATE")
34  self.already_defined = {"TProfiles" : False, "TProfile2Ds" : False,
35  "TH2Fs" : False, "TH2Ds" : False}
36 
37  if os.path.exists(self._filename): #we try to open input file if fail
38  self._root_file = R.TFile.Open(self._filename) #-> close script
39  if args.debug:
40  print("## DEBUG ##:")
41  print(" Input: %s\n Output: %s" % (input_filename,
42  output_filename))
43 
44  else:
45  print("File %s does not exists" % self._filename)
46  sys.exit(1)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

Member Function Documentation

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

Definition at line 47 of file DQMIO2histo.py.

References print(), sistrip::SpyUtilities.range(), str, DQMIO2histo.DQMIO.types, and DQMIO2histo.DQMIO.write_to_file().

47 
48  def print_index(self):
49  """
50  Loop over the complete index and dump it on the screen.
51  """
52  indices = self._root_file.Get("Indices")
53  if args.debug:
54  print("## DEBUG ##:")
55  print("Run,\tLumi,\tType,\t\tFirstIndex,\tLastIndex")
56  for i in range(indices.GetEntries()):
57  indices.GetEntry(i)
58  print('{0:4d}\t{1:4d}\t{2:4d}({3:s})\t\t{4:4d}\t{5:4d}'.format(
59  indices.Run, indices.Lumi, indices.Type,
60  DQMIO.types[indices.Type], indices.FirstIndex, indices.LastIndex))
61 
62  for i in range(indices.GetEntries()):
63  indices.GetEntry(i)
64  if indices.Type < len(DQMIO.types):
65  self.write_to_file(self.types[indices.Type],
66  [indices.FirstIndex,indices.LastIndex], str(indices.Run))
67 
68  else:
69  print("Unknown histogram type. Type numer: %s" % (indices.Type))
70  self.f.Close()
const uint16_t range(const Frame &aFrame)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
#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 71 of file DQMIO2histo.py.

References DQMIO2histo.DQMIO.already_defined, join(), print(), sistrip::SpyUtilities.range(), and str.

Referenced by DQMIO2histo.DQMIO.print_index().

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

Member Data Documentation

DQMIO2histo.DQMIO._canvas
private

Definition at line 31 of file DQMIO2histo.py.

DQMIO2histo.DQMIO._filename
private

Definition at line 30 of file DQMIO2histo.py.

DQMIO2histo.DQMIO._root_file
private

Definition at line 37 of file DQMIO2histo.py.

DQMIO2histo.DQMIO.already_defined

Definition at line 33 of file DQMIO2histo.py.

Referenced by DQMIO2histo.DQMIO.write_to_file().

DQMIO2histo.DQMIO.f

Definition at line 32 of file DQMIO2histo.py.

Referenced by ztail.Decoder.initial_synchronize().

list DQMIO2histo.DQMIO.types
static
Initial value:
1 = ["Ints","Floats","Strings", ##defined DQMIO types
2  "TH1Fs","TH1Ss","TH1Ds",
3  "TH2Fs", "TH2Ss", "TH2Ds",
4  "TH3Fs", "TProfiles","TProfile2Ds", "kNIndicies"]

Definition at line 24 of file DQMIO2histo.py.

Referenced by DQMIO2histo.DQMIO.print_index().