CMS 3D CMS Logo

Inspector.py
Go to the documentation of this file.
1 from __future__ import print_function
2 #____________________________________________________________
3 #
4 # cuy
5 #
6 # A very simple way to make plots with ROOT via an XML file
7 #
8 # Francisco Yumiceva
9 # yumiceva@fnal.gov
10 #
11 # Fermilab, 2008
12 #
13 #____________________________________________________________
14 
15 import sys
16 import ROOT
17 from ROOT import TFile
18 
19 
20 class Inspector:
21 
22  def SetFilename(self, value):
23  self.Filename = value
24  def Verbose(self, value):
25  self.Verbose = value
26 
27  def createXML(self, value):
28  self.XML = value
29 
30  def SetTag(self,value):
31  self.tag = value
32  self.TagOption = True
33 
34  def Loop(self):
35 
36  afile = TFile(self.Filename)
37  afilename = self.Filename
38  stripfilename = afilename
39 
40  try:
41  if self.TagOption:
42  stripfilename = self.tag
43  except:
44  stripfilename = afilename.split('/')[len(afilename.split('/')) -1]
45  stripfilename = stripfilename[0:(len(stripfilename)-5)]
46 
47  alist = self.dir.GetListOfKeys()
48 
49  for i in alist:
50  aobj = i.ReadObj()
51  if aobj.IsA().InheritsFrom("TDirectory"):
52  if self.Verbose:
53  print(' found directory: '+i.GetName())
54 
55  if self.XML:
56  print(' <!-- '+i.GetName()+' -->')
57 
58  bdir = self.dir
59  afile.GetObject(i.GetName(),bdir)
60  blist = bdir.GetListOfKeys()
61  for j in blist:
62  bobj = j.ReadObj()
63  if bobj.IsA().InheritsFrom(ROOT.TH1.Class()):
64  if self.Verbose:
65  print(' --> found TH1: name = '+j.GetName() + ' title = '+j.GetTitle())
66  if self.XML:
67  print(' <TH1 name=\"'+stripfilename+'_'+j.GetName()+'\" source=\"'+'/'+i.GetName()+'/'+j.GetName()+'\"/>')
68 
69  def GetListObjects(self):
70 
71  afile = TFile(self.Filename)
72 
73  if afile.IsZombie():
74  print(" error trying to open file: " + self.Filename)
75  sys.exit()
76 
77  if self.XML:
78 
79  print('''
80 <cuy>
81 ''')
82  print(' <validation type=\"'+afile.GetName()+'\" file=\"'+self.Filename+'\" release=\"x.y.z\">')
83 
84  self.dir = ROOT.gDirectory
85  self.Loop()
86 
87  if self.XML:
88 
89  print('''
90  </validation>
91 
92 </cuy>
93 ''')
94 
95 
96 
97 
98 
99 
100 
101 
102 
def Loop(self)
Definition: Inspector.py:34
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def GetListObjects(self)
Definition: Inspector.py:69
def SetFilename(self, value)
Definition: Inspector.py:22
def createXML(self, value)
Definition: Inspector.py:27
def SetTag(self, value)
Definition: Inspector.py:30