20 import shlex, subprocess
23 parser = argparse.ArgumentParser(description=
'''
24 Creates reference ESD/AOD by running a series of Reco_tf.py from a given input
25 file (typically RDO or RAW).
26 Performs typically 2 jobs :
29 Each step produces a file which is expected to be similar to the reference
30 files in /afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/.
33 %s MC # -> create reference files from /afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/RDO
34 %s MC MyDir # -> same but creates files under MyDir/
35 %s ESD.root MyDir # -> create an AOD reference file from ESD.root under MyDir/
36 '''%((os.path.basename(sys.argv[0]),)*3),
37 formatter_class=argparse.RawDescriptionHelpFormatter,
40 parser.add_argument(
'sampleType', type=str, help=
'full path to a file. Or "mc" or "data" : will start with a reference RDO or RAW file from the JetEtmiss afs space' )
41 parser.add_argument(
'outputDir', type=str, nargs=
'?', default=
'jetRefFiles/')
43 parser.add_argument(
'-n',
'--noRun', action=
'store_true', help=
'Do not run the Reco_tf commands, just print them.')
44 parser.add_argument(
'--maxEvents', type=int, default=50, help=
"Propaged to the maxEvents of the Reco_tf commands")
45 parser.add_argument(
'--oneStep', action=
'store_true' , help=
"stop after 1st step processed")
46 parser.add_argument(
'--overWrite', action=
'store_true' , help=
"force to overWrite the output dir")
49 arg=parser.parse_args()
54 maxEvents=arg.maxEvents
66 specifyCondAndGeo=
False
67 geometryVersion=
"ATLAS-GEO-20-00-01"
68 conditionsTagMC=
"OFLCOND-MC12-SDR-06"
69 conditionsTagData=
"COMCOND-BLKPA-RUN1-01"
76 defaultMC=
"/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/RDO/mc12_8TeV.CurrentRef.RDO.pool.root"
77 defaultData=
"/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/DATA/RAW/data12_8TeV.CurrentRef.RAW"
82 if not os.path.exists(dir):
84 elif not arg.overWrite:
87 print (
" Directory ",dir,
'already exists. Not overwriting it (use --overWrite option if needed)')
94 if not os.path.exists(inputFile)
and not arg.noRun:
95 print (
'ERROR input file ', inputFile ,
' missing')
99 transform=
"Reco_tf.py"
101 inputFileBase = os.path.basename(inputFile)
103 if 'HITS' in inputFileBase:
109 elif "RDO" in inputFileBase:
111 inputDataType=inputType
113 preExec=
'''flags.Reco.EnableTrigger=False; flags.Reco.EnableBTagging=False'''
115 elif "RAW" in inputFileBase:
119 preExec=
'''flags.Reco.EnableTrigger=False'''
121 elif 'ESD' in inputFileBase:
123 inputDataType=inputType
125 preExec=
'''flags.Reco.EnableTrigger=False'''
128 print (
"ERROR RunStep: Input file does not appear to be a supported type (RAW, HITS, RDO, ESD)")
129 print (
' -> got', inputFileBase)
132 print (
"Starting ",inputType,
' to ', outputType)
135 runDir = arg.outputDir +
'/' + inputType+
'to'+outputType +
'/'
136 if not os.path.exists(runDir):
138 outputFile = runDir + inputFileBase.replace(inputType, outputType)
139 if arg.overWrite
and os.path.exists(outputFile):
140 os.remove(outputFile)
142 outputLog = runDir+
'log'
144 if specifyCondAndGeo:
146 fullComand=
"${transform} preExec=${preExec} input${inputDataType}File=${inputDir}/${inputFile} output${outputType}File=${outputFile} maxEvents=${maxEvents} skipEvents=${skipEvents} geometryVersion=$geometryVersion conditionsTag=$conditionsTag autoConfiguration=everything"
148 comandArgs = [
'--preExec='+preExec,
149 '--input%sFile=%s'%(inputDataType, inputFile),
150 '--output%sFile=%s'%(outputType, outputFile),
151 '--maxEvents='+
str(maxEvents),
152 '--skipEvents='+
str(skipEvents),
153 '--autoConfiguration=everything',
158 print (transform,
' '.
join(comandArgs))
164 logfile =
open(outputLog,
'w')
165 res = subprocess.call( [transform] + comandArgs, stdout=logfile, stderr=logfile)
169 print (
'ERROR RunStep: Transform appears to have failed - exiting. Check ', outputLog)
174 print (
'Done %s to %s step'%(inputType, outputType))
179 print (
'runChain ', inputFile)
180 while any( [t
in os.path.basename(inputFile)
for t
in [
'HITS',
'RDO',
'RAW',
'ESD'] ] ):
181 print (
'runStep at ',os.path.basename(inputFile))
187 if arg.sampleType.lower() ==
'mc':
189 elif arg.sampleType.lower() ==
'data':
190 inputFile=defaultData
193 inputFile = os.path.abspath(arg.sampleType)
195 if not os.path.exists(inputFile):
196 print (
'ERROR Input path does not exist ', inputFile)
200 arg.outputDir = os.path.abspath(arg.outputDir)