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_fastjet.sh
0004 #  description: BASH script for the installation of the fastjet package,
0005 #               can be used standalone or called from other scripts
0006 #
0007 #  author:      Markus Merschmeyer, RWTH Aachen University
0008 #  date:        2013/07/29
0009 #  version:     1.0
0010 #
0011 
0012 print_help() {
0013     echo "" && \
0014     echo "install_fastjet version 1.0" && echo && \
0015     echo "options: -v  version    define fastjet version ( "${FJVER}" )" && \
0016     echo "         -d  path       define fastjet installation directory" && \
0017     echo "                         -> ( "${IDIR}" )" && \
0018     echo "         -W  location   (web)location of fastjet tarball ( "${FJWEBLOCATION}" )" && \
0019     echo "         -S  filename   file name of fastjet tarball ( "${FJFILE}" )" && \
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 fastjet source code tree after installation ( "${FGLKEEPT}" )" && \
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 FJVER="2.4.5"              # version to be installed
0037 FJWEBLOCATION=""           # (web)location of fastjet tarball
0038 FJFILE=""                  # file name of fastjet 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 FGLKEEPT="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) FJVER=$OPTARG ;;
0051   d) IDIR=$OPTARG ;;
0052   W) FJWEBLOCATION=$OPTARG ;;
0053   S) FJFILE=$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_fastjet: 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 fastjet download location
0077 if [ "$FJWEBLOCATION" = "" ]; then
0078   FJWEBLOCATION="http://fastjet.fr/repo"
0079 else
0080   if [ -e ${FJWEBLOCATION} ]; then   # is the location a local subdirectory?
0081     if [ -d ${FJWEBLOCATION} ]; then
0082       cd ${FJWEBLOCATION}; FJWEBLOCATION=`pwd`; cd ${HDIR}
0083     fi
0084   fi
0085 fi
0086 if [ "$FJFILE" = "" ]; then
0087   FJFILE="fastjet-${FJVER}.tar.gz"
0088 fi
0089 
0090 
0091 # make fastjet version a global variable
0092 export FJVER=${FJVER}
0093 # always use absolute path name...
0094 cd ${IDIR}; IDIR=`pwd`
0095 
0096 echo " fastjet installation: "
0097 echo "  -> fastjet version: '"${FJVER}"'"
0098 echo "  -> installation directory: '"${IDIR}"'"
0099 echo "  -> fastjet location: '"${FJWEBLOCATION}"'"
0100 echo "  -> fastjet file name: '"${FJFILE}"'"
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 
0108 
0109 # set path to local HEPMC2 installation
0110 export FJDIR=${IDIR}"/fastjet-"${FJVER}
0111 export FJIDIR=${IDIR}"/FJ_"${FJVER}
0112 
0113 
0114 # add compiler & linker flags
0115 echo "CXX      (old):  "$CXX
0116 echo "CXXFLAGS (old):  "$CXXFLAGS
0117 echo "LDFLAGS  (old):  "$LDFLAGS
0118 ##MM FIXME
0119 #  export CXX=""
0120 #  export CXXFLAGS=""
0121 #  export LDFLAGS=""
0122 ##MM FIXME
0123 if [ "$FLGDEBUG" = "TRUE" ]; then
0124   CFDEBUG="-g"
0125   export CXXFLAGS=${CXXFLAGS}" "${CFDEBUG}
0126 fi
0127 echo "CXX      (new):  "$CXX
0128 echo "CXXFLAGS (new):  "$CXXFLAGS
0129 echo "LDFLAGS  (new):  "$LDFLAGS
0130 
0131 # add compiler & linker flags
0132 COPTS=""
0133 MOPTS=""
0134 POPTS=""
0135 if [ "$FLGMCORE" = "TRUE" ]; then
0136     nprc=`cat /proc/cpuinfo | grep  -c processor`
0137     let nprc=$nprc
0138     if [ $nprc -gt 1 ]; then
0139       echo " <I> multiple CPU cores detected: "$nprc
0140       POPTS=" -j"$nprc" "
0141     fi
0142 fi
0143 
0144 
0145 # download, extract compile/install fastjet
0146 cd ${IDIR}
0147 if [ ! -d ${FJIDIR} ]; then
0148   if [ `echo ${FJWEBLOCATION} | grep -c "http:"` -gt 0 ]; then
0149     echo " -> downloading fastjet "${FJVER}" from "${FJWEBLOCATION}/${FJFILE}
0150     wget ${FJWEBLOCATION}/${FJFILE}
0151   elif [ `echo ${FJWEBLOCATION} | grep -c "srm:"` -gt 0 ]; then
0152     echo " -> srm-copying fastjet "${FJVER}" from "${FJWEBLOCATION}/${FJFILE}
0153     srmcp ${FJWEBLOCATION}/${FJFILE} file:////${FJFILE}
0154   else
0155     echo " -> copying fastjet "${FJVER}" from "${FJWEBLOCATION}/${FJFILE}
0156     cp ${FJWEBLOCATION}/${FJFILE} ./
0157   fi
0158   tar -xzf ${FJFILE}
0159   if [ ! "$FLGKEEPT" = "TRUE" ]; then
0160     rm ${FJFILE}
0161   fi
0162   cd ${FJDIR}
0163 
0164   echo " -> configuring fastjet with options "${COPTS} && \
0165   ./configure --prefix=${FJIDIR} ${momflag} ${lenflag} ${COPTS} && \
0166   echo " -> making fastjet with options "${POPTS} ${MOPTS} && \
0167   make ${POPTS} ${MOPTS} && \
0168   echo " -> installing fastjet with options "${MOPTS} && \
0169   make install ${MOPTS}
0170   if [ ${LVLCLEAN} -gt 0 ]; then 
0171     echo " -> cleaning up fastjet installation, level: "${LVLCLEAN}" ..."
0172     if [ ${LVLCLEAN} -ge 1 ]; then  # normal cleanup (objects)
0173       make clean
0174     fi
0175   fi
0176   cd ${HDIR}
0177   if [ "$FLGKEEPT" = "TRUE" ]; then
0178     echo "-> keeping source code..."
0179   else
0180     rm -rf ${FJDIR}
0181   fi
0182 else
0183   echo " <W> path exists => using already installed fastjet"
0184 fi
0185 export FJDIR=${FJIDIR}
0186 cd ${HDIR}
0187 
0188 
0189 # create XML file fro SCRAM
0190 if [ "${FLGXMLFL}" = "TRUE" ]; then
0191   xmlfile="fastjet_"${FJVER}".xml"
0192   echo " <I>"
0193   echo " <I> creating fastjet tool definition XML file"
0194   if [ -e ${xmlfile} ]; then rm ${xmlfile}; fi; touch ${xmlfile}
0195   echo "  <tool name=\"fastjet\" version=\""${FJVER}"\">" >> ${xmlfile}
0196   tmppath=`find ${FJDIR} -type f -name libfastjet.so\*`
0197 #
0198         echo "FJDIR: "$FJDIR
0199         echo "TMPPATH: "$tmppath
0200 #
0201   tmpcnt=`echo ${tmppath} | grep -o "/" | grep -c "/"`
0202   tmppath=`echo ${tmppath} | cut -f 1-${tmpcnt} -d "/"`
0203   for LIB in `cd ${tmppath}; ls *.so | cut -f 1 -d "." | sed -e 's/lib//'; cd ${HDIR}`; do
0204     echo "    <lib name=\""${LIB}"\"/>" >> ${xmlfile}
0205   done
0206   echo "    <client>" >> ${xmlfile}
0207   echo "      <Environment name=\"FJ_BASE\" value=\""${FJDIR}"\"/>" >> ${xmlfile}
0208   echo "      <Environment name=\"LIBDIR\" default=\"\$FJ_BASE/lib\"/>" >> ${xmlfile}
0209   echo "      <Environment name=\"INCLUDE\" default=\"\$FJ_BASE/include\"/>" >> ${xmlfile}
0210   echo "    </client>" >> ${xmlfile}
0211   echo "  </tool>" >> ${xmlfile}
0212   if [ ! "$PWD" = "${HDIR}" ]; then
0213     mv ${xmlfile} ${HDIR}/
0214   fi
0215 
0216   if [ ! "$CMSSW_BASE" = "" ]; then
0217     cd $CMSSW_BASE
0218     tmpom=`scramv1 tool info fastjet | grep "FJ_BASE" | cut -f2 -d"="`
0219     tmpxml=`find $CMSSW_BASE/config -type f -name qd.xml -printf %h`
0220     echo " <I>"
0221     echo " <I> fastjet version currently being used: "${tmpom}
0222     echo " <I> ...defined in "${tmpxml}
0223     cd ${tmpxml}; tmpxml=$PWD; cd ${HDIR}
0224     echo " <I>"
0225     echo " <I> If you want to override this version with the freshly produced "${xmlfile}","
0226     echo " <I> ...please type the following commands:"
0227     echo " <I>"
0228     echo "       cd $CMSSW_BASE"
0229     echo "       scramv1 tool remove fastjet"
0230     echo "       cp ${HDIR}/${xmlfile} ${tmpxml}/"
0231     echo "       scramv1 setup fastjet"
0232     echo "       cd -"
0233     echo " <I>"
0234   fi
0235 
0236 fi
0237 
0238 
0239 echo " -> fastjet installation directory is: " &&\
0240 echo "  "${FJIDIR} && \
0241 echo "" &&\
0242 echo "   + please make sure to add (prepend)" &&\
0243 echo "       "${FJIDIR}"/lib" &&\
0244 echo "      to LD_LIBRARY_PATH environment variable" &&\
0245 echo "" &&\
0246 echo ""
0247 
0248 
0249 ## update LD_LIBRARY_PATH