Skip to content

Commit d220ff1

Browse files
committed
Some fixes and improvements for topology caching
1 parent d4b18f5 commit d220ff1

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

DATA/tools/epn/gen_topo_o2dpg.sh

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
#!/bin/bash
22

33
# Check settings coming from AliECS via env variables
4-
if [ -z $GEN_TOPO_HASH ]; then echo \$GEN_TOPO_HASH missing; exit 1; fi # Flag whether source is a hash or a folder
5-
if [ -z $GEN_TOPO_SOURCE ]; then echo \$GEN_TOPO_SOURCE missing; exit 1; fi # O2DPG repository source, either a commit hash or a path
6-
if [ -z $GEN_TOPO_LIBRARY_FILE ]; then echo \$GEN_TOPO_LIBRARY_FILE missing; exit 1; fi # Topology description library file in the DATA path of the O2DPG repository
7-
if [ -z $GEN_TOPO_WORKFLOW_NAME ]; then echo \$GEN_TOPO_WORKFLOW_NAME missing; exit 1; fi # Workflow name in library file
8-
if [ -z ${WORKFLOW_DETECTORS+x} ]; then echo \$WORKFLOW_DETECTORS missing; exit 1; fi # Comma-separated list of detectors to run processing for
9-
if [ -z ${WORKFLOW_DETECTORS_QC+x} ]; then echo \$WORKFLOW_DETECTORS_QC missing; exit 1; fi # Comma-separated list of detectors to run QC for
10-
if [ -z ${WORKFLOW_DETECTORS_CALIB+x} ]; then echo \$WORKFLOW_DETECTORS_CALIB missing; exit 1; fi # Comma-separated list of detectors to run calibration for
11-
if [ -z ${WORKFLOW_PARAMETERS+x} ]; then echo \$WORKFLOW_PARAMETERS missing; exit 1; fi # Additional parameters for workflow
12-
if [ -z ${RECO_NUM_NODES_OVERRIDE+x} ]; then echo \$RECO_NUM_NODES_OVERRIDE missing; exit 1; fi # Override number of nodes
13-
if [ -z $DDMODE ] && [ -z $DDWORKFLOW ]; then echo Either \$DDMODE or \$DDWORKFLOW must be set; exit 1; fi # Select data distribution workflow
14-
if [ -z "$MULTIPLICITY_FACTOR_RAWDECODERS" ]; then echo \$MULTIPLICITY_FACTOR_RAWDECODERS missing; exit 1; fi # Process multiplicity scaling parameter
15-
if [ -z "$MULTIPLICITY_FACTOR_CTFENCODERS" ]; then echo \$MULTIPLICITY_FACTOR_CTFENCODERS missing; exit 1; fi # Process multiplicity scaling parameter
16-
if [ -z "$MULTIPLICITY_FACTOR_REST" ]; then echo \$MULTIPLICITY_FACTOR_REST missing; exit 1; fi # Process multiplicity scaling parameter
4+
if [[ -z $GEN_TOPO_HASH ]]; then echo \$GEN_TOPO_HASH missing; exit 1; fi # Flag whether source is a hash or a folder
5+
if [[ -z $GEN_TOPO_SOURCE ]]; then echo \$GEN_TOPO_SOURCE missing; exit 1; fi # O2DPG repository source, either a commit hash or a path
6+
if [[ -z $GEN_TOPO_LIBRARY_FILE ]]; then echo \$GEN_TOPO_LIBRARY_FILE missing; exit 1; fi # Topology description library file in the DATA path of the O2DPG repository
7+
if [[ -z $GEN_TOPO_WORKFLOW_NAME ]]; then echo \$GEN_TOPO_WORKFLOW_NAME missing; exit 1; fi # Workflow name in library file
8+
if [[ -z ${WORKFLOW_DETECTORS+x} ]]; then echo \$WORKFLOW_DETECTORS missing; exit 1; fi # Comma-separated list of detectors to run processing for
9+
if [[ -z ${WORKFLOW_DETECTORS_QC+x} ]]; then echo \$WORKFLOW_DETECTORS_QC missing; exit 1; fi # Comma-separated list of detectors to run QC for
10+
if [[ -z ${WORKFLOW_DETECTORS_CALIB+x} ]]; then echo \$WORKFLOW_DETECTORS_CALIB missing; exit 1; fi # Comma-separated list of detectors to run calibration for
11+
if [[ -z ${WORKFLOW_PARAMETERS+x} ]]; then echo \$WORKFLOW_PARAMETERS missing; exit 1; fi # Additional parameters for workflow
12+
if [[ -z ${RECO_NUM_NODES_OVERRIDE+x} ]]; then echo \$RECO_NUM_NODES_OVERRIDE missing; exit 1; fi # Override number of nodes
13+
if [[ -z $DDMODE ] && [ -z $DDWORKFLOW ]]; then echo Either \$DDMODE or \$DDWORKFLOW must be set; exit 1; fi # Select data distribution workflow
14+
if [[ -z "$MULTIPLICITY_FACTOR_RAWDECODERS" ]]; then echo \$MULTIPLICITY_FACTOR_RAWDECODERS missing; exit 1; fi # Process multiplicity scaling parameter
15+
if [[ -z "$MULTIPLICITY_FACTOR_CTFENCODERS" ]]; then echo \$MULTIPLICITY_FACTOR_CTFENCODERS missing; exit 1; fi # Process multiplicity scaling parameter
16+
if [[ -z "$MULTIPLICITY_FACTOR_REST" ]]; then echo \$MULTIPLICITY_FACTOR_REST missing; exit 1; fi # Process multiplicity scaling parameter
1717

