File indexing completed on 2025-08-05 08:12:56
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="PYTHIA8_PP_MB", help='Input type: PYTHIA8_PP_MB, HIJING_[0-20/0-4P88], HF_CHARM[D0], HF_BOTTOM[D0], JET_[10GEV/30GEV/PHOTON], SINGLE_PARTICLE')
0007 parser.add_argument('-f', '--nFilesPerJob', default=5, 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 parser.add_argument('-r', '--run', default=11, type=int, help='Production run to use')
0010 parser.add_argument('--nopileup', help='Get data without pileup', action="store_true")
0011 parser.add_argument('--truth', help='Enable truth DST reading', action="store_true")
0012 parser.add_argument('--calo', help='Enable calo DST reading', action="store_true")
0013 parser.add_argument('--trkr_hit', help='Enable tracker hit DST reading', action="store_true")
0014 parser.add_argument('--mbd', help='Enable MBD/ZDC DST reading', action="store_true")
0015 parser.add_argument('--mbd_g4hit', help='Enable MBD G4 hit DST reading', action="store_true")
0016 parser.add_argument('--g4hit', help='Enable G4 hit DST reading', action="store_true")
0017 parser.add_argument('--truth_table', help='Use DSTs for running tracking and making the truth/reco table', action="store_true")
0018
0019 args = parser.parse_args()
0020
0021 inputType = args.inputType.upper()
0022
0023 types = {'PYTHIA8_PP_MB' : 3, 'HIJING_0-20' : 4, 'HIJING_0-4P88' : 6, 'HF_CHARM' : 7, 'HF_BOTTOM' : 8, 'HF_CHARMD0' : 9, 'HF_BOTTOMD0' : 10
0024 , 'JET_30GEV' : 11, 'JET_10GEV' : 12, 'JET_PHOTON' : 13, 'SINGLE_PARTICLE' : 14 , 'D0JETS' : 17}
0025 if inputType not in types:
0026 print("The argument, {}, was not known. Use --help to see available types".format(args.inputType))
0027 sys.exit()
0028
0029
0030 dstSets = ['DST_TRACKS', 'DST_GLOBAL']
0031 if args.truth:
0032 args.g4hit = False
0033 dstSets.append('DST_TRUTH')
0034
0035 dstSets.append('G4Hits')
0036 dstSets.append('DST_TRACKSEEDS')
0037 dstSets.append('DST_TRKR_CLUSTER')
0038 if args.calo: dstSets.append('DST_CALO_CLUSTER')
0039 if args.trkr_hit: dstSets.append('DST_TRKR_HIT')
0040 if args.mbd:
0041 dstSets.append('DST_MBD_EPD')
0042 if args.mbd_g4hit:
0043 args.g4hit = False
0044 dstSets.append('DST_BBC_G4HIT')
0045 if args.g4hit: dstSets.append('G4Hits')
0046 if args.truth_table:
0047 dstSets.append('DST_TRUTH_RECO')
0048 if args.truth == False: dstSets.append('DST_TRUTH')
0049
0050 myShell = str(environ['SHELL'])
0051 goodShells = ['/bin/bash', '/bin/tcsh']
0052 if myShell not in goodShells:
0053 print("Your shell {} was not recognised".format(myShell))
0054 sys.exit()
0055
0056 memory = 8
0057
0058 def makeCondorJob():
0059 print("Creating condor submission files for {} production".format(inputType))
0060 inputFiles = []
0061 line = []
0062 for i in range(len(dstSets)):
0063 inputFiles.append(open("{0}.list".format(dstSets[i].lower()), "r"))
0064 line.append(inputFiles[i].readline())
0065 myOutputPath = os.getcwd()
0066 condorDir = "{}/condorJob".format(myOutputPath)
0067 os.makedirs("{}/log".format(condorDir), exist_ok=True)
0068 os.makedirs("{}/fileLists".format(condorDir), exist_ok=True)
0069 nJob = 0;
0070 while line[0]:
0071 listFile = []
0072 listFileGeneric = []
0073 for i in range(len(dstSets)):
0074 fileStart = "fileLists/productionFiles-{1}-{2}-".format(condorDir, inputType, dstSets[i].lower())
0075 listFile.append("{0}/{1}{2:05d}.list".format(condorDir, fileStart, nJob))
0076 listFileGeneric.append("$(condorDir)/{0}$INT(Process,%05d).list".format(fileStart))
0077 productionFilesToUse = open(listFile[i], "w")
0078 for j in range(0, args.nFilesPerJob):
0079 splitLine = line[i].split("/")
0080 fileName = splitLine[-1]
0081 productionFilesToUse.write(fileName)
0082 line[i] = inputFiles[i].readline()
0083 nJob += 1
0084 condorFileName = "{0}/my{1}.job".format(condorDir, inputType)
0085 condorFile = open("{}".format(condorFileName), "w")
0086 condorFile.write("Universe = vanilla\n")
0087 condorFile.write("initialDir = {}\n".format(myOutputPath))
0088 if myShell == '/bin/bash': condorFile.write("Executable = $(initialDir)/run_MDC2reco.sh\n")
0089 if myShell == '/bin/tcsh': condorFile.write("Executable = $(initialDir)/run_MDC2reco.csh\n")
0090 condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
0091 condorFile.write("request_memory = {}GB\n".format(memory))
0092 condorFile.write("Priority = 20\n")
0093 condorFile.write("job_lease_duration = 3600\n")
0094 condorFile.write("condorDir = $(initialDir)/condorJob\n")
0095 condorOutputInfo = "$(condorDir)/log/condor-{0}-$INT(Process,%05d)".format(inputType)
0096 condorFile.write("Output = {0}.out\n".format(condorOutputInfo))
0097 condorFile.write("Error = {0}.err\n".format(condorOutputInfo))
0098 condorFile.write("Log = {0}.log\n".format(condorOutputInfo))
0099 condorFile.write("Arguments = \"{}\"\n".format(' '.join(listFileGeneric)))
0100 condorFile.write("Queue {}\n".format(nJob))
0101 print("Submission setup complete!")
0102 print("This setup will submit {} subjobs".format(nJob))
0103 print("You can submit your job with the script:\n{}".format(condorFileName))
0104
0105 catalogCommand = "CreateFileList.pl -run {0} -type {1} {2}".format(args.run, types[inputType], ' '.join(dstSets))
0106 if args.nTotEvents != -1: catalogCommand += " -n {}".format(args.nTotEvents)
0107 if args.nopileup: catalogCommand += " -nopileup"
0108 os.system(catalogCommand)
0109 makeCondorJob()