Skip to content

Commit db033b7

Browse files
committed
Developments for 2-tag software processing
a) make workflow construction more independent from actual O2 commit: Allow to detect if options are present in DPL executables and react accordingly. This can allow to write more resilit workflow construction code. b) Improvements to swap in and out software environments in the anchoring script
1 parent 8fc1003 commit db033b7

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed

MC/bin/o2dpg_sim_config.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from functools import lru_cache
2+
import subprocess
3+
import re
4+
15
def create_sim_config(args):
26
# creates a generic simulation config
37
# based on arguments args (run number, energy, ...) originally passed
@@ -138,3 +142,41 @@ def constructConfigKeyArg(config):
138142
arg = arg + mainkey + '.' + subkey + '=' + config[mainkey][subkey] + ';'
139143
arg = arg + '"'
140144
return arg
145+
146+
# some functions to determine dpl option availability on the fly
147+
def parse_dpl_help_output(executable):
148+
"""Parses the --help full output of an executable to extract available options."""
149+
try:
150+
output = subprocess.check_output([executable, "--help", "full"], text=True)
151+
except subprocess.CalledProcessError:
152+
return {}, {}
153+
154+
option_pattern = re.compile(r"(\-\-[\w\-]+)")
155+
sections = {}
156+
inverse_lookup = {}
157+
current_section = "global"
158+
159+
for line in output.split("\n"):
160+
section_match = re.match(r"^([A-Za-z\s]+):$", line.strip())
161+
if section_match:
162+
current_section = section_match.group(1).strip()
163+
sections[current_section] = []
164+
continue
165+
166+
option_match = option_pattern.findall(line)
167+
if option_match:
168+
for option in option_match:
169+
sections.setdefault(current_section, []).append(option)
170+
inverse_lookup.setdefault(option, []).append(current_section)
171+
172+
return sections, inverse_lookup
173+
174+
@lru_cache(maxsize=10)
175+
def get_dpl_options_for_executable(executable):
176+
"""Returns available options and inverse lookup for a given executable, caching the result."""
177+
return parse_dpl_help_output(executable)
178+
179+
def option_if_available(executable, option):
180+
"""Checks if an option is available for a given executable and returns it as a string. Otherwise empty string"""
181+
_, inverse_lookup = get_dpl_options_for_executable(executable)
182+
return ' ' + option if option in inverse_lookup else ''

MC/bin/o2dpg_sim_workflow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import itertools
2828
import math
2929
import requests, re
30+
from functools import lru_cache
31+
3032
pandas_available = True
3133
try:
3234
import pandas as pd
@@ -37,7 +39,7 @@
3739

3840
from o2dpg_workflow_utils import createTask, createGlobalInitTask, dump_workflow, adjust_RECO_environment, isActive, activate_detector, deactivate_detector, compute_n_workers, merge_dicts
3941
from o2dpg_qc_finalization_workflow import include_all_QC_finalization
40-
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg
42+
from o2dpg_sim_config import create_sim_config, create_geant_config, constructConfigKeyArg, option_if_available
4143

4244
parser = argparse.ArgumentParser(description='Create an ALICE (Run3) MC simulation workflow')
4345

@@ -1154,7 +1156,8 @@ def getDigiTaskName(det):
11541156
TPCRECOtask['cmd'] = '${O2_ROOT}/bin/o2-tpc-reco-workflow ' + getDPL_global_options(bigshm=True) + ' --input-type clusters --output-type tracks,send-clusters-per-sector ' \
11551157
+ putConfigValuesNew(["GPU_global","TPCGasParam", "TPCCorrMap", "GPU_rec_tpc", "trackTuneParams"], {"GPU_proc.ompThreads":NWORKERS_TF} | tpcLocalCFreco) + ('',' --disable-mc')[args.no_mc_labels] \
11561158
+ tpc_corr_scaling_options + tpc_corr_options_mc \
1157-
+ ' --tpc-mc-time-gain'
1159+
+ option_if_available('o2-tpc-reco-workflow', '--tpc-mc-time-gain')
1160+
11581161
workflow['stages'].append(TPCRECOtask)
11591162

11601163
# END TPC reco

MC/run/ANCHOR/anchorMC.sh

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,23 @@ NWORKERS=${NWORKERS:-8}
145145
# set a default seed if not given
146146
SEED=${ALIEN_PROC_ID:-${SEED:-1}}
147147

148-
#<----- START OF part that should run under a clean alternative software environment if this was given ------
149-
(
148+
ONCVMFS=0
149+
[[ "${BASEDIR}" == /cvmfs/* ]] && ONCVMFS=1
150+
if [ ! "${MODULEPATH}" ]; then
151+
export MODULEPATH=${BASEDIR}/../Modules/modulefiles
152+
if [ "${ONCVMFS}" == "1" ]; then
153+
PLATFORM=$(echo "${BASEDIR}" | sed -E 's|.*/([^/]+)/Packages|\1|')
154+
export MODULEPATH=${MODULEPATH}:${BASEDIR}/../../etc/toolchain/modulefiles/${PLATFORM}
155+
fi
156+
echo "Determined Modulepath to be ${MODULEPATH}"
157+
fi
150158

159+
#<----- START OF part that should run under a clean alternative software environment if this was given ------
151160
if [ "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" ]; then
161+
if [ "${LOADEDMODULES}" ]; then
162+
module save initial_modules.list # we stash the current modules environment
163+
module purge
164+
fi
152165
echo_info "Using tag ${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG} to setup anchored MC"
153166
/cvmfs/alice.cern.ch/bin/alienv printenv "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" &> async_environment.env
154167
source async_environment.env
@@ -201,8 +214,6 @@ if [[ "${RECO_RC}" != "0" ]] ; then
201214
exit ${RECO_RC}
202215
fi
203216

204-
)
205-
#<----- END OF part that should run under a clean alternative software environment if this was given ------
206217

207218
ALIEN_JDL_LPMPRODUCTIONTAG=$ALIEN_JDL_LPMPRODUCTIONTAG_KEEP
208219
echo_info "Setting back ALIEN_JDL_LPMPRODUCTIONTAG to $ALIEN_JDL_LPMPRODUCTIONTAG"
@@ -217,6 +228,16 @@ if [[ "${ASYNC_WF_RC}" != "0" || `grep "o2-ctf-reader-workflow-options" config-j
217228
exit 1
218229
fi
219230

231+
# get rid of the temporary software environment
232+
if [ "${ALIEN_JDL_O2DPG_ASYNC_RECO_TAG}" ]; then
233+
module purge
234+
# restore the initial software environment
235+
echo "Restoring initial environment"
236+
module --no-pager restore initial_modules.list
237+
module saverm initial_modules.list
238+
fi
239+
#<----- END OF part that should run under a clean alternative software environment if this was given ------
240+
220241
# -- CREATE THE MC JOB DESCRIPTION ANCHORED TO RUN --
221242

222243
MODULES="--skipModules ZDC"

0 commit comments

Comments
 (0)