######################################################################'
# This script will check out and build all executables which you need '
# to initialize, populate (hits, digis) and control (dump, validate)  '
# an objectivity database (user federation)                           '
#                                                                     '
# usage :                                                             '
#  source checkdbtools.csh  [myoption]                                '
#                                                                     '
#  Author : Pal Hidas,  January 18, 2001      hidaspal@fnal.gov       '
#                                                                     '
#  omitting the options it will overwrite the necessary things        '
#  in your orca tree, or creates it if you do not have one            '
#                                                                     '
#  options : new_orca      old orca tree is totally removed           '
#                                                                     '
######################################################################'

#-----------------------------------------------------------------------
# SET THESE VARIABLES
#
setenv MYORCAVERSION  'ORCA_4_4_0'
setenv MYCHECKTOP $SCRATCH01
#-----------------------------------------------------------------------

setenv myoption $1

setenv MYOSVERSION `scram arch`
setenv MYRUNPATH $MYCHECKTOP/$MYORCAVERSION/bin/$MYOSVERSION
setenv MYBEGIN $PWD
setenv MYWORKDIR $PWD

rm -rf $MYWORKDIR/checkdbtools.out
touch $MYWORKDIR/checkdbtools.out

echo  " myoption = " $1 >> $MYWORKDIR/checkdbtools.out

echo ' *** setup cms ' >> $MYWORKDIR/checkdbtools.out

source /afs/fnal.gov/files/code/cms/code3/cms/utils/cms_setup.csh

cd $MYCHECKTOP

# only if you want to check out orca again destroying the existing
# orca tree and everything that was included by your other tasks ;-)

if ( $myoption == "new_orca" ) then

   echo ' *** remove old orca tree !!!'  >> $MYWORKDIR/checkdbtools.out
   rm -rf $MYORCAVERSION

else

   echo ' *** old orca tree used'  >> $MYWORKDIR/checkdbtools.out

endif

cmscvsroot ORCA

# the first time you use the repository: 
# cvs login
# 98passwd

scram project ORCA $MYORCAVERSION

##########

echo ' *** check out orca Examples/ExProduction '>> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src
 
cvs co -r $MYORCAVERSION Examples/ExProduction
cd Examples/ExProduction/
 
echo ' *** create library '  >> $MYWORKDIR/checkdbtools.out
 
scram b shared_debug
 
echo ' *** create executables '  >> $MYWORKDIR/checkdbtools.out
 
scram b bin_debug_local

##########

echo ' *** check out CARF/MDTools/test ' >> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src

cvs co -r $MYORCAVERSION CARF/MDTools

echo ' *** create library '  >> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src/CARF/MDTools/src

scram b clean
scram b

echo ' *** create executables '  >> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src/CARF/MDTools/test

scram b clean
scram b

##########

echo ' *** check out CARF/MetaData/test ' >> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src

cvs co -r $MYORCAVERSION CARF/MetaData

echo ' *** create library '  >> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src/CARF/MetaData/src

scram b clean
scram b

echo ' *** create executables '  >> $MYWORKDIR/checkdbtools.out
cd $MYCHECKTOP/$MYORCAVERSION/src/CARF/MetaData/test

scram b clean
scram b


#### final operations (cleaning etc.)

cd $MYCHECKTOP/$MYORCAVERSION/src

cd $MYRUNPATH


exit 0



