Skip to content

Commit

Permalink
Merge branch 'main' into v2.0-optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
GernotMaier committed Feb 22, 2024
2 parents 7bd73db + 5f43e18 commit 1393ed6
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 210 deletions.
50 changes: 28 additions & 22 deletions scripts/care.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
prepare_care_containers()
{
DATA_DIR="$1"
WOBBLE="$2"
NSB="$3"
OBS_MODE="$4"
OBS_MODE="$2"

CARE_DATA_DIR="${DATA_DIR}/CARE_${OBS_MODE}/W${WOBBLE}/NSB${NSB}"
CARE_DATA_DIR="${DATA_DIR}/CARE_${OBS_MODE}"
TMP_CONFIG_DIR="${CARE_DATA_DIR}/model_files/"
mkdir -p "$TMP_CONFIG_DIR"

Expand All @@ -35,22 +33,11 @@ generate_care_submission_script()
LOG_DIR=$(dirname "$CAREFSCRIPT")
OUTPUT_FILE="$2"
rm -f "$OUTPUT_FILE.care.log"
WOBBLE="$3"
NSB="$4"
CARE_CONFIG="$5"
OBS_MODE="$6"

# mount directories
GROPTICS_DATA_DIR="${DATA_DIR}/GROPTICS/W${WOBBLE}"
CARE_DATA_DIR="${DATA_DIR}/CARE_${OBS_MODE}/W${WOBBLE}/NSB${NSB}"
TMP_CONFIG_DIR="${CARE_DATA_DIR}/model_files/"
CONTAINER_EXTERNAL_DIR="-v \"${GROPTICS_DATA_DIR}:/workdir/external/groptics\""
CONTAINER_EXTERNAL_DIR="$CONTAINER_EXTERNAL_DIR -v \"${CARE_DATA_DIR}:/workdir/external/care\""
CONTAINER_EXTERNAL_DIR="$CONTAINER_EXTERNAL_DIR -v \"${TMP_CONFIG_DIR}:/workdir/CARE/data\""
CONTAINER_EXTERNAL_DIR="$CONTAINER_EXTERNAL_DIR -v \"$LOG_DIR:/workdir/external/log/\""
CARE_CONFIG="$3"
OBS_MODE="$4"

CARE="./CameraAndReadout \
NSBRATEPERPIXEL \\\"0 0 ${NSB}\\\" \
NSBRATEPERPIXEL \\\"0 0 \${NSB_LEVEL}\\\" \
HIGHGAINPULSESHAPE \\\"0 /workdir/CARE/data/${CARE_HIGH_GAIN}\\\" \
LOWGAINPULSESHAPE \\\"0 /workdir/CARE/data/${CARE_LOW_GAIN}\\\" \
SIMULATORNAME \\\"$(echo $LOGNAME)\\\" \
Expand All @@ -61,16 +48,35 @@ generate_care_submission_script()
--vbfrunnumber 10000 \
--writepedestals 1 \
--configfile /workdir/CARE/data/${CARE_CONFIG} \
--outputfile /workdir/external/care/$(basename "$OUTPUT_FILE") \
--inputfile /workdir/external/groptics/$(basename "$OUTPUT_FILE").groptics.root"
--outputfile /workdir/external/care/DAT\${RUN_NUMBER} \
--inputfile /workdir/external/groptics/DAT\${RUN_NUMBER}.groptics.root"

echo "#!/bin/bash" > "$CAREFSCRIPT.sh"
echo "RUN_NUMBER=\$1" >> "$CAREFSCRIPT.sh"
echo "WOBBLE_OFFSET=\$2" >> "$CAREFSCRIPT.sh"
echo "NSB_LEVEL=\$3" >> "$CAREFSCRIPT.sh"
echo "" >> "$CAREFSCRIPT.sh"
echo "mkdir -p ${DATA_DIR}/CARE_${OBS_MODE}/W\${WOBBLE_OFFSET}/NSB\${NSB_LEVEL}" >> "$CAREFSCRIPT.sh"

# mount directories
{
cat << EOF
GROPTICS_DATA_DIR="${DATA_DIR}/GROPTICS/W\${WOBBLE_OFFSET}"
CARE_DATA_DIR="${DATA_DIR}/CARE_${OBS_MODE}/W\${WOBBLE_OFFSET}/NSB\${NSB_LEVEL}"
TMP_CONFIG_DIR="\${CARE_DATA_DIR}/model_files/"
CONTAINER_EXTERNAL_DIR="-v \${GROPTICS_DATA_DIR}:/workdir/external/groptics"
CONTAINER_EXTERNAL_DIR="\$CONTAINER_EXTERNAL_DIR -v \${CARE_DATA_DIR}:/workdir/external/care"
CONTAINER_EXTERNAL_DIR="\$CONTAINER_EXTERNAL_DIR -v ${TMP_CONFIG_DIR}:/workdir/CARE/data"
CONTAINER_EXTERNAL_DIR="\$CONTAINER_EXTERNAL_DIR -v $LOG_DIR:/workdir/external/log/"
EOF
} >> "$CAREFSCRIPT.sh"

if [[ $VTSSIMPIPE_CONTAINER == "docker" ]]; then
CARE_EXE="docker run --rm $CONTAINER_EXTERNAL_DIR ${VTSSIMPIPE_CONTAINER_URL}${VTSSIMPIPE_CARE_IMAGE}"
elif [[ $VTSSIMPIPE_CONTAINER == "apptainer" ]]; then
CARE_EXE="apptainer exec --cleanenv ${CONTAINER_EXTERNAL_DIR//-v/--bind} ${VTSSIMPIPE_CONTAINER_DIR}/${VTSSIMPIPE_CARE_IMAGE/:/_}.sif"
CARE_EXE="apptainer exec --cleanenv --no-mount bind-paths \${CONTAINER_EXTERNAL_DIR//-v/--bind} ${VTSSIMPIPE_CONTAINER_DIR}/${VTSSIMPIPE_CARE_IMAGE/:/_}.sif"
fi
CARE_EXE="${CARE_EXE} bash -c \"cd /workdir/CARE && ${CARE}\""
echo "$CARE_EXE > $CARE_DATA_DIR/$(basename "$OUTPUT_FILE").care.log 2>&1" >> "$CAREFSCRIPT.sh"
echo "$CARE_EXE > \${CARE_DATA_DIR}/DAT\${RUN_NUMBER}.care.log 2>&1" >> "$CAREFSCRIPT.sh"
chmod u+x "$CAREFSCRIPT.sh"
}
20 changes: 8 additions & 12 deletions scripts/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@
generate_cleanup_submission_script()
{
CLEANUPSCRIPT="$1"
OUTPUT_FILE="$2"
WOFF_LIST="$4"
OUTPUT_DIR="$2"
CLEANUP_DATA_DIR="${DATA_DIR}/CLEANUP/"
mkdir -p "${CLEANUP_DATA_DIR}"
rm -f "$CLEANUP_DATA_DIR/$(basename "$OUTPUT_FILE").cleanup.log"

# CORSIKA - files are bzipped2
CORSIKA_DATA_DIR="${DATA_DIR}/CORSIKA"

echo "#!/bin/bash" > "$CLEANUPSCRIPT.sh"
for WOBBLE in ${WOFF_LIST}; do
# GROPTICS - files are removed
GROPTICS_DATA_DIR="${DATA_DIR}/GROPTICS/W${WOBBLE}"
CLEANUP_GROPTICS="rm -f -v ${GROPTICS_DATA_DIR}/$(basename "$OUTPUT_FILE").groptics.root"
echo "$CLEANUP_GROPTICS > $CLEANUP_DATA_DIR/$(basename "$OUTPUT_FILE").cleanup.log 2>&1" >> "$CLEANUPSCRIPT.sh"
done
echo "bzip2 -f -v ${CORSIKA_DATA_DIR}/$(basename "$OUTPUT_FILE").telescope >> $CLEANUP_DATA_DIR/$(basename "$OUTPUT_FILE").cleanup.log 2>&1" >> "$CLEANUPSCRIPT.sh"
echo "bzip2 -f -v ${CORSIKA_DATA_DIR}/$(basename "$OUTPUT_FILE").log >> $CLEANUP_DATA_DIR/$(basename "$OUTPUT_FILE").cleanup.log 2>&1" >> "$CLEANUPSCRIPT.sh"
echo "RUN_NUMBER=\$1" >> "$CLEANUPSCRIPT.sh"
echo "rm -f \"$CLEANUP_DATA_DIR/DAT\${RUN_NUMBER}.cleanup.log\"" >> "$CLEANUPSCRIPT.sh"
# GROPTICS - files are removed
CLEANUP_GROPTICS="find ${DATA_DIR}/GROPTICS/ -name \"DAT\${RUN_NUMBER}*.groptics.root\" -print -exec rm -f -v {} \\;" >> "$CLEANUPSCRIPT.sh"
echo "$CLEANUP_GROPTICS > $CLEANUP_DATA_DIR/DAT\${RUN_NUMBER}.cleanup.log 2>&1" >> "$CLEANUPSCRIPT.sh"
echo "bzip2 -f -v ${CORSIKA_DATA_DIR}/DAT\${RUN_NUMBER}.telescope >> $CLEANUP_DATA_DIR/DAT\${RUN_NUMBER}.cleanup.log 2>&1" >> "$CLEANUPSCRIPT.sh"
echo "bzip2 -f -v ${CORSIKA_DATA_DIR}/DAT\${RUN_NUMBER}.log >> $CLEANUP_DATA_DIR/DAT\${RUN_NUMBER}.cleanup.log 2>&1" >> "$CLEANUPSCRIPT.sh"
chmod u+x "$CLEANUPSCRIPT.sh"
}
149 changes: 98 additions & 51 deletions scripts/corsika.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ prepare_corsika_containers()
if [[ $VTSSIMPIPE_CONTAINER == "docker" ]]; then
COPY_COMMAND="docker run --rm $CONTAINER_EXTERNAL_DIR ${VTSSIMPIPE_CONTAINER_URL}${VTSSIMPIPE_CORSIKA_IMAGE}"
elif [[ $VTSSIMPIPE_CONTAINER == "apptainer" ]]; then
COPY_COMMAND="apptainer exec --cleanenv ${CONTAINER_EXTERNAL_DIR//-v/--bind} ${VTSSIMPIPE_CONTAINER_DIR}/${VTSSIMPIPE_CORSIKA_IMAGE/:/_}.sif"
COPY_COMMAND="apptainer exec --cleanenv --no-mount bind-paths ${CONTAINER_EXTERNAL_DIR//-v/--bind} ${VTSSIMPIPE_CONTAINER_DIR}/${VTSSIMPIPE_CORSIKA_IMAGE/:/_}.sif"
fi
# copy corsika directory to data dir (as apptainers are readonly)
echo "Copy CORSIKA files to ${DATA_DIR}/CORSIKA/tmp_corsika_run_files"
Expand All @@ -22,28 +22,6 @@ prepare_corsika_containers()
eval "$COPY_COMMAND"
}

