Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripts for DQM #105

Merged
merged 14 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

function usage ()
{
echo "Usage: $(basename $0) -r <run number>"
echo "Usage: $(basename "$0") -r <run number>"
}

function help ()
Expand Down Expand Up @@ -36,7 +36,7 @@ while getopts ":hr:" option; do
done
shift $((OPTIND-1))

if [ -z $runnb ]; then
if [ -z "$runnb" ]; then
usage
exit 1
fi
Expand All @@ -55,18 +55,18 @@ function exit_script() {
# Some cleanup before leaving:
# [ -d $CONTAINER ] && rm -rf $CONTAINER
# [ -f $CONTAINER ] && rm -f $CONTAINER
[ -d $NECTARCAMDATA ] && rm -rf $NECTARCAMDATA
[ -d $OUTDIR ] && rm -rf $OUTDIR
[ -f ${OUTDIR}.tar.gz ] && rm -f ${OUTDIR}.tar.gz
[ -d ${OUTDIR} ] && rm -rf ${OUTDIR}
[ -d "$NECTARCAMDATA/runs" ] && rm -rf "$NECTARCAMDATA/runs"
[ -d "$OUTDIR" ] && rm -rf "$OUTDIR"
[ -f "${OUTDIR}.tar.gz" ] && rm -f "${OUTDIR}.tar.gz"
[ -d "${OUTDIR}" ] && rm -rf "${OUTDIR}"
[ -f $WRAPPER ] && rm -f $WRAPPER

exit $return_code
exit "$return_code"
}

export NECTARCAMDATA=$PWD/runs
[ ! -d $NECTARCAMDATA ] && mkdir -p $NECTARCAMDATA || exit_script $?
mv nectarcam*.sqlite NectarCAM.Run*.fits.fz $NECTARCAMDATA/.
export NECTARCAMDATA=$PWD
[ ! -d "$NECTARCAMDATA/runs" ] && mkdir -p "$NECTARCAMDATA/runs" || exit_script $?
mv nectarcam*.sqlite NectarCAM.Run*.fits.fz "$NECTARCAMDATA/runs/."

# Halim's DQM code needs to use a specific output directory:
export NECTARDIR=$PWD/$OUTDIR
Expand All @@ -79,22 +79,19 @@ export NECTARDIR=$PWD/$OUTDIR
# Create a wrapper BASH script with cleaned environment, see https://redmine.cta-observatory.org/issues/51483
cat > $WRAPPER <<EOF
#!/bin/env bash
# See https://redmine.cta-observatory.org/issues/51483: start container from a clean environment
echo "Cleaning environment \$CLEANED_ENV"
[ -z "\$CLEANED_ENV" ] && exec /bin/env -i CLEANED_ENV="Done" HOME=\${HOME} SHELL=/bin/bash /bin/bash -l "\$0" "\$@"

# From https://github.com/DIRACGrid/COMDIRAC/wiki/Injob
# initialize job for COMDIRAC commands
export DCOMMANDS_CONFIG_DIR=$PWD
dconfig --guess
dinit --fromProxy

# Some environment variables related to python, to be passed to container, be it for old Singularity version or recent Apptainer ones:
# Some environment variables, related to python or nectarchain, have to be passed to container, be it for old Singularity versions or recent Apptainer ones:
export SINGULARITYENV_MPLCONFIGDIR=/tmp
export SINGULARITYENV_NUMBA_CACHE_DIR=/tmp
export SINGULARITYENV_NECTARCAMDATA=$NECTARCAMDATA
export SINGULARITYENV_NECTARDIR=$NECTARDIR

export APPTAINERENV_MPLCONFIGDIR=/tmp
export APPTAINERENV_NUMBA_CACHE_DIR=/tmp
export APPTAINERENV_NECTARCAMDATA=$NECTARCAMDATA
export APPTAINERENV_NECTARDIR=$NECTARDIR

# Handle Singularity or Apptainer case:
Expand All @@ -111,7 +108,7 @@ echo
echo "Running"
# Instantiate the nectarchain Singularity image, run our DQM example run within it:
# cmd="\$CALLER exec --home $PWD $CONTAINER /opt/conda/envs/nectarchain/bin/python /opt/cta/nectarchain/src/nectarchain/dqm/start_dqm.py --r0 $NECTARCAMDATA $NECTARDIR -i $LISTRUNS"
cmd="\$CALLER exec --home $PWD $CONTAINER /opt/conda/envs/nectarchain/bin/python /opt/cta/nectarchain/src/nectarchain/dqm/start_dqm.py --r0 -r $runnb $NECTARCAMDATA $NECTARDIR"
cmd="\$CALLER exec --home $PWD $CONTAINER /opt/conda/envs/nectarchain/bin/python /opt/cta/nectarchain/src/nectarchain/dqm/start_dqm.py --r0 --plot --runnb $runnb $NECTARCAMDATA $NECTARDIR"
echo \$cmd
eval \$cmd
EOF
Expand All @@ -121,7 +118,7 @@ chmod u+x $WRAPPER || exit_script $?


# Archive the output directory and push it on DIRAC before leaving the job:
tar zcf ${OUTDIR}.tar.gz ${OUTDIR}/ || exit_script $?
dirac-dms-add-file ${DIRAC_OUTDIR}/${OUTDIR}.tar.gz ${OUTDIR}.tar.gz || exit_script $?
tar zcf "${OUTDIR}.tar.gz" "${OUTDIR}/" || exit_script $?
dirac-dms-add-file "${DIRAC_OUTDIR}/${OUTDIR}.tar.gz" "${OUTDIR}.tar.gz" CC-IN2P3-USER || exit_script $?

exit_script 0
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import sys
from time import sleep

# The magic DIRAC 2 lines
# DIRAC client initialization
import DIRAC

DIRAC.initialize()

# astropy imports
from astropy import time
from astropy import units as u

DIRAC.initialize()

# DIRAC imports
from DIRAC.Interfaces.API.Dirac import Dirac
from DIRAC.Interfaces.API.Job import Job
Expand All @@ -28,7 +28,7 @@
dirac = Dirac()

# Option and argument parser
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(description="Submit jobs on DIRAC to run the DQM")
parser.add_argument(
"-d",
"--date",
Expand All @@ -37,7 +37,11 @@
type=str,
)
parser.add_argument(
"-r", "--run", default=None, help="only process a specific run (optional)", type=str
"-r",
"--run",
default=None,
help="only process a specific run (optional). When omitted, all the runs acquired on DATE are processed (1 job per run).",
type=str,
)
parser.add_argument(
"--dry-run",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ cd $ORIGPWD

# Archive the output directory and push it on DIRAC before leaving the job:
tar zcf ${OUTDIR}.tar.gz ${OUTDIR}/
dirac-dms-add-file ${DIRAC_OUTDIR}/${OUTDIR}.tar.gz ${OUTDIR}.tar.gz LPNHE-USER
dirac-dms-add-file ${DIRAC_OUTDIR}/${OUTDIR}.tar.gz ${OUTDIR}.tar.gz GRIF-USER

# Some cleanup before leaving:
[ -d $OUTDIR ] && rm -rf $OUTDIR
Expand Down
Loading