Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
makeCondorJobs.py
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file makeCondorJobs.py
1 import sys, os
2 from os import environ
3 import argparse
4 
5 parser = argparse.ArgumentParser(description='sPHENIX MDC2 Reco Job Creator')
6 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')
7 parser.add_argument('-f', '--nFilesPerJob', default=5, type=int, help='Number of input files to pass to each job')
8 parser.add_argument('-t', '--nTotEvents', default=-1, type=int, help='Total number of events to run over')
9 parser.add_argument('-r', '--run', default=40, type=int, help='Production run to use')
10 parser.add_argument('-o', '--condorDir', default="./", help='Condor Output Folder')
11 parser.add_argument('--nopileup', help='Get data without pileup', action="store_true")
12 parser.add_argument('--truth', help='Enable truth DST reading', action="store_true")
13 parser.add_argument('--calo', help='Enable calo DST reading', action="store_true")
14 parser.add_argument('--trkr_hit', help='Enable tracker hit DST reading', action="store_true")
15 parser.add_argument('--bbc_g4hit', help='Enable BBC G4 hit DST reading', action="store_true")
16 parser.add_argument('--g4hit', help='Enable G4 hit DST reading', action="store_true")
17 parser.add_argument('--truth_table', help='Use DSTs for running tracking and making the truth/reco table', action="store_true")
18 
19 args = parser.parse_args()
20 
21 inputType = args.inputType.upper()
22 
23 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
24  , 'JET_30GEV' : 11, 'JET_10GEV' : 12, 'JET_PHOTON' : 13, 'SINGLE_PARTICLE' : 14 , 'D0JETS' : 16}
25 if inputType not in types:
26  print("The argument, {}, was not known. Use --help to see available types".format(args.inputType))
27  sys.exit()
28 
29 
30 dstSets = ['DST_TRACKS']
31 dstSets.append('DST_CALO_CLUSTER')
32 dstSets.append('DST_TRUTH')
33 #dstSets.append('DST_TRUTH_JET')
34 #added run 8
35 #dstSets.append('DST_TRACKSEEDS')
36 dstSets.append('DST_GLOBAL')
37 
38 
39 """
40 if not args.nopileup:
41  stSets.append('DST_VERTEX')
42 if args.truth:
43  #args.g4hit = False
44  dstSets.append('DST_TRUTH')
45  if not args.nopileup:
46  dstSets.append('DST_TRKR_G4HIT')
47  dstSets.append('DST_TRACKSEEDS')
48  dstSets.append('DST_TRKR_CLUSTER')
49 if args.calo: dstSets.append('DST_CALO_CLUSTER')
50 if args.trkr_hit: dstSets.append('DST_TRKR_HIT')
51 if args.bbc_g4hit:
52  args.g4hit = False
53  dstSets.append('DST_BBC_G4HIT')
54 if args.g4hit: dstSets.append('G4Hits')
55 if args.truth_table:
56  dstSets.append('DST_TRUTH_RECO')
57  if args.truth == False: dstSets.append('DST_TRUTH')
58 """
59 myShell = str(environ['SHELL'])
60 goodShells = ['/bin/bash', '/bin/tcsh']
61 if myShell not in goodShells:
62  print("Your shell {} was not recognised".format(myShell))
63  sys.exit()
64 
65 
66 def makeCondorJob():
67  print("Creating condor submission files for {} production".format(inputType))
68  inputFiles = []
69  line = []
70  for i in range(len(dstSets)):
71  inputFiles.append(open("{0}.list".format(dstSets[i].lower()), "r"))
72  line.append(inputFiles[i].readline())
73  myOutputPath = args.condorDir
74  os.makedirs(myOutputPath)
75  condorDir = "{}/condorJob".format(myOutputPath)
76  os.makedirs("{}/log".format(condorDir), exist_ok=True)
77  os.makedirs("{}/fileLists".format(condorDir), exist_ok=True)
78  nJob = 0;
79  while line[0]:
80  listFile = []
81  listFileGeneric = []
82  for i in range(len(dstSets)):
83  fileStart = "fileLists/productionFiles-{1}-{2}-".format(condorDir, inputType, dstSets[i].lower())
84  listFile.append("{0}/{1}{2:05d}.list".format(condorDir, fileStart, nJob))
85  listFileGeneric.append("$(condorDir)/{0}$INT(Process,%05d).list".format(fileStart))
86  productionFilesToUse = open(listFile[i], "w")
87  for j in range(0, args.nFilesPerJob):
88  splitLine = line[i].split("/")
89  fileName = splitLine[-1]
90  productionFilesToUse.write(fileName)
91  line[i] = inputFiles[i].readline()
92  nJob += 1
93  condorFileName = "{0}/my{1}.job".format(condorDir, inputType)
94  condorFile = open("{}".format(condorFileName), "w")
95  condorFile.write("Universe = vanilla\n")
96  condorFile.write("initialDir = {}\n".format(os.getcwd()))
97  if myShell == '/bin/bash': condorFile.write("Executable = $(initialDir)/run_MDC2reco.sh\n")
98  if myShell == '/bin/tcsh': condorFile.write("Executable = $(initialDir)/run_MDC2reco.csh\n")
99  condorFile.write("PeriodicHold = (NumJobStarts>=1 && JobStatus == 1)\n")
100  condorFile.write("request_memory = 4GB\n")
101  condorFile.write("Priority = 20\n")
102  condorFile.write("job_lease_duration = 3600\n")
103  condorFile.write("condorDir = {}\n".format(condorDir))
104  condorOutputInfo = "$(condorDir)/log/condor-{0}-$INT(Process,%05d)".format(inputType)
105  condorFile.write("Output = {0}.out\n".format(condorOutputInfo))
106  condorFile.write("Error = {0}.err\n".format(condorOutputInfo))
107  condorFile.write("Log = {0}.log\n".format(condorOutputInfo))
108  condorFile.write("Arguments = \"$(condorDir) {}\"\n".format(' '.join(listFileGeneric)))
109  condorFile.write("Queue {}\n".format(nJob))
110  print("Submission setup complete!")
111  print("This setup will submit {} subjobs".format(nJob))
112  print("You can submit your job with the script:\n{}".format(condorFileName))
113 
114 catalogCommand = "CreateFileList.pl -run {0} -type {1} {2}".format(args.run, types[inputType], ' '.join(dstSets))
115 if args.nTotEvents != -1: catalogCommand += " -n {}".format(args.nTotEvents)
116 if args.nopileup: catalogCommand += " -nopileup"
117 print (catalogCommand)
118 os.system(catalogCommand)