Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
runCondor_recotracklet.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file runCondor_recotracklet.py
1 from optparse import OptionParser
2 import time
3 import os
4 import pwd
5 import sys
6 import re
7 
8 def dir_empty(dir_path):
9  return not any((True for _ in os.scandir(dir_path)))
10 
11 # Ref: https://www.geeksforgeeks.org/how-to-search-and-replace-text-in-a-file-in-python/
12 def replacetext(filename, search_text, replace_text):
13  with open(filename, 'r+') as f:
14  file = f.read()
15  file = re.sub(search_text, replace_text, file)
16  f.seek(0)
17  f.write(file)
18  f.truncate()
19  # return 'Text {} replaced by {}'.format(search_text, replace_text)
20 
21 
22 if __name__ == '__main__':
23  parser = OptionParser(usage="usage: %prog ver [options -n]")
24  parser.add_option("-d", "--isdata", dest="isdata", action="store_true", default=False, help="Is data")
25  parser.add_option("-f", "--filedesc", dest="filedesc", default='HIJING_ana398_xvtx-0p04cm_yvtx0p24cm_zvtx-20cm_dummyAlignParams', help="File description")
26  parser.add_option("-e", "--nEvents", dest="nEvents", default=200, help="Number of events per job")
27  parser.add_option("-j", "--nJob", dest="nJob", default=400, help="nJob")
28  parser.add_option("-r", "--drcut", dest="drcut", default=0.5, help="Delta R cut for tracklets")
29  parser.add_option("-s", "--submitcondor", dest="submitcondor", action="store_true", default=False, help="Submit condor jobs")
30 
31  (opt, args) = parser.parse_args()
32  print('opt: {}'.format(opt))
33 
34  isdata = opt.isdata
35  filedesc = opt.filedesc
36  nEvents = int(opt.nEvents)
37  drcut = float(opt.drcut)
38  nJob = int(opt.nJob)
39  submitcondor = opt.submitcondor
40  username = pwd.getpwuid(os.getuid())[0]
41 
42  finaloutfiledir = '/sphenix/user/{}/TrackletAna/minitree/INTT/TrackletMinitree_{}/{}'.format(username, filedesc, 'dRcut'+str(drcut).replace('.', 'p'))
43  os.makedirs(finaloutfiledir, exist_ok=True)
44 
45  os.makedirs('./log_recotracklet/', exist_ok=True)
46  if not dir_empty('./log_recotracklet/'):
47  os.system('rm ./log_recotracklet/*')
48 
49  condorFileName = "submitCondor_recotracklet_{}.job".format('data' if isdata else 'sim')
50  condorFile = open("{}".format(condorFileName), "w")
51  condorFile.write("Universe = vanilla\n")
52  condorFile.write("InitialDir = /sphenix/user/{}/TrackletAna/analysis_INTT\n".format(username))
53  condorFile.write("Executable = $(InitialDir)/condor_recotracklet.sh\n")
54  condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
55  condorFile.write("request_memory = 6GB\n")
56  condorFile.write("Priority = 20\n")
57  condorFile.write("job_lease_duration = 3600\n")
58  condorFile.write("isdata = {}\n".format(1 if isdata else 0))
59  condorFile.write("evtvtxmap = /sphenix/user/{}/TrackletAna/minitree/INTT/VtxEvtMap_{}/minitree_$(Process).root\n".format(username, filedesc))
60  condorFile.write("infilename = /sphenix/user/{}/TrackletAna/data/INTT/{}/ntuple_$(Process).root\n".format(username, filedesc))
61  condorFile.write("outfilename = {}/minitree_$(Process).root\n".format(finaloutfiledir))
62  condorFile.write("nevt = {}\n".format(nEvents))
63  condorFile.write("drcut = {:.3g}\n".format(drcut))
64  condorFile.write("Output = $(Initialdir)/condor/log_recotracklet/condorlog_$(Process).out\n")
65  condorFile.write("Error = $(Initialdir)/condor/log_recotracklet/condorlog_$(Process).err\n")
66  condorFile.write("Log = $(Initialdir)/condor/log_recotracklet/condorlog_$(Process).log\n")
67  condorFile.write("Arguments = \"$(isdata) $(evtvtxmap) $(infilename) $(outfilename) $(nevt) $(drcut)\"\n")
68  condorFile.write("Queue {}\n".format(nJob))
69  condorFile.close() # Close the file before submitting the job
70 
71  if submitcondor:
72  cmd = 'condor_submit ' + condorFileName
73  os.system(cmd)