24 import sys, os, pickle, pprint, subprocess
31 if os.path.isfile(fname) :
32 dataMap = {
'lfn': fname,
37 dataMap[
'GUID'] = guid
47 print (
"\n##################################################################")
48 print (
"## ATLAS Tier0 LAr CAF file Merging ##")
49 print (
"##################################################################\n")
51 print (
"\nFull Tier-0 run options:\n")
52 pprint.pprint(dataMap)
57 for val
in dataMap[
'inputLArFiles'] :
58 inputList.append(val.split(
'#')[1])
60 inputDSName = val.split(
'#')[0]
62 print (
"\ninputLArFiles list:\n")
63 pprint.pprint(inputList)
66 outputDSName = dataMap[
'outputLArFile'].
split(
'#')[0]
67 outputFile = dataMap[
'outputLArFile'].
split(
'#')[1]
69 print (
'\nOutput file name:', outputFile)
78 cmdline=[
"LArSamplesMerge.exe"]
79 for fileName
in inputList:
80 if os.access(fileName,os.R_OK):
81 cmdline.append(fileName)
83 print (
'ERROR : could not open file', fileName)
85 acronym =
'TRF_LAR_FILE_INPUT_ERROR'
90 writepath=os.path.split(outputFile)[0]
93 if (os.access(writepath,os.W_OK)):
94 cmdline.append(outputFile)
96 print (
"ERROR, not allowed to write to oututfile", outputFile)
98 acronym =
'TRF_LAR_MERGE_ERROR'
104 logfile=
open(
"log.LArMerge",
"w")
107 subprocess.check_call(cmdline,stdout=logfile,stderr=subprocess.STDOUT)
108 except Exception
as e:
109 print (
"ERROR exectution of subprocess failed")
111 acronym =
'TRF_LAR_MERGE_ERROR'
115 logfile=
open(
"log.LArMerge",
"r")
119 if line.startswith(
"Open file "):
120 linetok=line.split(
" ")
121 inFiles.append(
getFileMap(linetok[2],
None, nevts=
int(linetok[4])))
123 if line.startswith(
"Wrote output file "):
124 linetok=line.split(
" ")
125 nEvents=
int(linetok[5])
126 outFiles=[
getFileMap(linetok[3], outputDSName, nevts=nEvents),]
134 outMap = {
'prodsys': {
'trfCode': retcode,
135 'trfAcronym': acronym,
136 'jobOutputs': outFiles,
137 'jobInputs': inFiles,
141 f =
open(
'jobReport.gpickle',
'wb')
142 pickle.dump(outMap, f)
145 print (
"\n##################################################################")
146 print (
"## End of job.")
147 print (
"##################################################################\n")
155 if __name__ ==
"__main__":
157 if len(sys.argv) == 2
and sys.argv[1].startswith(
'--argdict=') :
158 picklefile = sys.argv[1][len(
'--argdict='):]
160 print (
"Using pickled file ", picklefile,
" for input parameters")
162 dataMap = pickle.load(f)
165 elif len(sys.argv) == 3
and sys.argv[1].startswith(
'--inputFiles=')
and sys.argv[2].startswith(
'--outputFile=') :
166 inputFiles = sys.argv[1][13:].
split(
',')
167 outputFile = sys.argv[2][13:]
169 dataMap[
'inputLArFiles'] = inputFiles
170 dataMap[
'outputLArFile'] = outputFile
173 print (
"Input format wrong --- either have: ")
174 print (
" --argdict=<pickled-dictionary containing input info> ")
175 print (
" with key/value pairs: ")
176 print (
" or (old way): ")
177 print (
" --inputFiles=file1,file2,...,fileN --outputFile=file")