Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:34:34

0001 from pathlib import Path
0002 import json
0003 import os
0004 from optparse import OptionParser
0005 import subprocess
0006 import uproot3
0007 
0008 parser=OptionParser()
0009 MYDIR=os.getcwd()
0010 
0011 parser.add_option("-q","--flavour",dest="jobFlavour",type="str",default="workday",help="job FLAVOUR",metavar="FLAVOUR")
0012 
0013 parser.add_option("--filePU",dest="PU_file",type=str, default=None,help="input PU file")
0014 
0015 parser.add_option("--isotrackNtupler", dest="IsotrackNtupler", type=str, default=None, help="location of isotrackNtupler")
0016 
0017 
0018 
0019 
0020 parser.add_option("--fileNPU", dest="NoPU_file", type=str, default=None,
0021                     help="input NoPU file")
0022 
0023 parser.add_option("--output", "-o", dest="output_dir", type=str,
0024                     help="location of output file directory without '/' ", )
0025 
0026 opts, args = parser.parse_args()
0027 
0028 jobDir = MYDIR + '/condor_jobs_vF4'
0029 Path(jobDir).mkdir(parents=True, exist_ok=False)
0030 job_files = []
0031 
0032 PU_tree = uproot3.open(opts.PU_file)['hcalIsoTrkAnalyzer/CalibTree']
0033 pu_entries = PU_tree.numentries
0034 print("No of elements in pileup samples",pu_entries)
0035 
0036 scale = 5000000
0037 pu_start = 0
0038 i = 0
0039 
0040 print("Creating jobs ------->")
0041 for index in range(0,pu_entries, scale):
0042     print(i)
0043     pu_stop = index+scale
0044     if (pu_stop > pu_entries):
0045         pu_stop = pu_entries
0046     output_file = opts.output_dir + "/IsoTrkNtupler"
0047     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)
0048     pu_start = pu_stop
0049     file_name = "IsoTrkNtupler_" + str(i)
0050     job_file_name = os.path.join(jobDir, f"{file_name}.sub")
0051     job_file_out = os.path.join(jobDir, f"{file_name}.out")
0052     job_file_err = os.path.join(jobDir, f"{file_name}.err")
0053 
0054     with open(job_file_name, "w") as submit_file:
0055         submit_file.write(f"executable = /eos/user/d/dasgupsu/anaconda3/envs/dna/bin/python3.8\n")
0056         submit_file.write(f"arguments =  {arguments}\n")
0057         submit_file.write(f"output = {job_file_out}\n")
0058         submit_file.write(f"error = {job_file_err}\n")
0059         submit_file.write("getenv = True\n")
0060         submit_file.write(f'+JobFlavour = "{opts.jobFlavour}"\n')
0061         submit_file.write("queue 1\n")
0062     job_files.append(job_file_name)
0063     i+= 1
0064 
0065 for jf in job_files:
0066     if jobDir.startswith("/eos"):
0067         subprocess.run(["condor_submit", "-spool", jf])
0068     else:                
0069         subprocess.run(["condor_submit", jf])