#!/bin/bash -f
#==============================================================
#
#  Abs:  Start Alarm Handler
#
#  Name: alhgui
#
#  param 1: acc = accelerator (e.g. facet, lcls2)
#  param 2: TOPalhConfigNm = name of toplevel alhConfig file (e.g. FACET, LCLS2, LCLS_MCC, etc.)

# on dev, lcls2 and facet, and eventually lcls will all have a presence.
# therefore there are several prod links for alarm configs
# version on production hosts will not need the separate links, with a link called prod only


export acc=$1
export subsys=$2

# capture whether we're running on production or not, and set the prod symlink name accordingly
# default is the "standard lcls" development (meaning lcls-dev2) scenario, where each accelerator 
# directory has its own symlink 
# similar for asta and xta, where there would be 2 symlinks, one for xta and one for asta
export prodlink=prod-$acc
export onProd="N"

if [ -d "/usr/local/lcls" ]; then
   # lcls production
   export onProd="Y"
elif [ -d "/usr/local/facet" ]; then
   # facet production
   export onProd="Y"
elif [ "$acc" = "spear" ]; then
   # check to see if we're in the SPEAR dev or prod env,
   # otherwise we're in the lcls-dev2 environment
   if [ "$EPICS_BASE" = "/afs/slac/g/spear/epics/base" -o "$EPICS_BASE" = "/prod/epics/base" ]; then
      export onProd="Y"
   fi
fi

if [ "$subsys" = "cryo" ]; then
   # cryo alh always uses prodlink=prod
   export onProd="Y"
fi

if [ "$onProd" = "Y" ]; then
   export prodlink=prod
fi

export ALHTOP=$TOOLS/AlarmConfigsTop
source $ALHTOP/SCRIPT/AlarmEnvSetup.bash
#echo $ALHTOP
export ALHCONFIGFILES=$ALHTOP/GLOBAL/$prodlink/$acc/alh
#echo $ALHCONFIGFILES
export PATH=${PATH}:$TOOLS/AlarmConfigsTop/SCRIPT

#echo $acc
#echo $subsys
# always run in passive mode
alhgui_for_subsystem $acc $subsys passiveMode

# end of script
