Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:28

0001 #! /bin/bash
0002 #set -x
0003 
0004 source /afs/cern.ch/cms/caf/setup.sh
0005 curdir=$( pwd )
0006 
0007 workdir="<MYCMSSW>/src/"
0008 CASTOR_OUT="<CASTOROUT>"
0009 
0010 DQM_OUT="${curdir}/MONITORING/DQM/CTF/"
0011 #DQM_OUT=$1 
0012 ALCAFILELIST=$1
0013 MAXEVENTS=18000
0014 
0015 
0016 checkCorruptedFiles(){
0017 
0018 
0019     FOUND=4 #not found by default 
0020     if [ $# != 1 ]
0021         then
0022 #       echo "wrong number of input parameters ( $# ). Please provide a number (index of job to check). Exiting with error."
0023         echo 3
0024     fi
0025  
0026     LISTBADJOBS="/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HIP/bonato/CMSSW_3_8_4_patch2/src/Alignment/TrackerAlignment/scripts/badjobs_Run2010A-v4.lst" 
0027   #  echo "Called checkCorruptedFiles with input $1"
0028 
0029     IND=$1
0030    while read myline
0031 
0032       do
0033 #      echo "LINE is $myline" 
0034 #      VAR1=$( echo $myline | awk '{print $1}' )
0035 #      VAR2=$( echo $VAR1 | sed 's/^M$//' )
0036       if [[ "$1" -eq "$myline" ]]
0037           then
0038 #       echo "Found INDEX $1"
0039         FOUND=0
0040           break
0041     #  else
0042         #  echo "INDEX $1 !!== $myline"
0043       fi
0044     done  < $LISTBADJOBS
0045     
0046     echo $FOUND
0047     
0048 }
0049 # end checkCorruptedFiles()
0050 
0051 
0052 
0053 ########################
0054 ### START MAIN BODY OF THE SCRIPT
0055 
0056 #check if output directory exists
0057 nsls -d /castor/cern.ch/cms/$CASTOR_OUT
0058 if [ $? -ne 0 ]
0059 then
0060 echo "Output directory: "
0061 echo $CASTOR_OUT
0062 echo "does not exist. Please check the scripts. Exiting."
0063 exit 1
0064 fi
0065 
0066 
0067 echo ""
0068 echo "I am in $curdir"
0069 
0070 cnt=0;
0071 
0072 if [ $# -gt 1 ]
0073     then  
0074     if [ $2 -gt 2 ]
0075         then
0076         echo "Cleaning from Prescaled files the output directory: /castor/cern.ch/cms/$CASTOR_OUT"  
0077         for file in $(nsls /castor/cern.ch/cms/$CASTOR_OUT/ | grep 'Prescaled') 
0078           do
0079 #echo "deleting $file"
0080           rfrm  /castor/cern.ch/cms/$CASTOR_OUT/$file
0081           let cnt=cnt+1
0082         done
0083         echo "Deleted $cnt files"
0084     fi
0085 fi
0086 
0087 
0088 cd $workdir
0089 eval `scramv1 runtime -sh`
0090 export STAGE_SVCCLASS=cmscaf
0091 cd -
0092 
0093 for ALCATAG in $( cat $ALCAFILELIST  )
0094 do
0095 
0096   echo
0097   echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
0098   echo "%%% Starting the ALCATAG: ${ALCATAG}"
0099   echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
0100   echo
0101   ###DAT_FILE="/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/HIP/bonato/DEVEL/HIPWorkflow/ALCARECOskim/v1.4/data/${ALCATAG}.dat"
0102   DAT_FILE="${curdir}/../data/${ALCATAG}.dat"
0103   TPL_FILE="TkAlCaRecoPrescaling.${ALCATAG}.tpl"
0104   BASE_TPL=$(basename "$TPL_FILE" .tpl)
0105   TAG=$ALCATAG #"CRAFT" 
0106   JOBTAG="ALCAPresc_"${TAG}
0107 
0108 #produce list of the DQM files produced at the Skim loop
0109 cd $DQM_OUT
0110 dqmlist=${DQM_OUT}"/AlignmentDQMHitMaps_CTF_${TAG}.txt"
0111 rm -f $dqmlist
0112 for dqmfile in  $(ls  TkAl*Skim*${TAG}*HitMaps*.root)
0113 do
0114 echo $(pwd)/$dqmfile >> $dqmlist
0115 done
0116 
0117 #run the merging of DQM and calculation of the prescaling factors.
0118 #It is fast, do it locally
0119 cd $curdir
0120 dqmtotfile="${curdir}/TkAlDQMHitMaps_CTF_${TAG}.root"
0121 #replace "<DQMLIST>" $dqmlist "<DQMTOTFILE>" $dqmtotfile  < mergemytree_cfg.tpl > mergemytree_${TAG}_cfg.py
0122 sed -e "s|<DQMLIST>|${dqmlist}|g"  -e "s|<DQMTOTFILE>|${dqmtotfile}|g"   < mergemytree_cfg.tpl > mergemytree_${TAG}_cfg.py
0123 echo "Merging DQM into $dqmtotfile"
0124 time cmsRun mergemytree_${TAG}_cfg.py
0125 
0126 
0127 
0128 #repeat procedure of SkimLooper.sh, splitting the data sample in even bunches of events
0129   TOTFILES=0
0130   INDEX=1
0131   for i in $( cat $DAT_FILE )
0132     do
0133 
0134 #pick the total nr events in this file from the previously produced nevents.out
0135     let TOTFILES=TOTFILES+1
0136     TOTEVTS=$(sed -n $TOTFILES'p' ../data/nevents${TAG}.out)
0137 #echo "The file #$TOTFILES has $TOTEVTS events"
0138     if [ $TOTEVTS == 0 ]
0139         then
0140 #       echo "The file #$TOTFILES has $TOTEVTS events"
0141         continue
0142     fi 
0143     TOTSPLITS=$(( ( $TOTEVTS / $MAXEVENTS ) +1 ))
0144     firstev=0
0145     lastev=-1
0146     
0147 #echo "I will split it into $TOTSPLITS"
0148     if [ $TOTSPLITS > 1 ]
0149         then
0150         nsplits=1
0151 
0152 #prepare configs for prescaling
0153         while [ $nsplits -le $TOTSPLITS  ]
0154           do
0155 #echo "Splitting the file $TOTFILE : $nsplits"
0156           firstev=$(( $MAXEVENTS*$(( $nsplits-1 ))+1 ))
0157           lastev=$MAXEVENTS    #$(( ($MAXEVENTS*$nsplits) ))
0158           JOB=$JOBTAG"_file"$INDEX 
0159           CFG_FILE=$BASE_TPL"."$TAG"_cfg."$INDEX".py"
0160           sed -e "s|<JOB>|${JOB}|g"  -e "s|<INPATH>|${i}|g"   -e "s|<INIEVT>|${firstev}|g"  -e "s|<FINEVT>|${lastev}|g"  -e "s|<ALCATAG>|${ALCATAG}|g"  -e "s|<MERGEDHITMAP>|${dqmtotfile}|g"  < $TPL_FILE > $CFG_FILE
0161           let INDEX=INDEX+1
0162           let nsplits=nsplits+1
0163 #         if [ $INDEX -ge 3 ]
0164 #             then
0165 #             echo "Reached a maximum number of files: $INDEX. Stopping the submission"
0166 #             break
0167 #         fi
0168 
0169         done
0170 
0171     else #file is small and does not contain too many events
0172         firstev=0
0173         lastev=-1
0174         JOB=$JOBTAG"_file"$INDEX 
0175         CFG_FILE=$BASE_TPL"."$TAG"_cfg."$INDEX".py"
0176         sed -e "s|<JOB>|${JOB}|g"  -e "s|<INPATH>|${i}|g"   -e "s|<INIEVT>|${firstev}|g"  -e "s|<FINEVT>|${lastev}|g"  -e "s|<ALCATAG>|${ALCATAG}|g"  -e "s|<MERGEDHITMAP>|$dqmtotfile|g"  < $TPL_FILE > $CFG_FILE
0177         let INDEX=INDEX+1
0178 #       if [ $INDEX -ge 3 ]
0179 #           then
0180 #           echo "Reached a maximum number of files: $INDEX. Stopping the submission"
0181 #           break
0182 #       fi
0183 
0184     fi
0185 
0186 
0187 #     if [ $INDEX -ge 3 ]
0188 #       then
0189 #       echo "Reached a maximum number of files: $INDEX. Stopping the submission"
0190 #       break
0191 #     fi
0192 
0193 #echo "--- moving to next file. At the moment INDEX=$INDEX"
0194   done
0195   
0196 
0197 
0198 TOTPRESCALEDJOBS=$(( $INDEX -1 ))
0199 echo 
0200 echo "TOTPRESCALEDJOBS = $TOTPRESCALEDJOBS"
0201 
0202 
0203 #submit them
0204 echo
0205 echo
0206 echo "@@@@@@@@@@@@@@@@@@@@@"
0207 echo
0208 INDEX=1
0209 while [ $INDEX -le $TOTPRESCALEDJOBS ]
0210 do
0211 JOBNAME="ALCAPresc"$TAG"_"$INDEX
0212 LOGFILE="${JOBNAME}.log"
0213 CFG_FILE=$BASE_TPL"."$TAG"_cfg."$INDEX".py"
0214 
0215 
0216 CHECKCORRUPTED=1 # if greater than zero it overrides the checks
0217 FILECORRUPTED=$( checkCorruptedFiles $INDEX )
0218 
0219 
0220 if [[ $FILECORRUPTED == 0 || CHECKCORRUPTED -gt 0 ]]
0221 then
0222     echo "Submitting $JOBNAME with config file $CFG_FILE"
0223     REM=0
0224     let "REM=$INDEX % 300"
0225     if [ $REM -lt 100 ]
0226         then 
0227 #echo "dummy D" > /dev/null
0228         bsub -q cmscaf1nd -J $JOBNAME -oo $LOGFILE presc_exec.sh "$curdir/$CFG_FILE" "$CASTOR_OUT"  "$DQM_OUT"
0229     elif [ $REM -lt 200 ] 
0230         then
0231         #echo "dummy E" > /dev/null
0232         bsub -q cmsexpress -J $JOBNAME -oo $LOGFILE presc_exec.sh "$curdir/$CFG_FILE" "$CASTOR_OUT"  "$DQM_OUT"
0233     else
0234         #echo "dummy F" > /dev/null
0235         bsub -q cmscaf1nd    -J $JOBNAME -oo $LOGFILE presc_exec.sh "$curdir/$CFG_FILE" "$CASTOR_OUT"  "$DQM_OUT"
0236     fi
0237 
0238 fi #end if file is corrupted
0239 
0240 let INDEX=INDEX+1
0241 done #end while loop on submissions
0242 
0243 
0244 done #end for loop on TAG list