## myathena.sh
# 
# Author: Paul Poffenberger
#
# This script can eithe checkout a set of packages for the
# G4 simulation of the the TestBeams or it can be used as
# a tool to setup the environment after the checkout.
#
# Example:
#   To checkout the packages for the first time at uvic
#    source myathena.sh new
#   To setup your environment for working with the packages
#   after they have been checked-out
#    source myathena.sh
#
###############################

export VERS="9.0.2"
export WDIR="Test-${VERS}"
export ATLUSER="igable"

###############################
#

export CWD=$PWD

if [ $# -eq 0 ]; then
  ARG1="old"
  echo "Setting environment for athena ${VERS}"
elif [ $# -eq 1 ] && [ "$1" = "new" ]; then
  ARG1="new"
  shift
  echo "Building package with athena ${VERS}"
else
  echo "Execute from top athena directory as:"
  echo "      \"source myathena.sh new\" to build from scratch"
  echo "   or \"source myathena.sh\"     to just set the environment"
  return
fi

if [ "$ARG1" = "new" ]; then
  if [ ! -d "${VERS}/${WDIR}" ] ; then
    mkdir -p ${VERS}/${WDIR}
  fi
fi

cd ${VERS}/${WDIR}

if [ "$ARG1" = "new" ]; then
  echo "Setting up CMT environment..."
  cat > requirements << EOF
set CMTSITE STANDALONE
macro ATLAS_DIST_AREA "/hepuser/atlas/atlas-kit/${VERS}/dist"
macro ATLAS_RELEASE  ${VERS} "${VERS}"
path_remove  CMTPATH ${CWD}/${VERS}/${WDIR}
path_prepend CMTPATH ${CWD}/${VERS}/${WDIR}
EOF
  export CMTPATH=${PWD}
  export CVSROOT='/hepuser/cvs-atlas/atlasroot'
  export CVS_RSH='ssh'
fi

source /hepuser/atlas/atlas-kit/gcc_env
source /hepuser/atlas/atlas-kit/${VERS}/setup.sh

if [ "$ARG1" = "new" ]; then
  cmt config
fi

source setup.sh -tag=opt

if [ "$ARG1" = "new" ]; then
  ## Reset some variables that have just been wiped by "source setup.sh -tag=opt"...
  #export CVSROOT=':ext:'${ATLUSER}'@atlas-sw.cern.ch:/atlascvs'
  export CVSROOT='/hepuser/cvs-atlas/atlasroot'
  export CVS_RSH='ssh'
  echo "Checking out some packages..."
  cmt co LArCalorimeter/LArGeoModel/LArGeoCode
  cmt co LArCalorimeter/LArG4TB/H6G4Sim
  cmt co LArCalorimeter/LArG4TB/LArG4TBEmecHec
  cmt co LArCalorimeter/LArG4TB/LArG4TBEndcap
  cmt co LArCalorimeter/LArG4TB/LArG4TBExpHall
  cmt co LArCalorimeter/LArG4TB/LArG4TBH6
  cmt co LArCalorimeter/LArG4TB/LArG4TBHEC
  cmt co LArCalorimeter/LArG4/LArG4Sim
  cmt co LArCalorimeter/LArG4/LArG4Analysis
  cmt co LArCalorimeter/LArG4/LArG4Utils
  cmt co -r LArG4EC-uvic-00 LArCalorimeter/LArG4/LArG4EC
fi


cd LArCalorimeter/LArG4TB/H6G4Sim/H6G4Sim-*/cmt

if [ "$ARG1" = "new" ]; then
  cmt config
  cmt broadcast cmt config
fi

source setup.sh

if [ "$ARG1" = "new" ]; then
  echo "Building the packages now..."
  cmt broadcast gmake
fi

cd ../run

echo "Now do:"
echo "athena.py ../share/jobOptions.H6G4Sim.py"
echo "You should get 100 events."
