###########################################################################
# Author  : Pal Hidas        (01/03/00)  ORCA_3
# Updates : Salavat Abdullin (01/07/00)  ORCA_4
#           Salavat Abdullin (10/11/00)  ORCA_4_3_2
#           Pal Hidas        (16/11/00)  new_orca option
#           Pal Hidas        (28/03/01)  JetMetAnalysis into repository
###########################################################################

echo '#####################################################################'
echo '# usage : source checkout450.csh [option]                            '
echo '#                                                                    '
echo '#  omitting the options it will use the orca tree created earlier    '
echo '#  updating the code in your area                                    '
echo '#                                                                    '
echo '#  options : new_orca      check out orca again (old is removed)     '
echo '#                                                                    '
echo '#####################################################################'

######################################################################
# SET THIS to the directory where you want the ORCA tree ckecked out
######################################################################

#setenv MYCHECKTOP $SCRATCH
setenv MYCHECKTOP $PWD

######################################################################
# orca and operating system version
######################################################################

setenv ORCAVERSION  ORCA_4_5_4
setenv MYBUILDTAG   orca453
setenv JMAVERSION   Hidas01Sep2001
# setenv MYOSVERSION `scram arch`
# setenv MYOSVERSION `scram arch |awk '{print $4}'`
setenv MYOSVERSION Linux__2.2

######################################################################
# where the jetmet ntuple maker code can be found
######################################################################

setenv GROUPCODE    '/afs/cern.ch/cms/Physics/jetmet/getcode'

######################################################################
# source and working dirs of ORCA tree
######################################################################

setenv MYTDIR $MYCHECKTOP/$ORCAVERSION/src/JetMetAnalysis/domain/test
setenv RUNPATH $MYCHECKTOP/$ORCAVERSION/bin/$MYOSVERSION
setenv JMANAL  $MYCHECKTOP/$ORCAVERSION/src/JetMetAnalysis

################################################################
# checking orca out and building it
################################################################

cd $MYCHECKTOP
pwd 

if ( $1 == "new_orca" ) then

  #-------------------------------------
  ### remove old ORCA tree
  #-------------------------------------

  echo ' *** '
  echo ' *** removing old ORCA tree'
  echo ' *** '

  rm -rf $ORCAVERSION

else

  echo ' *** using the old orca tree, checking out private code only '

endif

echo '------------------------------------------------------'
echo '--- setup ORCA'
echo $PWD

echo ' *** building new tree in ' $MYCHECKTOP
echo ' *** '

echo ' *** cmscvsroot ORCA '
cmscvsroot ORCA
### project ORCA
### setenv CVS_RSH `which ssh`
### setenv CVSROOT :ext:hidaspal@cmscvs.cern.ch:/cvs_server/repositories/ORCA

echo ' *** ' 
echo ' *** CVSROOT = ' $CVSROOT

echo ' *** '
echo ' *** scram project ORCA'  $ORCAVERSION
echo ' *** '

scram project ORCA $ORCAVERSION


echo '-------------------------------------------------------'
echo '--- check out some orca code to be corrected'

cd $MYCHECKTOP/$ORCAVERSION/src
echo $PWD
 
cvs co -r $ORCAVERSION Utilities/CHBook4

echo '-------------------------------------------------------'
echo '--- check out our code and the corrections code as well'

cd $MYCHECKTOP/$ORCAVERSION/src
echo $PWD

cvs co -r $JMAVERSION JetMetAnalysis

### cvs co JetMetAnalysis

echo '------------------------------------------------------'
echo '--- building corrected orca libraries'

cd $MYCHECKTOP/$ORCAVERSION/src/Utilities
echo $PWD
 
cp $JMANAL/domain/buffer/CHObject.h CHBook4/interface
 
scram b clean
scram b |& tee build_$MYOSVERSION.txt

echo '------------------------------------------------------'
echo '--- building our JetMet libraries'

cd $JMANAL
echo $PWD

scram b clean
scram b |& tee build_`scram arch`.txt

echo '------------------------------------------------------'
echo '--- building our executables     '

cd $JMANAL/domain/test
cp BuildFile_$MYBUILDTAG BuildFile
echo $PWD

scram b clean
scram b |& tee build_`scram arch`.txt

echo '------------------------------------------------------'
echo '--- copying job scripts where the executable is '

cp *.csh *.job *.pl $RUNPATH


cd $RUNPATH
echo ' '
echo ' *** working area : '
echo ' '
pwd
echo ' '

chmod +x *.csh *.job

ls -lt 
echo ' '
echo ' ********************************************'
echo ' *** B U I L D I N G  is  F I N I S H E D ***'
echo ' ********************************************'
echo ' ' 
echo ' The script  "run_db.csh"  can be run interactively in '
echo ' ' $RUNPATH
echo ' (try "source run_db.csh" and you will get the details) '
echo ' ' 
echo ' ' 
echo ' The batch job  "run_db_batch.job"  can be submitted anywhere '
echo ' ( try "bsub [options] run_db_batch.job" ),'
echo ' see the beginning of the file for details, '
echo ' it runs run_db.csh for you. '
echo ' '  

exit 0