generate_corsika_submission_script()
{
FSCRIPT="$1"
INPUT="$2"
OUTPUT_FILE="$3"
CONTAINER_EXTERNAL_DIR="$4"
rm -f "$OUTPUT_FILE.log"
rm -f "$OUTPUT_FILE.telescope"

INPUT="/workdir/external/log/$(basename "$INPUT")"

echo "#!/bin/bash" > "$FSCRIPT.sh"
mkdir -p "$(dirname $OUTPUT_FILE)"
if [[ $VTSSIMPIPE_CONTAINER == "docker" ]]; then
CORSIKA_EXE="docker run --rm $CONTAINER_EXTERNAL_DIR ${VTSSIMPIPE_CONTAINER_URL}${VTSSIMPIPE_CORSIKA_IMAGE}"
elif [[ $VTSSIMPIPE_CONTAINER == "apptainer" ]]; then
CORSIKA_EXE="apptainer exec --cleanenv ${CONTAINER_EXTERNAL_DIR//-v/--bind} ${VTSSIMPIPE_CONTAINER_DIR}/${VTSSIMPIPE_CORSIKA_IMAGE/:/_}.sif"
fi
CORSIKA_EXE="${CORSIKA_EXE} bash -c \"cd /workdir/corsika-run && ./corsika77500Linux_QGSII_urqmd < $INPUT\""
echo "$CORSIKA_EXE > $OUTPUT_FILE.log" >> "$FSCRIPT.sh"
chmod u+x "$FSCRIPT.sh"
}

