22 import sys, os, json, time, pprint, subprocess
28 if os.path.isfile(fname) :
29 sz = os.path.getsize(fname)
30 map = {
'name': fname,
46 print(
"\n##################################################################")
47 print(
"## ATLAS Tier0 LAr CAF file Merging ##")
48 print(
"##################################################################\n")
53 exitMsg =
'trf finished OK'
59 print(
"\nFull Tier-0 run options:\n")
60 pprint.pprint(dataMap)
63 inputDSName = dataMap[
'inputLArFiles'][0][
'dsn']
65 for fdict
in dataMap[
'inputLArFiles'] :
66 inputList.append(fdict[
'lfn'])
68 print(
"\ninputLArFiles list:\n")
69 pprint.pprint(inputList)
72 outputDSName = dataMap[
'outputLArFile'].
split(
'#')[0]
73 outputFile = dataMap[
'outputLArFile'].
split(
'#')[1]
75 print(
'\nOutput file name:', outputFile)
77 cmdline=[
"LArSamplesMerge"]
78 for fileName
in inputList:
79 if os.access(fileName,os.R_OK):
80 cmdline.append(fileName)
82 print(
'ERROR : could not open file', fileName)
84 exitAcronym =
'TRF_LAR_FILE_INPUT_ERROR'
85 exitMsg =
'LAr input file not accessible'
90 writepath=os.path.split(outputFile)[0]
91 if writepath==
"": writepath=
"./"
92 if (os.access(writepath,os.W_OK)):
93 cmdline.append(outputFile)
95 print(
"ERROR, not allowed to write to oututfile", outputFile)
97 exitAcronym =
'TRF_LAR_MERGE_ERROR'
98 exitMsg =
'LAR merging error'
103 logfile=
open(
"log.LArMerge",
"w")
106 subprocess.check_call(cmdline,stdout=logfile,stderr=subprocess.STDOUT)
107 except Exception
as e:
108 print(
"ERROR exectution of subprocess failed")
110 exitAcronym =
'TRF_LAR_MERGE_ERROR'
111 exitMsg =
'LAR merging error'
115 logfile=
open(
"log.LArMerge",
"r")
119 if line.startswith(
"Open file "):
120 linetok=line.split(
" ")
122 if line.startswith(
"Wrote output file "):
123 linetok=line.split(
" ")
124 nEvents=
int(linetok[5])
127 dt =
int(time.time() - tstart)
129 outMap = {
'exitAcronym' : exitAcronym,
130 'exitCode' : exitCode,
132 'files' : {
'output' : [{
'dataset' : outputDSName,
133 'subFiles' : outFiles
135 'input' : [{
'dataset' : inputDSName,
139 'resource' : {
'transform' : {
'processedEvents' :
int(nEvents),
'wallTime' : dt} }
142 f =
open(
'jobReport.json',
'w')
146 print(
"\n##################################################################")
147 print(
"## End of job.")
148 print(
"##################################################################\n")
156 if __name__ ==
"__main__":
159 if len(sys.argv) == 2
and sys.argv[1].startswith(
'--argJSON=') :
160 jsonfile = sys.argv[1][len(
'--argJSON='):]
162 print(
"Using json file ", jsonfile,
" for input parameters")
164 dataMap = json.load(f)
167 elif len(sys.argv) == 3
and sys.argv[1].startswith(
'--inputFiles=')
and sys.argv[2].startswith(
'--outputFile=') :
168 inputFiles = sys.argv[1][13:].
split(
',')
169 outputFile = sys.argv[2][13:]
171 dataMap[
'inputLArFiles'] = inputFiles
172 dataMap[
'outputLArFile'] = outputFile
175 print(
"Input format wrong --- either have: ")
176 print(
" --argJSON=<json-dictionary containing input info> ")
177 print(
" with key/value pairs: ")
178 print(
" or (old way): ")
179 print(
" --inputFiles=file1,file2,...,fileN --outputFile=file")