Skip to content

Commit 59a5746

Browse files
Benedikt Volkelsawenzel
authored andcommitted
Tidy a bit and abort as early as possible
* check for GRID token at the very beginning * check for jq tool at the very beginning * set a default seed if nothing is given * adjust tests
1 parent 3b4451e commit 59a5746

File tree

3 files changed

+72
-52
lines changed

3 files changed

+72
-52
lines changed

MC/run/ANCHOR/anchorMC.sh

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
# helper functionality #
1616
########################
1717

18+
echo_info()
19+
{
20+
echo "INFO [anchorMC]: ${*}"
21+
}
22+
23+
echo_error()
24+
{
25+
echo "ERROR [anchorMC]: ${*}"
26+
}
27+
1828
print_help()
1929
{
2030
echo "Usage: ./anchorMC.sh"
@@ -53,7 +63,7 @@ print_help()
5363
# Prevent the script from being soured to omit unexpected surprises when exit is used
5464
SCRIPT_NAME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
5565
if [ "${SCRIPT_NAME}" != "$(basename ${BASH_SOURCE[0]})" ] ; then
56-
echo "ERROR: This script cannot not be sourced" >&2
66+
echo_error "This script cannot not be sourced" >&2
5767
return 1
5868
fi
5969

@@ -70,8 +80,15 @@ while [ "$1" != "" ] ; do
7080
done
7181

7282
# make sure O2DPG + O2 is loaded
73-
[ ! "${O2DPG_ROOT}" ] && echo "Error: This needs O2DPG loaded" && exit 1
74-
[ ! "${O2_ROOT}" ] && echo "Error: This needs O2 loaded" && exit 1
83+
[ ! "${O2DPG_ROOT}" ] && echo_error "This needs O2DPG loaded" && exit 1
84+
[ ! "${O2_ROOT}" ] && echo_error "This needs O2 loaded" && exit 1
85+
86+
# check if jq is there
87+
which jq >/dev/null 2>&1
88+
[ "${?}" != "0" ] && { echo_error "jq is not found. Install or load via alienv." ; exit 1 ; }
89+
90+
alien-token-info >/dev/null 2>&1
91+
[ "${?}" != "0" ] && { echo_error "No GRID token found, required to run." ; exit 1 ; }
7592

7693
#################################################################
7794
# Set all required variables to identify an anchored production #
@@ -87,8 +104,8 @@ export ALIEN_JDL_WORKFLOWDETECTORS=${ALIEN_JDL_WORKFLOWDETECTORS:-ITS,TPC,TOF,FV
87104
export ALIEN_JDL_ANCHOR_SIM_OPTIONS=${ALIEN_JDL_ANCHOR_SIM_OPTIONS:--gen pythia8}
88105
# all others MUST be set by the user/on the outside
89106
export ALIEN_JDL_LPMANCHORPASSNAME=${ALIEN_JDL_LPMANCHORPASSNAME:-${ANCHORPASSNAME}}
90-
export ALIEN_JDL_MCANCHOR=${ALIEN_JDL_MCANCHOR:-${MCANCHOR}}
91-
export ALIEN_JDL_LPMPASSNAME=${ALIEN_JDL_LPMPASSNAME:-${PASSNAME}}
107+
# LPMPASSNAME is used in O2 and O2DPG scripts, however on the other hand, ALIEN_JDL_LPMANCHORPASSNAME is the one that is set in JDL templates; so use ALIEN_JDL_LPMANCHORPASSNAME and set ALIEN_JDL_LPMPASSNAME
108+
export ALIEN_JDL_LPMPASSNAME=${ALIEN_JDL_LPMANCHORPASSNAME}
92109
export ALIEN_JDL_LPMRUNNUMBER=${ALIEN_JDL_LPMRUNNUMBER:-${RUNNUMBER}}
93110
export ALIEN_JDL_LPMPRODUCTIONTYPE=${ALIEN_JDL_LPMPRODUCTIONTYPE:-${PRODUCTIONTYPE}}
94111
export ALIEN_JDL_LPMINTERACTIONTYPE=${ALIEN_JDL_LPMINTERACTIONTYPE:-${INTERACTIONTYPE}}
@@ -101,29 +118,29 @@ export ALIEN_JDL_ADDTIMESERIESINMC=${ALIEN_JDL_ADDTIMESERIESINMC:-1}
101118

102119
# cache the production tag, will be set to a special anchor tag; reset later in fact
103120
ALIEN_JDL_LPMPRODUCTIONTAG_KEEP=$ALIEN_JDL_LPMPRODUCTIONTAG
104-
echo "Substituting ALIEN_JDL_LPMPRODUCTIONTAG=$ALIEN_JDL_LPMPRODUCTIONTAG with ALIEN_JDL_LPMANCHORPRODUCTION=$ALIEN_JDL_LPMANCHORPRODUCTION for simulating reco pass..."
121+
echo_info "Substituting ALIEN_JDL_LPMPRODUCTIONTAG=$ALIEN_JDL_LPMPRODUCTIONTAG with ALIEN_JDL_LPMANCHORPRODUCTION=$ALIEN_JDL_LPMANCHORPRODUCTION for simulating reco pass..."
105122
ALIEN_JDL_LPMPRODUCTIONTAG=$ALIEN_JDL_LPMANCHORPRODUCTION
106123

107124
# check variables that need to be set
108-
[ -z "${ALIEN_JDL_LPMANCHORPASSNAME}" ] && { echo "ERROR: Set ALIEN_JDL_LPMANCHORPASSNAME or ANCHORPASSNAME" ; exit 1 ; }
109-
[ -z "${ALIEN_JDL_MCANCHOR}" ] && { echo "ERROR: Set ALIEN_JDL_MCANCHOR or MCANCHOR" ; exit 1 ; }
110-
[ -z "${ALIEN_JDL_LPMPASSNAME}" ] && { echo "ERROR: Set ALIEN_JDL_LPMPASSNAME or PASSNAME" ; exit 1 ; }
111-
[ -z "${ALIEN_JDL_LPMRUNNUMBER}" ] && { echo "ERROR: Set ALIEN_JDL_LPMRUNNUMBER or RUNNUMBER" ; exit 1 ; }
112-
[ -z "${ALIEN_JDL_LPMPRODUCTIONTYPE}" ] && { echo "ERROR: Set ALIEN_JDL_LPMPRODUCTIONTYPE or PRODUCTIONTYPE" ; exit 1 ; }
113-
[ -z "${ALIEN_JDL_LPMINTERACTIONTYPE}" ] && { echo "ERROR: Set ALIEN_JDL_LPMINTERACTIONTYPE or INTERACTIONTYPE" ; exit 1 ; }
114-
[ -z "${ALIEN_JDL_LPMPRODUCTIONTAG}" ] && { echo "ERROR: Set ALIEN_JDL_LPMPRODUCTIONTAG or PRODUCTIONTAG" ; exit 1 ; }
115-
[ -z "${ALIEN_JDL_LPMANCHORRUN}" ] && { echo "ERROR: Set ALIEN_JDL_LPMANCHORRUN or ANCHORRUN" ; exit 1 ; }
116-
[ -z "${ALIEN_JDL_LPMANCHORPRODUCTION}" ] && { echo "ERROR: Set ALIEN_JDL_LPMANCHORPRODUCTION or ANCHORPRODUCTION" ; exit 1 ; }
117-
[ -z "${ALIEN_JDL_LPMANCHORYEAR}" ] && { echo "ERROR: Set ALIEN_JDL_LPMANCHORYEAR or ANCHORYEAR" ; exit 1 ; }
118-
119-
[ -z "${NTIMEFRAMES}" ] && { echo "ERROR: Set NTIMEFRAMES" ; exit 1 ; }
120-
[ -z "${NSIGEVENTS}" ] && { echo "ERROR: Set NSIGEVENTS" ; exit 1 ; }
121-
[ -z "${SPLITID}" ] && { echo "ERROR: Set SPLITID" ; exit 1 ; }
122-
[ -z "${CYCLE}" ] && { echo "ERROR: Set CYCLE" ; exit 1 ; }
123-
[ -z "${PRODSPLIT}" ] && { echo "ERROR: Set PRODSPLIT" ; exit 1 ; }
125+
[ -z "${ALIEN_JDL_LPMANCHORPASSNAME}" ] && { echo_error "Set ALIEN_JDL_LPMANCHORPASSNAME or ANCHORPASSNAME" ; exit 1 ; }
126+
[ -z "${ALIEN_JDL_LPMRUNNUMBER}" ] && { echo_error "Set ALIEN_JDL_LPMRUNNUMBER or RUNNUMBER" ; exit 1 ; }
127+
[ -z "${ALIEN_JDL_LPMPRODUCTIONTYPE}" ] && { echo_error "Set ALIEN_JDL_LPMPRODUCTIONTYPE or PRODUCTIONTYPE" ; exit 1 ; }
128+
[ -z "${ALIEN_JDL_LPMINTERACTIONTYPE}" ] && { echo_error "Set ALIEN_JDL_LPMINTERACTIONTYPE or INTERACTIONTYPE" ; exit 1 ; }
129+
[ -z "${ALIEN_JDL_LPMPRODUCTIONTAG}" ] && { echo_error "Set ALIEN_JDL_LPMPRODUCTIONTAG or PRODUCTIONTAG" ; exit 1 ; }
130+
[ -z "${ALIEN_JDL_LPMANCHORRUN}" ] && { echo_error "Set ALIEN_JDL_LPMANCHORRUN or ANCHORRUN" ; exit 1 ; }
131+
[ -z "${ALIEN_JDL_LPMANCHORPRODUCTION}" ] && { echo_error "Set ALIEN_JDL_LPMANCHORPRODUCTION or ANCHORPRODUCTION" ; exit 1 ; }
132+
[ -z "${ALIEN_JDL_LPMANCHORYEAR}" ] && { echo_error "Set ALIEN_JDL_LPMANCHORYEAR or ANCHORYEAR" ; exit 1 ; }
133+
134+
[ -z "${NTIMEFRAMES}" ] && { echo_error "Set NTIMEFRAMES" ; exit 1 ; }
135+
[ -z "${NSIGEVENTS}" ] && { echo_error "Set NSIGEVENTS" ; exit 1 ; }
136+
[ -z "${SPLITID}" ] && { echo_error "Set SPLITID" ; exit 1 ; }
137+
[ -z "${CYCLE}" ] && { echo_error "Set CYCLE" ; exit 1 ; }
138+
[ -z "${PRODSPLIT}" ] && { echo_error "Set PRODSPLIT" ; exit 1 ; }
124139

125140
# also for this keep a real default
126141
NWORKERS=${NWORKERS:-8}
142+
# set a default seed if not given
143+
SEED=${ALIEN_PROC_ID:-${SEED:-1}}
127144

128145

129146
# default async_pass.sh script
@@ -143,14 +160,14 @@ fi
143160
# if there is no setenv_extra.sh in this directory (so no special version is "shipped" with this rpodcution), copy the default one
144161
if [[ ! -f setenv_extra.sh ]] ; then
145162
cp ${DPGSETENV} .
146-
echo "[INFO alien_setenv_extra.sh] Use default setenv_extra.sh from ${DPGSETENV}."
163+
echo_info "Use default setenv_extra.sh from ${DPGSETENV}."
147164
else
148-
echo "[INFO alien_setenv_extra.sh] setenv_extra.sh was found in the current working directory, use it."
165+
echo_info "setenv_extra.sh was found in the current working directory, use it."
149166
fi
150167

151168
chmod u+x setenv_extra.sh
152169

153-
echo "[INFO alien_async_pass.sh] Setting up DPGRECO to ${DPGRECO}"
170+
echo_info "Setting up DPGRECO to ${DPGRECO}"
154171

155172
# settings that are MC-specific, modify setenv_extra.sh in-place
156173
sed -i 's/GPU_global.dEdxUseFullGainMap=1;GPU_global.dEdxDisableResidualGainMap=1/GPU_global.dEdxSplineTopologyCorrFile=splines_for_dedx_V1_MC_iter0_PP.root;GPU_global.dEdxDisableTopologyPol=1;GPU_global.dEdxDisableGainMap=1;GPU_global.dEdxDisableResidualGainMap=1;GPU_global.dEdxDisableResidualGain=1/' setenv_extra.sh
@@ -167,30 +184,28 @@ touch list.list
167184
./async_pass.sh ${CTF_TEST_FILE:-""} 2&> async_pass_log.log
168185
RECO_RC=$?
169186

170-
echo "RECO finished with ${RECO_RC}"
187+
echo_info "async_pass.sh finished with ${RECO_RC}"
171188

172189
if [[ "${RECO_RC}" != "0" ]] ; then
173190
exit ${RECO_RC}
174191
fi
175192

176193
ALIEN_JDL_LPMPRODUCTIONTAG=$ALIEN_JDL_LPMPRODUCTIONTAG_KEEP
177-
echo "Setting back ALIEN_JDL_LPMPRODUCTIONTAG to $ALIEN_JDL_LPMPRODUCTIONTAG"
194+
echo_info "Setting back ALIEN_JDL_LPMPRODUCTIONTAG to $ALIEN_JDL_LPMPRODUCTIONTAG"
178195

179196
# now create the local MC config file --> config-config.json
180197
${O2DPG_ROOT}/UTILS/parse-async-WorkflowConfig.py
181198
ASYNC_WF_RC=${?}
182199

183200
# check if config reasonably created
184201
if [[ "${ASYNC_WF_RC}" != "0" || `grep "o2-ctf-reader-workflow-options" config-json.json 2> /dev/null | wc -l` == "0" ]]; then
185-
echo "Problem in anchor config creation. Exiting."
202+
echo_error "Problem in anchor config creation. Exiting."
186203
exit 1
187204
fi
188205

189206
# -- CREATE THE MC JOB DESCRIPTION ANCHORED TO RUN --
190207

191208
MODULES="--skipModules ZDC"
192-
# introduce variable to make usage clear
193-
SEED=${ALIEN_PROC_ID}
194209
# Since this is used, set it explicitly
195210
ALICEO2_CCDB_LOCALCACHE=${ALICEO2_CCDB_LOCALCACHE:-$(pwd)/ccdb}
196211

@@ -205,28 +220,31 @@ remainingargs="${remainingargs} -productionTag ${ALIEN_JDL_LPMPRODUCTIONTAG:-ali
205220
# since the last passed argument wins, e.g. -productionTag cannot be overwritten by the user
206221
remainingargs="${ALIEN_JDL_ANCHOR_SIM_OPTIONS} ${remainingargs} --anchor-config config-json.json"
207222

208-
echo "baseargs: ${baseargs}"
209-
echo "remainingargs: ${remainingargs}"
223+
echo_info "baseargs passed to o2dpg_sim_workflow_anchored.py: ${baseargs}"
224+
echo_info "remainingargs forwarded to o2dpg_sim_workflow.py: ${remainingargs}"
210225

211226
# query CCDB has changed, w/o "_"
212227
${O2DPG_ROOT}/MC/bin/o2dpg_sim_workflow_anchored.py ${baseargs} -- ${remainingargs} &> timestampsampling_${ALIEN_JDL_LPMRUNNUMBER}.log
213-
if [ "$?" != "0" ] ; then
214-
echo "Problem during anchor timestamp sampling and workflow creation. Exiting."
215-
exit 1
228+
WF_RC="${?}"
229+
if [ "${WF_RC}" != "0" ] ; then
230+
echo_error "Problem during anchor timestamp sampling and workflow creation. Exiting."
231+
exit ${WF_RC}
216232
fi
217233

218234
TIMESTAMP=`grep "Determined timestamp to be" timestampsampling_${ALIEN_JDL_LPMRUNNUMBER}.log | awk '//{print $6}'`
219-
echo "TIMESTAMP IS ${TIMESTAMP}"
235+
echo_info "TIMESTAMP IS ${TIMESTAMP}"
220236

221237
# -- Create aligned geometry using ITS ideal alignment to avoid overlaps in geant
222238
CCDBOBJECTS_IDEAL_MC="ITS/Calib/Align"
223239
TIMESTAMP_IDEAL_MC=1
224240
${O2_ROOT}/bin/o2-ccdb-downloadccdbfile --host http://alice-ccdb.cern.ch/ -p ${CCDBOBJECTS_IDEAL_MC} -d ${ALICEO2_CCDB_LOCALCACHE} --timestamp ${TIMESTAMP_IDEAL_MC}
225-
if [ ! "$?" == "0" ]; then
226-
echo "Problem during CCDB prefetching of ${CCDBOBJECTS_IDEAL_MC}. Exiting."
227-
exit 1
241+
CCDB_RC="${?}"
242+
if [ ! "${CCDB_RC}" == "0" ]; then
243+
echo_error "Problem during CCDB prefetching of ${CCDBOBJECTS_IDEAL_MC}. Exiting."
244+
exit ${CCDB_RC}
228245
fi
229246

247+
# TODO This can potentially be removed or if needed, should be taken over by o2dpg_sim_workflow_anchored.py and O2_dpg_workflow_runner.py
230248
echo "run with echo in pipe" | ${O2_ROOT}/bin/o2-create-aligned-geometry-workflow --configKeyValues "HBFUtils.startTime=${TIMESTAMP}" --condition-remap=file://${ALICEO2_CCDB_LOCALCACHE}=ITS/Calib/Align -b
231249
mkdir -p $ALICEO2_CCDB_LOCALCACHE/GLO/Config/GeometryAligned
232250
ln -s -f $PWD/o2sim_geometry-aligned.root $ALICEO2_CCDB_LOCALCACHE/GLO/Config/GeometryAligned/snapshot.root
@@ -235,22 +253,22 @@ ln -s -f $PWD/o2sim_geometry-aligned.root $ALICEO2_CCDB_LOCALCACHE/GLO/Config/Ge
235253

236254
export FAIRMQ_IPC_PREFIX=./
237255

238-
echo "Ready to start main workflow"
256+
echo_info "Ready to start main workflow"
239257

240258
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json -tt ${ALIEN_JDL_O2DPGWORKFLOWTARGET:-aod} --cpu-limit ${ALIEN_JDL_CPULIMIT:-8}
241259
MCRC=$? # <--- we'll report back this code
242260
exit 0
243261
if [[ "${ALIEN_JDL_ADDTIMESERIESINMC}" != "0" ]]; then
244262
# Default value is 1 so this is run by default.
245-
echo "Running TPC time series"
263+
echo_info "Running TPC time series"
246264
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json -tt tpctimes
247265
fi
248266

249-
[[ ! -z "${DISABLE_QC}" ]] && echo "INFO: QC is disabled, skip it."
267+
[[ ! -z "${DISABLE_QC}" ]] && echo_info "QC is disabled, skip it."
250268

251269
if [[ -z "${DISABLE_QC}" && "${MCRC}" = "0" && "${remainingargs}" == *"--include-local-qc"* ]] ; then
252270
# do QC tasks
253-
echo "Doing QC"
271+
echo_info "Doing QC"
254272
${O2DPG_ROOT}/MC/bin/o2_dpg_workflow_runner.py -f workflow.json --target-labels QC --cpu-limit ${ALIEN_JDL_CPULIMIT:-8} -k
255273
# NOTE that with the -k|--keep-going option, the runner will try to keep on executing even if some tasks fail.
256274
# That means, even if there is a failing QC task, the return code will be 0

MC/run/ANCHOR/tests/test_anchor_2023_apass2_PbPb.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
# taken from https://its.cern.ch/jira/browse/O2-4586
99
export ALIEN_JDL_LPMANCHORPASSNAME=apass2
1010
export ALIEN_JDL_MCANCHOR=apass2
11-
export ALIEN_JDL_COLLISIONSYSTEM=Pb-Pb
1211
export ALIEN_JDL_CPULIMIT=8
13-
export ALIEN_JDL_LPMPASSNAME=apass2
1412
export ALIEN_JDL_LPMRUNNUMBER=544121
1513
export ALIEN_JDL_LPMPRODUCTIONTYPE=MC
1614
export ALIEN_JDL_LPMINTERACTIONTYPE=PbPb
@@ -25,12 +23,15 @@ export SPLITID=100
2523
export PRODSPLIT=153
2624
export CYCLE=0
2725

28-
# on the GRID, this is set, for our use case, we can mimic any job ID
29-
export ALIEN_PROC_ID=2963436952
26+
# on the GRID, this is set and used as seed; when set, it takes precedence over SEED
27+
#export ALIEN_PROC_ID=2963436952
28+
export SEED=5
3029

3130
# run the central anchor steering script; this includes
3231
# * derive timestamp
3332
# * derive interaction rate
3433
# * extract and prepare configurations (which detectors are contained in the run etc.)
3534
# * run the simulation (and QC)
35+
# To disable QC, uncomment the following line
36+
#export DISABLE_QC=1
3637
${O2DPG_ROOT}/MC/run/ANCHOR/anchorMC.sh

MC/run/ANCHOR/tests/test_anchor_2023_apass2_pp.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
# taken from https://its.cern.ch/jira/browse/O2-4586
99
export ALIEN_JDL_LPMANCHORPASSNAME=apass2
1010
export ALIEN_JDL_MCANCHOR=apass2
11-
export ALIEN_JDL_COLLISIONSYSTEM=p-p
1211
export ALIEN_JDL_CPULIMIT=8
13-
export ALIEN_JDL_LPMPASSNAME=apass2
1412
export ALIEN_JDL_LPMRUNNUMBER=535069
1513
export ALIEN_JDL_LPMPRODUCTIONTYPE=MC
1614
export ALIEN_JDL_LPMINTERACTIONTYPE=pp
@@ -25,15 +23,18 @@ export SPLITID=100
2523
export PRODSPLIT=153
2624
export CYCLE=0
2725

28-
# on the GRID, this is set, for our use case, we can mimic any job ID
29-
export ALIEN_PROC_ID=2963436952
26+
# on the GRID, this is set and used as seed; when set, it takes precedence over SEED
27+
#export ALIEN_PROC_ID=2963436952
28+
export SEED=5
3029

3130
# for pp and 50 events per TF, we launch only 4 workers.
32-
export NWORKERS=4
31+
export NWORKERS=2
3332

3433
# run the central anchor steering script; this includes
3534
# * derive timestamp
3635
# * derive interaction rate
3736
# * extract and prepare configurations (which detectors are contained in the run etc.)
3837
# * run the simulation (and QC)
38+
# To disable QC, uncomment the following line
39+
#export DISABLE_QC=1
3940
${O2DPG_ROOT}/MC/run/ANCHOR/anchorMC.sh

0 commit comments

Comments
 (0)