1818
# Check settings coming from the EPN
19-
if [ -z "$FILEWORKDIR" ]; then echo \$FILEWORKDIR missing; exit 1; fi
20-
if [ -z "$INRAWCHANNAME" ]; then echo \$INRAWCHANNAME missing; exit 1; fi
21-
if [ -z "$CTF_DIR" ]; then echo \$CTF_DIR missing; exit 1; fi
22-
if [ -z "$CTF_METAFILES_DIR" ]; then echo \$CTF_METAFILES_DIR missing; exit 1; fi
23-
if [ -z "$GEN_TOPO_WORKDIR" ]; then echo \$GEN_TOPO_WORKDIR missing; exit 1; fi
24-
if [ -z "$GEN_TOPO_STDERR_LOGGING" ]; then echo \$GEN_TOPO_STDERR_LOGGING missing; exit 1; fi
25-
if [ -z "$IS_SIMULATED_DATA" ]; then echo \$IS_SIMULATED_DATA missing; exit 1; fi
26-
if [ -z "$GEN_TOPO_ODC_EPN_TOPO_ARGS" ]; then echo \$GEN_TOPO_ODC_EPN_TOPO_ARGS missing; exit 1; fi
27-
if [ -z "$GEN_TOPO_EPN_CCDB_SERVER" ]; then echo \$GEN_TOPO_EPN_CCDB_SERVER missing; exit 1; fi
19+
if [[ -z "$FILEWORKDIR" ]]; then echo \$FILEWORKDIR missing; exit 1; fi
20+
if [[ -z "$INRAWCHANNAME" ]]; then echo \$INRAWCHANNAME missing; exit 1; fi
21+
if [[ -z "$CTF_DIR" ]]; then echo \$CTF_DIR missing; exit 1; fi
22+
if [[ -z "$CTF_METAFILES_DIR" ]]; then echo \$CTF_METAFILES_DIR missing; exit 1; fi
23+
if [[ -z "$GEN_TOPO_WORKDIR" ]]; then echo \$GEN_TOPO_WORKDIR missing; exit 1; fi
24+
if [[ -z "$GEN_TOPO_STDERR_LOGGING" ]]; then echo \$GEN_TOPO_STDERR_LOGGING missing; exit 1; fi
25+
if [[ -z "$IS_SIMULATED_DATA" ]]; then echo \$IS_SIMULATED_DATA missing; exit 1; fi
26+
if [[ -z "$GEN_TOPO_ODC_EPN_TOPO_ARGS" ]]; then echo \$GEN_TOPO_ODC_EPN_TOPO_ARGS missing; exit 1; fi
27+
if [[ -z "$GEN_TOPO_EPN_CCDB_SERVER" ]]; then echo \$GEN_TOPO_EPN_CCDB_SERVER missing; exit 1; fi
2828

2929
for i in `seq 1 100`; do
3030
exec 100>${GEN_TOPO_WORKDIR}/${i}.lock || { echo Cannot create file descriptor for lock file 1>&2; exit 1; }
@@ -44,30 +44,29 @@ if [[ "0$DDMODE" == "0discard" ]] || [[ "0$DDMODE" == "0disk" ]]; then
4444
fi
4545