# core scatter area (in m)
get_corsika_core_scatter()
Expand Down Expand Up @@ -74,38 +52,107 @@ get_corsika_energy_min()
# CORSIKA input card
generate_corsika_input_card()
{
LOG_DIR="$1"
run_number="$2"
S1="$3"
INPUT_TEMPLATE="$4"
N_SHOWER="$5"
ZENITH="$6"
OFILE="$1"
N_SHOWER="$2"
ZENITH="$3"
ENERGY_MIN=$(get_corsika_energy_min "$ZENITH")
CORE_SCATTER=$(get_corsika_core_scatter "$ZENITH")
ATMOSPHERE="$7"
CORSIKA_DATA_DIR="$8"
ATMOSPHERE="$4"
CORSIKA_DATA_DIR="$5"

echo "S1=\$((RANDOM % 900000000 - 1))" >> "$OFILE"
echo "S2=\$((S1 + 2))" >> "$OFILE"
echo "S3=\$((S2 + 2))" >> "$OFILE"
echo "S4=\$((S3 + 2))" >> "$OFILE"

INPUT="$LOG_DIR"/"input_$run_number.dat"
rm -f "$INPUT"
{
cat << EOF
# CORSIKACONFIG DATDIR $CORSIKA_DATA_DIR/tmp_corsika_run_files
# CORSIKACONFIG RUNNR RUN_NUMBER
# CORSIKACONFIG EVTNR 1
# CORSIKACONFIG NSHOW $N_SHOWER
# CORSIKACONFIG CSCAT 5 $CORE_SCATTER 0.
# CORSIKACONFIG PRMPAR 1
# CORSIKACONFIG ERANGE $ENERGY_MIN 200.E3
# CORSIKACONFIG ESLOPE -1.5
# CORSIKACONFIG THETAP $ZENITH $ZENITH
# CORSIKACONFIG PHIP 0. 360.
# CORSIKACONFIG SEED S1 0 0
# CORSIKACONFIG SEED S2 0 0
# CORSIKACONFIG SEED S3 0 0
# CORSIKACONFIG SEED S4 0 0
# CORSIKACONFIG ATMOD 1
# CORSIKACONFIG MAGNET 25.2 40.88
# CORSIKACONFIG ARRANG 10.4
# CORSIKACONFIG ELMFLG F T
# CORSIKACONFIG RADNKG 200.E2
# CORSIKACONFIG FIXCHI 0.
# CORSIKACONFIG HADFLG 0 0 0 0 0 2
# CORSIKACONFIG QGSJET T 0
# CORSIKACONFIG QGSSIG T
# CORSIKACONFIG HILOW 100.
# CORSIKACONFIG ECUTS 0.30 0.05 0.02 0.02
# CORSIKACONFIG MUADDI F
# CORSIKACONFIG MUMULT T
# CORSIKACONFIG LONGI T 20. F F
# CORSIKACONFIG MAXPRT 50
# CORSIKACONFIG PAROUT F F
# CORSIKACONFIG ECTMAP 1.E5
# CORSIKACONFIG DEBUG F 6 F 1000000
# CORSIKACONFIG DIRECT $CORSIKA_DATA_DIR
# CORSIKACONFIG USER user
# CORSIKACONFIG ATMOSPHERE $ATMOSPHERE T
# CORSIKACONFIG OBSLEV 1270.E2
# CORSIKACONFIG TELESCOPE -23.7E2 37.6E2 0.E2 7.E2
# CORSIKACONFIG TELESCOPE -47.7E2 -44.1E2 4.4E2 7.E2
# CORSIKACONFIG TELESCOPE 60.1E2 -29.4E2 9.8E2 7.E2
# CORSIKACONFIG TELESCOPE 11.3E2 35.9E2 7.E2 7.E2
# CORSIKACONFIG TELESCOPE -8.61E2 -135.48E2 12.23E2 7.E2
# CORSIKACONFIG TELFIL $CORSIKA_DATA_DIR/DATRUN_NUMBER.telescope
# CORSIKACONFIG CERFIL 0
# CORSIKACONFIG CERSIZ 5.
# CORSIKACONFIG CWAVLG 250. 700.
# CORSIKACONFIG EXIT
EOF
} >> ${OFILE}

S1=$((S1 + 2))
S2=$((S1 + 2))
S3=$((S2 + 2))
S4=$((S3 + 2))
echo "input_file=$(dirname "$OFILE")/input_\${RUN_NUMBER}.dat" >> $OFILE

echo "DATDIR $CORSIKA_DATA_DIR/tmp_corsika_run_files" > "$INPUT"
sed -e "s|run_number|$run_number|" \
-e "s|number_of_showers|$N_SHOWER|" \
-e "s|core_scatter_area|$CORE_SCATTER|" \
-e "s|energy_min|$ENERGY_MIN|" \
-e "s|atmosphere_id|$ATMOSPHERE|" \
-e "s|zenith_angle|$ZENITH|g" \
-e "s|output_directory|$CORSIKA_DATA_DIR|" \
-e "s|seed_1|$S1|" \
-e "s|seed_2|$S2|" \
-e "s|seed_3|$S3|" \
-e "s|seed_4|$S4|" \
"$INPUT_TEMPLATE" >> "$INPUT"
echo "rm -f \$input_file" >> $OFILE
echo "sed -n '/DATDIR/,/EXIT/{/DATDIR/!{/EXIT/!s/# CORSIKACONFIG //p}}' "\$0" > \$input_file" >> $OFILE
echo "sed -i \"s/RUN_NUMBER/\$RUN_NUMBER/\" \$input_file" >> $OFILE
echo "sed -i \"s/S1/\$S1/\" \$input_file" >> $OFILE
echo "sed -i \"s/S2/\$S2/\" \$input_file" >> $OFILE
echo "sed -i \"s/S3/\$S3/\" \$input_file" >> $OFILE
echo "sed -i \"s/S4/\$S4/\" \$input_file" >> $OFILE

echo "$S4"
}

