File indexing completed on 2024-04-06 12:14:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 function print_help() {
0020 echo "" && \
0021 echo "PrepareSherpaLibs version 4.2" && echo && \
0022 echo "options: -i path path to SHERPA datacard, library & cross section files" && \
0023 echo " can also be in WWW (http://...) or SE (srm://...)" && \
0024 echo " -> ( "${datadir}" )" && \
0025 echo " -p process SHERPA dataset/process name ( "${dataset}" )" && \
0026
0027
0028
0029
0030 echo " -D filename (optional) name of data card file ( "${cfdc}" )" && \
0031 echo " -L filename (optional) name of library file ( "${cflb}" )" && \
0032 echo " -C filename (optional) name of cross section file ( "${cfcr}" )" && \
0033 echo " -G filename (optional) name of MI grid file ( "${cfgr}" )" && \
0034 echo " -e filename (optional) name of extended weight list file ( "${weightfile}" ) " && \
0035 echo " (example file in GeneratorInterface/SherpaInterface/python/ExtendedSherpaWeights_cfi.py)" && \
0036
0037
0038 echo " -h display this help and exit" && echo
0039 }
0040
0041
0042
0043
0044
0045 function build_python_cff() {
0046
0047
0048 cfffilename=$1
0049 process=$2
0050 checksum=$3
0051
0052 if [ -e ${cfffilename} ]; then rm ${cfffilename}; fi
0053 touch ${cfffilename}
0054
0055 echo "import FWCore.ParameterSet.Config as cms" >> ${cfffilename}
0056 echo "import os" >> ${cfffilename}
0057 if [ ! $weightlist == "" ]; then
0058 echo "from $weightlist import *" >> ${cfffilename}
0059 fi
0060 echo "" >> ${cfffilename}
0061 echo "source = cms.Source(\"EmptySource\")" >> ${cfffilename}
0062 echo "" >> ${cfffilename}
0063 echo "generator = cms.EDFilter(\"SherpaGeneratorFilter\"," >> ${cfffilename}
0064 echo " maxEventsToPrint = cms.int32(0)," >> ${cfffilename}
0065 echo " filterEfficiency = cms.untracked.double(1.0)," >> ${cfffilename}
0066 echo " crossSection = cms.untracked.double(-1)," >> ${cfffilename}
0067 echo " SherpaProcess = cms.string('"${process}"')," >> ${cfffilename}
0068 echo " SherpackLocation = cms.string('./')," >> ${cfffilename}
0069 echo " SherpackChecksum = cms.string('"${checksum}"')," >> ${cfffilename}
0070 echo " FetchSherpack = cms.bool(False)," >> ${cfffilename}
0071
0072 echo " SherpaPath = cms.string('./')," >> ${cfffilename}
0073 echo " SherpaPathPiece = cms.string('./')," >> ${cfffilename}
0074
0075
0076
0077
0078 echo " SherpaResultDir = cms.string('Result')," >> ${cfffilename}
0079 echo " SherpaDefaultWeight = cms.double(1.0)," >> ${cfffilename}
0080 if [ ! $weightlist == "" ]; then
0081 echo " SherpaWeightsBlock = SherpaWeightsBlock," >> ${cfffilename}
0082 fi
0083 echo " SherpaParameters = cms.PSet(parameterSets = cms.vstring(" >> ${cfffilename}
0084 fcnt=0
0085 for file in `ls *.dat`; do
0086 let fcnt=${fcnt}+1
0087 done
0088 for file in `ls *.dat`; do
0089 let fcnt=${fcnt}-1
0090 pstnam=`echo ${file} | cut -f1 -d"."`
0091 if [ ${fcnt} -gt 0 ]; then
0092 echo " \""${pstnam}"\"," >> ${cfffilename}
0093 else
0094 echo " \""${pstnam}"\")," >> ${cfffilename}
0095 fi
0096 done
0097 for file in `ls *.dat`; do
0098 pstnam=`echo ${file} | cut -f1 -d"."`
0099 echo " "${pstnam}" = cms.vstring(" >> ${cfffilename}
0100 cp ${file} ${file}.tmp1
0101 sed -e 's/[%\!].*//g' < ${file}.tmp1 > ${file}.tmp2
0102 mv ${file}.tmp2 ${file}.tmp1
0103 sed -e 's/^[ \t]*//;s/[ \t]*$//' < ${file}.tmp1 > ${file}.tmp2
0104 mv ${file}.tmp2 ${file}.tmp1
0105 sed '/^$/d' < ${file}.tmp1 > ${file}.tmp2
0106 mv ${file}.tmp2 ${file}.tmp1
0107
0108 sed -e 's/^/ /g;s/ }/}/' < ${file}.tmp1 > ${file}.tmp2
0109 mv ${file}.tmp2 ${file}.tmp1
0110
0111 sed -e 's/\"/\\"/g' < ${file}.tmp1 > ${file}.tmp2
0112 mv ${file}.tmp2 ${file}.tmp1
0113
0114 sed -e 's/^/\t\t\t\t"/;s/$/\",/' < ${file}.tmp1 > ${file}.tmp2
0115 mv ${file}.tmp2 ${file}.tmp1
0116 sed -e '$s/\",/\"/' < ${file}.tmp1 > ${file}.tmp2
0117 mv ${file}.tmp2 ${file}.tmp1
0118 cat ${file}.tmp1 >> ${cfffilename}
0119 echo " )," >> ${cfffilename}
0120 rm ${file}.tmp*
0121 done
0122 echo " )" >> ${cfffilename}
0123 echo ")" >> ${cfffilename}
0124 echo "" >> ${cfffilename}
0125
0126 echo "ProductionFilterSequence = cms.Sequence(generator)" >> ${cfffilename}
0127 echo "" >> ${cfffilename}
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 }
0140
0141
0142
0143 function file_copy() {
0144
0145
0146
0147
0148
0149 srmopt=" -streams_num=1 "
0150
0151 tpath="aaa/"
0152 fname="xxx.yyy"
0153 dpath="bbb/"
0154 if [ $
0155 tpath=$1
0156 if [ $
0157 fname=$2
0158 if [ $
0159 dpath=$3
0160 fi
0161 fi
0162 fi
0163
0164 if [ ! "${tpath}" = "${dpath}" ]; then
0165 if [ "${tpath}" = "./" ]; then
0166 tpath=${PWD}
0167 fi
0168 if [ "${dpath}" = "./" ]; then
0169 dpath=${PWD}
0170 fi
0171 cd /tmp
0172
0173 TLOC0=`echo ${tpath} | cut -f1 -d "/" | grep -c -i http`
0174 TLOC1=`echo ${tpath} | cut -f1 -d "/" | grep -c -i srm`
0175 if [ ${TLOC0} -gt 0 ]; then
0176 echo " <I> retrieving WWW file: "${fname}
0177 echo " <I> from path: "${tpath}
0178 wget ${tpath}/${fname}
0179 elif [ ${TLOC1} -gt 0 ]; then
0180 echo " <I> retrieving SE file: "${fname}
0181 echo " <I> from path: "${tpath}
0182 srmcp ${srmopt} ${tpath}/${fname} file:///${PWD}/${fname}
0183 else
0184 echo " <I> copying local file: "${fname}
0185 echo " <I> from path: "${tpath}
0186 if [ -e ${tpath}/${fname} ]; then
0187 cp ${tpath}/${fname} ./
0188 else
0189 echo " <W> file does not exist, make sure everything is OK"
0190 fi
0191 fi
0192
0193 DLOC0=`echo ${dpath} | cut -f1 -d "/" | grep -c -i http`
0194 DLOC1=`echo ${dpath} | cut -f1 -d "/" | grep -c -i srm`
0195 if [ ${DLOC1} -gt 0 ]; then
0196 echo " <I> storing SE file: "${fname}
0197 echo " <I> to path: "${dpath}
0198 srmcp ${srmopt} file:///${PWD}/${fname} ${dpath}/${fname}
0199 else
0200 echo " <I> copying local file: "${fname}
0201 echo " <I> to path: "${dpath}
0202 if [ -e ${fname} ]; then
0203 cp ${fname} ${dpath}/
0204 else
0205 echo " <W> file does not exist, make sure everything is OK"
0206 fi
0207 fi
0208
0209 rm -f ${fname}
0210 cd -
0211 fi
0212 }
0213
0214
0215 function parse_extended_weight() {
0216 if [ -e $CMSSW_BASE/src/$weightlist ]
0217 then
0218 weightlist=$(echo "$weightlist" | sed 's:/python/:.:g' | sed 's:/:.:g' | sed 's:.py::g' )
0219 else
0220 echo '$CMSSW_BASE/src/$weightlist does not exist.'
0221 exit 1
0222 fi
0223 }
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237 HDIR=`pwd`
0238
0239
0240 ip=1
0241 cproc="XXX"
0242 for file in `ls sherpa_*_libs.tgz`; do
0243 if [ $ip -eq 1 ]; then
0244 cproc=`echo $file | awk -F"sherpa_" '{print $2}' | awk -F"_libs" '{print $1}'`
0245 fi
0246 let ip=$ip+1
0247 done
0248
0249
0250 datadir=${HDIR}
0251 dataset=${cproc}
0252 if [ -e ${CMSSW_BASE} ]; then
0253 CMSSWDIR=${CMSSW_BASE}
0254
0255
0256
0257
0258
0259
0260 fi
0261
0262
0263
0264 cfdc=""
0265 cflb=""
0266 cfcr=""
0267 cfgr=""
0268 weightfile=""
0269
0270 TDIR=TMP
0271
0272
0273
0274
0275 while getopts :i:p:d:D:L:C:G:e:h OPT
0276 do
0277 case $OPT in
0278 i) datadir=$OPTARG ;;
0279 p) dataset=$OPTARG ;;
0280
0281
0282 D) cfdc=$OPTARG ;;
0283 L) cflb=$OPTARG ;;
0284 C) cfcr=$OPTARG ;;
0285 G) cfgr=$OPTARG ;;
0286 e) weightlist=$OPTARG && parse_extended_weight;;
0287
0288 h) print_help && exit 0 ;;
0289 \?)
0290 shift `expr $OPTIND - 1`
0291 if [ "$1" = "--help" ]; then print_help && exit 0;
0292 else
0293 echo -n "PrepareSherpaLibs: error: unrecognized option "
0294 if [ $OPTARG != "-" ]; then echo "'-$OPTARG'. try '-h'"
0295 else echo "'$1'. try '-h'"
0296 fi
0297 print_help && exit 1
0298 fi
0299 shift 1
0300 OPTIND=1
0301 esac
0302 done
0303
0304
0305 xpth=`echo ${datadir} | cut -f1 -d"/"`
0306 if [ "$xpth" = "" ] || [ "$xpth" = "." ] || [ "$xpth" = ".." ] || [ "$xpth" = "~" ]; then
0307 echo " <I> fixing data directory: "${datadir}
0308 cd ${datadir} && datadir=`pwd`; cd ${HDIR}
0309 echo " <I> to: "${datadir}
0310 fi
0311
0312
0313 echo " -> data card directory '"${datadir}"'"
0314 echo " -> dataset name '"${dataset}"'"
0315
0316
0317
0318
0319
0320
0321 MYCMSSWTEST=${HDIR}/${TDIR}
0322 MYCMSSWPYTH=${HDIR}/${TDIR}
0323 MYCMSSWSHPA=${HDIR}/${TDIR}
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342 cardfile=sherpa_${dataset}_crdE.tgz
0343 libsfile=sherpa_${dataset}_libs.tgz
0344 crssfile=sherpa_${dataset}_crss.tgz
0345 gridfile=sherpa_${dataset}_migr.tgz
0346 if [ ! "${cfdc}" = "" ]; then cardfile=${cfdc}; fi
0347 if [ ! "${cflb}" = "" ]; then libsfile=${cflb}; fi
0348 if [ ! "${cfcr}" = "" ]; then crssfile=${cfcr}; fi
0349 if [ ! "${cfgr}" = "" ]; then gridfile=${cfgr}; fi
0350
0351
0352
0353
0354
0355
0356 if [ -e ${MYCMSSWSHPA} ]; then
0357 echo " <W> dataset directory "${MYCMSSWSHPA}" exists"
0358 echo " <W> ...removing..."
0359 rm -rf ${MYCMSSWSHPA}
0360 fi
0361 mkdir -p ${MYCMSSWSHPA}
0362
0363
0364 cd ${MYCMSSWSHPA}
0365 file_copy ${datadir} ${cardfile} ${PWD}
0366 file_copy ${datadir} ${libsfile} ${PWD}
0367 file_copy ${datadir} ${crssfile} ${PWD}
0368 file_copy ${datadir} ${gridfile} ${PWD}
0369 if [ -e ${cardfile} ]; then
0370 tar -xzf ${cardfile} && rm ${cardfile}
0371 else
0372 echo " <E> file not found: "${cardfile}
0373 exit 1
0374 fi
0375 if [ -e ${libsfile} ]; then
0376 tar -xzf ${libsfile} && rm ${libsfile}
0377 else
0378 echo " <E> file not found: "${libsfile}
0379 exit 1
0380 fi
0381 if [ -e ${crssfile} ]; then
0382 tar -xzf ${crssfile} && rm ${crssfile}
0383 else
0384 echo " <E> file not found: "${crssfile}
0385 exit 1
0386 fi
0387 if [ -e ${gridfile} ]; then
0388 tar -xzf ${gridfile} && rm ${gridfile}
0389 else
0390 echo " <W> no MI grid file: "${gridfile}
0391 fi
0392 cd -
0393
0394
0395
0396
0397
0398 spsummd5=""
0399
0400
0401 shpamstfile="sherpa_"${dataset}"_MASTER.tgz"
0402 shpamstmd5s="sherpa_"${dataset}"_MASTER.md5"
0403 shpacfffile="sherpa_"${dataset}"_MASTER_cff.py"
0404
0405 cd ${MYCMSSWSHPA}
0406
0407 tar -czf ${shpamstfile} *
0408
0409 md5sum ${shpamstfile} > ${shpamstmd5s}
0410 spsummd5=`md5sum ${shpamstfile} | cut -f1 -d" "`
0411
0412
0413
0414 build_python_cff ${shpacfffile} ${dataset} ${spsummd5}
0415
0416 mv ${shpamstfile} $HDIR
0417 mv ${shpamstmd5s} $HDIR
0418 mv ${shpacfffile} $HDIR
0419
0420 cd $HDIR
0421
0422 rm -rf $TDIR
0423
0424
0425
0426
0427 echo " <I> "
0428 echo " <I> "
0429 echo " <I> "
0430 echo " <I> generated sherpack:"
0431 echo " <I> "${shpamstfile}
0432 echo " <I> generated python fragment:"
0433 echo " <I> "${shpacfffile}
0434 echo " <I> MD5 checksum file:"
0435 echo " <I> "${shpamstmd5s}
0436 echo " <I> "
0437 echo " <I> "
0438 echo " <I> "
0439 echo " <I> ATTENTION,"
0440 echo " <I> please edit the generated python fragment according to your needs:"
0441 echo " <I> "
0442 echo " <I> for a local production edit the line"
0443 echo " <I> SherpackLocation = cms.string('[local path to your sherpack]')"
0444 echo " <I> and make sure that the SherpaInterface does not try to fetch the sherpack"
0445 echo " <I> FetchSherpack = cms.bool(False)"
0446 echo " <I> "
0447 echo " <I> "
0448 echo " <I> for a production using the frontier database use"
0449 echo " <I> SherpackLocation = cms.string('[frontier database path to your sherpack]')"
0450 echo " <I> and this time make sure that the SherpaInterface fetches the sherpack"
0451 echo " <I> FetchSherpack = cms.bool(true)"
0452 echo " <I> "
0453 echo " <I> "
0454 echo " <I> for a production with CRAB add the sherpack to the list of additional files"
0455 echo " <I> additional_input_files = [name of the ..._MASTER.tgz sherpack]"
0456 echo " <I> make sure that the sherpack location is"
0457 echo " <I> SherpackLocation = cms.string('./')"
0458 echo " <I> and make sure that the SherpaInterface does not try to fetch the sherpack"
0459 echo " <I> FetchSherpack = cms.bool(False)"
0460 echo " <I> "
0461 echo " <I> "
0462 echo " <I> "
0463 echo " <I> a good way to test the generated python file is to cross-check it with cmsDriver.py:"
0464 echo " cmsDriver.py A/B/python/"${shpacfffile}" \\"
0465 echo " -s GEN -n 100 --no_exec --conditions auto:mc --eventcontent RAWSIM"
0466 echo " <I> "
0467 echo " <I> "
0468 echo " <I> "
0469