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