ATLAS Offline Software
Loading...
Searching...
No Matches
LArHistMerge_trf.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
5
6import sys, os, pickle, pprint, subprocess
7
8from LArCafJobs.GetLBsToIgnore import getLBsToIgnore
9
10
11
12
13# Utility function
14
15def getFileMap(fname, dsname, nevts=0, guid='') :
16 if os.path.isfile(fname) :
17 dataMap = { 'lfn': fname,
18 'dataset' : dsname,
19 'events' : nevts
20 }
21 if guid :
22 dataMap['GUID'] = guid
23 else :
24 dataMap = {}
25 return dataMap
26
27
28
29
30def getPFN(filespec):
31 if isinstance(filespec,dict):
32 if "svcclass" in filespec:
33 os.environ["STAGE_SVCCLASS"]=filespec["svcclass"]
34 pass
35
36 if 'pfn' in filespec:
37 return filespec['pfn']
38 else:
39 print ("ERROR: Unknown file specification (dict):")
40 print (filespec)
41 sys.exit(-1)
42
43
44 if isinstance(filespec,str):
45 names=filespec.split('#')
46 if len(names)!=2:
47 print ("ERROR: Unexpected file specification (string):")
48 print (filespec)
49 sys.exit(-1)
50 else:
51 return names[1]
52
53
54
55
56def getRunLB(fname):
57 filename=fname.split("/")[-1] #Strip off path
58 elem=filename.split(".")
59 #File name example:
60 #data11_7TeV.00190618.physics_CosmicCalo.recon.HIST.f411._lb0826._SFO-ALL._0001.1
61 if (len(elem) <6):
62 print ("ERROR: Invalid file name format. Expected at least six subfileds, got",filename)
63 sys.exit(-1)
64 pass
65
66 step=elem[3]
67 if step != 'recon':
68 return (-1,-1)
69
70 rnStr=elem[1]
71
72 if not rnStr.isdigit():
73 print ("ERROR: Can't get run number, got",rnStr)
74 sys.exit(-1)
75 pass
76 run=int(rnStr,10)
77
78 LBStr=elem[6]
79 if (len(LBStr)<4):
80 print ("ERROR: Can't get LB number, got",LBStr)
81 sys.exit(-1)
82 pass
83
84 LBStr=LBStr[3:]
85 if not LBStr.isdigit():
86 print ("ERROR: Can't get LB number, got",LBStr)
87 sys.exit(-1)
88 pass
89
90 LB=int(LBStr,10)
91 return (run,LB)
92
93
94def larMerge(dataMap) :
95
96 print ("\n##################################################################")
97 print ( "## ATLAS Tier0 LAr CAF file Merging ##")
98 print ( "##################################################################\n")
99
100 print ("\nFull Tier-0 run options:\n")
101 pprint.pprint(dataMap)
102
103 inputList = []
104
105 badLBs=set()
106
107 inFiles=dataMap['inputHistFiles']
108
109
110 if len(inFiles)>0:
111 firstFile=getPFN(inFiles[0])
112 runnumber=getRunLB(firstFile)[0]
113 if runnumber==-1:
114 print ("Encountered pre-merged file, no bad-LB checking done" )
115 else:
116 print ("Found run number",runnumber)
117 badLBs=getLBsToIgnore(runnumber)
118
119
120 for val in inFiles:
121 pfn=getPFN(val)
122 if len(badLBs)>0:
123 LB=getRunLB(pfn)[1]
124 if LB in badLBs:
125 print ("Ignoring bad LumiBlock",LB)
126 continue
127 inputList.append(pfn)
128 sys.stdout.flush()
129 #print ("\ninputLArFiles list:\n")
130 #pprint.pprint(inputList)
131
132 #Write input file list to temporary file:
133 templist=open("inputfiles.txt","w")
134 for infile in inputList:
135 templist.write(infile+"\n")
136 pass
137 templist.close()
138
139
140 # output file
141 outputDSName = dataMap['outputLArHistFile'].split('#')[0]
142 outputFile = dataMap['outputLArHistFile'].split('#')[1]
143
144 print ('\nOutput file name:', outputFile)
145
146 retcode = 0
147
148 cmd="LArQuickHistMerge.exe -i inputfiles.txt " + outputFile
149
150 try:
151 retcode = subprocess.call(cmd, shell=True)
152 print ('retcode =',retcode)
153 if retcode != 0 :
154 retcode = 62601
155 acronym = "LARQUICKHISTMEGE PROBLEM"
156 except OSError as e :
157 retcode = 62600
158 print (e)
159 acronym = "SUBPROCESS EXECUTION PROBLEM"
160 pass
161
162 if retcode==0:
163 cmd ="DQWebDisplay.py " + outputFile +" LArDisplay 111"
164 print ("Attempt to run",cmd)
165 try:
166 retcodeDQM = subprocess.call(cmd, shell=True)
167 print ('retcode =',retcodeDQM)
168 except Exception as e:
169 print ("Attempt failed with exception")
170 print (e)
171
172
173 # get info for report gpickle file
174 if retcode == 0 :
175 outputMap = getFileMap(outputFile, outputDSName, nevts=0)
176 outFiles = [ outputMap ]
177 acronym = 'OK'
178 else:
179 outFiles = []
180 outputMap = {}
181 print ("ERROR: problem in LAr Histogram merging!")
182 if retcode == 62600 :
183 acronym = 'TRF_LAR_FILE_INPUT_ERROR'
184 elif retcode == 62601 :
185 acronym = 'TRF_LAR_MERGE_ERROR'
186
187
188
189 # assemble job report map, pickle it
190 outMap = { 'prodsys': { 'trfCode': retcode,
191 'trfAcronym': acronym,
192 'jobOutputs': outFiles,
193 'jobInputs': inFiles,
194 }
195 }
196 f = open('jobReport.gpickle', 'wb')
197 pickle.dump(outMap, f)
198 f.close()
199
200 print ("\n##################################################################")
201 print ( "## End of job.")
202 print ( "##################################################################\n")
203
204
205
206
209
210if __name__ == "__main__":
211
212 if len(sys.argv) == 2 and sys.argv[1].startswith('--argdict=') :
213 picklefile = sys.argv[1][len('--argdict='):]
214 # extract parameters from pickle file
215 print ("Using pickled file ", picklefile, " for input parameters")
216 f = open(picklefile, 'rb')
217 dataMap = pickle.load(f)
218 f.close()
219 larMerge(dataMap)
220 elif len(sys.argv) == 3 and sys.argv[1].startswith('--inputFiles=') and sys.argv[2].startswith('--outputFile=') :
221 inputFiles = sys.argv[1][13:].split(',')
222 outputFile = sys.argv[2][13:]
223 dataMap = {}
224 dataMap['inputHistFiles'] = inputFiles
225 dataMap['outputLArHistFile'] = outputFile
226 larMerge(dataMap)
227 else :
228 print ("Input format wrong --- either have: ")
229 print (" --argdict=<pickled-dictionary containing input info> ")
230 print (" with key/value pairs: ")
231 print (" or (old way): ")
232 print (" --inputFiles=file1,file2,...,fileN --outputFile=file")
233 exit(1)
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
getFileMap(fname, dsname, nevts=0, guid='')