Newer
Older
# This script helps the shifter to easily operate both the line and
# the DAQ processes until the ControlUnit will be finalised.
#
# Author: Carmelo Pellegrino <carmelo.pellegrino@bo.infn.it>
#
function put_lock() {
touch /tmp/auto_ss
}
function rm_lock() {
unlink /tmp/auto_ss
}
function test_lock() {
if [ -e /tmp/auto_ss ]; then
return 1
else
return 0
fi
function createList() {
local LIST
local file
for file in *.detectorfile; do
LIST=(${LIST[*]} "FALSE" ${file})
done
unset file
echo ${LIST[*]}
}
function dm_driver() {
echo "set session target = run"
sleep $1
echo exit
echo y
}
function log() {
[ ! -d ~/.km3_private ] && mkdir -p ~/.km3_private
local logfile="~/.km3_private/auto_ss.log"
date >>${logfile}
echo ${*} >>${logfile}
}
function nowUTC() {
# print the number of seconds elapsed since Jan 1 1970 00:00 in UTC
date -u +%s
}
function get_run_number() {
[ ! -d ~/.km3_private ] && mkdir -p ~/.km3_private
[ ! -e ~/.km3_private/last_run_number ] && echo 0 >~/.km3_private/last_run_number
local last_run_number=`cat ~/.km3_private/last_run_number`
local run_number
let "run_number = ${last_run_number} + 1"
echo ${run_number} > ~/.km3_private/last_run_number
echo ${run_number}
}
test_lock || { zenity --error --text="There is another instance running of this program."; exit 1;}
put_lock
while [ 1 ]; do
# Ask for the run setup
rs_file=`zenity --title "Run Setup Selector" \
--list \
--text "Select one of the following Run Setups:" \
--radiolist \
--column="Selection" \
--column="Run Setup file" \
$(createList ${folder})`
if [ -z "${rs_file}" ]; then
zenity --error --text="No Run Setup file selectet, aborting"
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
exit -1
fi
# Ask for run duration
run_duration=`zenity --title "Run duration" \
--list \
--text "Select one of the following duration:" \
--radiolist \
--column="Selection" \
--column="Minutes" \
FALSE Cancel FALSE 5 TRUE 10 FALSE 20`
if [ "$run_duration" == "Cancel" ]; then
break
fi
done
# Wait 10 seconds
i=0;
while [ $i -lt 100 ]; do
echo $i
sleep 1
let "i = $i + 10"
done | zenity --progress \
--auto-close \
--text="You have 10 seconds to cancel the current operation:\nrunsetup: ${rs_file}\nduration: ${run_duration}" \
--auto-kill
# Peak the run number
run_number=`get_run_number`
daq_log_file=~/.km3_private/daq_${run_number}.log
JGetMessage -H localhost -T MSG -d 3 >${daq_log_file} &
## impl: get the pid and add to the list of must_kill_at_the_exit
# Copy selected run setup file, changing the run number
cat ${rs_file} | sed -e 's/RUNNUMBER/${run_number}/' >dm.detectorfile
run_start_time=`nowUTC`
# Launch the DM
dm_driver ${run_duration} | mono DetectorControl.exe --control --reset &
# Launch the DAQ
log "Launching the DAQ with the following command line: daq.sh ${run_number} ${run_start_time} ${run_duration}"
daq.sh ${run_number} ${run_start_time} ${run_duration}
# Point the browser to the correct address, if required
zenity --question \
--text="Would you like to open the DetectorManager GUI?" \
--cancel-label="No, thanks" && firefox http://localhost:1301/ &
# Wait the end of the run
sleep ${run_duration}
zenity --info --text="Run ${run_number} finished!"
rm_lock