51
55
56
57
58
59 if isinstance(c.server, str):
60 if c.server == '':
61 c.server = []
62 else:
63 c.server = [c.server]
64
65 if c.server != [] or c.webHandoffDir != "" or c.lockFile == '':
67 print(
"Lockfile is disabled")
69 instance = None
70 else:
71 while True:
72 try:
73 instance = SingleAppInstance( c.htmlDir + "/" + c.lockFile, True )
74 islocked = instance.acquire()
75 except SingleAppInstance.FileLockAcquisitionError as e:
76 print(
'=========================================================================')
77 print(
'Cannot acquire lock on', c.htmlDir)
78 print(
'This usually means either')
79 print(
' -> the directory does not exist,')
80 print(
' -> you do not have the required permissions, or')
81 print(
' -> the directory is out of space.')
82 print(
'If you ran into this error while trying to test the web display, please')
83 print(
'read the instructions at:')
84 print(
'https://twiki.cern.ch/twiki/bin/view/Atlas/DQOperationalRecipes#Obtain_SVN_and_disk_write_permis')
86 print(
'Explicit error:', e)
87 print(
'=========================================================================')
88 sys.exit(1)
89 if islocked:
90 break
91 print(
"Another instance is running; waiting 60 seconds...")
92 sleep(60)
93
94
98
99
100
101 allDirsScriptLoc = c.htmlWeb
102 runlistLoc = c.htmlWeb + "/" + c.runlist
103
104 compare = True
105
106 browserMenu = True
107
108 if ( c.hanResultsDir.rfind("/")!=(len(c.hanResultsDir)-1) ):
109 c.hanResultsDir+="/"
110
111 if ( c.htmlDir.rfind("/")!=(len(c.htmlDir)-1) ):
112 c.htmlDir+="/"
113
114 inputFileName = inputFilePath
115 i = inputFilePath.rfind("/")
117 inputFileName = inputFilePath[i+1:]
118
119 runid = 99999999
120 shortStream = "NoStream"
121 amitag = None
122 procpass = int(sys.argv[3])
123
124 if c.config == "RTT":
125 shortStream = time.strftime("%A")
126 else:
127 fields = inputFileName.split(".")
128 if len(fields) >= 3:
129 runid = int(fields[1])
130 shortStream = fields[2]
131 if len(fields) >= 6:
132 amitag = fields[5]
133
134 if runAccumulating:
136 print(
"Searching for existing histogram cache to merge with input histograms...")
137 try:
138 inputFilePath = _local_apply(mergeAndCache, ( inputFilePath, runid, shortStream, c.histogramCache ) )
139 except LockAcquisitionException:
140 sys.exit(LOCK_ERROR)
141 shortStream = "tmp_" + shortStream
142 elif c.histogramCache != "":
143 cacheFile, version = findCacheFile( inputFilePath, runid, shortStream, c.histogramCache )
144 if cacheFile != "":
146 print(
"Removing cached histograms used during accumulation mode")
147 try:
148 while cacheFile != '':
149 fullCachePath = c.histogramCache + "/" + cacheFile
150 os.unlink( fullCachePath )
151 cacheFile, version = findCacheFile( inputFilePath, runid, shortStream, c.histogramCache )
152 except OSError:
153 pass
154
155 stream = shortStream
156 if len(sys.argv) >= 5:
157 stream = repr(procpass) + "/" + shortStream
158
159 outputHanResultsDir = c.hanResultsDir + stream + '/run_' + repr(runid)
160 outputHtmlDir = c.htmlDir + stream + "/"
161
162 if c.server != [] or c.webHandoffDir != "" or c.eosResultsDir:
163 print(
"Writing all output to \'./\'; will copy at the end to ", end=
'')
164 if c.webHandoffDir != "":
165 print(
"a handoff directory:", c.webHandoffDir)
166 else:
167 print(
"the web server(s):",
', '.join(c.server))
169 outputHanResultsDir = "./han_results/" + stream + '/run_' + repr(runid)
170 outputHtmlDir = "./www/" + stream + "/"
171
172 makeOutputDirectory( outputHanResultsDir )
173 makeOutputDirectory( outputHtmlDir )
174
175 total=_local_apply(getHanResults, ( inputFilePath, outputHanResultsDir, inputFilePath, c.hcfg, c.hcfg_min10, c.hcfg_min30 ))
176 fileList=total.rsplit('\n')
177 if amitag is not None:
178 addAmiTags(fileList, amitag)
179
180 number=len(fileList)
181 if (len(fileList[number-1])<1):
182 number-=1
183
184
185 runfile=fileList[0].rsplit()
186 if (len(runfile) == 0):
187 print(
"ERROR: TFile has no \"run_*\" directories. The input monitoring file is not organized for production use,")
188 print(
"probably because AthenaMonitoring is not configured properly. Exiting.\n")
189 sys.exit(1)
190
191 xferFileList = []
192 for allLines in fileList:
193 splitLine = allLines.rsplit()
194 if len(splitLine) >= 1:
195 xferFileList.append( splitLine[0] + "\n" )
196
197
198 runNumber = runfile[1]
199 rN=runNumber.lstrip("run_")
200 if not runAccumulating:
201 print(
"Getting COOL authentications")
202
203
204
205
206
207
208
209
210 if 'COOLUPLOADS' in os.environ:
211 uploadAllowed = (os.environ['COOLUPLOADS'] == '1')
212 else:
213 uploadAllowed = True
214
215 if not uploadAllowed:
216 print(
'hancool run and upload to DB switched off by request')
217
218 if (uploadAllowed and c.dbConnection):
220 print(
"Now calling hancool ...")
221
222 if '_' in stream: stream = stream.split('_',1)[-1]
223 if amitag is not None and 'x' in amitag and stream.startswith('express'):
224 dbTagName = c.dbTagNameESn
225 isESn = True
226 else:
227 dbTagName = c.dbTagName
228 isESn = False
229 if '%' in dbTagName:
230
231 uploadTag = dbTagName % { 'stream': stream,
232 'amitag': amitag,
233 'procpass': procpass }
234 doUpload = True
235 else:
236 uploadTag = dbTagName
237 doUpload = ('-%s-' % stream in uploadTag)
238
239 if (doUpload):
240 print(
'isESn?', isESn)
241 _local_apply(hancool, (int(rN),outputHanResultsDir,c.dbConnection,isESn))
242
243
244 if c.server != []:
245 failures = 0
246 for server in c.server:
247 print(
"Transfering han files to server: ", server)
248 success = transferFilesToServer( xferFileList[:], "./han_results/", c.hanResultsDir, server )
249 if success:
252 else:
253 failures += 1
254 print(
"FAILED!", end=
'')
255 if c.emailWarnings:
256 email('The transfer of han files\n\n' +
257 ''.join(xferFileList) +
258 '\nto server ' + server +
259 ' failed. This may indicate that this server is down.\n'
260 'Please investigate as soon as possible!',
261 'WARNING! File transfer from Tier-0 failed',
262 FROMEMAIL,
263 'hn-atlas-data-quality-operations@cern.ch'
264 )
265 print(
"Email sent...")
266 else:
269 if failures == len(c.server):
270 print(
"SERIOUS PROBLEM: file transfers failed to ALL defined servers")
271 print(
"These are:",
', '.join(c.server))
272 print(
"Will die so as to alert Tier-0 shifter")
273 raise IOError('tarfile ssh transfer failed')
274 if c.eosResultsDir != "":
275 print(
"Transfering han files to EOS")
276 failures = 0
277 eos_attempts = 3
278 while failures < (eos_attempts+1) :
279 success_EOS = transferFilesToEOS( xferFileList[:], "./han_results/", c.eosResultsDir )
280 if success_EOS:
281 break
282 failures += 1
283 sleep(5**failures)
284 if success_EOS:
287 else:
289 raise IOError("Transfer to /eos failed after {} attempts".format(failures))
290 if c.emailWarnings:
291 email('The transfer of han files\n\n' +
292 ''.join(xferFileList) +
293 '\nto EOS failed.\n'
294 'Please investigate as soon as possible!',
295 'WARNING! File transfer from Tier-0 failed',
296 FROMEMAIL,
297 'hn-atlas-data-quality-operations@cern.ch'
298 )
299 print(
"Email sent...")
300 else:
302
303
304 if c.doHandi:
305 rundir=outputHtmlDir+runNumber+"/"
306 makeOutputDirectory( rundir )
307
308
309 now = time.localtime()
310 lastUpdate = "Last Update: "+time.strftime('%Y-%m-%d %H:%M %Z', now)
311
312
313 g=open(outputHtmlDir+runNumber +'/index.html','w')
314 g.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n')
315 g.write('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n')
316 g.write('<head>\n')
317 g.write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />\n')
318 g.write('<title>run ' +rN+ ' ' + stream + '</title>\n')
319 g.write('<link rel="stylesheet" href="AutomChecks.css" type="text/css" />\n')
320 g.write('</head>\n')
321 g.write('<body>\n')
322 g.write('<font class="DQGroup">[<a href="#" onclick="history.go(-1);return false;">Back</a>]</font>\n')
323 g.write('<h1>Run '+rN+', ' + stream + '</h1>\n\n')
324
325 makeCSSFile( rundir, "", "" )
326
327 if number >0:
328 min10List = []
329 min30List = []
330 for x in range(0,number):
331 sp=fileList[x].rsplit()
332 if (len(sp)==2):
333 print(
"Running handi on " + sp[0] +
":")
334 print(
'handi("Run '+rN+
', '+ stream +
'",' + sp[0] +
','+rundir+
'/run)')
335 _local_apply(handiWithComparisons, ( ('Run '+rN+', ' + stream), sp[0], (rundir+"/run"), runlistLoc, compare, browserMenu, allDirsScriptLoc) )
337 else:
338 if sp[1].
find(
"lowStat")!=-1:
339 print(
"Running handi on " + sp[0] +
":")
340 print(
'handi("Run '+rN+
', '+sp[1]+
', ' + stream +
'",' + sp[0] +
','+rundir+sp[3]+
')')
341 _local_apply(handiWithComparisons, ( ('Run '+rN+ ', '+sp[1]+', ' + stream), sp[0], (rundir+sp[3]), runlistLoc, compare, browserMenu, allDirsScriptLoc) )
343 mN = sp[1].removeprefix("lowStat_")
344 min10List.append( (sp[3], mN) )
345 elif sp[1].
find(
"medStat")!=-1:
346 print(
"Running handi on " + sp[0] +
":")
347 print(
'handi("Run '+rN+
', '+sp[1]+
', ' + stream +
'",' + sp[0] +
','+rundir+sp[3]+
')')
348 _local_apply(handiWithComparisons, (('Run '+rN+ ', '+sp[1]+', ' + stream), sp[0], (rundir+sp[3]), runlistLoc, compare, browserMenu, allDirsScriptLoc))
350 mN = sp[1].removeprefix("medStat_")
351 min30List.append( (sp[3], mN) )
352
353
354
355
356 g.write('<table>\n')
357
358 if len(min10List) == 0 and len(min30List) == 0:
359 g.write('<tr>\n')
360 g.write(' <td width=120>\n')
361 g.write(' <a href="run/index.html">Entire Run</a>\n')
362 g.write(' </td>\n')
363 g.write('</tr>\n')
364 elif len(min10List) == 0 or len(min30List) == 0:
365 minList = []
366 blockName = ""
367 if len(min10List) == 0:
368 minList = min30List
369 blockName = "medium stat interval"
370 else:
371 minList = min10List
372 blockName = "low stat interval"
373 g.write('<tr>\n')
374 g.write(' <td rowspan='+ str(len(minList)) +' valign="top" width=120>\n')
375 g.write(' <a href="run/index.html">Entire Run</a>\n')
376 g.write(' </td>\n')
377 margin = ""
378 minList.sort()
379 for page, nMin in minList:
380 g.write(margin)
381 g.write(' <td width=200>\n')
382 if nMin.find('merged_')!=-1:
383 g.write(' <a href="' + page + '/index.html">' + nMin + '</a>\n')
384 else:
385 g.write(' <a href="' + page + '/index.html">' + blockName + ' ' + nMin + '</a>\n')
386 g.write(' </td>\n')
387 margin = '</tr>\n<tr>\n'
388 g.write('</tr>\n')
389 else:
390 g.write('<tr>\n')
391 g.write(' <td rowspan='+ str(len(min10List)) +' valign="top" width=120>\n')
392 g.write(' <a href="run/index.html">Entire Run</a>\n')
393 g.write(' </td>\n')
394 margin = ""
395 count = 0
396 min10List.sort()
397 for page10, nMin10 in min10List:
398 g.write(margin)
399 nMin30 = 0
400 if count % 3 == 0:
401 iMin30 = (count // 3)
402 page30, nMin30 = min30List[iMin30]
403 g.write(' <td rowspan=3 valign="top" width=200>\n')
404 g.write(' <a href="' + page30 + '/index.html">medium stat interval ' + nMin30 + '</a>\n')
405 g.write(' </td>\n')
406 g.write(' <td width=200>\n')
407 g.write(' <a href="' + page10 + '/index.html">low stat interval ' + nMin10 + '</a>\n')
408 g.write(' </td>\n')
409 count = count + 1
410 margin = '</tr>\n<tr>\n'
411 g.write('</tr>\n')
412
413 g.write('</table>\n')
414
415
416 g.write('<br/>\n<font class=\"Note\">'+lastUpdate+'</font><br />\n')
417 g.write('</body>\n</html>')
418 g.close()
419
420 if c.webHandoffDir != "":
421 print(
'Transfering web files to handoff directory')
422 transferDirectoryToHandoffDir( rundir, './www/', c.webHandoffDir, c )
423 elif c.server != []:
424 failures = 0
425 for server in c.server:
426 print(
"Transfering web files to server: ", server)
427 success = transferDirectoryToServer( rundir, "./www/", c.htmlDir, server )
428 if success:
431 else:
432 failures += 1
433 if c.emailWarnings:
434 email('The transfer of web files\n'
435 + c.htmlDir +
436 '\nto server' + server +
437 'failed. This may indicate that this server is down.\n'
438 'Please investigate as soon as possible!',
439 'WARNING! File transfer from Tier-0 failed',
440 FROMEMAIL,
441 'hn-atlas-data-quality-operations@cern.ch'
442 )
445 if failures == len(c.server):
446 print(
"SERIOUS PROBLEM: web files transfer failed to ALL defined servers")
447 print(
"These are:",
', '.join(c.server))
448 print(
"Will die so as to alert Tier-0 shifter")
449 raise IOError('Directory ssh transfer failed')
450
451
452
453
454 if c.webHandoffDir == '':
455 print(
"Generating index files...")
456 for server in c.server:
458
459 if runAccumulating:
460 os.unlink(inputFilePath)
461
462 if instance is not None:
463 instance.release()
464 return fileList
465
466
std::string find(const std::string &s)
return a remapped string