Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:31

0001 #!/bin/bash
0002 #
0003 #  file:        install_lhapdf.sh
0004 #  description: BASH script for the installation of the LHAPDF package,
0005 #               can be used standalone or called from other scripts
0006 #
0007 #  author:      Markus Merschmeyer, RWTH Aachen University
0008 #  date:        2013/05/23
0009 #  version:     3.0
0010 #
0011 
0012 print_help() {
0013     echo "" && \
0014     echo "install_lhapdf version 3.0" && echo && \
0015     echo "options: -v  version    define LHAPDF version ( "${LHAPDFVER}" )" && \
0016     echo "         -d  path       define LHAPDF installation directory" && \
0017     echo "                         -> ( "${IDIR}" )" && \
0018     echo "         -n             use 'nopdf' version ( "${NOPDF}" )" && \
0019     echo "         -l             use '--enable-low-memory' option ( "${LOWMEM}")" && \
0020     echo "         -N  number     define maximum number of PDFs (" ${NUMPDF}" )" && \
0021     echo "         -W  location   (web)location of LHAPDF tarball ( "${LHAPDFWEBLOCATION}" )" && \
0022     echo "         -S  filename   file name of LHAPDF tarball ( "${LHAPDFFILE}" )" && \
0023     echo "         -C  level      cleaning level of SHERPA installation ( "${LVLCLEAN}" )" && \
0024     echo "                         -> 0: nothing, 1: +objects (make clean)" && \
0025     echo "         -D             debug flag, compile with '-g' option ( "${FLGDEBUG}" )" && \
0026     echo "         -X             create XML file for tool override in CMSSW ( "${FLGXMLFL}" )" && \
0027     echo "         -Z             use multiple CPU cores if available ( "${FLGMCORE}" )" && \
0028     echo "         -K             keep LHAPDF source code tree after installation ( "${FGLKEEPT}" )" && \
0029     echo "         -P  PDFset     retrieve the corresponding PDFset ( "${PDFSETS}" )" && \
0030     echo "         -h             display this help and exit" && echo
0031 }
0032 
0033 
0034 # save current path
0035 HDIR=`pwd`
0036 
0037 
0038 # dummy setup (if all options are missing)
0039 IDIR="/tmp"                # installation directory
0040 LHAPDFVER="5.6.0"          # LHAPDF version to be installed
0041 NOPDF="FALSE"              # install 'nopdf' version
0042 LOWMEM="FALSE"             # use 'low-memory' option
0043 NUMPDF=3                   # maximum number of PDFs
0044 LHAPDFWEBLOCATION=""       # (web)location of LHAPDF tarball
0045 LHAPDFFILE=""              # file name of LHAPDF tarball
0046 LVLCLEAN=0                 # cleaning level (0-2)
0047 FLGDEBUG="FALSE"           # debug flag for compilation
0048 FLGXMLFL="FALSE"           # create XML tool definition file for SCRAM?
0049 FLGMCORE="FALSE"           # use multiple cores for compilation
0050 FLGKEEPT="FALSE"           # keep the source code tree?
0051 PDFSETS=""                 # list of PDFsets to install
0052 
0053 
0054 # get & evaluate options
0055 while getopts :v:d:W:S:C:nlN:DXZKP:h OPT
0056 do
0057   case $OPT in
0058   v) LHAPDFVER=$OPTARG ;;
0059   d) IDIR=$OPTARG ;;
0060   n) NOPDF=TRUE ;;
0061   l) LOWMEM=TRUE ;;
0062   N) NUMPDF=$OPTARG ;;
0063   W) LHAPDFWEBLOCATION=$OPTARG ;;
0064   S) LHAPDFFILE=$OPTARG ;;
0065   C) LVLCLEAN=$OPTARG ;;
0066   D) FLGDEBUG=TRUE ;;
0067   X) FLGXMLFL=TRUE ;;
0068   Z) FLGMCORE=TRUE ;;
0069   K) FLGKEEPT=TRUE ;;
0070   P) PDFSETS=$PDFSETS" "$OPTARG ;;
0071   h) print_help && exit 0 ;;
0072   \?)
0073     shift `expr $OPTIND - 1`
0074     if [ "$1" = "--help" ]; then print_help && exit 0;
0075     else 
0076       echo -n "install_lhapdf: error: unrecognized option "
0077       if [ $OPTARG != "-" ]; then echo "'-$OPTARG'. try '-h'"
0078       else echo "'$1'. try '-h'"
0079       fi
0080       print_help && exit 1
0081     fi
0082 #    shift 1
0083 #    OPTIND=1
0084   esac
0085 done
0086 
0087 
0088 # set LHAPDF download location
0089 if [ "$LHAPDFWEBLOCATION" = "" ]; then
0090   LHAPDFWEBLOCATION="http://www.hepforge.org/archive/lhapdf"
0091 else
0092   if [ -e ${LHAPDFWEBLOCATION} ]; then   # is the location a local subdirectory?
0093     if [ -d ${LHAPDFWEBLOCATION} ]; then
0094       cd ${LHAPDFWEBLOCATION}; LHAPDFWEBLOCATION=`pwd`; cd ${HDIR}
0095     fi
0096   fi
0097 fi
0098 if [ "$LHAPDFFILE" = "" ]; then
0099   if [ "$NOPDF" = "TRUE" ]; then
0100     LHAPDFFILE="lhapdf-"${LHAPDFVER}"-nopdf.tar.gz"
0101   else
0102     LHAPDFFILE="lhapdf-"${LHAPDFVER}".tar.gz"
0103   fi
0104 fi
0105 
0106 
0107 # make LHAPDF version a global variable
0108 export LHAPDFVER=${LHAPDFVER}
0109 # always use absolute path name...
0110 cd ${IDIR}; IDIR=`pwd`
0111 
0112 echo " LHAPDF installation: "
0113 echo "  -> LHAPDF version: '"${LHAPDFVER}"'"
0114 echo "  -> installation directory: '"${IDIR}"'"
0115 echo "  -> flags: '"${FLAGS}"'"
0116 echo "  -> no PDF version: '"${NOPDF}"'"
0117 echo "  -> low-mem option: '"${LOWMEM}"'"
0118 echo "  -> max. # of PDFs: '"${NUMPDF}"'"
0119 echo "  -> LHAPDF location: '"${LHAPDFWEBLOCATION}"'"
0120 echo "  -> LHAPDF file name: '"${LHAPDFFILE}"'"
0121 echo "  -> cleaning level: '"${LVLCLEAN}"'"
0122 echo "  -> debugging mode: '"${FLGDEBUG}"'"
0123 echo "  -> CMSSW override: '"${FLGXMLFL}"'"
0124 echo "  -> keep sources:   '"${FLGKEEPT}"'"
0125 echo "  -> use multiple CPU cores: '"${FLGMCORE}"'"
0126 echo "  -> install PDFsets: '"${PDFSETS}"'"
0127 
0128 
0129 # set path to local LHAPDF installation
0130 export LHAPDFDIR=${IDIR}"/lhapdf-"${LHAPDFVER}
0131 export LHAPDFIDIR=${IDIR}"/LHAPDF_"${LHAPDFVER}
0132 
0133 
0134 # add compiler & linker flags
0135 echo "CXX      (old):  "$CXX
0136 echo "CXXFLAGS (old):  "$CXXFLAGS
0137 echo "LDFLAGS  (old):  "$LDFLAGS
0138 ##MM FIXME
0139 #  export CXX=""
0140 #  export CXXFLAGS=""
0141 #  export LDFLAGS=""
0142 ##MM FIXME
0143 if [ "$FLGDEBUG" = "TRUE" ]; then
0144   CFDEBUG="-g"
0145   export CXXFLAGS=${CXXFLAGS}" "${CFDEBUG}
0146 fi
0147 echo "CXX      (new):  "$CXX
0148 echo "CXXFLAGS (new):  "$CXXFLAGS
0149 echo "LDFLAGS  (new):  "$LDFLAGS
0150 
0151 
0152 # add compiler & linker flags
0153 COPTS=""
0154 MOPTS=""
0155 POPTS=""
0156 if [ "$FLGMCORE" = "TRUE" ]; then
0157     nprc=`cat /proc/cpuinfo | grep  -c processor`
0158     let nprc=$nprc
0159     if [ $nprc -gt 1 ]; then
0160       echo " <I> multiple CPU cores detected: "$nprc
0161       POPTS=" -j"$nprc" "
0162     fi
0163 fi
0164 
0165 
0166 # download, extract compile/install LHAPDF
0167 cd ${IDIR}
0168 #if [ ! -d ${LHAPDFDIR} ]; then
0169 if [ ! -d ${LHAPDFIDIR} ]; then
0170   if [ "${LOWMEM}" = "TRUE" ]; then
0171     COPTS=${COPTS}" --enable-low-memory"
0172   fi
0173   if [ ! ${NUMPDF} = 3 ]; then
0174 ####    COPTS=${COPTS}" --disable-pyext"
0175     COPTS=${COPTS}" --with-max-num-pdfsets="${NUMPDF}
0176   fi
0177 #  if [  ]; then
0178 #    COPTS=${COPTS}" --disable-pyext"
0179 #  fi
0180   if [ `echo ${LHAPDFWEBLOCATION} | grep -c "http:"` -gt 0 ]; then
0181     echo " -> downloading LHAPDF "${LHAPDFVER}" from "${LHAPDFWEBLOCATION}/${LHAPDFFILE}
0182     wget ${LHAPDFWEBLOCATION}/${LHAPDFFILE}
0183   elif [ `echo ${LHAPDFWEBLOCATION} | grep -c "srm:"` -gt 0 ]; then
0184     echo " -> srm-copying LHAPDF "${LHAPDFVER}" from "${LHAPDFWEBLOCATION}/${LHAPDFFILE}
0185     srmcp ${LHAPDFWEBLOCATION}/${LHAPDFFILE} file:////${LHAPDFFILE}
0186   else
0187     echo " -> copying LHAPDF "${LHAPDFVER}" from "${LHAPDFWEBLOCATION}/${LHAPDFFILE}
0188     cp ${LHAPDFWEBLOCATION}/${LHAPDFFILE} ./
0189   fi
0190   tar -xzf ${LHAPDFFILE}
0191   if [ ! "$FLGKEEPT" = "TRUE" ]; then
0192     rm ${LHAPDFFILE}
0193   fi
0194   cd ${LHAPDFDIR}
0195   echo " -> configuring LHAPDF with options: "${COPTS} && \
0196   ./configure --prefix=${LHAPDFIDIR} ${COPTS} && \
0197   echo " -> making LHAPDF with options "${POPTS} ${MOPTS} && \
0198   make ${POPTS} ${MOPTS} && \
0199   echo " -> installing LHAPDF with options "${MOPTS} && \
0200   make install ${MOPTS}
0201   if [ ${LVLCLEAN} -gt 0 ]; then 
0202     echo " -> cleaning up LHAPDF installation, level: "${LVLCLEAN}" ..."
0203     if [ ${LVLCLEAN} -ge 1 ]; then  # normal cleanup (objects)
0204       make clean
0205     fi
0206   fi
0207   cd ${HDIR}
0208   if [ "$FLGKEEPT" = "TRUE" ]; then
0209     echo "-> keeping source code..."
0210   else
0211     rm -rf ${LHAPDFDIR}
0212   fi
0213 else
0214   echo " <W> path exists => using already installed LHAPDF"
0215 fi
0216 export LHAPDFDIR=${LHAPDFIDIR}
0217 cd ${HDIR}
0218 
0219 # retrieve PDFsets (...)
0220 pdfweblocation="http://svn.hepforge.org/lhapdf/pdfsets/tags/"${LHAPDFVER}
0221 pdflocation=`find $LHAPDFDIR -type d -name lhapdf`
0222 if [ ! -e $pdflocation/PDFsets ]; then
0223   mkdir $pdflocation/PDFsets
0224 fi
0225 pdflocation=$pdflocation/PDFsets
0226 for pdfset in $PDFSETS; do
0227   echo " <I> retrieving PDFset(s): "$pdfset
0228 #  wget $pdfweblocation/$pdfset
0229 #  mv $pdfset $pdflocation/
0230   cd $pdflocation/
0231   $LHAPDFDIR/bin/lhapdf-getdata $pdfset
0232   cd -
0233 done
0234 
0235 
0236 
0237 # create XML file fro SCRAM
0238 if [ "${FLGXMLFL}" = "TRUE" ]; then
0239 #  xmlfile=lhapdf.xml
0240   xmlfile="lhapdf_"${LHAPDFVER}".xml"
0241   echo " <I>"
0242   echo " <I> creating LHAPDF tool definition XML file "${xmlfile}
0243   if [ -e ${xmlfile} ]; then rm ${xmlfile}; fi; touch ${xmlfile}
0244   echo "  <tool name=\"lhapdf\" version=\""${LHAPDFVER}"\">" >> ${xmlfile}
0245   tmppath=`find ${LHAPDFDIR} -type f -name libLHAPDF.so\*`
0246   tmpcnt=`echo ${tmppath} | grep -o "/" | grep -c "/"`
0247   tmppath=`echo ${tmppath} | cut -f 1-${tmpcnt} -d "/"`
0248   for LIB in `cd ${tmppath}; ls *.so | cut -f 1 -d "." | sed -e 's/lib//'; cd ${HDIR}`; do
0249     echo "    <lib name=\""${LIB}"\"/>" >> ${xmlfile}
0250   done
0251   echo "    <client>" >> ${xmlfile}
0252   echo "      <Environment name=\"LHAPDF_BASE\" value=\""${LHAPDFDIR}"\"/>" >> ${xmlfile}
0253   echo "      <Environment name=\"LIBDIR\" default=\"\$LHAPDF_BASE/lib\"/>" >> ${xmlfile}
0254   echo "      <Environment name=\"LHAPATH\" default=\"\$LHAPDF_BASE/share/lhapdf/PDFsets\"/>" >> ${xmlfile}
0255   echo "    </client>" >> ${xmlfile}
0256   echo "    <runtime name=\"LHAPATH\" value=\"\$LHAPDF_BASE/share/lhapdf/PDFsets\" type=\"path\"/>" >> ${xmlfile}
0257   echo "    <use name=\"f77compiler\"/>" >> ${xmlfile}
0258   echo "  </tool>" >> ${xmlfile}
0259   if [ ! "$PWD" = "${HDIR}" ]; then
0260     mv ${xmlfile} ${HDIR}/
0261   fi
0262 
0263   if [ ! "$CMSSW_BASE" = "" ]; then
0264     cd $CMSSW_BASE
0265     tmplha=`scramv1 tool info lhapdf | grep "LHAPDF_BASE" | cut -f2 -d"="`
0266     tmpxml=`find $CMSSW_BASE/config -type f -name lhapdf.xml -printf %h`
0267     echo " <I>"
0268     echo " <I> LHAPDF version currently being used: "${tmplha}
0269     echo " <I> ...defined in "${tmpxml}
0270     cd ${tmpxml}; tmpxml=$PWD; cd ${HDIR}
0271     echo " <I>"
0272     echo " <I> If you want to override this version with the freshly produced "${xmlfile}","
0273     echo " <I> ...please type the following commands:"
0274     echo " <I>"
0275     echo "       cd $CMSSW_BASE"
0276     echo "       scramv1 tool remove lhapdf"
0277     echo "       cp ${HDIR}/${xmlfile} ${tmpxml}/"
0278     echo "       scramv1 setup lhapdf"
0279     echo "       cd -"
0280     echo " <I>"
0281   fi
0282 
0283 fi
0284 
0285 
0286 echo " -> LHAPDF installation directory is: "
0287 echo "  "${LHAPDFIDIR}