5 from __future__
import print_function
21 import shlex, subprocess
24 parser = argparse.ArgumentParser(description=
'''
25 Creates reference ESD/AOD by running a series of Reco_tf.py from a given input
26 file (typically RDO or RAW).
27 Performs typically 2 jobs :
30 Each step produces a file which is expected to be similar to the reference
31 files in /afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/.
34 %s MC # -> create reference files from /afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/RDO
35 %s MC MyDir # -> same but creates files under MyDir/
36 %s ESD.root MyDir # -> create an AOD reference file from ESD.root under MyDir/
37 '''%((os.path.basename(sys.argv[0]),)*3),
38 formatter_class=argparse.RawDescriptionHelpFormatter,
41 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' )
42 parser.add_argument(
'outputDir', type=str, nargs=
'?', default=
'jetRefFiles/')
44 parser.add_argument(
'-n',
'--noRun', action=
'store_true', help=
'Do not run the Reco_tf commands, just print them.')
45 parser.add_argument(
'--maxEvents', type=int, default=50, help=
"Propaged to the maxEvents of the Reco_tf commands")
46 parser.add_argument(
'--oneStep', action=
'store_true' , help=
"stop after 1st step processed")
47 parser.add_argument(
'--overWrite', action=
'store_true' , help=
"force to overWrite the output dir")
50 arg=parser.parse_args()
55 maxEvents=arg.maxEvents
67 specifyCondAndGeo=
False
68 geometryVersion=
"ATLAS-GEO-20-00-01"
69 conditionsTagMC=
"OFLCOND-MC12-SDR-06"
70 conditionsTagData=
"COMCOND-BLKPA-RUN1-01"
77 defaultMC=
"/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/MC/RDO/mc12_8TeV.CurrentRef.RDO.pool.root"
78 defaultData=
"/afs/cern.ch/atlas/groups/JetEtmiss/ReferenceFiles/RTT/DATA/RAW/data12_8TeV.CurrentRef.RAW"
83 if not os.path.exists(dir):
85 elif not arg.overWrite:
88 print (
" Directory ",dir,
'already exists. Not overwriting it (use --overWrite option if needed)')
95 if not os.path.exists(inputFile)
and not arg.noRun:
96 print (
'ERROR input file ', inputFile ,
' missing')
100 transform=
"Reco_tf.py"
102 inputFileBase = os.path.basename(inputFile)
104 if 'HITS' in inputFileBase:
110 elif "RDO" in inputFileBase:
112 inputDataType=inputType
114 preExec=
'''flags.Reco.EnableTrigger=False; flags.Reco.EnableBTagging=False'''
116 elif "RAW" in inputFileBase:
120 preExec=
'''flags.Reco.EnableTrigger=False'''
122 elif 'ESD' in inputFileBase:
124 inputDataType=inputType
126 preExec=
'''flags.Reco.EnableTrigger=False'''
129 print (
"ERROR RunStep: Input file does not appear to be a supported type (RAW, HITS, RDO, ESD)")
130 print (
' -> got', inputFileBase)
133 print (
"Starting ",inputType,
' to ', outputType)
136 runDir = arg.outputDir +
'/' + inputType+
'to'+outputType +
'/'
137 if not os.path.exists(runDir):
139 outputFile = runDir + inputFileBase.replace(inputType, outputType)
140 if arg.overWrite
and os.path.exists(outputFile):
141 os.remove(outputFile)
143 outputLog = runDir+
'log'
145 if specifyCondAndGeo:
147 fullComand=
"${transform} preExec=${preExec} input${inputDataType}File=${inputDir}/${inputFile} output${outputType}File=${outputFile} maxEvents=${maxEvents} skipEvents=${skipEvents} geometryVersion=$geometryVersion conditionsTag=$conditionsTag autoConfiguration=everything"
149 comandArgs = [
'--preExec='+preExec,
150 '--input%sFile=%s'%(inputDataType, inputFile),
151 '--output%sFile=%s'%(outputType, outputFile),
152 '--maxEvents='+
str(maxEvents),
153 '--skipEvents='+
str(skipEvents),
154 '--autoConfiguration=everything',
159 print (transform,
' '.
join(comandArgs))
165 logfile =
open(outputLog,
'w')
166 res = subprocess.call( [transform] + comandArgs, stdout=logfile, stderr=logfile)
170 print (
'ERROR RunStep: Transform appears to have failed - exiting. Check ', outputLog)
175 print (
'Done %s to %s step'%(inputType, outputType))
180 print (
'runChain ', inputFile)
181 while any( [t
in os.path.basename(inputFile)
for t
in [
'HITS',
'RDO',
'RAW',
'ESD'] ] ):
182 print (
'runStep at ',os.path.basename(inputFile))
188 if arg.sampleType.lower() ==
'mc':
190 elif arg.sampleType.lower() ==
'data':
191 inputFile=defaultData
194 inputFile = os.path.abspath(arg.sampleType)
196 if not os.path.exists(inputFile):
197 print (
'ERROR Input path does not exist ', inputFile)
201 arg.outputDir = os.path.abspath(arg.outputDir)