Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:37

0001 #!/bin/zsh 
0002 #
0003 # Run script template for Mille jobs
0004 #
0005 # Adjustments might be needed for CMSSW environment.
0006 #
0007 # In the very beginning of this script, stager requests for the files will be added.
0008 
0009 # these defaults will be overwritten by MPS
0010 RUNDIR=$HOME/scratch0/some/path
0011 MSSDIR=/castor/cern.ch/user/u/username/another/path
0012 MSSDIRPOOL=
0013 
0014 clean_up () {
0015 #try to recover log files and root files
0016     echo try to recover log files and root files ...
0017     cp -p *.log $RUNDIR
0018     cp -p *.log.gz $RUNDIR
0019     cp -p millePedeMonitor*root $RUNDIR
0020     exit
0021 }
0022 #LSF signals according to http://batch.web.cern.ch/batch/lsf-return-codes.html
0023 trap clean_up HUP INT TERM SEGV USR2 XCPU XFSZ IO
0024 
0025 # a helper function to repeatedly try failing copy commands
0026 untilSuccess () {
0027 # trying "${1} ${2} ${3} > /dev/null" until success, if ${4} is a
0028 # positive number run {1} with -f flag and using --cksum md5,
0029 # break after ${5} tries (with four arguments do up to 5 tries).
0030     if  [[ ${#} -lt 4 || ${#} -gt 5 ]]
0031     then
0032         echo ${0} needs 4 or 5 arguments
0033         return 1
0034     fi
0035 
0036     TRIES=0
0037     MAX_TRIES=5
0038     if [[ ${#} -eq 5 ]]
0039     then
0040         MAX_TRIES=${5}
0041     fi
0042 
0043 
0044     if [[ ${4} -gt 0 ]]
0045     then 
0046         ${1} -f --cksum md5 ${2} ${3} > /dev/null
0047     else 
0048         ${1} ${2} ${3} > /dev/null
0049     fi
0050     while [[ ${?} -ne 0 ]]
0051     do # if not successfull, retry...
0052         if [[ ${TRIES} -ge ${MAX_TRIES} ]]
0053         then # ... but not until infinity!
0054             if [[ ${4} -gt 0 ]]
0055             then
0056                 echo ${0}: Give up doing \"${1} -f --cksum md5 ${2} ${3} \> /dev/null\".
0057                 return 1
0058             else
0059                 echo ${0}: Give up doing \"${1} ${2} ${3} \> /dev/null\".
0060                 return 1
0061             fi
0062         fi
0063         TRIES=$((${TRIES}+1))
0064         if [[ ${4} -gt 0 ]]
0065         then
0066             echo ${0}: WARNING, problems with \"${1} -f --cksum md5 ${2} ${3} \> /dev/null\", try again.
0067             sleep $((${TRIES}*5)) # for before each wait a litte longer...
0068             ${1} -f --cksum md5 ${2} ${3} > /dev/null
0069         else
0070             echo ${0}: WARNING, problems with \"${1} ${2} ${3} \> /dev/null\", try again.
0071             sleep $((${TRIES}*5)) # for before each wait a litte longer...
0072             ${1} ${2} ${3} > /dev/null
0073         fi
0074     done
0075 
0076     if [[ ${4} -gt 0 ]]
0077     then
0078         echo successfully executed \"${1} -f --cksum md5 ${2} ${3} \> /dev/null\"
0079     else
0080         echo successfully executed \"${1} ${2} ${3} \> /dev/null\"
0081     fi
0082     return 0
0083 }
0084 
0085 export X509_USER_PROXY=${RUNDIR}/.user_proxy
0086 
0087 
0088 # The batch job directory (will vanish after job end):
0089 BATCH_DIR=$(pwd)
0090 echo "Running at $(date) \n        on $HOST \n        in directory $BATCH_DIR."
0091 
0092 # set up the CMS environment (choose your release and working area):
0093 cd CMSSW_RELEASE_AREA
0094 echo Setting up $(pwd) as CMSSW environment. 
0095 eval `scram runtime -sh`
0096 rehash
0097 
0098 cd $BATCH_DIR
0099 echo The running directory is $(pwd).
0100 # Execute. The cfg file name will be overwritten by MPS
0101 time cmsRun the.cfg
0102 
0103 gzip -f *.log
0104 gzip milleBinaryISN.dat
0105 echo "\nDirectory content after running cmsRun and zipping log+dat files:"
0106 ls -lh 
0107 # Copy everything you need to MPS directory of your job,
0108 # but you might want to copy less stuff to save disk space
0109 # (separate cp's for each item, otherwise you loose all if one file is missing):
0110 cp -p *.log.gz $RUNDIR
0111 # store  millePedeMonitor also in $RUNDIR, below is backup in $MSSDIR
0112 cp -p millePedeMonitor*root $RUNDIR
0113 
0114 # Copy MillePede binary file to Castor
0115 # Must use different command for the cmscafuser pool
0116 if [ "$MSSDIRPOOL" != "cmscafuser" ]; then
0117 # Not using cmscafuser pool => rfcp command must be used
0118   export STAGE_SVCCLASS=$MSSDIRPOOL
0119   export STAGER_TRACE=
0120   nsrm -f $MSSDIR/milleBinaryISN.dat.gz
0121   echo "rfcp milleBinaryISN.dat.gz $MSSDIR/"
0122   untilSuccess rfcp milleBinaryISN.dat.gz   $MSSDIR/ 0
0123   untilSuccess rfcp treeFile*root         $MSSDIR/treeFileISN.root 0
0124   untilSuccess rfcp millePedeMonitor*root $MSSDIR/millePedeMonitorISN.root 0
0125 else
0126   MSSCAFDIR=`echo $MSSDIR | perl -pe 's/\/castor\/cern.ch\/cms//gi'`
0127   # ensure the directories exists
0128   mkdir -p ${MSSCAFDIR}/binaries
0129   mkdir -p ${MSSCAFDIR}/tree_files
0130   mkdir -p ${MSSCAFDIR}/monitors
0131   # copy the files
0132   echo "xrdcp -f milleBinaryISN.dat.gz ${MSSCAFDIR}/binaries/milleBinaryISN.dat.gz > /dev/null"
0133   untilSuccess xrdcp milleBinaryISN.dat.gz    ${MSSCAFDIR}/binaries/milleBinaryISN.dat.gz  1
0134   untilSuccess xrdcp treeFile.root            ${MSSCAFDIR}/tree_files/treeFileISN.root 1
0135   untilSuccess xrdcp millePedeMonitorISN.root ${MSSCAFDIR}/monitors/millePedeMonitorISN.root 1
0136 fi