10 |
|
from optparse import OptionParser |
11 |
|
from array import * |
12 |
|
from decimal import * |
13 |
+ |
import subprocess |
14 |
|
|
15 |
|
from OSUT3Analysis.Configuration.configurationOptions import * |
16 |
|
from OSUT3Analysis.Configuration.processingUtilities import * |
19 |
|
|
20 |
|
gROOT.SetBatch(True) # This is to prevent pop-up graphical windows |
21 |
|
|
22 |
+ |
|
23 |
+ |
def MakeCondorSubmitFile(arguments, dataset): |
24 |
+ |
p = subprocess.Popen(["which", "makeBNTreePlot.py"], stdout=subprocess.PIPE) |
25 |
+ |
executable = p.communicate()[0] # read the stdout of the command |
26 |
+ |
workdir = os.getcwd() + "/" |
27 |
+ |
outdir = "condor/"+arguments.condorDir+"/"+dataset+"/" |
28 |
+ |
out = open(outdir+"/condorBNTree.sub", "w") |
29 |
+ |
out.write("Executable = " + executable + " \n") |
30 |
+ |
out.write("Universe = vanilla \n") |
31 |
+ |
out.write("Getenv = True \n") |
32 |
+ |
out.write("Arguments = -D " + dataset + " -l " + arguments.localConfig + " -c " + arguments.condorDir + " \n") |
33 |
+ |
out.write("Output = " + workdir + outdir + "condorBNTree_$(Process).out \n") |
34 |
+ |
out.write("Error = " + workdir + outdir + "condorBNTree_$(Process).err \n") |
35 |
+ |
out.write("Log = " + workdir + outdir + "condorBNTree_$(Process).log \n") |
36 |
+ |
out.write("+IsLocalJob = true \n") |
37 |
+ |
out.write("Rank = TARGET.IsLocalSlot \n") |
38 |
+ |
out.write("Queue 1 \n") |
39 |
+ |
out.close() |
40 |
+ |
|
41 |
+ |
|
42 |
+ |
def RunOnCondor(arguments, split_datasets): |
43 |
+ |
print "Running jobs on condor, instead of interactively." |
44 |
+ |
## print "Found condorDir = %s" % (condorDir) |
45 |
+ |
## print "Found split_datasets = " |
46 |
+ |
## print split_datasets |
47 |
+ |
|
48 |
+ |
for dataset in split_datasets: |
49 |
+ |
MakeCondorSubmitFile(arguments, dataset) |
50 |
+ |
# Now submit the condor job |
51 |
+ |
# os.system("condor_submit condor/"+arguments.condorDir+"/"+dataset+"condorBNTree.sub") |
52 |
+ |
print "Submitted job for: %s/%s" % (arguments.condorDir, dataset) |
53 |
+ |
|
54 |
+ |
return |
55 |
+ |
|
56 |
+ |
|
57 |
|
watch = TStopwatch() |
58 |
|
|
59 |
|
parser = OptionParser() |
70 |
|
if arguments.condorDir: |
71 |
|
condor_dir = "condor/%s" % arguments.condorDir |
72 |
|
|
73 |
+ |
if arguments.datasetName: # If datasetName is specified on command line, then override the value from localConfig |
74 |
+ |
datasets = [ |
75 |
+ |
arguments.datasetName, |
76 |
+ |
] |
77 |
+ |
|
78 |
|
#save a list of composite datasets |
79 |
|
composite_datasets = get_composite_datasets(datasets, composite_dataset_definitions) |
80 |
|
#save a list of datasets with composite datasets split up |
81 |
|
split_datasets = split_composite_datasets(datasets, composite_dataset_definitions) |
82 |
|
|
83 |
+ |
if arguments.runOnCondor: |
84 |
+ |
RunOnCondor(arguments, split_datasets) |
85 |
+ |
exit() |
86 |
+ |
|
87 |
+ |
print "Running interactively instead" |
88 |
+ |
|
89 |
+ |
|
90 |
|
#write new histogram to dataset |
91 |
|
for dataset in split_datasets: |
92 |
|
for hist in input_histograms: |
95 |
|
ch.Add(condor_dir + "/" + dataset + "/hist_*.root") |
96 |
|
print "Looping over chain with # entries = %f" % ch.GetEntries() |
97 |
|
|
98 |
< |
inputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE") |
99 |
< |
inputFile.cd("OSUAnalysis/"+hist['channel']) |
98 |
> |
outputFile = TFile(condor_dir + "/" + dataset + ".root", "UPDATE") |
99 |
> |
if not outputFile or outputFile.IsZombie(): print "Could not open file: %s/%s.root" % (condor_dir, dataset) |
100 |
> |
outputFile.cd("OSUAnalysis/"+hist['channel']) |
101 |
|
|
102 |
|
deleteString = hist['histName'] + ";*" # delete all existing instances of the object |
103 |
< |
currentDir = inputFile.GetDirectory("OSUAnalysis/"+hist['channel']); |
104 |
< |
if not currentDir: print "Could not find directory OSUAnalysis/%s" % hist['channel'] |
103 |
> |
currentDir = outputFile.GetDirectory("OSUAnalysis/"+hist['channel']); |
104 |
> |
if not currentDir: print "Could not find directory OSUAnalysis/%s in file %s" % (hist['channel'], outputFile.GetName()) |
105 |
|
currentDir.Delete(deleteString); |
106 |
|
|
107 |
|
h = TH1D(hist['histName'], hist['histName'], hist['nbins'], hist['xMin'], hist['xMax']) |
109 |
|
cut = TCut(hist['cutString']) |
110 |
|
ch.Draw(hist['varToPlot']+">>"+hist['histName'], cut) |
111 |
|
h.Write() |
112 |
< |
inputFile.Close() |
112 |
> |
outputFile.Close() |
113 |
|
print "Histogram " + hist['histName'] + " has been added to " + condor_dir + "/"+ dataset + ".root" |
114 |
|
|
115 |
|
#merge output if composite dataset |
131 |
|
|
132 |
|
|
133 |
|
|
85 |
– |
|