#!/bin/bash # # $Id$ # $HeadURL$ # # RUN_PERIOD and RAWDATA_DIR environment variables are set in the file # /gluex/etc/hdonline.cshrc # # CODA will write files to: # # $RAWDATA_DIR/active/$RUN_PERIOD/rawdata/RunXXXXXX # # where "XXXXXX" is the zero padded run number. Other files # related to the run are also placed in this directory. # Some details on the strategy here are given in: # # https://halldweb1/wiki/index.php/Raid-to-Silo_Transfer_Strategy # #---- jcedit -------- # %(DAQ_HOME)/scripts # run_prestart %(rn) %(udl) %(config) %(rt) # run_go %(rn) %(udl) %(config) %(rt) # run_end %(rn) %(udl) %(config) %(rt) #=========================================================================================== # !!!!!!!! STD in/out is not allowed in this script !!!!!! STDO=/tmp/${USER}_PRE.$1 exec >$STDO 2>&1 date echo "----- > run_prestart ENTER host=$HOST <---- " #source /gluex/etc/hdonline.cshrc ENV_RAWDATA_DIR=`awk '/RAWDATA_DIR/ {printf "%s %s=%s\n",$1,$2,$3 }' /gluex/etc/hdonline.cshrc | grep setenv | sed s/setenv/export/g ` ENV_RUN_PERIOD=`awk '/RUN_PERIOD/ {printf "%s %s=%s\n",$1,$2,$3 }' /gluex/etc/hdonline.cshrc | grep setenv | sed s/setenv/export/g | sed s/\"//g` $ENV_RAWDATA_DIR $ENV_RUN_PERIOD echo "ENV_RAWDATA_DIR=$ENV_RAWDATA_DIR : $RAWDATA_DIR " echo "ENV_RUN_PERIOD=$ENV_RUN_PERIOD : $RUN_PERIOD" UDL=$2 CONFIG_FILE=$3 source run_lib.sh CONFIG_DIR=`dirname $CONFIG_FILE ` ER_name=ERsoftROC get_host $ER_name ER_host #--------------------------------------- get_host USE_LOCAL USE_LOCAL_SCRIPT echo " USE_LOCAL = $USE_LOCAL_SCRIPT " if [ $USE_LOCAL_SCRIPT = "yes" ]; then echo "exec: ssh $ER_host run_prestart.local $* " ssh $ER_host "run_prestart.local '$1' '$2' '$3' '$4' '$5' " exit $? fi #-------- delete everything below this line later --------------!! # Keep in sync with run_end ! get_host MONITOR_HOST MONITOR_START_HOST # n.b. monitoring is turned on/off in the "hosts" file get_host MONITOR MONITOR_START echo "start MONITOR = $MONITOR_START" #=========================================================================================== RCM_HOST=gluon25 RCM_PORT=32767 RCM_LOG=/dev/tcp/${RCM_HOST}/${RCM_PORT} RCM_LOG_FILE=$DAQ_HOME/../work/rcm_rc.log #------------------------------------------------------------------------------------------- function rcm_log() { echo -e " $1 $2 " # cMsgCommand -u cMsg://gluon100:45000/cMsg/$EXPID -name run_prestart -subject Prestart -type DAQ -text "$1" -string severity=$2 [ -n "$RCM_LOG" ] && echo -e "msg:GUI_runconf prestart:: $1 " > $RCM_LOG [ -n "$UDL" ] && cMsgCommand -u $UDL -name run_prestart -subject Prestart -type DAQ -text "$1" -string severity=$2 2>&1 > /tmp/${USER}_cMsgCommand echo -e "`date` :run_pre:: $2: $1 " >> $RCM_LOG_FILE } rcm_log " script = $0 " "INFO" rcm_log "Run=$1 user=$USER `date` UDL=$2 config=$3 4=$4 5=$5 " "INFO" if [ "$#" -lt 1 ]; then echo "You must provide a run number!" echo "" echo "Usage:" echo " run_prestart RUN" echo "" exit -1 fi export RUN=$(printf '%06d' $1) #=========================================================================================== # DAQ TEST MODE # if [ x$DAQMODE == "xtest" ] ; then rcm_log "WARN: DAQMODE=$DAQMODE " "WARN" exit 0 fi #=========================================================================================== # any other accounts .. # if [ $USER != "hdops" ] ; then which run_log.sh run_log.sh "PRESTART" $RUN $CONFIG_FILE exit 0 fi #=========================================================================================== # HDOPS account only ... #------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------- # Record run configuration to database and copy files to RAID # disk so they can be copied to tape library #------------------------------------------------------------------------------------------- rcm_log "run_log.sh " "INFO" which run_log.sh run_log.sh "PRESTART" $RUN $CONFIG_FILE rcm_log "start epics and monitoring " "INFO" #------------------------------------------------------------------------------------------- # start epics2et # Moved to run_go on 1/16/2018. See comments there for details. David L. #------------------------------------------------------------------------------------------- #${DAQ_HOME}/scripts/run_epics2et #------------------------------------------------------------------------------------------- # run atm_pressure_monitor.py # (also runs from cron in hdops@gluon47) #------------------------------------------------------------------------------------------- apm=/gluex/builds/devel/Linux_RHEL7-x86_64-gcc5.3.0/bin/atm_pressure_monitor.py [ -x ${apm} ] && ${apm} PRESTART #------------------------------------------------------------------------------------------- # start online monitoring system #------------------------------------------------------------------------------------------- if [ $MONITOR_START = "yes" ]; then # The check on start_monitoring being in the PATH is # unusable since we split the compiler and thus BMS_OSNAME # for gluon0X and gluon4X. The DAQ system is sometimes started # from say, gluon05 which uses gcc4.4.7. The online software # cannot compile with this so start_monitoring does not get # installed for that platform. Thus, we ssh to a gluon4X computer # to run it. I hate disabling this check, but we need to for # the moment to get this working. The whole control system vs. # online system needs an overhaul. #sm=`which start_monitoring` #ERR=$? #if [ $ERR != 0 ]; then # rcm_log "ERROR: start_monitoring not found! code=$ERR " "ERROR" # rcm_log "== Online monitoring must be started by hand!! ==" "ERROR" #else # if [ -x $sm ]; then sm=start_monitoring rcm_log "Running $sm on $MONITOR_START_HOST" "INFO" echo "====================== Online Monitoring Starting ======================" echo "** Stopping any pre-existing monitoring processes first ..." echo ssh $MONITOR_START_HOST $sm -R$1 -A -T -AI -e ssh $MONITOR_START_HOST $sm -R$1 -A -T -AI -e echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" echo "** Clearing corrupt data flag HD:coda:DataCorrupt" corrupt_data_alarm_clear echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" echo "** Starting monitoring processes ..." echo ssh $MONITOR_START_HOST $sm -R$1 -A -T -AI ssh $MONITOR_START_HOST $sm -R$1 -A -T -AI & echo "========================================================================" # fi #fi else rcm_log "do not start Monitoring" "WARN" fi #------------------------------------------------------------------------------------------- # Set the HD:coda:daq:cdc_used EPICS variable to reflect # whether the CDC is part of the current CODA readout. # This is used to mask alarms on the atmospheric pressure # difference so that the alarm is only possible if the CDC # is being read. The logic that uses this is implemented by # Hovanes in an IOC. # # Set the value to 0 so that the alarm is masked in case we # are unable to get the relevant information for any reason. caput HD:coda:daq:cdc_used 0 # Get the current CODA configuration CODA_RUN_TYPE=`plask -h localhost -n hdops -c:art,hdops` if [ $? -eq 0 ] ; then if [[ "$CODA_RUN_TYPE" == *"Error:"* ]] ; then # plask prints errors, but always returns 0. Thus we have to # explicitly check the output for the string "Error:" rcm_log "CDC readout check: Error getting CODA Run type from plask -h localhost -n hdops -c:art,hdops " "INFO" else rcm_log "CDC readout check: checking CODA components for $CODA_RUN_TYPE " "INFO" # Get the list of CDC components in the CODA configuration CDC_COMPONENTS=`plask -h gluon41 -n hdops -c:scs,${CODA_RUN_TYPE} | grep ROCCDC` # Check if the list is not empty if (( $(grep -c . <<<"$CDC_COMPONENTS") > 1 )); then # At least one CDC ROC is in the current readout configuration caput HD:coda:daq:cdc_used 1 fi fi else rcm_log "CDC readout check: Failed to get current CODA run type " "INFO" fi #------------------------------------------------------------------------------------------- #------------------------------------------------------------------------------------------- # start AIEC_CDC.py # # This script is used to modify the CDC HV based on the recommendation of an ML model. # The script will check the HD:coda:cdc_hv_ai:switch to decide whether to actually set # the HV or simply log what it would have set it to. The "switch" variable is set by # a toggle in the CDC HV control GUI. aiec_cdc="/group/halld/AIEC/utilities/CDC_control_ai/primex/AIEC_CDC.py" aiec_config="/group/halld/AIEC/utilities/CDC_control_ai/primex/AIEC_CDC.cfg" [ -x ${aiec_cdc} ] && /gluex/etc/crontabs/tcsh_AIEC_env "hdlog -c -o /gluex/log/AIEC_CDC.py_${HOST}.log ${aiec_cdc} --config ${aiec_config}" 2>&1 >/dev/null & caput HD:coda:cdc_hv_ai:error $? & #------------------------------------------------------------------------------------------- rcm_log "done " "INFO" echo "-------> run_prestart EXIT `date` <-------" sleep 60 echo "-------> run_prestart EXIT2 `date` <-------"