Skip to content

Commit 281b243

Browse files
benedikt-voelkelBenedikt Volkel
andauthored
[AnalysisQC] Align some depending code (#1594)
* update o2dpg_analysis_test_config.py * take user config if given * fall back to config in analysis output directory * fall back to default O2DPG config * update analysis_test.sh * copy a config to the analysis output directory to contain the MergedAnalyses analysis Co-authored-by: Benedikt Volkel <benedikt.volkel@cern.ch>
1 parent 6d50485 commit 281b243

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

MC/analysis_testing/analysis_test.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ else
4949
shift
5050
shift
5151
;;
52-
--add-common-args)
53-
add_common_args=" ${2} ${3} "
54-
shift
55-
shift
56-
shift
57-
;;
5852
*)
5953
echo "ERROR: Unknown argument ${1}"
6054
exit 1
@@ -66,7 +60,6 @@ fi
6660
# basic checks
6761
[[ "${testanalysis}" == "" ]] && { echo "ERROR: No analysis specified to be run" ; exit 1 ; }
6862
[[ "${aod}" == "" ]] && { echo "ERROR: No AOD found to be analysed" ; exit 1 ; }
69-
[[ "${add_common_args}" != "" ]] && add_common_args="--add-common-args ${add_common_args}"
7063

7164
# check if enabled
7265
enabled=$($O2DPG_ROOT/MC/analysis_testing/o2dpg_analysis_test_config.py check -t ${testanalysis} --status)
@@ -77,7 +70,7 @@ mkdir Analysis 2>/dev/null
7770
include_disabled=${include_disabled:+--include-disabled}
7871
workflow_path="Analysis/workflow_analysis_test_${testanalysis}.json"
7972
rm ${workflow_path} 2>/dev/null
80-
$O2DPG_ROOT/MC/analysis_testing/o2dpg_analysis_test_workflow.py --is-mc -f ${aod} -o ${workflow_path} --only-analyses ${testanalysis} ${include_disabled} ${add_common_args}
73+
$O2DPG_ROOT/MC/analysis_testing/o2dpg_analysis_test_workflow.py --is-mc --split-analyses -f ${aod} -o ${workflow_path} --only-analyses ${testanalysis} ${include_disabled}
8174
[[ ! -f "${workflow_path}" ]] && { echo "Could not construct workflow for analysis ${testanalysis}" ; exit 1 ; }
8275
$O2DPG_ROOT/MC/bin/o2_dpg_workflow_runner.py -f ${workflow_path} -tt Analysis_${testanalysis}$ --rerun-from Analysis_${testanalysis}$
8376

MC/analysis_testing/o2dpg_analysis_test_config.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import argparse
55
from os import environ
6-
from os.path import join, exists
6+
from os.path import join, exists, isdir
77
import json
88

99
# make sure O2DPG + O2 is loaded
@@ -14,14 +14,29 @@
1414
sys.exit(1)
1515

1616

17+
def get_config(path=None):
18+
default_path = join(O2DPG_ROOT, "MC", "config", "analysis_testing", "json", "analyses_config.json")
19+
if not path:
20+
return default_path
21+
22+
if isdir(path):
23+
# assume to look for analyses_config.json in this directory
24+
path = join(path, "analyses_config.json")
25+
26+
if not exists(path):
27+
print(f"WARNING: Cannot locate config for AnalysisQC at custom path {path}. USe default at {default_path}")
28+
return default_path
29+
30+
with open(path, "r") as f:
31+
return json.load(f)["analyses"]
32+
33+
1734
def modify(args):
1835
"""
1936
modify and create a new config
2037
"""
2138

22-
analyses = None
23-
with open (args.config, "r") as f:
24-
analyses = json.load(f)["analyses"]
39+
analyses = get_config(args.config)
2540

2641
for ana in analyses:
2742
if args.disable_tasks and ana["name"] in args.disable_tasks:
@@ -51,9 +66,7 @@ def print_status(enabled):
5166
return
5267
print("DISABLED")
5368

54-
analyses = None
55-
with open (args.config, "r") as f:
56-
analyses = json.load(f)["analyses"]
69+
analyses = get_config(args.config)
5770

5871
for ana in analyses:
5972
if ana["name"] == args.task:
@@ -80,9 +93,7 @@ def show_tasks(args):
8093
args.enabled = True
8194
args.disabled = True
8295

83-
analyses = None
84-
with open (args.config, "r") as f:
85-
analyses = json.load(f)["analyses"]
96+
analyses = get_config(args.config)
8697

8798
for ana in analyses:
8899
if (args.enabled and ana["enabled"]) or (args.disabled and not ana["enabled"]):
@@ -92,9 +103,12 @@ def show_tasks(args):
92103

93104

