Public Member Functions | |
def | __init__ |
def | process |
def | openFile |
def | processPath |
def | makeDirectory |
Public Attributes | |
filename | |
fileRoot | |
diskRoot | |
file | |
format |
Figure Generator Class
Definition at line 9 of file figures.py.
def figures::FigureGenerator::__init__ | ( | self, | ||
filename, | ||||
fileRoot, | ||||
diskRoot | ||||
) |
def figures::FigureGenerator::process | ( | self | ) |
Generate directories and figures
Definition at line 20 of file figures.py.
00020 : 00021 """Generate directories and figures""" 00022 if not self.openFile(): 00023 return 00024 self.processPath("") 00025 return 00026 def openFile(self):
def figures::FigureGenerator::openFile | ( | self | ) |
Definition at line 27 of file figures.py.
00027 : 00028 "Open root file" 00029 import ROOT 00030 gROOT = ROOT.gROOT 00031 gROOT.SetBatch(True) 00032 # Avoid verbose output 00033 ROOT.gErrorIgnoreLevel = ROOT.kInfo 00034 gROOT.SetStyle("Plain") 00035 ROOT.gStyle.SetTitleFillColor(0) 00036 ROOT.gStyle.SetTitleBorderSize(0) 00037 ROOT.gStyle.SetPalette(1) 00038 # I don't like ROOT. I have to set China timezone here 00039 # to get proper time axis in figure generation 00040 ROOT.gSystem.Setenv("TZ","PRC") 00041 rootFile = ROOT.TFile(self.filename) 00042 if not rootFile: 00043 print "Failed to open root file:",filename 00044 return False 00045 self.file = rootFile 00046 self.canvas = ROOT.TCanvas() 00047 return True 00048 def processPath(self, itemPath):
def figures::FigureGenerator::processPath | ( | self, | ||
itemPath | ||||
) |
Process a path in the current root file
Definition at line 49 of file figures.py.
00049 : 00050 """Process a path in the current root file""" 00051 #print "Processing:",itemPath 00052 filePath = self.fileRoot 00053 diskPath = self.diskRoot 00054 if len(itemPath)>0: 00055 filePath += "/"+itemPath 00056 diskPath += "/"+itemPath 00057 content = self.file.Get(filePath) 00058 if not content and itemPath=="": 00059 print "FIXME: Sim data has no run number" 00060 self.fileRoot = self.fileRoot[:-7] + "0000000" 00061 filePath = self.fileRoot 00062 content = self.file.Get(filePath) 00063 if not content: 00064 print "Failed to get item at: ", filePath 00065 return 00066 if content.IsA().InheritsFrom("TH1"): 00067 # Found a histogram. Draw it. 00068 if content.IsA().InheritsFrom("TH2F"): 00069 # Draw 2-D histograms with colz option 00070 content.Draw("colz"); 00071 elif content.IsA().InheritsFrom("TH1F"): 00072 # Draw 1-D histograms with log scale 00073 self.canvas.SetLogy(1) 00074 content.Draw(); 00075 else: 00076 content.Draw(); 00077 self.canvas.SaveAs(diskPath+"."+self.format) 00078 self.canvas.SetLogy(0) 00079 elif content.IsA().InheritsFrom("TGraph"): 00080 # Found a graph. Draw it. 00081 content.Draw("APL"); 00082 self.canvas.SaveAs(diskPath+"."+self.format) 00083 elif content.IsA().InheritsFrom("TDirectory"): 00084 self.makeDirectory(diskPath) 00085 keylist = content.GetListOfKeys() 00086 for key in keylist: 00087 dirItem = key.ReadObj() 00088 dirItemPath = None 00089 if len(itemPath)>0: 00090 dirItemPath = itemPath+"/"+dirItem.GetName() 00091 else: 00092 dirItemPath = dirItem.GetName() 00093 self.processPath(dirItemPath) 00094 else: 00095 # Won't handle this object 00096 print "Not handing %s of type %s" % (filepath,content.ClassName()) 00097 return 00098 def makeDirectory(self, diskPath):
def figures::FigureGenerator::makeDirectory | ( | self, | ||
diskPath | ||||
) |
Make sure the output directory exists
Definition at line 99 of file figures.py.
00099 : 00100 """Make sure the output directory exists""" 00101 import os 00102 os.system("mkdir -p "+diskPath) 00103 return 00104 if __name__ == "__main__":
Definition at line 13 of file figures.py.
Definition at line 14 of file figures.py.
Definition at line 15 of file figures.py.
Definition at line 16 of file figures.py.
Definition at line 17 of file figures.py.