generate_corsika_submission_script()
{
FSCRIPT="$1"
OUTPUT_DIR="$2"
CONTAINER_EXTERNAL_DIR="$3"
N_SHOWER="$4"
ZENITH="$5"
ATMOSPHERE="$6"
CORSIKA_DATA_DIR="${7}"

INPUT="/workdir/external/log/input_\${RUN_NUMBER}.dat"
OUTPUT="/workdir/external/data/DAT\${RUN_NUMBER}"

echo "#!/bin/bash" > "$FSCRIPT.sh"
echo "RUN_NUMBER=\$1" >> "$FSCRIPT.sh"

generate_corsika_input_card $FSCRIPT.sh "$N_SHOWER" "$ZENITH" "$ATMOSPHERE" "$CORSIKA_DATA_DIR"
echo "rm -f ${OUTPUT_DIR}/DAT\${RUN_NUMBER}.log" >> "$FSCRIPT.sh"
echo "rm -f ${OUTPUT_DIR}/DAT\${RUN_NUMBER}.telescope" >> "$FSCRIPT.sh"
if [[ $VTSSIMPIPE_CONTAINER == "docker" ]]; then
CORSIKA_EXE="docker run --rm $CONTAINER_EXTERNAL_DIR ${VTSSIMPIPE_CONTAINER_URL}${VTSSIMPIPE_CORSIKA_IMAGE}"
elif [[ $VTSSIMPIPE_CONTAINER == "apptainer" ]]; then
CORSIKA_EXE="apptainer exec --cleanenv --no-mount bind-paths ${CONTAINER_EXTERNAL_DIR//-v/--bind} ${VTSSIMPIPE_CONTAINER_DIR}/${VTSSIMPIPE_CORSIKA_IMAGE/:/_}.sif"
fi
CORSIKA_EXE="${CORSIKA_EXE} bash -c \"cd /workdir/external/data/tmp_corsika_run_files && /workdir/corsika-run/corsika77500Linux_QGSII_urqmd < $INPUT\""
echo "$CORSIKA_EXE > ${OUTPUT_DIR}/DAT\${RUN_NUMBER}.log" >> "$FSCRIPT.sh"
chmod u+x "$FSCRIPT.sh"
}
Loading

0 comments on commit 1393ed6

Please sign in to comment.