2
This utility takes a ROOT file containing TCanvas objects
3
and outputs the canvas images to a PDF file.
4
These ROOT files are typically produced by a program
5
e.g. from online reconstruction
6
Usage is rootCan2pdf.py <run-number>
7
output is <run-number>imageData.pdf
9
When used with -r <run-number>,
10
the output file will be Run<run-number>imageData.pdf
11
When used with -f <input-root-file>,
12
the output file will be Run0imageData.pdf
16
# pylint:disable=C0103, E1101, W0621, W0702
23
ROOT.gROOT.SetBatch(ROOT.kTRUE)
26
def imageify(inFile, outFile):
28
inFile is a root file with a list of canvases
29
outFile is a pdf output containing canvas images
32
if not os.path.isfile(inFile):
34
f1 = ROOT.TFile.Open(inFile,"r")
35
if not len(f1.GetListOfKeys()):
36
print "++ No keys in root file ", inFile
40
c1.Print("tmpFile(", "pdf")
43
for key in f1.GetListOfKeys():
44
cl = ROOT.gROOT.GetClass(key.GetClassName())
45
if not cl.InheritsFrom("TCanvas"):
49
imgFile = str(run_number) + "_" + key.GetName() + ".png"
51
c.Print("tmpFile", "pdf")
53
print "No keys in root file"
55
c1.Print("tmpFile)", "pdf")
56
os.rename("tmpFile", outFile)
58
if __name__ == "__main__":
63
getopt.getopt(sys.argv[1:], "r:f:v", ["run_number=", "file="])
65
print "Unrecognized option", sys.argv[1]
66
print 'Usage: %s [-r run_number ] [-f filename]' % (sys.argv[0])
69
if o in ('-r', '--run_number'):
72
inFile = "Run"+str(run_number)+"imageData.root"
73
elif o in ('-f', '--file'):
77
print "Unrecognized option ", o
79
outFile = "Run"+str(run_number)+"imageData.pdf"
80
imageify(inFile, outFile)