-
Notifications
You must be signed in to change notification settings - Fork 1
/
tdrAllStacks.py
44 lines (36 loc) · 1.23 KB
/
tdrAllStacks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from os import listdir, makedirs
from os.path import isfile, join, exists, basename
from shutil import rmtree
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-i", "--inDir", dest="inDir",
help = "the input directory")
parser.add_option("-b", action="store_true", dest="batch", default=False,
help = "turn on batch mode")
(options, args) = parser.parse_args()
if options.inDir is None:
parser.error('Input dir not given')
from tcanvasTDR import TDRify
from ROOT import *
if options.batch:
gROOT.SetBatch()
inFiles=[]
for inF in listdir(options.inDir):
if isfile(join(options.inDir, inF)):
inFiles.append(TFile(join(options.inDir, inF)))
print inFiles
print " "
outCans = {}
for inFile in inFiles:
for key in inFile.GetListOfKeys():
print key
fileObj = inFile.Get(key.GetName())
print fileObj
if fileObj.IsA().GetName() == "TCanvas":
outCans[inFile.GetName()]=fileObj
if exists("pdf_tdr_%s" % options.inDir):
rmtree("pdf_tdr_%s" % options.inDir)
makedirs("pdf_tdr_%s" % options.inDir)
for canKey in outCans.keys():
outName = "%s.pdf"%basename(canKey).replace(".root","")
outCans[canKey].Print(join("pdf_tdr_%s" % options.inDir, outName))