-
Notifications
You must be signed in to change notification settings - Fork 11
/
datacardResubmissionTool.py
185 lines (152 loc) · 5.19 KB
/
datacardResubmissionTool.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import glob
import os
import shutil
import math
#print(glob.glob("/home/adam/*"))
#test on this BF dir
#BF_dir = "BF_B135_TChipmWW_MCstats"
###job configuration
#cpu="request_cpus = 4"
#disk="request_disk = 15000000 KB"
#mem="request_memory = 4000 MB"
#BF_dir = "BF_B135_bugfix16_TChipmWW_MCstats"
#BF_dir = "BF_B135_bugfix16_TChiWZ_MCstats"
#BF_dir = "BF_B135_bugfix16_HinoN2C1_MCstats"
#cpu="request_cpus = 4"
#disk="request_disk = 2000000 KB"
#mem="request_memory = 4000 MB"
#BF_dir = "BF_B135_bugfix16_T2tt_MCstats"
#BF_dir = "BF_B135_bugfix16_TChipmWW_MCstats"
#BF_dir = "BF_B135_bugfix16_tthighdM_MCstats"
##BF_dir = "BF_B136_WZhighdM"
#BF_dir = "BF_B136_bWhighdM"
#BF_dir = "BF_B136_WWhighdM"
#BF_dir = "BF_B136_T2bW"#
BF_dir = "BF_B135_bugfix16_T2bW_MCstats"
#BF_dir = "BF_B135_bugfix16_T2bb_MCstats"
#BF_dir = "BF_B135_bugfix16_T2cc_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSnu_MCstats"
#BF_dir = "BF_B135_bugfix16_tthighdM_MCstats"
#BF_dir = "BF_B135_bugfix16_WZhighdM_MCstats"
#BF_dir = "BF_B135_bugfix16_WWhighdM_MCstats"
cpu="request_cpus = 4"
disk="request_disk = 4500000 KB"
mem="request_memory = 6000 MB"
#limitJobs = True
limitJobs = False
maxMP = 600
maxdM = 300
#BF_dir = "BF_B135_bugfix16_TSlepSlepEL_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepER_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepMUL_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepMUR_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepeLR_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepmuLR_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepmueL_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSlepmueR_MCstats"
#BF_dir = "BF_B135_bugfix16_TSlepSleptot_MCstats"
#cpu="request_cpus = 4"
#disk="request_disk = 1500000 KB"
#mem="request_memory = 4000 MB"
def getMasses( masspoint ):
#print("assessing masspoint", masspoint)
MP = math.trunc( float(masspoint)/10000. )
MP10k = MP*10000
MC = int(masspoint) - MP10k
dM = MP - MC
return [MP,MC,dM]
def jobLimiter(BF_dir, maxMP, maxdM, jobList ):
reducedJobList = []
for key in jobList:
subfile = BF_dir+"/src/submit_"+key+".sh"
subIn = open(subfile,"r")
lines = subIn.readlines()
for line in lines:
if( "Arguments" in line):
#signal i hope is always the last one
sig = line.split(' ')[-2]
masspoint = sig.split('_')[-1]
#print("scanning Args:", sig, masspoint)
masses = getMasses(masspoint)
if( (masses[0] <= maxMP) and (masses[2] <= maxdM) ):
#print("saving masspoint",sig, masspoint, masses[0], masses[2])
reducedJobList.append(key)
break
print("using jobLimiter: subDiff reduction-", len(jobList),"->",len(reducedJobList))
print("used limits MP<=",maxMP,"dM<=",maxdM)
return reducedJobList
subs = glob.glob(BF_dir+"/src/*")
#print(subs)
for i,sub in enumerate(subs):
jN = sub.split("/")[-1]
jN = jN[:-3]
jN = jN.split("_")[-1]
subs[i] = jN
#print(subs)
logs = glob.glob(BF_dir+"/log/*.out")
for i,log in enumerate(logs):
jN = log.split("/")[-1]
jN = jN[:-8]
jN = jN.split("_")[-1]
logs[i] = jN
#print(logs)
subSet = set(subs)
logSet = set(logs)
subDiff = subSet.difference(logSet)
print("Analyzing:", BF_dir)
if(limitJobs):
subDiff = jobLimiter(BF_dir, maxMP, maxdM, subDiff )
#exit()
print("found", len(subDiff), "missing jobs")
#exit()
print("generating resubmission scripts for this job list:")
print(subDiff)
resub_directory = BF_dir+"/resub_src"
if os.path.exists(resub_directory):
shutil.rmtree(resub_directory)
os.mkdir(resub_directory)
print("Directory '% s' created" % resub_directory)
print("Using these configurations:")
print(cpu)
print(disk)
print(mem)
print("Generating resubmission scripts...")
for key in subDiff:
# print("procesing #",key)
subfile = BF_dir+"/src/submit_"+key+".sh"
resubfile = BF_dir+"/resub_src/submit_"+key+".sh"
# print(subfile)
subIn = open(subfile,"r")
subOut = open(resubfile,"w")
lines = subIn.readlines()
for line in lines:
if( "request_memory" in line):
subOut.write(cpu+"\n")
subOut.write(disk+"\n")
subOut.write(mem+"\n")
else:
if("queue" in line):
subOut.write("Requirements = HAS_SINGULARITY == True\n")
subOut.write("+ApptainerImage = \"/cvmfs/singularity.opensciencegrid.org/cmssw/cms:rhel7\"\n")
subOut.write("+ProjectName=\"cms.org.cern\"\n")
subOut.write("+DesiredOS=\"rhel7\"\n")
subOut.write("+RequiresCVMFS=True\n")
subOut.write(line)
subIn.close()
subOut.close()
print("Generating submission aggregation script")
resub_agg_file = BF_dir+"/condor_resubmit.sh"
aggfile = open(resub_agg_file, "w")
for key in subDiff:
line = "condor_submit "+BF_dir+"/resub_src/submit_"+key+".sh\n"
aggfile.write(line)
aggfile.close()
os.chmod(resub_agg_file, 0o0777)
print("done, to launch datacards do this:")
print("./"+BF_dir+"/condor_resubmit.sh")
#in here
#vim condor_submit.sh
#condor_submit BF_B135_bugfix16_HinoN2C1_MCstats/src/submit_0.sh
#BF_B135_TChiWZ_MCstats/log/job_114.log.out
#how many sub src files are there?
#ls BF_dir/src