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 AthenaCommon.Logging
import logging
18 from TriggerMenuMT.menu_config_tests
import TriggerLevel, menu_tests
20 log = logging.getLogger(
"TriggerMenuConfigTest")
24 Run all consistency checks for the trigger on the config.
26 tests = menu_tests[trigger_level]
36 successes.append(test)
37 return {
"successes": successes,
"failures": failures }
41 if not os.path.isfile(file_path):
42 log.error(
"'{}' does not exist".
format(file_path))
43 elif not os.path.splitext(file_path)[1] ==
".json":
44 log.error(
"'{}' is not a JSON file".
format(file_path))
46 with open(file_path,
"r")
as config_file:
47 config = json.load(config_file)
49 return verify(config, trigger_level)
51 return {
"successes": [],
"failures": []}
54 if __name__ ==
"__main__":
55 parser = argparse.ArgumentParser(
56 description=
"Check a generated JSON configuration is valid")
57 individual = parser.add_argument_group(
58 title=
"Individual file options")
59 individual.add_argument(
60 "-hlt", help=
"Path to HLT menu config file")
61 individual.add_argument(
62 "-l1", help=
"Path to L1 menu config file")
63 parser.add_argument(
"-f",
"--folder", help=
"Path to a folder containing one or more configs to check")
64 args = parser.parse_args()
68 if not os.path.isdir(args.folder):
69 log.error(
"Folder '{}' does not exist".
format(args.folder))
72 json_files = [f
for f
in os.listdir(args.folder)
73 if f.endswith(
"json")]
75 return [args.folder + os.sep + f
76 for f
in json_files
if f.startswith(prefix)]
80 hlt_menu, TriggerLevel.HLT)
84 l1_menu, TriggerLevel.L1)
88 args.hlt, TriggerLevel.HLT)
91 args.l1, TriggerLevel.L1)
94 for filename, result
in results.items():
95 success_plural =
"" if len(result[
"successes"]) == 1 \
97 failure_plural =
"" if len(result[
"failures"]) == 1 \
100 "{} success{}, {} failure{} for {}".
format(
101 len(result[
"successes"]), success_plural,
102 len(result[
"failures"]), failure_plural,
104 for failed_test
in result[
"failures"]:
105 log.error(
"'{}' failed for: {}".
format(
106 failed_test.description,
107 ", ".
join([
str(i)
for i
in failed_test.failures])))
109 if result[
"failures"]: