#!/bin/csh

setenv ACDC $1
if( $ACDC !~ ACDC* ) then
    echo "set ACDC2 or ACDC3 as first command-line argument"
    exit
endif
if( ($ACDC != ACDC2) && ($ACDC != ACDC3) ) then
    echo "set ACDC2 or ACDC3 as first command-line argument"
    exit
endif
shift

if( $ACDC == ACDC3 ) then
    unsetenv CONF
    setenv CONF $1
    if( $CONF !~ HP* ) then
	echo "set cable Configuration as second argument. Either HP1,HP2 or HP3."
	exit
    endif
    if( ($CONF != HP1) && ($CONF != HP2) && ($CONF != HP3) && ($CONF != HP4)) then
	echo "set HP1, HP2, HP3 or HP4 as second command-line argument"
	exit
    endif
    shift
endif

unsetenv FILE
setenv FILE $1
if( $#argv == 0 ) then
    if($ACDC == ACDC3 ) then
	echo "set raw data FILENAME as third argument"
    else
	echo "set raw data FILENAME as second argument"
    endif
    exit
else
    setenv INPUT_FILE $1
    setenv ROOT_FILE `echo $INPUT_FILE | sed 's/.*\///' | cut -f 1 -d .`.root
shift

setenv OPT NZS
if( $#argv == 1 ) then
    if( ($1 == z) || ($1 == Z) ) then
	setenv OPT ZS
    endif
shift
endif
if( $INPUT_FILE =~ *.digi ) then
    setenv OPT ZS
endif
setenv DIGI_FILE `echo $ROOT_FILE | cut -f 1 -d .`_REPRO.digi
setenv ROOT_FILE `echo $ROOT_FILE | cut -f 1 -d .`_$OPT.root

lbcmt

setenv CMTPATH $BASE

VetraEnv v3r3

source $BASE/Velo/Vetra/v3r3/cmt/setup.csh
source $BASE/Velo/VeloACDC/v1r4/cmt/setup.csh

#The following is to ensure the newer versions of {VeloDet,PatVelo} specified in VeloACDC are picked-up first
setenv LD_LIBRARY_PATH ${VELOACDCROOT}/${CMTCONFIG}:${LD_LIBRARY_PATH}

setenv XMLDDDBROOT $VELOACDCROOT/xml
setenv XMLCONDITIONSROOT $XMLDDDBROOT

if( $ACDC == ACDC3) then
    if( $CONF == HP1 ) then
	setenv CONDITIONS_PATH $XMLCONDITIONSROOT/DDDB/Conditions/conditions_ACDC3_happy_pion_configuration1.xml
    else if ($CONF == HP2 ) then
	setenv CONDITIONS_PATH $XMLCONDITIONSROOT/DDDB/Conditions/conditions_ACDC3_happy_pion_configuration2.xml
    else if ($CONF == HP3 ) then
    setenv CONDITIONS_PATH $XMLCONDITIONSROOT/DDDB/Conditions/conditions_ACDC3_happy_pion_configuration3.xml
    else
    setenv CONDITIONS_PATH $XMLCONDITIONSROOT/DDDB/Conditions/conditions_ACDC3_happy_pion_configuration4.xml
    endif
else
    setenv CONDITIONS_PATH $XMLCONDITIONSROOT/DDDB/Conditions/conditions_ACDC2.xml
endif

if( $INPUT_FILE =~ *.digi ) then
    $VETRAROOT/$CMTCONFIG/Vetra.exe $VELOACDCOPTS/VetraZS_alignment_reprocessed.opts
else
    $VETRAROOT/$CMTCONFIG/Vetra.exe $VELOACDCOPTS/VetraZS_alignment.opts
endif
