389 args = get_parser().parse_args()
390 logging.basicConfig(stream=sys.stdout,
391 format='%(levelname)-8s %(message)s',
392 level=logging.DEBUG if args.verbose else logging.INFO)
393
394 name_dict = parse_name_dict(args.histDict)
395
396
399
400 in_file = open_root_file(args.inputFile)
401 if not in_file:
402 logging.error('Failed to open input file %s', args.inputFile)
403 return 1
404 logging.debug('Opened input file %s', args.inputFile)
405
406 if args.referenceFile:
407 ref_file = open_root_file(args.referenceFile)
408 if not ref_file:
409 logging.error('Failed to open input file %s', args.referenceFile)
410 return 1
411 logging.debug('Opened input file %s', args.referenceFile)
412
413
416
417 in_hists = load_histograms(in_file, args.countHists)
418 if len(in_hists) == 0:
419 logging.error('No count histograms could be loaded.')
420 return 1
421 logging.info('Loaded count histograms: %s', sorted(in_hists))
422
423 in_total_hists = load_histograms(in_file, args.totalHists)
424 if len(in_total_hists) == 0:
425 logging.error('No total-events histogram could be loaded')
426 return 1
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)
431
432 ref_hists = None
433 ref_total_hists = None
434 ref_total = None
435 if args.referenceFile:
436 ref_hists = load_histograms(ref_file, args.countHists)
437 logging.info('Loaded reference count histograms: %s', sorted(ref_hists))
438 missing_refs = [k for k in in_hists if k not in ref_hists]
439 if len(missing_refs) > 0:
440 logging.error('Count histogram(s) %s missing in the reference', missing_refs)
441 return 1
442 ref_total_hists = load_histograms(ref_file, args.totalHists)
443 if len(ref_total_hists) == 0:
444 logging.error('No total-events reference histogram could be loaded')
445 return 1
446 ref_total = list(ref_total_hists.values())[0].
GetEntries()
447 logging.info('Loaded total-events reference histogram %s, number of events: %d',
448 list(ref_total_hists.keys())[0], ref_total)
449
450
453
454 json_dict = {
455 total_events_key: {
456 'hist_name': list(in_total_hists.keys())[0],
457 'count': int(in_total),
458 'ref_count': int(ref_total) if ref_total else 'n/a'
459 }
460 }
461
462 for hist_name, hist in in_hists.items():
463 text_name = get_text_name(hist_name, name_dict)
464 if text_name in json_dict:
465 logging.error(
466 'Name "%s" assigned to more than one histogram, ', text_name,
467 'results would be overwritten. Use --countHists and ',
468 '--histDict options to avoid duplicates. Exiting.')
469
470 rowLabel = 'Express' if 'Express' in text_name else 'Output'
471 counts = get_2D_counts(hist) if text_name in ['HLTStep', 'HLTDecision'] else get_counts(hist, rowLabel)
472 ref_counts = {}
473 if ref_hists:
474 ref_hist = ref_hists[hist_name]
475 ref_counts = get_2D_counts(ref_hist) if text_name in ['HLTStep', 'HLTDecision'] else get_counts(ref_hist, rowLabel)
476 d = make_counts_json_dict(counts, ref_counts)
477
478 json_dict[text_name] = {
479 'hist_name': hist_name,
480 'counts': d
481 }
482
483
486
487 retcode = 0
488 if args.referenceFile:
489 logging.info('Comparing counts to reference')
490 retcode = compare_ref(json_dict, args.fracTolerance, args.intTolerance)
491
492 if args.printOnly and not args.diffOnly:
493 logging.info('Printing counts instead of dumping to files because of --printOnly option')
494 print_counts(json_dict)
495
496 if not args.printOnly:
497 write_txt_output(json_dict, args.diffOnly, args.printHeader)
498
499 if args.json:
500 logging.info('Writing results to %s', args.json)
501 with open(args.json, 'w') as outfile:
502 json.dump(json_dict, outfile, sort_keys=False)
503
504 if args.yaml:
505 logging.info('Writing results extract to %s', args.yaml)
506 light_dict = make_light_dict(json_dict, includeL1Counts = args.yamlL1)
507 with open(args.yaml, 'w') as outfile:
508 yaml.dump(light_dict, outfile, sort_keys=False)
509
510 return retcode
511
512
TGraphErrors * GetEntries(TH2F *histo)