287 def postExecute(self):
288
289
290
291
292
293 log = self._logFileName
294 msg.debug('Now scanning logfile {0} for HLTMPPU Child Issues'.format(log))
295
296
297
298 rejected = 0
299
300 accepted = 0
301
302 try:
303 myGen = lineByLine(log, substepName=self._substep)
304 except IOError as e:
305 msg.error('Failed to open transform logfile {0}: {1:s}'.format(log, e))
306 for line, lineCounter in myGen:
307
308 if 'Child Issue' in line:
309 try:
310 signal = int((re.search('signal ([0-9]*)', line)).group(1))
311 except AttributeError:
312
313 signal = 1
314 msg.error('Detected issue with HLTChild, setting mother return code to %s', signal)
315 self._rc = signal
316
317
318
319
320 try:
321
322 with open(self._logFileName, 'a') as merged_file:
323 for file in os.listdir('.'):
324
325 if fnmatch.fnmatch(file, 'athenaHLT:*'):
326 msg.info('Merging child log file (%s) into %s', file, self._logFileName)
327 with open(file) as log_file:
328
329 merged_file.write('### Output from {} ###\n'.format(file))
330
331 for line in log_file:
332 merged_file.write(line)
333
334 if 'rejected:' in line and int(line[14]) != 0:
335
336 rejected += int(line[14:])
337
338 if 'accepted:' in line and int(line[14]) != 0:
339
340 accepted += int(line[14:])
341 if re.search('DFDcmEmuSession.* Communication error', line) or re.search('DFDcmEmuSession.* No new event provided within the timeout limit', line):
342 msg.error('Caught DFDcmEmuSession error, aborting job')
343 self._rc = 1
344
345 if "HIST_DEBUGSTREAMMON" in self.conf.dataDictionary:
346
347 dbgStream.getHltDecision(accepted, rejected, self.conf.argdict["outputHIST_DEBUGSTREAMMONFile"].value[0])
348
349 except OSError as e:
350 raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_OUTPUT_FILE_ERROR'),
351 'Exception raised when merging log files into {0}: {1}'.format(self._logFileName, e))
352
353 msg.info("Check for expert-monitoring.root file")
354
355
356
357
358 expectedFileName = 'expert-monitoring.root'
359
360
361 if self._rc != 0:
362 msg.info('HLT step failed (with status %s) so skip HIST_HLTMON filename check', self._rc)
363
364 elif 'outputHIST_HLTMONFile' in self.conf.argdict:
365
366
367 expectedMotherFileName = 'expert-monitoring-mother.root'
368 if(os.path.isfile(expectedFileName)):
369 msg.info('Renaming %s to %s', expectedFileName, expectedMotherFileName)
370 try:
371 os.rename(expectedFileName, expectedMotherFileName)
372 except OSError as e:
373 raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_OUTPUT_FILE_ERROR'),
374 'Exception raised when renaming {0} to {1}: {2}'.format(expectedFileName, expectedMotherFileName, e))
375 else:
376 msg.error('HLTMON argument defined but mother %s not created', expectedFileName)
377
378
379 expectedWorkerFileName = 'athenaHLT_workers/athenaHLT-01/' + expectedFileName
380 if(os.path.isfile(expectedWorkerFileName)
and os.path.isfile(expectedMotherFileName)):
381 msg.info('Merging worker and mother %s files to %s', expectedFileName, self.conf.argdict['outputHIST_HLTMONFile'].value[0])
382 try:
383
384 cmd = 'hadd ' + self.conf.argdict['outputHIST_HLTMONFile'].value[0] + ' athenaHLT_workers/*/expert-monitoring.root expert-monitoring-mother.root'
385 subprocess.call(cmd, shell=True)
386 except OSError as e:
387 raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_OUTPUT_FILE_ERROR'),
388 'Exception raised when merging worker and mother {0} files to {1}: {2}'.format(expectedFileName, self.conf.argdict['outputHIST_HLTMONFile'].value[0], e))
389 else:
390 msg.error('HLTMON argument defined %s but worker %s not created', self.conf.argdict['outputHIST_HLTMONFile'].value[0], expectedFileName)
391
392 else:
393 msg.info('HLTMON argument not defined so skip %s check', expectedFileName)
394
395 msg.info("Search for created BS files, and rename if single file found")
396
397
398
399 argInDict = {}
400 if self._rc != 0:
401 msg.error('HLT step failed (with status %s) so skip BS filename check', self._rc)
402 elif 'BS' in self.conf.dataDictionary or 'DRAW_TRIGCOST' in self.conf.dataDictionary or 'HIST_DEBUGSTREAMMON' in self.conf.dataDictionary:
403
404 matchedOutputFileNames = self._findOutputFiles(self.expectedOutputFileName)
405
406
407
408 if len(matchedOutputFileNames) == 0:
409 msg.error('No BS files created with expected name: %s - please check for earlier failures', self.expectedOutputFileName)
410 raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_OUTPUT_FILE_ERROR'),
411 f'No BS files created with expected name: {self.expectedOutputFileName} - please check for earlier failures')
412 else:
413
414 if len(matchedOutputFileNames) == 1:
415 msg.info('Single BS file found: will split (if requested) and rename the file')
416 BSFile = matchedOutputFileNames[0]
417
418
419 else:
420 msg.info('Multiple BS files found. A single BS file is required by the next transform steps, so they will be merged. Will split the merged file (if requested) and rename the file')
421 mergedBSFile = matchedOutputFileNames[0].
split(
'._0001.data')[0] +
'.mrg._0001.data'
422
423 mergeFailed = self._mergeBSfiles(matchedOutputFileNames, mergedBSFile)
425 raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_OUTPUT_FILE_ERROR'),
426 'Did not produce a merged BS file with file_merging')
427
428 BSFile = 'tmp.BS.mrg'
429 msg.info(f'Renaming temporary merged BS file to {BSFile}')
430 self._renamefile(mergedBSFile, BSFile)
431
432
433 if 'DRAW_TRIGCOST' in self.conf.dataDictionary:
434 splitFailed = self._splitBSfile(['CostMonitoring'], BSFile, self.conf.dataDictionary['DRAW_TRIGCOST'].value[0])
436 raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_OUTPUT_FILE_ERROR'),
437 'Did not produce any BS file when selecting CostMonitoring stream with trigbs_extractStream.py in file')
438
439
440 if "HIST_DEBUGSTREAMMON" in self.conf.dataDictionary:
441 self._postExecuteDebug(BSFile)
442
443
444 if 'BS' in self.conf.dataDictionary:
445 argInDict = self.conf.dataDictionary['BS']
446
447 if 'streamSelection' in self.conf.argdict and self.conf.argdict['streamSelection'].value[0] != "All":
448 splitEmpty = self._splitBSfile(self.conf.argdict['streamSelection'].value, BSFile, argInDict.value[0])
450 msg.info('Did not produce any BS file when selecting stream with trigbs_extractStream.py in file')
451
452
453
454 cmd_splitFailed = 'trigbs_failedStreamSelection.py ' + BSFile
455 msg.info('running command for creating empty file: %s', cmd_splitFailed)
456 subprocess.call(cmd_splitFailed, shell=True)
457
458
459 runnumber = eformat.EventStorage.pickDataReader(BSFile).runNumber()
460 expectedOutputFileName = 'T0debug.00'+str(runnumber)+'.unknown_debug.unknown.RAW._lb0000._TRF._0001.data'
461
462 self._renamefile(expectedOutputFileName, argInDict.value[0])
463 else:
464 msg.info('Stream "All" requested, so not splitting BS file')
465 self._renamefile(BSFile, argInDict.value[0])
466 else:
467 msg.info('BS output filetype not defined so skip renaming BS')
468 else:
469 msg.info('BS, DRAW_TRIGCOST or HIST_DEBUGSTREAMMON output filetypes not defined so skip BS post processing')
470
471 msg.info('Now run athenaExecutor:postExecute')
472 super(trigRecoExecutor, self).postExecute()
473
474 if "HIST_DEBUGSTREAMMON" in self.conf.dataDictionary:
475
476 fileNameDbg = self.conf.argdict["outputHIST_DEBUGSTREAMMONFile"].value
477 dbgStream.dbgPostRun(argInDict.value[0], fileNameDbg[0], self.conf.argdict, isSplitStream=True)
478
479
std::vector< std::string > split(const std::string &s, const std::string &t=":")