File indexing completed on 2025-08-05 08:13:15
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="HF_CHARM", 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=40, type=int, help='Production run to use')
0010 parser.add_argument('-o', '--condorDir', default="./", help='Condor Output Folder')
0011 parser.add_argument('--nopileup', help='Get data without pileup', action="store_true")
0012 parser.add_argument('--truth', help='Enable truth DST reading', action="store_true")
0013 parser.add_argument('--calo', help='Enable calo DST reading', action="store_true")
0014 parser.add_argument('--trkr_hit', help='Enable tracker hit DST reading', action="store_true")
0015 parser.add_argument('--bbc_g4hit', help='Enable BBC 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' : 16}
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']
0031 dstSets.append('DST_CALO_CLUSTER')
0032 dstSets.append('DST_TRUTH')
0033
0034
0035
0036 dstSets.append('DST_GLOBAL')
0037
0038
0039 """
0040 if not args.nopileup:
0041 stSets.append('DST_VERTEX')
0042 if args.truth:
0043 #args.g4hit = False
0044 dstSets.append('DST_TRUTH')
0045 if not args.nopileup:
0046 dstSets.append('DST_TRKR_G4HIT')
0047 dstSets.append('DST_TRACKSEEDS')
0048 dstSets.append('DST_TRKR_CLUSTER')
0049 if args.calo: dstSets.append('DST_CALO_CLUSTER')
0050 if args.trkr_hit: dstSets.append('DST_TRKR_HIT')
0051 if args.bbc_g4hit:
0052 args.g4hit = False
0053 dstSets.append('DST_BBC_G4HIT')
0054 if args.g4hit: dstSets.append('G4Hits')
0055 if args.truth_table:
0056 dstSets.append('DST_TRUTH_RECO')
0057 if args.truth == False: dstSets.append('DST_TRUTH')
0058 """
0059 myShell = str(environ['SHELL'])
0060 goodShells = ['/bin/bash', '/bin/tcsh']
0061 if myShell not in goodShells:
0062 print("Your shell {} was not recognised".format(myShell))
0063 sys.exit()
0064
0065
0066 def makeCondorJob():
0067 print("Creating condor submission files for {} production".format(inputType))
0068 inputFiles = []
0069 line = []
0070 for i in range(len(dstSets)):
0071 inputFiles.append(open("{0}.list".format(dstSets[i].lower()), "r"))
0072 line.append(inputFiles[i].readline())
0073 myOutputPath = args.condorDir
0074 os.makedirs(myOutputPath)
0075 condorDir = "{}/condorJob".format(myOutputPath)
0076 os.makedirs("{}/log".format(condorDir), exist_ok=True)
0077 os.makedirs("{}/fileLists".format(condorDir), exist_ok=True)
0078 nJob = 0;
0079 while line[0]:
0080 listFile = []
0081 listFileGeneric = []
0082 for i in range(len(dstSets)):
0083 fileStart = "fileLists/productionFiles-{1}-{2}-".format(condorDir, inputType, dstSets[i].lower())
0084 listFile.append("{0}/{1}{2:05d}.list".format(condorDir, fileStart, nJob))
0085 listFileGeneric.append("$(condorDir)/{0}$INT(Process,%05d).list".format(fileStart))
0086 productionFilesToUse = open(listFile[i], "w")
0087 for j in range(0, args.nFilesPerJob):
0088 splitLine = line[i].split("/")
0089 fileName = splitLine[-1]
0090 productionFilesToUse.write(fileName)
0091 line[i] = inputFiles[i].readline()
0092 nJob += 1
0093 condorFileName = "{0}/my{1}.job".format(condorDir, inputType)
0094 condorFile = open("{}".format(condorFileName), "w")
0095 condorFile.write("Universe = vanilla\n")
0096 condorFile.write("initialDir = {}\n".format(os.getcwd()))
0097 if myShell == '/bin/bash': condorFile.write("Executable = $(initialDir)/run_MDC2reco.sh\n")
0098 if myShell == '/bin/tcsh': condorFile.write("Executable = $(initialDir)/run_MDC2reco.csh\n")
0099 condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
0100 condorFile.write("request_memory = 4GB\n")
0101 condorFile.write("Priority = 20\n")
0102 condorFile.write("job_lease_duration = 3600\n")
0103 condorFile.write("condorDir = {}\n".format(condorDir))
0104 condorOutputInfo = "$(condorDir)/log/condor-{0}-$INT(Process,%05d)".format(inputType)
0105 condorFile.write("Output = {0}.out\n".format(condorOutputInfo))
0106 condorFile.write("Error = {0}.err\n".format(condorOutputInfo))
0107 condorFile.write("Log = {0}.log\n".format(condorOutputInfo))
0108 condorFile.write("Arguments = \"$(condorDir) {}\"\n".format(' '.join(listFileGeneric)))
0109 condorFile.write("Queue {}\n".format(nJob))
0110 print("Submission setup complete!")
0111 print("This setup will submit {} subjobs".format(nJob))
0112 print("You can submit your job with the script:\n{}".format(condorFileName))
0113
0114 catalogCommand = "CreateFileList.pl -run {0} -type {1} {2}".format(args.run, types[inputType], ' '.join(dstSets))
0115 if args.nTotEvents != -1: catalogCommand += " -n {}".format(args.nTotEvents)
0116 if args.nopileup: catalogCommand += " -nopileup"
0117 print (catalogCommand)
0118 os.system(catalogCommand)
0119 makeCondorJob()