Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:33:26

0001 from __future__ import print_function
0002 #____________________________________________________________
0003 #
0004 #  cuy
0005 #
0006 # A very simple way to make plots with ROOT via an XML file
0007 #
0008 # Francisco Yumiceva
0009 # yumiceva@fnal.gov
0010 #
0011 # Fermilab, 2008
0012 #
0013 #____________________________________________________________
0014 
0015 import sys
0016 import ROOT
0017 from ROOT import TFile
0018 
0019 
0020 class Inspector:
0021 
0022     def SetFilename(self, value):
0023         self.Filename = value
0024     def Verbose(self, value):
0025         self.Verbose = value
0026 
0027     def createXML(self, value):
0028         self.XML = value
0029 
0030     def SetTag(self,value):
0031         self.tag = value
0032         self.TagOption = True
0033 
0034     def Loop(self):
0035 
0036         afile = TFile(self.Filename)
0037         afilename = self.Filename
0038         stripfilename = afilename
0039 
0040         try:
0041             if self.TagOption:
0042                 stripfilename = self.tag
0043         except:
0044             stripfilename = afilename.split('/')[len(afilename.split('/')) -1]
0045             stripfilename = stripfilename[0:(len(stripfilename)-5)]
0046 
0047         alist = self.dir.GetListOfKeys()
0048 
0049         for i in alist:
0050             aobj = i.ReadObj()
0051             if aobj.IsA().InheritsFrom("TDirectory"):
0052                 if self.Verbose:
0053                     print(' found directory: '+i.GetName())
0054 
0055                 if self.XML:
0056                     print('   <!-- '+i.GetName()+' -->')
0057 
0058                 bdir = self.dir
0059                 afile.GetObject(i.GetName(),bdir)
0060                 blist = bdir.GetListOfKeys()
0061                 for j in blist:
0062                     bobj = j.ReadObj()
0063                     if bobj.IsA().InheritsFrom(ROOT.TH1.Class()):
0064                         if self.Verbose:
0065                             print('  --> found TH1: name = '+j.GetName() + ' title = '+j.GetTitle())
0066                         if self.XML:
0067                             print('   <TH1 name=\"'+stripfilename+'_'+j.GetName()+'\" source=\"'+'/'+i.GetName()+'/'+j.GetName()+'\"/>')
0068 
0069     def GetListObjects(self):
0070 
0071         afile = TFile(self.Filename)
0072 
0073         if afile.IsZombie():
0074             print(" error trying to open file: " + self.Filename)
0075             sys.exit()
0076 
0077         if self.XML:
0078 
0079             print('''
0080 <cuy>
0081 ''')    
0082             print('  <validation type=\"'+afile.GetName()+'\" file=\"'+self.Filename+'\" release=\"x.y.z\">')
0083 
0084         self.dir = ROOT.gDirectory
0085         self.Loop()
0086 
0087         if self.XML:
0088 
0089             print('''
0090   </validation>
0091 
0092 </cuy>
0093 ''')
0094 
0095 
0096 
0097 
0098 
0099 
0100 
0101 
0102