CMS 3D CMS Logo

isotrackNtuplerCondor.py
Go to the documentation of this file.
1 from pathlib import Path
2 import json
3 import os
4 from optparse import OptionParser
5 import subprocess
6 import uproot3
7 
8 parser=OptionParser()
9 MYDIR=os.getcwd()
10 
11 parser.add_option("-q","--flavour",dest="jobFlavour",type="str",default="workday",help="job FLAVOUR",metavar="FLAVOUR")
12 
13 parser.add_option("--filePU",dest="PU_file",type=str, default=None,help="input PU file")
14 
15 parser.add_option("--isotrackNtupler", dest="IsotrackNtupler", type=str, default=None, help="location of isotrackNtupler")
16 
17 
18 
19 
20 parser.add_option("--fileNPU", dest="NoPU_file", type=str, default=None,
21  help="input NoPU file")
22 
23 parser.add_option("--output", "-o", dest="output_dir", type=str,
24  help="location of output file directory without '/' ", )
25 
26 opts, args = parser.parse_args()
27 
28 jobDir = MYDIR + '/condor_jobs_vF4'
29 Path(jobDir).mkdir(parents=True, exist_ok=False)
30 job_files = []
31 
32 PU_tree = uproot3.open(opts.PU_file)['hcalIsoTrkAnalyzer/CalibTree']
33 pu_entries = PU_tree.numentries
34 print("No of elements in pileup samples",pu_entries)
35 
36 scale = 5000000
37 pu_start = 0
38 i = 0
39 
40 print("Creating jobs ------->")
41 for index in range(0,pu_entries, scale):
42  print(i)
43  pu_stop = index+scale
44  if (pu_stop > pu_entries):
45  pu_stop = pu_entries
46  output_file = opts.output_dir + "/IsoTrkNtupler"
47  arguments = "%s -NPU %s -PU %s --start %i --end %i -O %s"%(opts.IsotrackNtupler, opts.NoPU_file, opts.PU_file, pu_start, pu_stop, output_file)
48  pu_start = pu_stop
49  file_name = "IsoTrkNtupler_" + str(i)
50  job_file_name = os.path.join(jobDir, f"{file_name}.sub")
51  job_file_out = os.path.join(jobDir, f"{file_name}.out")
52  job_file_err = os.path.join(jobDir, f"{file_name}.err")
53 
54  with open(job_file_name, "w") as submit_file:
55  submit_file.write(f"executable = /eos/user/d/dasgupsu/anaconda3/envs/dna/bin/python3.8\n")
56  submit_file.write(f"arguments = {arguments}\n")
57  submit_file.write(f"output = {job_file_out}\n")
58  submit_file.write(f"error = {job_file_err}\n")
59  submit_file.write("getenv = True\n")
60  submit_file.write(f'+JobFlavour = "{opts.jobFlavour}"\n')
61  submit_file.write("queue 1\n")
62  job_files.append(job_file_name)
63  i+= 1
64 
65 for jf in job_files:
66  if jobDir.startswith("/eos"):
67  subprocess.run(["condor_submit", "-spool", jf])
68  else:
69  subprocess.run(["condor_submit", jf])
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def mkdir(path)
Definition: eostools.py:251
#define str(s)