Skip to content

Commit

Permalink
[AnalysisQC] Small fix, add comments (#1600)
Browse files Browse the repository at this point in the history
* [AnalysisQC] Fix config checks

* [AnalysisQC} Add comments to config check script

(cherry picked from commit 6297361)
  • Loading branch information
benedikt-voelkel authored and Benedikt Volkel committed May 14, 2024
1 parent 25d25d3 commit 87a7786
Showing 1 changed file with 36 additions and 22 deletions.
58 changes: 36 additions & 22 deletions MC/analysis_testing/o2dpg_analysis_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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.")
Expand All @@ -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])
Expand Down

0 comments on commit 87a7786

Please sign in to comment.