#!/bin/tcsh

# test if the first argument is help
if ( $#argv > 0 ) then
    if ( $1 == help  || $1 == h || $1 == --help || $1 == --h ) then
	echo after a clean checkout to recompile: source config.csh init
	echo working on your project: source config.csh
	exit
    endif
endif

echo setting up root 5.34

#the root initialisation was copied from /lal/root/5.34/setup.csh
# to change the version, change the number in the line "set init_script=...."

# echo "Setting the ROOTSYS and PATH Variables"

set root_arch=`uname -i`
switch ( $root_arch )
case i386:
     set libdir=lib
     breaksw

case x86_64:
       set libdir=lib64
       breaksw

default:
       echo "Error: unsupported root_architecture ($root_arch)"
       exit 1
       breaksw
endsw

# ROOTSYS must point to the directory containing ROOT etc/
set init_script=`echo /lal/root/5.34/setup.sh`
if ( -z ${init_script} ) then
  echo "Failed to guess ROOT version. Cannot set the environment."
  exit 2
endif
set root_dir=`dirname ${init_script}`
set root_version=`basename ${root_dir}`

if ( ${init_script} == '.' ) then
  echo "Failed to guess ROOT version. Cannot set the environment."
  exit 3
endif
set root_sys_dir=/lal/root/${root_version}
if ( ! -d ${root_sys_dir} ) then
  echo "ROOT version ${root_version} not found"
  exit 4
endif
set root_bin_dir=${root_sys_dir}/bin/${root_arch}
if ( ! -d ${root_bin_dir} ) then
  echo "Architecture ${root_arch} not available for ROOT version ${root_version}"
  exit 5
endif
setenv ROOTSYS ${root_sys_dir}

# ROOT binaries are located in an root_arch-specific directory under bin
setenv PATH ${root_bin_dir}:${PATH}

setenv LD_LIBRARY_PATH ${ROOTSYS}/${libdir}:${LD_LIBRARY_PATH}

# test of this is for a global recompilation/installation
if ( $#argv > 0 ) then
    if ( $1 == init ) then
	cd Pythia8/pythia8170/
	./configure --with-hepmc=../../hepmc/x86_64-slc5-gcc41-opt/
	gmake
	cd examples
	./configure 
	cd ../../../
	cd Delphes-3.0.0
	./configure
	gmake
	cd ../
    endif
endif

echo setting up Pythia8 with HepMC
source `pwd`/Pythia8/pythia8170/examples/config.csh

echo setting up PythiaDelphes
setenv PYTHIA8LOCATION `pwd`/Pythia8/pythia8170
setenv PYTHIA8DATA `pwd`/Pythia8/pythia8170/xmldoc
