File indexing completed on 2025-08-05 08:14:33
0001 import sys, os
0002 from os import environ
0003 import argparse
0004
0005 parser = argparse.ArgumentParser(description='sPHENIX MDC2 Reco Job Creator')
0006 parser.add_argument('-i', '--inputType', default="JETS", help='Input type: PYTHIA8_PP_MB, HIJING_[0-20/0-4P88], CHARM[D0], BOTTOM[D0]')
0007 parser.add_argument('-f', '--nFilesPerJob', default=30, type=int, help='Number of input files to pass to each job')
0008 parser.add_argument('-t', '--nTotEvents', default=-1, type=int, help='Total number of events to run over')
0009
0010 args = parser.parse_args()
0011
0012 with open("Run_List_Generator/FileLists/NJA_Full_ppGoldenRunList_Version5.txt") as file_in:
0013 lines = [line.rstrip('\n') for line in file_in]
0014 print(len(lines))
0015
0016 inputType = args.inputType.upper()
0017
0018 dstSets = ['DST_CALO']
0019
0020 myShell = str(environ['SHELL'])
0021 goodShells = ['/bin/bash', '/bin/tcsh']
0022 if myShell not in goodShells:
0023 print("Your shell {} was not recognised".format(myShell))
0024 sys.exit()
0025
0026 def makeCondorJob():
0027 print("Creating condor submission files for {} production".format(inputType))
0028 inputFiles = []
0029 line = []
0030 NFiles = []
0031
0032 for i in range(len(lines)):
0033 f1 = open("Run_List_Generator/dst_list/{0}_run2pp-000{1}.list".format(dstSets[0].lower(), lines[i].lower()), "r")
0034 inputFiles.append(f1)
0035 line.append(inputFiles[i].readline())
0036 with open("Run_List_Generator/dst_list/{0}_run2pp-000{1}.list".format(dstSets[0].lower(), lines[i].lower()), "r") as f:
0037 for j, _ in enumerate(f):
0038 pass
0039 NFiles.append(j+1)
0040
0041 myOutputPath = os.getcwd()
0042 condorDir = "{}/condorJob".format(myOutputPath)
0043 os.makedirs("{}/log".format(condorDir), exist_ok=True)
0044 os.makedirs("{}/fileLists".format(condorDir), exist_ok=True)
0045
0046 nJob = 0;
0047 Current_Count = 0;
0048 while line[0]:
0049 listFile = []
0050 listFileGeneric = []
0051 fileStart = "fileLists/productionFiles-{1}-{2}-".format(condorDir, inputType, dstSets[0].lower(), lines[i].lower())
0052 with open('listRun.txt','w') as file:
0053 for i in range(len(lines)):
0054 Current_Count = 0;
0055 while(Current_Count < NFiles[i]*1/(args.nFilesPerJob)):
0056 file.write('{0}\n'.format(lines[i].lower()))
0057 listFile.append("{0}/{1}{2:05d}.list".format(condorDir, fileStart, nJob))
0058 productionFilesToUse = open(listFile[nJob], "w")
0059 for j in range(0, args.nFilesPerJob):
0060 splitLine = line[i].split("/")
0061 fileName = splitLine[-1]
0062 productionFilesToUse.write(fileName)
0063 line[i] = inputFiles[i].readline()
0064 if ((Current_Count + 1) > NFiles[i]*1/(args.nFilesPerJob)) and (Current_Count*args.nFilesPerJob + j == NFiles[i]):
0065 break
0066 nJob += 1
0067 Current_Count += 1
0068
0069 listFileGeneric.append("$(condorDir)/{0}$INT(Process,%05d).list".format(fileStart))
0070 listFileGeneric.append("$INT(Process,%05d)")
0071
0072 condorFileName = "{0}/my{1}.job".format(condorDir, inputType)
0073 condorFile = open("{}".format(condorFileName), "w")
0074 condorFile.write("Universe = vanilla\n")
0075 condorFile.write("initialDir = {}\n".format(myOutputPath))
0076 if myShell == '/bin/bash': condorFile.write("Executable = $(initialDir)/run_Events.sh\n")
0077 condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
0078 condorFile.write("request_memory = 6144MB\n")
0079 condorFile.write("concurrency_limits = CONCURRENCY_LIMIT_DEFAULT:1000\n")
0080 condorFile.write("Priority = 20\n")
0081 condorFile.write("job_lease_duration = 3600\n")
0082 condorFile.write("condorDir = $(initialDir)/condorJob\n")
0083 condorOutputInfo = "$(condorDir)/log/condor-{0}-$INT(Process,%05d)".format(inputType)
0084 condorFile.write("Output = {0}.out\n".format(condorOutputInfo))
0085 condorFile.write("Error = {0}.err\n".format(condorOutputInfo))
0086 condorFile.write("Log = /tmp/condor-napple-$INT(Process,%05d).log\n")
0087 condorFile.write("Arguments = \"{}\"\n".format(' '.join(listFileGeneric)))
0088 condorFile.write("Queue {}\n".format(nJob))
0089 print("Submission setup complete!")
0090 print("This setup will submit {} subjobs".format(nJob))
0091 print("You can submit your job with the script:\n{}".format(condorFileName))
0092
0093 makeCondorJob()