Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
runCondor.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file runCondor.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 if __name__ == '__main__':
12  parser = OptionParser(usage="usage: %prog ver [options -h]")
13  parser.add_option("-d", "--data", dest="data", action="store_true", default=False, help="Is data or simulation")
14  parser.add_option("-g", "--generator", dest="generator", default="HIJING", help="Generator type (HIJING, EPOS, AMPT)")
15  parser.add_option("-n", "--eventPerJob", dest="eventPerJob", default=200, help="Number of events per job")
16  parser.add_option("-j", "--nJob", dest="nJob", default=400, help="Number of jobs (queues)")
17  parser.add_option("-o", "--outputdir", dest="outputdir", default="HIJING_ana398_zvtx-20cm_dummyAlignParams", help="Output directory (under /sphenix/user/hjheng/TrackletAna/data/INTT/)")
18  parser.add_option("-s", "--softwareversion", dest="softwareversion", default="new", help="Software version (new, ana.3xx)")
19  parser.add_option("-c", "--submitcondor", dest="submitcondor", action="store_true", default=False, help="Submit condor jobs")
20 
21  (opt, args) = parser.parse_args()
22  print('opt: {}'.format(opt))
23 
24  data = opt.data
25  generator = opt.generator
26  eventPerJob = int(opt.eventPerJob)
27  nJob = int(opt.nJob)
28  outputdir = opt.outputdir
29  softwareversion = opt.softwareversion
30  submitcondor = opt.submitcondor
31  username = pwd.getpwuid(os.getuid())[0]
32  # print ('username: {}'.format(username))
33  # subdir = 'data' if data else 'sim/{}'.format(generator)
34  ntupledest = '/sphenix/user/{}/TrackletAna/data/INTT/{}'.format(username,outputdir)
35  os.makedirs(ntupledest, exist_ok=True)
36 
37  os.makedirs('./condorLog/', exist_ok=True)
38  if not dir_empty('./condorLog/'):
39  os.system('rm ./condorLog/*')
40 
41  condorFileName = "submitCondor_process{}.job".format('Data' if data else 'Sim{}'.format(generator))
42  condorFile = open("{}".format(condorFileName), "w")
43  condorFile.write("Universe = vanilla\n")
44  condorFile.write("initialDir = /sphenix/user/{}/sPHENIXdNdEta/macros/\n".format(username))
45  condorFile.write("Executable = $(initialDir)/production_INTT.sh\n")
46  condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
47  condorFile.write("request_memory = 4GB\n")
48  condorFile.write("Priority = 20\n")
49  condorFile.write("job_lease_duration = 3600\n")
50  condorFile.write("runData = {}\n".format(1 if data else 0))
51  condorFile.write("generator = {}\n".format(generator))
52  condorFile.write("nEvents = {}\n".format(eventPerJob))
53  condorFile.write("filename = {}/ntuple_$(Process).root\n".format(ntupledest))
54  condorFile.write("Output = $(Initialdir)/condor_INTT/condorLog/process{}_$(Process).out\n".format('Data' if data else 'Sim{}'.format(generator)))
55  condorFile.write("Error = $(Initialdir)/condor_INTT/condorLog/process{}_$(Process).err\n".format('Data' if data else 'Sim{}'.format(generator)))
56  condorFile.write("Log = $(Initialdir)/condor_INTT/condorLog/process{}_$(Process).log\n".format('Data' if data else 'Sim{}'.format(generator)))
57  condorFile.write("Arguments = \"$(runData) $(generator) $(nEvents) $(filename) $(Process) $(softwareversion)\"\n")
58  condorFile.write("Queue {}\n".format(nJob))
59  condorFile.close() # Close the file before submitting the job
60 
61  if submitcondor:
62  cmd = 'condor_submit ' + condorFileName
63  os.system(cmd)