Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-14 23:16:26

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 
0108 # Copy everything you need to MPS directory of your job,
0109 # but you might want to copy less stuff to save disk space
0110 # (separate cp's for each item, otherwise you loose all if one file is missing):
0111 rm -f $RUNDIR/STDOUT.gz $RUNDIR/alignment.log.gz
0112 cp -p *.log.gz $RUNDIR
0113 # store  millePedeMonitor also in $RUNDIR, below is backup in $MSSDIR
0114 cp -p millePedeMonitor*root $RUNDIR
0115 
0116 # After logfiles have been copied, check whether binary and metadata files exist.
0117 # Their absence indicates typically that no events have been processed, 
0118 #   e.g. due to JSON exclusion, and there is no point in trying to 
0119 #   copy any files to mass storage.
0120 if [[ ! -f milleBinaryISN.dat.gz ]]
0121 then
0122   echo "Missing milleBinary"
0123   return 1
0124 fi
0125 if [[ ! -f millePedeMonitorISN.root ]]
0126 then
0127   echo "Missing Monitor"
0128   return 1
0129 fi
0130 if [[ ! -f treeFile.root ]]
0131 then
0132   echo "Missing treeFile"
0133   return 1
0134 fi
0135 
0136 
0137 # Copy MillePede binary file to Castor
0138 # Must use different command for the cmscafuser pool
0139 if [ "$MSSDIRPOOL" != "cmscafuser" ]; then
0140 # Not using cmscafuser pool => rfcp command must be used
0141   export STAGE_SVCCLASS=$MSSDIRPOOL
0142   export STAGER_TRACE=
0143   nsrm -f $MSSDIR/milleBinaryISN.dat.gz
0144   echo "rfcp milleBinaryISN.dat.gz $MSSDIR/"
0145   untilSuccess rfcp milleBinaryISN.dat.gz   $MSSDIR/ 0
0146   untilSuccess rfcp treeFile*root         $MSSDIR/treeFileISN.root 0
0147   untilSuccess rfcp millePedeMonitor*root $MSSDIR/millePedeMonitorISN.root 0
0148 else
0149   MSSCAFDIR=`echo $MSSDIR | perl -pe 's/\/castor\/cern.ch\/cms//gi'`
0150   # ensure the directories exists
0151   mkdir -p ${MSSCAFDIR}/binaries
0152   mkdir -p ${MSSCAFDIR}/tree_files
0153   mkdir -p ${MSSCAFDIR}/monitors
0154   # copy the files
0155   echo "xrdcp -f milleBinaryISN.dat.gz ${MSSCAFDIR}/binaries/milleBinaryISN.dat.gz > /dev/null"
0156   untilSuccess xrdcp milleBinaryISN.dat.gz    ${MSSCAFDIR}/binaries/milleBinaryISN.dat.gz  1
0157   untilSuccess xrdcp treeFile.root            ${MSSCAFDIR}/tree_files/treeFileISN.root 1
0158   untilSuccess xrdcp millePedeMonitorISN.root ${MSSCAFDIR}/monitors/millePedeMonitorISN.root 1
0159 fi