Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:12

0001 #!/bin/bash
0002 #
0003 #  file:        install_hepmc2.sh
0004 #  description: BASH script for the installation of the HepMC2 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_hepmc2 version 3.0" && echo && \
0015     echo "options: -v  version    define HepMC2 version ( "${HEPMC2VER}" )" && \
0016     echo "         -d  path       define HepMC2 installation directory" && \
0017     echo "                         -> ( "${IDIR}" )" && \
0018     echo "         -W  location   (web)location of HepMC2 tarball ( "${HEPMC2WEBLOCATION}" )" && \
0019     echo "         -S  filename   file name of HepMC2 tarball ( "${HEPMC2FILE}" )" && \
0020     echo "         -C  level      cleaning level of SHERPA installation ( "${LVLCLEAN}" )" && \
0021     echo "                         -> 0: nothing, 1: +objects (make clean)" && \
0022     echo "         -D             debug flag, compile with '-g' option ( "${FLGDEBUG}" )" && \
0023     echo "         -X             create XML file for tool override in CMSSW ( "${FLGXMLFL}" )" && \
0024     echo "         -Z             use multiple CPU cores if available ( "${FLGMCORE}" )" && \
0025     echo "         -K             keep HEPMC2 source code tree after installation ( "${FLGKEEPT}" )" && \
0026     echo "         -h             display this help and exit" && echo
0027 }
0028 
0029 
0030 # save current path
0031 HDIR=`pwd`
0032 
0033 
0034 # dummy setup (if all options are missing)
0035 IDIR="/tmp"                # installation directory
0036 HEPMC2VER="2.03.06"        # HepMC2 version  to be installed
0037 HEPMC2WEBLOCATION=""       # (web)location of HEPMC2 tarball
0038 HEPMC2FILE=""              # file name of HEPMC2 tarball
0039 LVLCLEAN=0                 # cleaning level (0-2)
0040 FLGDEBUG="FALSE"           # debug flag for compilation
0041 FLGXMLFL="FALSE"           # create XML tool definition file for SCRAM?
0042 FLGKEEPT="FALSE"           # keep the source code tree?
0043 FLGMCORE="FALSE"           # use multiple cores for compilation
0044 
0045 
0046 # get & evaluate options
0047 while getopts :v:d:W:S:C:DXZKh OPT
0048 do
0049   case $OPT in
0050   v) HEPMC2VER=$OPTARG ;;
0051   d) IDIR=$OPTARG ;;
0052   W) HEPMC2WEBLOCATION=$OPTARG ;;
0053   S) HEPMC2FILE=$OPTARG ;;
0054   C) LVLCLEAN=$OPTARG ;;
0055   D) FLGDEBUG=TRUE ;;
0056   X) FLGXMLFL=TRUE ;;
0057   Z) FLGMCORE=TRUE ;;
0058   K) FLGKEEPT=TRUE ;;
0059   h) print_help && exit 0 ;;
0060   \?)
0061     shift `expr $OPTIND - 1`
0062     if [ "$1" = "--help" ]; then print_help && exit 0;
0063     else 
0064       echo -n "install_hepmc2: error: unrecognized option "
0065       if [ $OPTARG != "-" ]; then echo "'-$OPTARG'. try '-h'"
0066       else echo "'$1'. try '-h'"
0067       fi
0068       print_help && exit 1
0069     fi
0070 #    shift 1
0071 #    OPTIND=1
0072   esac
0073 done
0074 
0075 
0076 # set HEPMC2 download location
0077 if [ "$HEPMC2WEBLOCATION" = "" ]; then
0078   HEPMC2WEBLOCATION="http://lcgapp.cern.ch/project/simu/HepMC/download"
0079 else
0080   if [ -e ${HEPMC2WEBLOCATION} ]; then   # is the location a local subdirectory?
0081     if [ -d ${HEPMC2WEBLOCATION} ]; then
0082       cd ${HEPMC2WEBLOCATION}; HEPMC2WEBLOCATION=`pwd`; cd ${HDIR}
0083     fi
0084   fi
0085 fi
0086 if [ "$HEPMC2FILE" = "" ]; then
0087   HEPMC2FILE="HepMC-"${HEPMC2VER}".tar.gz"
0088 fi
0089 
0090 
0091 # make HEPMC2 version a global variable
0092 export HEPMC2VER=${HEPMC2VER}
0093 # always use absolute path name...
0094 cd ${IDIR}; IDIR=`pwd`
0095 
0096 echo " HepMC2 installation: "
0097 echo "  -> HepMC2 version: '"${HEPMC2VER}"'"
0098 echo "  -> installation directory: '"${IDIR}"'"
0099 echo "  -> HepMC2 location: '"${HEPMC2WEBLOCATION}"'"
0100 echo "  -> HepMC2 file name: '"${HEPMC2FILE}"'"
0101 echo "  -> cleaning level: '"${LVLCLEAN}"'"
0102 echo "  -> debugging mode: '"${FLGDEBUG}"'"
0103 echo "  -> CMSSW override: '"${FLGXMLFL}"'"
0104 echo "  -> keep sources:   '"${FLGKEEPT}"'"
0105 echo "  -> use multiple CPU cores: '"${FLGMCORE}"'"
0106 
0107 # analyze HEPMC2 version
0108 va=`echo ${HEPMC2VER} | cut -f1 -d"."`
0109 vb=`echo ${HEPMC2VER} | cut -f2 -d"."`
0110 vc=`echo ${HEPMC2VER} | cut -f3 -d"."`
0111 #echo "VA,VB,VC: "$va","$vb","$vc
0112 if [ $va -ge 2 ] && [ $vb -ge 4 ]; then
0113 # CMS conventions: https://twiki.cern.ch/twiki/bin/view/CMS/CMSConventions#CMS_units
0114   momflag="--with-momentum=GEV"
0115   lenflag="--with-length=CM"
0116 #  momflag=""
0117 else
0118   momflag=""
0119   lenflag=""
0120 fi
0121 
0122 
0123 
0124 # set path to local HEPMC2 installation
0125 export HEPMC2DIR=${IDIR}"/HepMC-"${HEPMC2VER}
0126 export HEPMC2IDIR=${IDIR}"/HEPMC_"${HEPMC2VER}
0127 
0128 
0129 # add compiler & linker flags
0130 echo "CXX      (old):  "$CXX
0131 echo "CXXFLAGS (old):  "$CXXFLAGS
0132 echo "LDFLAGS  (old):  "$LDFLAGS
0133 ##MM FIXME
0134 #  export CXX=""
0135 #  export CXXFLAGS=""
0136 #  export LDFLAGS=""
0137 ##MM FIXME
0138 if [ "$FLGDEBUG" = "TRUE" ]; then
0139   CFDEBUG="-g"
0140   export CXXFLAGS=${CXXFLAGS}" "${CFDEBUG}
0141 fi
0142 echo "CXX      (new):  "$CXX
0143 echo "CXXFLAGS (new):  "$CXXFLAGS
0144 echo "LDFLAGS  (new):  "$LDFLAGS
0145 
0146 # add compiler & linker flags
0147 COPTS=""
0148 MOPTS=""
0149 POPTS=""
0150 if [ "$FLGMCORE" = "TRUE" ]; then
0151     nprc=`cat /proc/cpuinfo | grep  -c processor`
0152     let nprc=$nprc
0153     if [ $nprc -gt 1 ]; then
0154       echo " <I> multiple CPU cores detected: "$nprc
0155       POPTS=" -j"$nprc" "
0156     fi
0157 fi
0158 
0159 
0160 # download, extract compile/install HEPMC2
0161 cd ${IDIR}
0162 #if [ ! -d ${HEPMC2DIR} ]; then
0163 if [ ! -d ${HEPMC2IDIR} ]; then
0164   if [ `echo ${HEPMC2WEBLOCATION} | grep -c "http:"` -gt 0 ]; then
0165     echo " -> downloading HepMC2 "${HEPMC2VER}" from "${HEPMC2WEBLOCATION}/${HEPMC2FILE}
0166     wget ${HEPMC2WEBLOCATION}/${HEPMC2FILE}
0167   elif [ `echo ${HEPMC2WEBLOCATION} | grep -c "srm:"` -gt 0 ]; then
0168     echo " -> srm-copying HepMC2 "${HEPMC2VER}" from "${HEPMC2WEBLOCATION}/${HEPMC2FILE}
0169     srmcp ${HEPMC2WEBLOCATION}/${HEPMC2FILE} file:////${HEPMC2FILE}
0170   else
0171     echo " -> copying HepMC2 "${HEPMC2VER}" from "${HEPMC2WEBLOCATION}/${HEPMC2FILE}
0172     cp ${HEPMC2WEBLOCATION}/${HEPMC2FILE} ./
0173   fi
0174   tar -xzf ${HEPMC2FILE}
0175   if [ ! "$FLGKEEPT" = "TRUE" ]; then
0176     rm ${HEPMC2FILE}
0177   fi
0178   cd ${HEPMC2DIR}
0179   if [ ! -e configure ]; then
0180     ./bootstrap
0181   fi
0182 
0183   echo " -> configuring HepMC2 with options "${COPTS} && \
0184   ./configure --prefix=${HEPMC2IDIR} ${momflag} ${lenflag} ${COPTS} && \
0185   echo " -> making HepMC2 with options "${POPTS} ${MOPTS} && \
0186   make ${POPTS} ${MOPTS} && \
0187   echo " -> installing HepMC2 with options "${MOPTS} && \
0188   make install ${MOPTS}
0189   if [ ${LVLCLEAN} -gt 0 ]; then 
0190     echo " -> cleaning up HEPMC2 installation, level: "${LVLCLEAN}" ..."
0191     if [ ${LVLCLEAN} -ge 1 ]; then  # normal cleanup (objects)
0192       make clean
0193     fi
0194   fi
0195   cd ${HDIR}
0196   if [ "$FLGKEEPT" = "TRUE" ]; then
0197     echo "-> keeping source code..."
0198   else
0199     rm -rf ${HEPMC2DIR}
0200   fi
0201 else
0202   echo " <W> path exists => using already installed HepMC2"
0203 fi
0204 export HEPMC2DIR=${HEPMC2IDIR}
0205 cd ${HDIR}
0206 
0207 
0208 # create XML file fro SCRAM
0209 if [ "${FLGXMLFL}" = "TRUE" ]; then
0210 #  xmlfile=hepmc.xml
0211   xmlfile="hepmc_"${HEPMC2VER}".xml"
0212   echo " <I>"
0213   echo " <I> creating HepMC tool definition XML file"
0214   if [ -e ${xmlfile} ]; then rm ${xmlfile}; fi; touch ${xmlfile}
0215   echo "  <tool name=\"HepMC\" version=\""${HEPMC2VER}"\">" >> ${xmlfile}
0216   tmppath=`find ${HEPMC2DIR} -type f -name libHepMC.so\*`
0217   tmpcnt=`echo ${tmppath} | grep -o "/" | grep -c "/"`
0218   tmppath=`echo ${tmppath} | cut -f 1-${tmpcnt} -d "/"`
0219   for LIB in `cd ${tmppath}; ls *.so | cut -f 1 -d "." | sed -e 's/lib//'; cd ${HDIR}`; do
0220     echo "    <lib name=\""${LIB}"\"/>" >> ${xmlfile}
0221   done
0222   echo "    <client>" >> ${xmlfile}
0223   echo "      <Environment name=\"HEPMC_BASE\" value=\""${HEPMC2DIR}"\"/>" >> ${xmlfile}
0224   echo "      <Environment name=\"LIBDIR\" default=\"\$HEPMC_BASE/lib\"/>" >> ${xmlfile}
0225   echo "      <Environment name=\"INCLUDE\" default=\"\$HEPMC_BASE/include\"/>" >> ${xmlfile}
0226   echo "    </client>" >> ${xmlfile}
0227   echo "    <runtime name=\"CMSSW_FWLITE_INCLUDE_PATH\" value=\"\$HEPMC_BASE/include\" type=\"path\"/>" >> ${xmlfile}
0228   echo "    <use name=\"CLHEP\"/>" >> ${xmlfile}
0229   echo "  </tool>" >> ${xmlfile}
0230   if [ ! "$PWD" = "${HDIR}" ]; then
0231     mv ${xmlfile} ${HDIR}/
0232   fi
0233 
0234   if [ ! "$CMSSW_BASE" = "" ]; then
0235     cd $CMSSW_BASE
0236     tmphmc=`scramv1 tool info hepmc | grep "HEPMC_BASE" | cut -f2 -d"="`
0237     tmpxml=`find $CMSSW_BASE/config -type f -name hepmc.xml -printf %h`
0238     echo " <I>"
0239     echo " <I> HEPMC version currently being used: "${tmphmc}
0240     echo " <I> ...defined in "${tmpxml}
0241     cd ${tmpxml}; tmpxml=$PWD; cd ${HDIR}
0242     echo " <I>"
0243     echo " <I> If you want to override this version with the freshly produced "${xmlfile}","
0244     echo " <I> ...please type the following commands:"
0245     echo " <I>"
0246     echo "       cd $CMSSW_BASE"
0247     echo "       scramv1 tool remove hepmc"
0248     echo "       cp ${HDIR}/${xmlfile} ${tmpxml}/"
0249     echo "       scramv1 setup hepmc"
0250     echo "       cd -"
0251     echo " <I>"
0252   fi
0253 
0254 fi
0255 
0256 
0257 echo " -> HEPMC2 installation directory is: "
0258 echo "  "${HEPMC2IDIR}