Skip to content

Commit 942d128

Browse files
Benedikt Volkelchiarazampolli
authored andcommitted
Update RelVal wrapper
* update default value * add functionality to inspect JSON produced by RelVal script
1 parent 62a95ef commit 942d128

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

RelVal/o2dpg_release_validation.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from os.path import join, abspath, exists
2828
from subprocess import Popen
2929
from shlex import split
30+
import json
3031

3132
# make sure O2DPG + O2 is loaded
3233
O2DPG_ROOT=environ.get('O2DPG_ROOT')
@@ -37,28 +38,49 @@
3738

3839
ROOT_MACRO=join(O2DPG_ROOT, "RelVal", "ReleaseValidation.C")
3940

40-
def run(args):
41+
def rel_val(args):
4142
if not exists(args.output):
4243
makedirs(args.output)
4344
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}\\)"
4546
cmd = f"root -l -b -q {ROOT_MACRO}{cmd}"
4647
print(f"Running {cmd}")
4748
p = Popen(split(cmd), cwd=args.output)
4849
p.wait()
4950
return 0
5051

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+
5165
def main():
5266
"""entry point when run directly from command line"""
5367
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)
6284

6385
args = parser.parse_args()
6486
return(args.func(args))

0 commit comments

Comments
 (0)