Files
sf_daq_buffer/scripts/retrieve_detector_data.sh
T
2021-07-16 09:41:33 +02:00

200 lines
7.9 KiB
Bash
Executable File

#!/bin/bash
#cores for the extraction from detector buffer
coreAssociated="9,10,11,12,13,14,15,16,17"
#max number of simultaneously running extraction from detector buffer processes
NUMBER_BUFFER_EXTRACT=9
#cores used for conversion
coreAssociatedConversion="35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18"
#max number of simultaneously running convertion processes
NUMBER_CONVERTION_PROCESSES=15
if [ $# -lt 3 ]
then
echo "Usage : $0 detector_name start_pulse_id end_pulse_id "
echo "Example : $0 JF07T32V01 11709404000 11709405000 "
echo "Optional parameters: output_file_name rate_multiplicator jf_conversion run_file raw_file"
exit
fi
DETECTOR=$1
START_PULSE_ID=$2
STOP_PULSE_ID=$3
PULSE_ID_STEP=1 # by default assume 100Hz
JF_CONVERSION=0 # by default don't call ju_export
RUN_FILE=None
RAW_FILE=None
echo "Request to retrieve : $@ "
echo "Started : "`date`
date1=$(date +%s)
if [ $# -ge 4 ]
then
OUTFILE=$4
else
OUTFILE=/gpfs/photonics/swissfel/buffer/test.${START_PULSE_ID}-${STOP_PULSE_ID}.h5
fi
if [ $# -ge 5 ]
then
PULSE_ID_STEP=$5
fi
if [ $# -ge 6 ]
then
JF_CONVERSION=$6
if [ $# -ge 7 ]
then
RUN_FILE=$7
fi
if [ $# -eq 8 ]
then
RAW_FILE=$8
fi
fi
NM=`echo ${DETECTOR} | cut -c 6-7`
DET_CONFIG_FILE=/gpfs/photonics/swissfel/buffer/config/${DETECTOR}.json
touch /tmp/detector_retrieve.log
cd /gpfs/photonics/swissfel/buffer/
PREVIOUS_STILL_RUN=0
while [ ${PREVIOUS_STILL_RUN} == 0 ]
do
sleep 15 # we need to sleep at least to make sure that we don't read from CURRENT file
n=`ps -fe | grep "bin/sf_writer " | grep -v grep | grep sf_writer | wc -l`
if [ ${n} -lt ${NUMBER_BUFFER_EXTRACT} ]
then
PREVIOUS_STILL_RUN=1
fi
done
date2=$(date +%s)
echo -n "Waited Time : "
echo $((date2-date1)) | awk '{print int($1/60)":"int($1%60)}'
echo "Started actual retrieve : "`date`
if [ ${JF_CONVERSION} == 0 ]
then
OUTFILE_RAW=${OUTFILE}
else
if [ ${RAW_FILE} != "None" ]
then
OUTFILE_RAW=${RAW_FILE}
D1=`dirname ${OUTFILE_RAW}`
mkdir -p ${D1}
else
RUN_NUMBER=`basename ${RUN_FILE} | awk -F '.' '{print $1}'`
D1=`dirname ${RUN_FILE}`
D2=`dirname ${D1}`
OUTFILE_RAW=${D2}/RAW_DATA/${RUN_NUMBER}.${DETECTOR}.h5
mkdir -p ${D2}/RAW_DATA/
fi
fi
taskset -c ${coreAssociated} /usr/local/bin/sf_writer ${OUTFILE_RAW} /gpfs/photonics/swissfel/buffer/${DETECTOR} ${NM} ${START_PULSE_ID} ${STOP_PULSE_ID} ${PULSE_ID_STEP}>> /tmp/detector_retrieve.log &
wait
#TODO: calculate this number from coreAssociatedConversion
#export NUMBA_NUM_THREADS=18
#not clear why, but bitshuffle doesn't respect OMP_NUM_THREADS set in jungfrau_utils anymore, thus we set it here
export OMP_NUM_THREADS=1
date3=$(date +%s)
echo "Finished : "`date`
echo -n "Retrieve Time : "
echo $((date3-date2)) | awk '{print int($1/60)":"int($1%60)}'
if [ ${JF_CONVERSION} == 0 ]
then
echo "File is written in raw format, no compression"
dir_name=`dirname ${OUTFILE_RAW}`
base_name=`basename ${dir_name}`
if [ ${base_name} == "JF_pedestals" ]
then
echo "Pedestal run will make conversion"
source /home/dbe/miniconda3/etc/profile.d/conda.sh
conda deactivate
conda activate sf-daq
if [ ${DETECTOR} == "JF07T32V01" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --add_pixel_mask /sf/bernina/config/jungfrau/pixel_mask/JF07T32V01/pixel_mask_13_full.h5
elif [ ${DETECTOR} == "JF03T01V02" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --add_pixel_mask /sf/bernina/config/jungfrau/pixel_mask/JF03T01V02/pixel_mask_half_chip.h5
# time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG
elif [ ${DETECTOR} == "JF02T09V02" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --number_bad_modules=1
elif [ ${DETECTOR} == "JF06T08V02" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --add_pixel_mask /sf/alvra/config/jungfrau/pixel_mask/JF06T08V01/mask_2lines_module3.h5
# time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --add_pixel_mask /sf/alvra/config/jungfrau/pixel_mask/JF06T08V01/mask_2lines_module3.asics_lines.h5
# elif [ ${DETECTOR} == "JF06T32V02" ]
# then
# time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --add_pixel_mask /sf/alvra/config/jungfrau/pixel_mask/JF06T32V02/mask_noise_in_28.h5
elif [ ${DETECTOR} == "JF13T01V01" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --add_pixel_mask /sf/bernina/config/jungfrau/pixel_mask/JF13T01V01/pixel_mask_bad_rb_22.09.2020.h5
elif [ ${DETECTOR} == "JF11T04V01" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --number_bad_modules=2
elif [ ${DETECTOR} == "JF10T01V01" ]
then
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG --number_bad_modules=1
else
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/jungfrau_create_pedestals.py --filename ${OUTFILE_RAW} --directory ${dir_name} --verbosity DEBUG
fi
PEDESTAL_FILE=`echo ${OUTFILE_RAW} | sed 's/.h5/.res.h5/'`
taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/copy_pedestal_file.py ${PEDESTAL_FILE} ${RUN_FILE} ${DETECTOR} ${DET_CONFIG_FILE}
fi
else
echo "Will call compression/convertion ${OUTFILE_RAW} --> ${OUTFILE}"
PREVIOUS_STILL_RUN=0
while [ ${PREVIOUS_STILL_RUN} == 0 ]
do
sleep $[ ( $RANDOM % 10 ) + ${NUMBER_CONVERTION_PROCESSES} ]s # sleep some random time
n=`ps -fe | grep "scripts/export_file.py " | grep -v grep | grep export | wc -l`
if [ ${n} -lt 15 ]
then
PREVIOUS_STILL_RUN=1
fi
done
date4=$(date +%s)
echo -n "Sleep Time : "
echo $((date4-date3)) | awk '{print int($1/60)":"int($1%60)}'
source /home/dbe/miniconda3/etc/profile.d/conda.sh
conda deactivate
conda activate sf-daq
time taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/export_file.py ${OUTFILE_RAW} ${OUTFILE} ${RUN_FILE} ${DET_CONFIG_FILE}
# if [ ${DETECTOR} == "JF06T32V02" ] || [ ${DETECTOR} == "JF06T08V02" ]
# then
# taskset -c ${coreAssociatedConversion} python /home/dbe/git/sf_daq_buffer/scripts/make_crystfel_list.py ${OUTFILE} ${RUN_FILE} ${DETECTOR}
# fi
date5=$(date +%s)
echo "Finished : "`date`
echo -n "Conversion Time : "
echo $((date5-date4)) | awk '{print int($1/60)":"int($1%60)}'
fi