6 Script for verifying menu configurations.
8 Can be run on individual files with the -hlt and/or -l1 options,
9 or on multiple files with the --folder option.
17 from collections
import OrderedDict
as odict
18 from AthenaCommon.Logging
import logging
19 from TriggerMenuMT.menu_config_tests
import TriggerLevel, menu_tests
21 log = logging.getLogger(
"TriggerMenuConfigTest")
25 Run all consistency checks for the trigger on the config.
27 tests = menu_tests[trigger_level]
37 successes.append(test)
38 return {
"successes": successes,
"failures": failures }
42 if not os.path.isfile(file_path):
43 log.error(
"'{}' does not exist".
format(file_path))
44 elif not os.path.splitext(file_path)[1] ==
".json":
45 log.error(
"'{}' is not a JSON file".
format(file_path))
47 with open(file_path,
"r")
as config_file:
48 config = json.load(config_file, object_pairs_hook = odict)
50 return verify(config, trigger_level)
52 return {
"successes": [],
"failures": []}
55 if __name__ ==
"__main__":
56 parser = argparse.ArgumentParser(
57 description=
"Check a generated JSON configuration is valid")
58 individual = parser.add_argument_group(
59 title=
"Individual file options")
60 individual.add_argument(
61 "-hlt", help=
"Path to HLT menu config file")
62 individual.add_argument(
63 "-l1", help=
"Path to L1 menu config file")
64 parser.add_argument(
"-f",
"--folder", help=
"Path to a folder containing one or more configs to check")
65 args = parser.parse_args()
69 if not os.path.isdir(args.folder):
70 log.error(
"Folder '{}' does not exist".
format(args.folder))
73 json_files = [f
for f
in os.listdir(args.folder)
74 if f.endswith(
"json")]
76 return [args.folder + os.sep + f
77 for f
in json_files
if f.startswith(prefix)]
81 hlt_menu, TriggerLevel.HLT)
85 l1_menu, TriggerLevel.L1)
89 args.hlt, TriggerLevel.HLT)
92 args.l1, TriggerLevel.L1)
95 for filename, result
in results.items():
96 success_plural =
"" if len(result[
"successes"]) == 1 \
98 failure_plural =
"" if len(result[
"failures"]) == 1 \
101 "{} success{}, {} failure{} for {}".
format(
102 len(result[
"successes"]), success_plural,
103 len(result[
"failures"]), failure_plural,
105 for failed_test
in result[
"failures"]:
106 log.error(
"'{}' failed for: {}".
format(
107 failed_test.description,
108 ", ".
join([
str(i)
for i
in failed_test.failures])))
110 if result[
"failures"]: