-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunMEM.py
80 lines (66 loc) · 2.59 KB
/
RunMEM.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from Definitions import *
import ROOT
import os
import stat
import glob
def get_event_ranges(number_of_events_per_job,sample):
n_entries=sample.GetEntries()
#print n_entries
#print number_of_events_per_job
ranges=[]
i=0
while (((i+1)*number_of_events_per_job)<n_entries):
print i
range_=[]
range_.append(i*number_of_events_per_job)
range_.append((i+1)*number_of_events_per_job-1)
ranges.append(range_)
i=i+1
ranges.append([i*number_of_events_per_job,int(n_entries-1)])
return ranges
def create_script(cmsswpath,looperpath,rootfile,firstevent,lastevent,jobnumber,samplename,do_mem):
print samplename
script='#!/bin/bash\n'
script+='export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch\n'
script+='source $VO_CMS_SW_DIR/cmsset_default.sh\n'
script+='cd '+cmsswpath+'src\neval `scram runtime -sh`\n'
if do_mem:
script+='python '+looperpath+'cc_looper_new.py --infile '+InputDirectoryOfMEMTrees+rootfile+' --firstEvent '+str(firstevent)+' --lastEvent '+str(lastevent)+' --outfile '+OutputDirectoryForMEMTrees+samplename+'_'+str(jobnumber)+'.root'+' --conf CSV --doMem'
else:
script+='python '+looperpath+'cc_looper_new.py --infile '+InputDirectoryOfMEMTrees+rootfile+' --firstEvent '+str(firstevent)+' --lastEvent '+str(lastevent)+' --outfile '+OutputDirectoryForMEMTrees+samplename+'_'+str(jobnumber)+'.root'+' --conf CSV'
filename='scripts/'+samplename+'_'+str(jobnumber)+'.sh'
f=open(filename,'w')
f.write(script)
f.close()
st = os.stat(filename)
os.chmod(filename, st.st_mode | stat.S_IEXEC)
do_mem=True
trees=[]
plot_ranges=[]
print [sample[0] for sample in Samples]
for sample in Samples:
print sample[0]
array=glob.glob(InputDirectoryOfMEMTrees+sample[1])
if not (len(array)>0):
print "not found"
print "removed sample ",sample[0]
Samples.remove(sample)
print "---------------------------------"
for sample in Samples:
tree = ROOT.TChain("tree",sample[0])
tree.Add(InputDirectoryOfMEMTrees+sample[1])
print tree.GetTitle()
trees.append(tree)
#print trees
for tree,sample in zip(trees,Samples):
plot_ranges.append(get_event_ranges(sample[2],tree))
#sample = ROOT.TChain("tree","test")
#print MaxEventsPerTree
#print InputDirectoryOfMEMTrees+Samples[0][1]
#sample.Add(InputDirectoryOfMEMTrees+Samples[0][1])
#print get_event_ranges(MaxEventsPerTree,sample)
for sample,plot_range in zip(Samples,plot_ranges):
i=0
for plot_range_ in plot_range:
create_script(cmsswpath,looperpath,sample[1],plot_range_[0],plot_range_[1],i,sample[0],do_mem)
i=i+1