94105
def validate_output(args):
95-
analyses = None
96-
with open (args.config, "r") as f:
97-
analyses = json.load(f)["analyses"]
106+
107+
if not args.config:
108+
# first see if config is not explicitly given, then use the directory where the analyses to check are located
109+
args.config = args.directory
110+
111+
analyses = get_config(args.config)
98112

99113
# global return code
100114
ret = 0
@@ -105,11 +119,10 @@ def validate_output(args):
105119
analysis_name = ana["name"]
106120

107121
if args.tasks:
108-
if analysis_name in args.tasks:
109-
# tasks were specified explicitly, make sure to take them into account at all costs
110-
include_disabled = True
111-
else:
122+
if analysis_name not in args.tasks:
112123
continue
124+
# tasks were specified explicitly, make sure to take them into account at all costs
125+
include_disabled = True
113126

114127
if not ana["enabled"] and not include_disabled:
115128
# continue if disabled and not including those
@@ -160,7 +173,7 @@ def main():
160173
sub_parsers = parser.add_subparsers(dest="command")
161174

162175
config_parser = argparse.ArgumentParser(add_help=False)
163-
config_parser.add_argument("-c", "--config", help="input configuration to modify", default=join(O2DPG_ROOT, "MC", "config", "analysis_testing", "json", "analyses_config.json"))
176+
config_parser.add_argument("-c", "--config", help="input configuration to modify")
164177

165178
# modify config
166179
modify_parser = sub_parsers.add_parser("modify", parents=[config_parser])

MC/analysis_testing/o2dpg_analysis_test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ANALYSIS_VALID_DATA = "data"
2525
ANALYSIS_COLLISION_SYSTEM_PP = "pp"
2626
ANALYSIS_COLLISION_SYSTEM_PBPB = "pbpb"
27+
ANALYSIS_MERGED_ANALYSIS_NAME = "MergedAnalyses"
2728

2829

2930
def adjust_configuration_line(line, data_or_mc, collision_system):

MC/analysis_testing/o2dpg_analysis_test_workflow.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def add_analysis_tasks(workflow, input_aod="./AO2D.root", output_dir="./Analysis
216216
merged_analysis_pipe = additional_workflows.copy()
217217
# cpu and mem of merged analyses
218218
merged_analysis_cpu_mem = [0, 0]
219+
# expected output of merged analysis
220+
merged_analysis_expected_output = []
221+
# analyses config to write
222+
analyses_config = []
219223

220224
for ana in load_analyses(analyses_only, include_disabled_analyses=include_disabled_analyses):
221225
if is_mc and not ana.get("valid_mc", False):
@@ -233,26 +237,41 @@ def add_analysis_tasks(workflow, input_aod="./AO2D.root", output_dir="./Analysis
233237
analysis_pipes.append(ana['tasks'])
234238
analysis_names.append(ana['name'])
235239
analysis_cpu_mem.append((1, 2000))
240+
analyses_config.append(ana)
236241
continue
237242

238243
merged_analysis_pipe.extend(ana['tasks'])
239244
# underestimate what a single analysis would take in the merged case.
240245
# Putting everything into one big pipe does not mean that the resources scale the same!
241246
merged_analysis_cpu_mem[0] += 0.5
242247
merged_analysis_cpu_mem[1] += 700
248+
merged_analysis_expected_output.extend(ana['expected_output'])
243249

244250
if not split_analyses:
245251
# add the merged analysis
246252
analysis_pipes.append(merged_analysis_pipe)
247-
analysis_names.append('MergedAnalyses')
253+
analysis_names.append(ANALYSIS_MERGED_ANALYSIS_NAME)
248254
# take at least the resources estimated for a single analysis
249255
analysis_cpu_mem.append((max(1, merged_analysis_cpu_mem[0]), max(2000, merged_analysis_cpu_mem[1])))
256+
merged_analysis_expected_output = list(set(merged_analysis_expected_output))
257+
# config of the merged analysis. Since it doesn't exist in the previous config, but we would like to have it defined, do it here
258+
analyses_config.append({'name': ANALYSIS_MERGED_ANALYSIS_NAME,
259+
'valid_mc': is_mc,
260+
'valid_data': not is_mc,
261+
'enabled': True,
262+
'tasks': merged_analysis_pipe,
263+
'expected_output': merged_analysis_expected_output})
264+
250265

251266
# now we need to create the output directory where we want the final configurations to go
252267
output_dir_config = join(output_dir, 'config')
253268
if not exists(output_dir_config):
254269
makedirs(output_dir_config)
255270

271+
# write the analysis config of this
272+
with open(join(output_dir, 'analyses_config.json'), 'w') as f:
273+
json.dump({'analyses': analyses_config}, f, indent=2)
274+
256275
configuration = adjust_and_get_configuration_path(data_or_mc, collision_system, output_dir_config)
257276

258277
for analysis_name, analysis_pipe, analysis_res in zip(analysis_names, analysis_pipes, analysis_cpu_mem):

0 commit comments

Comments
 (0)