From 66e699546c5a7046e7c9041437fa1ecd66fc9b1c Mon Sep 17 00:00:00 2001 From: benedikt-voelkel Date: Fri, 19 Apr 2024 08:50:24 +0200 Subject: [PATCH] [AnalysisQC] Small fix, add comments (#1600) * [AnalysisQC] Fix config checks * [AnalysisQC} Add comments to config check script --- .../o2dpg_analysis_test_config.py | 58 ++++++++++++------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/MC/analysis_testing/o2dpg_analysis_test_config.py b/MC/analysis_testing/o2dpg_analysis_test_config.py index 46ae5c31c..c188fc881 100755 --- a/MC/analysis_testing/o2dpg_analysis_test_config.py +++ b/MC/analysis_testing/o2dpg_analysis_test_config.py @@ -17,15 +17,15 @@ def get_config(path=None): default_path = join(O2DPG_ROOT, "MC", "config", "analysis_testing", "json", "analyses_config.json") if not path: - return default_path + path = default_path + else: + if isdir(path): + # assume to look for analyses_config.json in this directory + path = join(path, "analyses_config.json") - if isdir(path): - # assume to look for analyses_config.json in this directory - path = join(path, "analyses_config.json") - - if not exists(path): - print(f"WARNING: Cannot locate config for AnalysisQC at custom path {path}. USe default at {default_path}") - return default_path + if not exists(path): + print(f"WARNING: Cannot locate config for AnalysisQC at custom path {path}. Use default at {default_path}") + path = default_path with open(path, "r") as f: return json.load(f)["analyses"] @@ -69,25 +69,26 @@ def print_status(enabled): analyses = get_config(args.config) for ana in analyses: - if ana["name"] == args.task: - if args.status: - print_status(ana["enabled"]) - if args.applicable_to: - if ana.get("valid_mc", False): - print("mc") - if ana.get("valid_data", False): - print("data") + if ana["name"] != args.task: + continue + if args.status: + print_status(ana["enabled"]) + if args.applicable_to: + if ana.get("valid_mc", False): + print("mc") + if ana.get("valid_data", False): + print("data") - return 0 + return 0 # analysis not found - print(f"UNKNOWN") + print(f"WARNING: Unknown task {args.task}") return 1 def show_tasks(args): """ - Browse through analyses and see what is en-/disabled + Browse through analyses and print what is en-/disabled """ if not args.enabled and not args.disabled: args.enabled = True @@ -103,6 +104,13 @@ def show_tasks(args): def validate_output(args): + """ + Validation after running tasks + + * check for corresponding *.log_done files from WF runner + * check for exit code in *.log + * check if expected output files are there + """ if not args.config: # first see if config is not explicitly given, then use the directory where the analyses to check are located @@ -139,6 +147,7 @@ def validate_output(args): # expected to have no output continue + # check if the expected outputs are there for expected_output in ana["expected_output"]: expected_output = join(analysis_dir, expected_output) if not exists(expected_output): @@ -148,6 +157,7 @@ def validate_output(args): logfile = join(analysis_dir, f"Analysis_{analysis_name}.log") if exists(logfile): + # check the exit code in the *.log file exit_code = "0" with open(logfile, "r") as f: for line in f: @@ -159,6 +169,8 @@ def validate_output(args): break if exit_code != "0": continue + + # check if the *.log_done file is there logfile_done = join(analysis_dir, f"Analysis_{analysis_name}.log_done") if not exists(logfile_done): print(f"Apparently, analysis {analysis_name} did not run successfully, {logfile_done} does not exist.") @@ -168,12 +180,14 @@ def validate_output(args): def main(): - """entry point when run directly from command line""" - parser = argparse.ArgumentParser(description='Modify analysis configuration and write new config') + """ + entry point when run directly from command line + """ + parser = argparse.ArgumentParser(description='Check, validate or modify analysis configuration') sub_parsers = parser.add_subparsers(dest="command") config_parser = argparse.ArgumentParser(add_help=False) - config_parser.add_argument("-c", "--config", help="input configuration to modify") + config_parser.add_argument("-c", "--config", help="input configuration to use") # modify config modify_parser = sub_parsers.add_parser("modify", parents=[config_parser])