5 from __future__
import print_function
7 import sys, os, pickle, pprint, subprocess
9 from LArCafJobs.GetLBsToIgnore
import getLBsToIgnore
17 if os.path.isfile(fname) :
18 dataMap = {
'lfn': fname,
23 dataMap[
'GUID'] = guid
32 if isinstance(filespec,dict):
33 if "svcclass" in filespec:
34 os.environ[
"STAGE_SVCCLASS"]=filespec[
"svcclass"]
38 return filespec[
'pfn']
40 print (
"ERROR: Unknown file specification (dict):")
45 if isinstance(filespec,str):
46 names=filespec.split(
'#')
48 print (
"ERROR: Unexpected file specification (string):")
58 filename=fname.split(
"/")[-1]
59 elem=filename.split(
".")
63 print (
"ERROR: Invalid file name format. Expected at least six subfileds, got",filename)
73 if not rnStr.isdigit():
74 print (
"ERROR: Can't get run number, got",rnStr)
81 print (
"ERROR: Can't get LB number, got",LBStr)
86 if not LBStr.isdigit():
87 print (
"ERROR: Can't get LB number, got",LBStr)
97 print (
"\n##################################################################")
98 print (
"## ATLAS Tier0 LAr CAF file Merging ##")
99 print (
"##################################################################\n")
101 print (
"\nFull Tier-0 run options:\n")
102 pprint.pprint(dataMap)
108 inFiles=dataMap[
'inputHistFiles']
112 firstFile=
getPFN(inFiles[0])
115 print (
"Encountered pre-merged file, no bad-LB checking done" )
117 print (
"Found run number",runnumber)
126 print (
"Ignoring bad LumiBlock",LB)
128 inputList.append(pfn)
134 templist=
open(
"inputfiles.txt",
"w")
135 for infile
in inputList:
136 templist.write(infile+
"\n")
142 outputDSName = dataMap[
'outputLArHistFile'].
split(
'#')[0]
143 outputFile = dataMap[
'outputLArHistFile'].
split(
'#')[1]
145 print (
'\nOutput file name:', outputFile)
149 cmd=
"LArQuickHistMerge.exe -i inputfiles.txt " + outputFile
152 retcode = subprocess.call(cmd, shell=
True)
153 print (
'retcode =',retcode)
156 acronym =
"LARQUICKHISTMEGE PROBLEM"
157 except OSError
as e :
160 acronym =
"SUBPROCESS EXECUTION PROBLEM"
164 cmd =
"DQWebDisplay.py " + outputFile +
" LArDisplay 111"
165 print (
"Attempt to run",cmd)
167 retcodeDQM = subprocess.call(cmd, shell=
True)
168 print (
'retcode =',retcodeDQM)
169 except Exception
as e:
170 print (
"Attempt failed with exception")
176 outputMap =
getFileMap(outputFile, outputDSName, nevts=0)
177 outFiles = [ outputMap ]
182 print (
"ERROR: problem in LAr Histogram merging!")
183 if retcode == 62600 :
184 acronym =
'TRF_LAR_FILE_INPUT_ERROR'
185 elif retcode == 62601 :
186 acronym =
'TRF_LAR_MERGE_ERROR'
191 outMap = {
'prodsys': {
'trfCode': retcode,
192 'trfAcronym': acronym,
193 'jobOutputs': outFiles,
194 'jobInputs': inFiles,
197 f =
open(
'jobReport.gpickle',
'wb')
198 pickle.dump(outMap, f)
201 print (
"\n##################################################################")
202 print (
"## End of job.")
203 print (
"##################################################################\n")
211 if __name__ ==
"__main__":
213 if len(sys.argv) == 2
and sys.argv[1].startswith(
'--argdict=') :
214 picklefile = sys.argv[1][len(
'--argdict='):]
216 print (
"Using pickled file ", picklefile,
" for input parameters")
218 dataMap = pickle.load(f)
221 elif len(sys.argv) == 3
and sys.argv[1].startswith(
'--inputFiles=')
and sys.argv[2].startswith(
'--outputFile=') :
222 inputFiles = sys.argv[1][13:].
split(
',')
223 outputFile = sys.argv[2][13:]
225 dataMap[
'inputHistFiles'] = inputFiles
226 dataMap[
'outputLArHistFile'] = outputFile
229 print (
"Input format wrong --- either have: ")
230 print (
" --argdict=<pickled-dictionary containing input info> ")
231 print (
" with key/value pairs: ")
232 print (
" or (old way): ")
233 print (
" --inputFiles=file1,file2,...,fileN --outputFile=file")