#!/bin/sh
# 
# setup script for D0trigsim
# author: Dugan O'Neil - August 27, 2001
#
# set up L1/L2 (including default trigger list for L1/L2)
#
if [ -r $SRT_PRIVATE_CONTEXT/tsim_l1l2/bin/initL1L2.sh ]; then
    $SRT_PRIVATE_CONTEXT/tsim_l1l2/bin/initL1L2.sh
else
    $SRT_PUBLIC_CONTEXT/tsim_l1l2/bin/initL1L2.sh
fi
#
# set up L3
#
if [ -r $SRT_PRIVATE_CONTEXT/tsim_l3/bin/initScriptRunner.sh ]; then
    $SRT_PRIVATE_CONTEXT/tsim_l3/bin/initScriptRunner.sh
else
    $SRT_PUBLIC_CONTEXT/tsim_l3/bin/initScriptRunner.sh
fi
#
# set default trigger list for L3
# 
if [ -r $SRT_PRIVATE_CONTEXT/tsim_l3/trigger_lists/level3.sim ];
then
   ln -sf $SRT_PRIVATE_CONTEXT/tsim_l3/trigger_lists/level3.sim .
else
   ln -sf $SRT_PUBLIC_CONTEXT/tsim_l3/trigger_lists/level3.sim .
fi 
#
# If coorsim has run there are new trigger configuration files to be copied which
# will override the defaults. They are in a directory defined by the $SIMDIR environment
# variable set in the runD0TrigSim script which ultimately calls this script.
#
numsim=`ls $SIMDIR/*.sim 2>1 | wc -w`
#
#

if [ $COORSIM = "Y" ];
then
 if [ $numsim != 0 ]; 
 then
   echo initD0TrigSim.sh:Copying new trigger list from $SIMDIR
   cp -f $SIMDIR/* .
 else
   echo
   echo initD0TrigSim.sh: YOU HAVE ASKED TO RUN WITH COORSIM BUT THERE ARE 
   echo NO NEW .SIM FILES.....SOMETHING IS WRONG!!!!!!
   echo USING DEFAULT TRIGGER LIST FROM SIM FILES INSTEAD!!!
   echo
 fi
#
# if no coorsim has been run this time we must still check to see if it has been run 
# previously. If no .sim file exist in preferred location we just use the ones 
# from the distribution
#
else
 if [ $numsim != 0 ];
 then
   echo initD0TrigSim.sh:Copying trigger list simfiles from $SIMDIR
   cp -f $SIMDIR/* .
 else
   echo initD0TrigSim.sh:Using default trigger list from released .sim files!!!
 fi
fi 

#
exit 0

