|
27 | 27 | from os.path import join, abspath, exists |
28 | 28 | from subprocess import Popen |
29 | 29 | from shlex import split |
| 30 | +import json |
30 | 31 |
|
31 | 32 | # make sure O2DPG + O2 is loaded |
32 | 33 | O2DPG_ROOT=environ.get('O2DPG_ROOT') |
|
37 | 38 |
|
38 | 39 | ROOT_MACRO=join(O2DPG_ROOT, "RelVal", "ReleaseValidation.C") |
39 | 40 |
|
40 | | -def run(args): |
| 41 | +def rel_val(args): |
41 | 42 | if not exists(args.output): |
42 | 43 | makedirs(args.output) |
43 | 44 | select_critical = "kTRUE" if args.select_critical else "kFALSE" |
44 | | - cmd = f"\\(\\\"{abspath(args.input_files[0])}\\\",\\\"{abspath(args.input_files[1])}\\\",{args.test},{args.chi2_value},{args.rel_bc_diff},{args.rel_entries_diff},{select_critical}\\)" |
| 45 | + cmd = f"\\(\\\"{abspath(args.input_files[0])}\\\",\\\"{abspath(args.input_files[1])}\\\",{args.test},{args.chi2_value},{args.rel_mean_diff},{args.rel_entries_diff},{select_critical}\\)" |
45 | 46 | cmd = f"root -l -b -q {ROOT_MACRO}{cmd}" |
46 | 47 | print(f"Running {cmd}") |
47 | 48 | p = Popen(split(cmd), cwd=args.output) |
48 | 49 | p.wait() |
49 | 50 | return 0 |
50 | 51 |
|
| 52 | +def inspect(args): |
| 53 | + res = None |
| 54 | + with open(args.file, "r") as f: |
| 55 | + res = json.load(f) |
| 56 | + for s in args.severity: |
| 57 | + names = res.get(s) |
| 58 | + if not names: |
| 59 | + continue |
| 60 | + print(f"Histograms for severity {s}:") |
| 61 | + for n in names: |
| 62 | + print(f" {n}") |
| 63 | + return 0 |
| 64 | + |
51 | 65 | def main(): |
52 | 66 | """entry point when run directly from command line""" |
53 | 67 | parser = argparse.ArgumentParser(description='Wrapping ReleaseValidation macro') |
54 | | - parser.add_argument("-f", "--input-files", dest="input_files", nargs=2, help="input files for comparison", required=True) |
55 | | - parser.add_argument("-t", "--test", type=int, help="index of test case", choices=list(range(1, 8)), required=True) |
56 | | - parser.add_argument("--chi2-value", dest="chi2_value", type=float, help="Chi2 threshold", default=1.5) |
57 | | - parser.add_argument("--rel-bc-diff", dest="rel_bc_diff", type=float, help="Threshold of relative difference in normalised bin content", default=0.01) |
58 | | - parser.add_argument("--rel-entries-diff", dest="rel_entries_diff", type=float, help="Threshold of relative difference in number of entries", default=0.01) |
59 | | - parser.add_argument("--select-critical", dest="select_critical", action="store_true", help="Select the critical histograms and dump to file") |
60 | | - parser.add_argument("--output", "-o", help="output directory", default="./") |
61 | | - parser.set_defaults(func=run) |
| 68 | + sub_parsers = parser.add_subparsers(dest="command") |
| 69 | + |
| 70 | + rel_val_parser = sub_parsers.add_parser("rel-val") |
| 71 | + rel_val_parser.add_argument("-f", "--input-files", dest="input_files", nargs=2, help="input files for comparison", required=True) |
| 72 | + rel_val_parser.add_argument("-t", "--test", type=int, help="index of test case", choices=list(range(1, 8)), required=True) |
| 73 | + rel_val_parser.add_argument("--chi2-value", dest="chi2_value", type=float, help="Chi2 threshold", default=1.5) |
| 74 | + rel_val_parser.add_argument("--rel-mean-diff", dest="rel_mean_diff", type=float, help="Threshold of relative difference in mean", default=1.5) |
| 75 | + rel_val_parser.add_argument("--rel-entries-diff", dest="rel_entries_diff", type=float, help="Threshold of relative difference in number of entries", default=0.01) |
| 76 | + rel_val_parser.add_argument("--select-critical", dest="select_critical", action="store_true", help="Select the critical histograms and dump to file") |
| 77 | + rel_val_parser.add_argument("--output", "-o", help="output directory", default="./") |
| 78 | + rel_val_parser.set_defaults(func=rel_val) |
| 79 | + |
| 80 | + inspect_parser = sub_parsers.add_parser("inspect") |
| 81 | + inspect_parser.add_argument("file", help="pass a JSON produced from ReleaseValidation (rel-val)") |
| 82 | + inspect_parser.add_argument("--severity", nargs="*", default=["BAD", "CRIT_NC"], choices=["GOOD", "WARNING", "BAD", "CRIT_NC", "NONCRIT_NC"], help="Choose severity levels to search for") |
| 83 | + inspect_parser.set_defaults(func=inspect) |
62 | 84 |
|
63 | 85 | args = parser.parse_args() |
64 | 86 | return(args.func(args)) |
|
0 commit comments