CMS 3D CMS Logo

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