4646
mkdir -p $GEN_TOPO_WORKDIR/cache || { echo Error creating directory 1>&2; exit 1; }
47-
if [ $GEN_TOPO_HASH == 1 ]; then
47+
if [[ $GEN_TOPO_HASH == 1 ]]; then
4848
cd $GEN_TOPO_WORKDIR || { echo Cannot enter work dir 1>&2; exit 1; }
49-
if [ ! -d O2DPG ]; then git clone https://github.com/AliceO2Group/O2DPG.git 1>&2 || { echo O2DPG checkout failed 1>&2; exit 1; }; fi
50-
if [ "0$GEN_TOPO_ONTHEFLY" == "01" ]; then
51-
# Disable caching until fully tested
52-
# export GEN_TOPO_CACHEABLE=1
49+
if [[ ! -d O2DPG ]]; then git clone https://github.com/AliceO2Group/O2DPG.git 1>&2 || { echo O2DPG checkout failed 1>&2; exit 1; }; fi
50+
if [[ "0$GEN_TOPO_ONTHEFLY" == "01" && ! -z $GEN_TOPO_CACHE_HASH ]]; then
51+
export GEN_TOPO_CACHEABLE=1
5352
fi
54-
CACHE_HASH=`echo $GEN_TOPO_SOURCE $GEN_TOPO_LIBRARY_FILE $GEN_TOPO_WORKFLOW_NAME $OVERRIDE_PDPSUITE_VERSION $SET_QCJSON_VERSION $DD_DISK_FRACTION $SHM_MANAGER_SHMID $WORKFLOW_DETECTORS $WORKFLOW_DETECTORS_QC $WORKFLOW_DETECTORS_CALIB $WORKFLOW_PARAMETERS $RECO_NUM_NODES_OVERRIDE $DDMODE $DDWORKFLOW $INRAWCHANNAME $FILEWORKDIR $CTF_DIR | md5sum | awk '{print $1}'`
55-
if [ "0$GEN_TOPO_WIPE_CACHE" == "01" ]; then
56-
rm -f cache/$CACHE_HASH
57-
fi
58-
if [ -f cache/$CACHE_HASH ]; then
53+
if [[ "0$GEN_TOPO_CACHEABLE" == "01" && -f cache/$GEN_TOPO_CACHE_HASH ]]; then
54+
if [[ "0$GEN_TOPO_WIPE_CACHE" == "01" ]]; then
55+
rm -f cache/$GEN_TOPO_CACHE_HASH
56+
fi
5957
echo Reusing cached XML topology 1>&2
60-
touch cache/$CACHE_HASH
61-
cat cache/$CACHE_HASH
58+
touch cache/$GEN_TOPO_CACHE_HASH
59+
cat cache/$GEN_TOPO_CACHE_HASH
6260
exit 0
6361
fi
6462
cd O2DPG
6563
git checkout $GEN_TOPO_SOURCE &> /dev/null
66-
if [ $? != 0 ]; then
64+
if [[ $? != 0 ]]; then
6765
git fetch origin 1>&2 || { echo Repository update failed 1>&2; exit 1; }
6866
git checkout $GEN_TOPO_SOURCE &> /dev/null || { echo commit does not exist 1>&2; exit 1; }
6967
fi
70-
if ! git describe --exact-match --tags HEAD &> /dev/null; then
68+
# At a tag, or a detached non-dirty commit, but not on a branch
69+
if ! git describe --exact-match --tags HEAD &> /dev/null && ( git symbolic-ref -q HEAD &> /dev/null || ! git diff-index --quiet HEAD &> /dev/null ); then
7170
unset GEN_TOPO_CACHEABLE
7271
fi
7372
cd DATA
@@ -78,12 +77,12 @@ export EPNSYNCMODE=1
7877
export O2DPG_ROOT=`realpath \`pwd\`/../`
7978
echo Running topology generation to temporary file $GEN_TOPO_WORKDIR/output.xml 1>&2
8079
./tools/parse "$GEN_TOPO_LIBRARY_FILE" $GEN_TOPO_WORKFLOW_NAME $GEN_TOPO_WORKDIR/output.xml 1>&2 || { echo Error during workflow description parsing 1>&2; exit 1; }
81-
if [ "0$GEN_TOPO_CACHEABLE" == "01" ]; then
80+
if [[ "0$GEN_TOPO_CACHEABLE" == "01" ]]; then
8281
cd $GEN_TOPO_WORKDIR
83-
if [ `ls cache/ | wc -l` -ge 1000 ]; then
82+
if [[ `ls cache/ | wc -l` -ge 1000 ]]; then
8483
ls -t cache/* | tail -n +1000 | xargs rm
8584
fi
86-
cp $GEN_TOPO_WORKDIR/output.xml cache/$CACHE_HASH
85+
cp $GEN_TOPO_WORKDIR/output.xml cache/$GEN_TOPO_CACHE_HASH
8786
fi
8887
cat $GEN_TOPO_WORKDIR/output.xml
8988
echo Removing temporary output file $GEN_TOPO_WORKDIR/output.xml 1>&2

0 commit comments

Comments
 (0)