390 logging.basicConfig(stream=sys.stdout,
391 format=
'%(levelname)-8s %(message)s',
392 level=logging.DEBUG
if args.verbose
else logging.INFO)
402 logging.error(
'Failed to open input file %s', args.inputFile)
404 logging.debug(
'Opened input file %s', args.inputFile)
406 if args.referenceFile:
409 logging.error(
'Failed to open input file %s', args.referenceFile)
411 logging.debug(
'Opened input file %s', args.referenceFile)
418 if len(in_hists) == 0:
419 logging.error(
'No count histograms could be loaded.')
421 logging.info(
'Loaded count histograms: %s',
sorted(in_hists.keys()))
424 if len(in_total_hists) == 0:
425 logging.error(
'No total-events histogram could be loaded')
427 items =
list(in_total_hists.items())
429 logging.info(
'Loaded total-events histogram %s, number of events: %d',
430 items[0][0], in_total)
433 ref_total_hists =
None
435 if args.referenceFile:
437 logging.info(
'Loaded reference count histograms: %s',
sorted(ref_hists.keys()))
438 missing_refs = [k
for k
in in_hists.keys()
if k
not in ref_hists.keys()]
439 if len(missing_refs) > 0:
440 logging.error(
'Count histogram(s) %s missing in the reference', missing_refs)
443 if len(ref_total_hists) == 0:
444 logging.error(
'No total-events reference histogram could be loaded')
447 logging.info(
'Loaded total-events reference histogram %s, number of events: %d',
448 list(ref_total_hists.keys())[0], ref_total)
454 json_dict = OrderedDict()
455 json_dict[total_events_key] = OrderedDict()
456 json_dict[total_events_key][
'hist_name'] =
list(in_total_hists.keys())[0]
457 json_dict[total_events_key][
'count'] =
int(in_total)
458 json_dict[total_events_key][
'ref_count'] =
int(ref_total)
if ref_total
else 'n/a'
460 for hist_name, hist
in in_hists.items():
462 if text_name
in json_dict.keys():
464 'Name "%s" assigned to more than one histogram, ', text_name,
465 'results would be overwritten. Use --countHists and ',
466 '--histDict options to avoid duplicates. Exiting.')
468 rowLabel =
'Express' if 'Express' in text_name
else 'Output'
472 ref_hist = ref_hists[hist_name]
473 ref_counts =
get_2D_counts(ref_hist)
if text_name
in [
'HLTStep',
'HLTDecision']
else get_counts(ref_hist, rowLabel)
476 json_dict[text_name] = OrderedDict()
477 json_dict[text_name][
'hist_name'] = hist_name
478 json_dict[text_name][
'counts'] = d
485 if args.referenceFile:
486 logging.info(
'Comparing counts to reference')
487 retcode =
compare_ref(json_dict, args.fracTolerance, args.intTolerance)
489 if args.printOnly
and not args.diffOnly:
490 logging.info(
'Printing counts instead of dumping to files because of --printOnly option')
493 if not args.printOnly:
497 logging.info(
'Writing results to %s', args.json)
498 with open(args.json,
'w')
as outfile:
499 json.dump(json_dict, outfile, sort_keys=
True)
502 logging.info(
'Writing results extract to %s', args.yaml)
504 with open(args.yaml,
'w')
as outfile:
505 yaml.dump(light_dict, outfile, sort_keys=
True)