#######################################################################
# 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 checkout510.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 MYORCAVERSION  ORCA_5_3_1
setenv MYCOBRAVERSION COBRA_5_3_2
setenv JMAVERSION     jma206_orca531_23Feb2002
setenv MYOSVERSION `scram arch`
# setenv MYOSVERSION `scram arch |awk '{print $4}'`

######################################################################
# 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 MYTPATH $MYCHECKTOP/$MYORCAVERSION/src/JetMetAnalysis/domain/test
setenv RUNPATH $MYCHECKTOP/$MYORCAVERSION/bin/$MYOSVERSION
setenv JMANAL  $MYCHECKTOP/$MYORCAVERSION/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 $MYORCAVERSION
  rm -rf $MYCOBRAVERSION

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 CVSROOT :ext:hidaspal@cmscvs.cern.ch:/cvs_server/repositories/ORCA
# setenv CVS_RSH `which ssh`

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

echo ' *** '
echo ' *** scram project ORCA'  $MYORCAVERSION
echo ' *** '

scram project ORCA $MYORCAVERSION

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

cd $MYCHECKTOP/$MYORCAVERSION/src
echo $PWD

cvs co -r $JMAVERSION JetMetAnalysis
# cvs co JetMetAnalysis

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

echo ' *** COBRA COMMENTED OUT *** '

# cd $MYCHECKTOP
# cmscvsroot COBRA
# scram project COBRA $MYCOBRAVERSION

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

# setenv MYTARGET $MYCHECKTOP/$MYCOBRAVERSION/src/Utilities/CHBook4/interface

# cp $JMANAL/domain/buffer/CHObject.h $MYTARGET

echo '------------------------------------------------------'
echo '--- building corrected cobra libraries'

# cd $MYCHECKTOP/$MYCOBRAVERSION/src/Utilities
# echo $PWD
 
# scram b clean
# scram b |& tee build_$MYOSVERSION.txt

# setenv MYTARGET $MYCHECKTOP/$MYORCAVERSION/lib/$MYOSVERSION

# cp $MYCHECKTOP/$MYCOBRAVERSION/lib/$MYOSVERSION/* $MYTARGET

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

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

cd $JMANAL
echo $PWD

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

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

cd $JMANAL/domain/test
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 anywhere '
echo ' in the ORCA tree, in different directories parallel '
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


