3 import os, sys, subprocess
19 mc_wishlist.append(
"SMS-T1tttt_mGluino")
22 mc_wishlist.append(
"TTJets_DiLept_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
23 mc_wishlist.append(
"TTJets_HT-1200to2500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
24 mc_wishlist.append(
"TTJets_HT-2500toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
25 mc_wishlist.append(
"TTJets_HT-600to800_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
26 mc_wishlist.append(
"TTJets_HT-800to1200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
27 mc_wishlist.append(
"TTJets_SingleLeptFromT_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
28 mc_wishlist.append(
"TTJets_SingleLeptFromTbar_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
29 mc_wishlist.append(
"TTJets_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
32 mc_wishlist.append(
"QCD_HT1000to1500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
33 mc_wishlist.append(
"QCD_HT1500to2000_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
34 mc_wishlist.append(
"QCD_HT2000toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
35 mc_wishlist.append(
"QCD_HT200to300_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
36 mc_wishlist.append(
"QCD_HT300to500_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
37 mc_wishlist.append(
"QCD_HT500to700_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
38 mc_wishlist.append(
"QCD_HT700to1000_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
41 mc_wishlist.append(
"DYJetsToLL_M-50_HT-100to200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
42 mc_wishlist.append(
"DYJetsToLL_M-50_HT-200to400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
43 mc_wishlist.append(
"DYJetsToLL_M-50_HT-400to600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
44 mc_wishlist.append(
"DYJetsToLL_M-50_HT-600toInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
45 mc_wishlist.append(
"DYJetsToLL_M-50_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
46 mc_wishlist.append(
"ST_s-channel_4f_leptonDecays_13TeV-amcatnlo-pythia8_TuneCUETP8M1_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
47 mc_wishlist.append(
"ST_t-channel_antitop_4f_leptonDecays_13TeV-powheg-pythia8_TuneCUETP8M1_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
48 mc_wishlist.append(
"ST_t-channel_top_4f_leptonDecays_13TeV-powheg-pythia8_TuneCUETP8M1_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
49 mc_wishlist.append(
"ST_tW_antitop_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M1_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
50 mc_wishlist.append(
"ST_tW_top_5f_inclusiveDecays_13TeV-powheg-pythia8_TuneCUETP8M1_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
51 mc_wishlist.append(
"TTGJets_TuneCUETP8M1_13TeV-amcatnloFXFX-madspin-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
52 mc_wishlist.append(
"TTTT_TuneCUETP8M1_13TeV-amcatnlo-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
53 mc_wishlist.append(
"TTWJetsToLNu_TuneCUETP8M1_13TeV-amcatnloFXFX-madspin-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
54 mc_wishlist.append(
"TTWJetsToQQ_TuneCUETP8M1_13TeV-amcatnloFXFX-madspin-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
55 mc_wishlist.append(
"TTZToLLNuNu_M-10_TuneCUETP8M1_13TeV-amcatnlo-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
56 mc_wishlist.append(
"TTZToQQ_TuneCUETP8M1_13TeV-amcatnlo-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
57 mc_wishlist.append(
"WJetsToLNu_HT-100To200_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
58 mc_wishlist.append(
"WJetsToLNu_HT-200To400_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
59 mc_wishlist.append(
"WJetsToLNu_HT-400To600_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
60 mc_wishlist.append(
"WJetsToLNu_HT-600ToInf_TuneCUETP8M1_13TeV-madgraphMLM-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
61 mc_wishlist.append(
"WWTo2L2Nu_13TeV-powheg_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
62 mc_wishlist.append(
"WWToLNuQQ_13TeV-powheg_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
63 mc_wishlist.append(
"WZTo2L2Q_13TeV_amcatnloFXFX_madspin_pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
64 mc_wishlist.append(
"WZTo3LNu_TuneCUETP8M1_13TeV-powheg-pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9")
65 mc_wishlist.append(
"ttHJetTobb_M125_13TeV_amcatnloFXFX_madspin_pythia8_RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9_ext3")
76 jsonlist = glob.glob(
"data/json/subgolden_*.json")
80 for jsonfile
in jsonlist:
82 with open(jsonfile)
as jfile:
83 jdata = json.load(jfile)
84 goldruns[jsonfile] = [int(i)
for i
in jdata.keys()]
87 maxfiles = int(raw_input(
'Enter max number of files per job: '))
94 comb_keys = [
'RunIISpring15DR74_Asympt25ns_MCRUN2_74_V9',
'RunIISpring15FSPremix_MCRUN2_74_V9',
'RunIISpring15MiniAODv2_74X_mcRun2_asymptotic_v2',
'Run2015D']
101 if (maxjobs!=-1
or maxevents_perjob!=-1
or maxds!=-1):
102 istest = raw_input(
'Running in test mode with %i jobs, %i events per job, over %i datasets. Enter \'y\' to continue: ' % (maxjobs, maxevents_perjob, maxds))
104 sys.exit(
"No jobs submitted. Edit sub_cond.py to exit test mode.")
108 whitelist =
"T2_US_UCSD,T2_US_WISCONSIN,T2_US_FLORIDA,T2_US_PURDUE,T2_US_NEBRASKA,T2_US_CALTECH" 115 host = os.environ.get(
"HOSTNAME")
116 if "ucsd" in host: host =
"sd" 117 elif (
"compute" in host)
or (
"physics.ucsb.edu" in host) : host =
"sb" 118 else: sys.exit(
"\033[91mERROR: Unknown host: "+host+
" Exit. \033[0m")
119 print "INFO: Setting up job submission at",(
'UCSB.' if host==
'sb' else 'UCSD.')
120 hadoop =
'/mnt/hadoop/cms' 121 if host==
"sd": hadoop =
'/hadoop/cms/phedex' 124 codedir = os.getcwd()
125 if not (
"/src/babymaker")
in codedir:
126 print "\033[91mERROR: Please submit from path consistent with: .../src/babymaker/ \033[0m\n" 132 proc = subprocess.Popen(
'voms-proxy-info', stdout=subprocess.PIPE)
133 tmp = proc.stdout.read()
134 if "Proxy not found" in tmp:
135 sys.exit(
"\033[91mERROR: Proxy not found. \033[0m")
136 elif (
'timeleft' in tmp)
and (
'0:00:00' in tmp):
137 sys.exit(
"\033[91mERROR: Proxy expired. \033[0m")
139 for info
in tmp.splitlines():
140 if (
"/tmp/x509" in info): proxy =
"/tmp/x509"+(string.split(info,
"/tmp/x509"))[1]
141 if (
"timeleft" in info): valid =
"Time left before proxy expires: "+info.split()[-1]
143 print "INFO: Found proxy path",proxy
147 outdir = os.getcwd()+
'/out/' 148 sub_time = time.strftime(
"%y%m%d_%H%M%S", time.gmtime())
149 if not (os.path.exists(os.path.realpath(outdir))):
150 sys.exit(
"\033[91m ERROR: Directory "+outdir+
" does not exist. Please either create a sym link or dir. \033[0m")
151 outdir = os.path.join(os.path.realpath(outdir),sub_time)
154 logdir = os.path.join(os.getcwd(),
"logs", sub_time)
155 if not os.path.exists(logdir):
157 print "INFO: Babies will be written to: ", outdir
158 print "INFO: Logs will be written to: ", logdir
161 if not (os.path.exists(os.getcwd()+
'/run')):
162 os.mkdir(os.getcwd()+
'/run')
163 rundir = os.path.join(os.path.realpath(os.getcwd()+
'/run'),sub_time)
168 flistdir = os.path.join(os.getenv(
"CMSSW_BASE"),
"src/flists/")
169 if not os.path.exists(flistdir):
170 sys.exit(
"ERROR: flists repository not found.")
174 flists_pd = glob.glob(os.path.join(flistdir,
"flist*.txt"))
175 for fnm
in flists_pd:
176 if any(wish
in fnm
for wish
in mc_wishlist):
178 if any(ikey
in fnm
for ikey
in comb_keys):
179 for ikey
in comb_keys:
181 dsname = string.split(string.split(fnm,
"flist_").pop(),ikey)[0] + ikey
184 sys.exit(
"ERROR: None of the combination keys (%s) were found in this flist:%s\n" % (comb_keys,fnm))
186 print "INFO: Adding PD: ",fnm.replace(
"flist_",
"").replace(
".txt",
"")
188 if dsname
not in files_dict.keys():
189 nent_dict[dsname] = 0
190 files_dict[dsname] = []
193 if (
"nEventsTotal" in line):
194 nent_dict[dsname] = nent_dict[dsname] + int(line.split().pop())
195 if "/store" not in line:
continue 197 files_dict[dsname].append(col[2])
200 for pd
in data_wishlist:
202 for json
in jsonlist:
203 dsname = pd + json.replace(
'data/json/subgolden',
'').replace(
'.json',
'')
204 files_dict[dsname] = []
205 nent_dict[dsname] = 0
207 flists_pd = glob.glob(os.path.join(flistdir,
"flist_"+pd+
"_Run2015D*.txt"))
208 for fnm
in flists_pd:
211 if "/store" not in line:
continue 213 runlist = [int(irun)
for irun
in string.split(col[3],
",")]
215 for jsonfile
in goldruns.keys():
216 if run
in goldruns[jsonfile]:
217 dsname = pd + jsonfile.replace(
'data/json/subgolden',
'').replace(
'.json',
'')
218 if (col[2]
not in files_dict[dsname]):
219 files_dict[dsname].append(col[2])
223 print "INFO: Creating babymaker tarball to transfer to work node..." 224 tarcmd =
"tar --directory=../ --exclude=\"out\" --exclude=\"run\"" 225 tarcmd +=
" --exclude=\"logs\" --exclude=\"bmaker/interface/release.hh\"" 226 tarcmd +=
" --exclude=\"data/csc_beamhalo_filter/*\"" 227 tarcmd +=
" --exclude=\".git\"" 228 tarcmd +=
" -c babymaker | xz > ../babymaker.tar.xz" 232 for ids, ds
in enumerate(sorted(files_dict.keys())):
233 if (maxds!=-1
and ids>=maxds):
break 236 cmssw =
"CMSSW_7_4_6_patch6" 237 if (
"Run2015" in ds)
or (
"RunIISpring15MiniAODv2" in ds): cmssw =
"CMSSW_7_4_14" 240 nfiles = len(files_dict[ds])
242 if (maxjobs==-1): njobs = (nfiles/maxfiles)
if (nfiles%maxfiles==0)
else (nfiles/maxfiles+1)
244 for job
in range(0,njobs):
246 bname =
"_".join([
"baby",ds,
"mf"+str(maxfiles),
"batch"+str(job)])
247 print(
"INF0: "+bname)
250 outpath = os.path.join(outdir,bname+
".root")
251 if os.path.exists(outpath):
252 print "\033[38m WARNING: "+outpath+
" already exists. Skip job submission. \033[0m" 257 condor_args.append(
"nEvents="+str(maxevents_perjob))
258 condor_args.append(
"nEventsSample="+str(nent_dict[ds]))
259 condor_args.append(
"inputFiles=\\\n"+
",\\\n".join(files_dict[ds][(job*maxfiles):((job+1)*maxfiles)]))
260 if (host==
"sb"): condor_args.append(
"outputFile="+outpath)
261 else: condor_args.append(
"outputFile="+bname+
".root")
262 condor_args.append(
"condorSubTime="+sub_time)
263 if (
"Run2015D" in ds):
264 json_name =
"data/json/subgolden_Run2015D" + ds.split(
"Run2015D").pop() +
".json" 265 if (json_name
not in jsonlist): sys.exit(
"ERROR: Could not find json!")
266 condor_args.append(
"json=babymaker/"+json_name)
269 exefile =rundir+
"/"+bname+
".sh" 270 fexe = open(exefile,
"w")
272 fexe.write(
"#! /bin/bash\n")
273 fexe.write(
"source /cvmfs/cms.cern.ch/cmsset_default.sh\n")
274 fexe.write(
"cd "+codedir+
"\n")
275 fexe.write(
"eval `scramv1 runtime -sh`\n")
276 fexe.write(
"export ORIGIN_USER="+os.getenv(
"USER")+
"\n")
277 fexe.write(
"cmsRun bmaker/python/bmaker_basic_cfg.py \\\n"+
" \\\n".join(condor_args)+
"\n")
279 fexe.write(
"#! /bin/bash\n")
280 fexe.write(
"source /code/osgcode/cmssoft/cmsset_default.sh\n")
281 fexe.write(
"export SCRAM_ARCH=slc6_amd64_gcc491\n")
282 fexe.write(
"eval `scramv1 project CMSSW "+cmssw+
"`\n")
283 fexe.write(
"cd "+cmssw+
"/src\n")
284 fexe.write(
"eval `scramv1 runtime -sh`\n")
285 fexe.write(
"export ORIGIN_USER="+os.getenv(
"USER")+
"\n")
286 fexe.write(
"tar -xf ../../babymaker.tar.xz\n")
287 fexe.write(
"cd babymaker\n")
288 fexe.write(
"./compile.sh\n")
289 fexe.write(
"cmsRun bmaker/python/bmaker_basic_cfg.py \\\n"+
" \\\n".join(condor_args)+
"\n")
290 fexe.write(
"echo \"cmsRun exit code \"$?\n")
292 if "T1tttt" in bname:
293 fexe.write(
"./bmaker/genfiles/run/skim_scan_onefile.exe "+bname+
".root\n")
294 fexe.write(
"for i in $(ls *.root); do\n")
295 fexe.write(
"\tlcg-cp -b -D srmv2 --vo cms -t 2400 --verbose file:$i srm://bsrm-3.t2.ucsd.edu:8443/srm/v2/server?SFN="+outdir+
"/$i\n")
297 fexe.write(
"cd ../../..\n")
298 fexe.write(
"rm -rf "+cmssw+
"\n")
300 os.system(
"chmod u+x "+exefile)
303 cmdfile = rundir+
"/"+bname+
".cmd" 304 print "cmdfile is "+ cmdfile
305 fcmd = open(cmdfile,
"w")
307 fcmd.write(
"Executable = "+exefile+
"\n")
308 fcmd.write(
"Universe = vanilla\n")
311 fcmd.write(
"use_x509userproxy = True\n")
312 fcmd.write(
"x509userproxy="+proxy+
"\n")
313 fcmd.write(
"Log = "+logdir+
"/"+bname+
".log\n")
314 fcmd.write(
"output = "+logdir+
"/"+bname+
".out\n")
315 fcmd.write(
"error = "+logdir+
"/"+bname+
".err\n")
316 fcmd.write(
"Notification = never\n")
317 fcmd.write(
"Queue\n")
319 fcmd.write(
"Universe = grid\n")
320 fcmd.write(
"Grid_Resource = condor cmssubmit-r1.t2.ucsd.edu glidein-collector.t2.ucsd.edu\n")
321 fcmd.write(
"use_x509userproxy = True\n")
322 fcmd.write(
"x509userproxy="+proxy+
"\n")
323 fcmd.write(
"+remote_DESIRED_Sites=\""+whitelist+
"\"\n")
324 fcmd.write(
"Executable = "+exefile+
"\n")
325 fcmd.write(
"Transfer_Executable = True\n")
326 fcmd.write(
"should_transfer_files = YES\n")
327 fcmd.write(
"transfer_input_files = ../babymaker.tar.xz\n")
328 fcmd.write(
"Notification = Never\n")
329 fcmd.write(
"Log = "+logdir+
"/"+bname+
".log\n")
330 fcmd.write(
"output = "+logdir+
"/"+bname+
".out\n")
331 fcmd.write(
"error = "+logdir+
"/"+bname+
".err\n")
332 fcmd.write(
"queue 1\n")
334 total_jobs = total_jobs + 1
338 cmd =
"ssh cms25.physics.ucsb.edu condor_submit " 340 cmd =
"condor_submit " 341 print "INFO: Submitting", cmdfile
345 os.system(
"scp " + proxy +
" cms25.physics.ucsb.edu:/tmp")
346 os.system(
"cat " + rundir +
"/baby*.cmd > " + rundir +
"/submit_all.cmd")
347 os.system(cmd + rundir +
"/submit_all.cmd")
348 print "Submitted ", total_jobs,
"jobs"