Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:49

0001 #!/bin/bash
0002 
0003 #script to run generic lhe generation tarballs
0004 #kept as simply as possible to minimize need
0005 #to update the cmssw release
0006 #(all the logic goes in the run script inside the tarball
0007 # on frontier)
0008 #J.Bendavid
0009 
0010 #exit on first error
0011 set -e
0012 
0013 echo "   ______________________________________     "
0014 echo "         Running Generic Tarball/Gridpack     "
0015 echo "   ______________________________________     "
0016 
0017 path=${1}
0018 echo "gridpack tarball path = $path"
0019 
0020 nevt=${2}
0021 echo "%MSG-MG5 number of events requested = $nevt"
0022 
0023 rnum=${3}
0024 echo "%MSG-MG5 random seed used for the run = $rnum"
0025 
0026 ncpu=${4}
0027 echo "%MSG-MG5 thread count requested = $ncpu"
0028 
0029 echo "%MSG-MG5 residual/optional arguments = ${@:5}"
0030 
0031 if [ -n "${5}" ]; then
0032   use_gridpack_env=${5}
0033   echo "%MSG-MG5 use_gridpack_env = $use_gridpack_env"
0034 fi
0035 
0036 if [ -n "${6}" ]; then
0037   scram_arch_version=${6}
0038   echo "%MSG-MG5 override scram_arch_version = $scram_arch_version"
0039 fi
0040 
0041 if [ -n "${7}" ]; then
0042   cmssw_version=${7}
0043   echo "%MSG-MG5 override cmssw_version = $cmssw_version"
0044 fi
0045 
0046 LHEWORKDIR=`pwd`
0047 echo "%MSG-MG5 LHEWORKDIR = "${LHEWORKDIR}
0048 
0049 if [ "$use_gridpack_env" = false -a -n "$scram_arch_version" -a -n  "$cmssw_version" ]; then
0050   echo "%MSG-MG5 CMSSW version = $cmssw_version"
0051   export SCRAM_ARCH=${scram_arch_version}
0052   scramv1 project CMSSW ${cmssw_version}
0053   cd ${cmssw_version}/src
0054   eval `scramv1 runtime -sh`
0055   cd $LHEWORKDIR
0056 fi
0057 
0058 ##########################
0059 echo "%MSG-MG5 multithread loop start"
0060 ##########################
0061 nevt_run=$(echo print $nevt/$ncpu | python)
0062 resid_run=$(echo print $nevt%$ncpu | python)
0063 
0064 for (( thread=0; thread<$ncpu; thread++ ))
0065 do
0066 
0067     echo "%MSG-MG5 thread "${thread}" started"
0068     if [[ -d lheevent_$thread ]]
0069         then
0070         echo '%MSG-MG5 lheevent_'$thread' directory found, removing before to proceed'
0071         rm -rf lheevent_$thread
0072     fi
0073     mkdir lheevent_$thread; cd lheevent_$thread
0074 
0075     echo "%MSG-MG5 untar the tarball from cvmfs"
0076     tar -xaf ${path} 
0077 
0078     if [[ thread -eq 0 ]]; then
0079         #generate events
0080         ./runcmsgrid.sh $((nevt_run+resid_run)) $rnum 1 ${@:5} &
0081     else
0082         #generate events
0083         ./runcmsgrid.sh $((nevt_run)) $rnum 1 ${@:5} &
0084     fi
0085     
0086     rnum=$((rnum+10))
0087     
0088     cd $LHEWORKDIR
0089 
0090 done
0091 ##########################
0092 # multithread loop end
0093 ##########################
0094 
0095 wait # wait for all the subprocesses to finish
0096 
0097 for (( thread=0; thread<$ncpu; thread++ ))
0098 do
0099     mv lheevent_$thread/cmsgrid_final.lhe $LHEWORKDIR/cmsgrid_final_$thread.lhe
0100 done
0101 
0102 # merge multiple lhe files if needed
0103 ls -lrt $LHEWORKDIR/cmsgrid_final_*.lhe
0104 if [  $thread -gt "1" ]; then
0105     echo "%MSG-MG5 Merging files and deleting unmerged ones"
0106     cp /cvmfs/cms.cern.ch/phys_generator/gridpacks/lhe_merger/merge.pl ./
0107     chmod 755 merge.pl
0108     ./merge.pl $LHEWORKDIR/cmsgrid_final_*.lhe cmsgrid_final.lhe.gz banner.txt
0109     gzip -d cmsgrid_final.lhe.gz
0110     rm $LHEWORKDIR/cmsgrid_final_*.lhe banner.txt;
0111 else
0112     mv $LHEWORKDIR/cmsgrid_final_$thread.lhe $LHEWORKDIR/cmsgrid_final.lhe
0113 fi
0114 
0115 
0116 cd $LHEWORKDIR
0117 
0118 #cleanup working directory (save space on worker node for edm output)
0119 rm -rf lheevent_*
0120 
0121 exit 0
0122