Skip to content
Snippets Groups Projects
build_detector.sh 3.73 KiB
Newer Older
  • Learn to ignore specific revisions
  • Whitney Armstrong's avatar
    Whitney Armstrong committed
    #!/bin/bash
    
    ## =============================================================================
    ## Build and install the JUGGLER_DETECTOR detector package into our local prefix
    ## =============================================================================
    
    ## =============================================================================
    ## Load the environment variables. To build the detector we need the following
    ## variables:
    ##
    ## - JUGGLER_DETECTOR: the detector package we want to use for this benchmark
    ## - LOCAL_PREFIX:     location where local packages should be installed
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    ## - LOCAL_DATA_PATH:  local storage for pipeline jobs
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    ## - DETECTOR_PREFIX:  prefix for the detector definitions 
    ## - DETECTOR_PATH:    full path for the detector definitions
    ##                     this is the same as ${DETECTOR_PREFIX}/${JUGGLER_DETECTOR}
    
    
    if [ -n "${LOCAL_PREFIX}" ] ; then 
      source .local/bin/env.sh
    else
      source ${LOCAL_PREFIX}/bin/env.sh
    fi
    
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    
    ## =============================================================================
    ## Step 1: download/update the detector definitions (if needed)
    pushd ${DETECTOR_PREFIX}
    
    ## We need an up-to-date copy of the detector
    
    ## start clean to avoid issues...
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    if [ -d "${JUGGLER_DETECTOR}" ]; then
    
      echo "cleaning up ${JUGGLER_DETECTOR}" 
    
      mv "${JUGGLER_DETECTOR}" "$(mktemp)-${JUGGLER_DETECTOR}"
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    fi
    
    echo "Fetching ${JUGGLER_DETECTOR}"
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    git clone -b ${JUGGLER_DETECTOR_VERSION} --depth 1 https://eicweb.phy.anl.gov/EIC/detectors/${JUGGLER_DETECTOR}.git
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    [[ "$?" == "0" ]]  ||  exit 1
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    rm -rf "${JUGGLER_DETECTOR}/.git"
    
    ## We need an up-to-date copy of the detector
    ## start clean to avoid issues...
    if [ -d "${BEAMLINE_CONFIG}" ]; then
      echo "cleaning up ${BEAMLINE_CONFIG}" 
    
      mv "${BEAMLINE_CONFIG}" "$(mktemp)-${BEAMLINE_CONFIG}"
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    fi
    echo "Fetching ${BEAMLINE_CONFIG}"
    echo "git clone -b ${BEAMLINE_CONFIG_VERSION} --depth 1 https://eicweb.phy.anl.gov/EIC/detectors/${BEAMLINE_CONFIG}.git"
    git clone -b ${BEAMLINE_CONFIG_VERSION} --depth 1 https://eicweb.phy.anl.gov/EIC/detectors/${BEAMLINE_CONFIG}.git
    
    [[ "$?" == "0" ]]  ||  exit 1
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    rm -rf "${BEAMLINE_CONFIG}/.git"
    
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    ## We also need an up-to-date copy of the accelerator. For now this is done
    ## manually. Down the road we could maybe automize this with cmake
    
    if [ -d accelerator ]; then
      echo "cleaning up accelerator"
    
      mv "accelerator" "$(mktemp)-accelerator"
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    fi
    
    echo "Fetching accelerator"
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    git clone --depth 1 https://eicweb.phy.anl.gov/EIC/detectors/accelerator.git
    
    [[ "$?" == "0" ]]  ||  exit 1
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    rm -rf "accelerator/.git"
    
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    ## Now symlink the accelerator definition into the detector definition
    echo "Linking accelerator definition into detector definition"
    ln -s -f ${DETECTOR_PREFIX}/accelerator/eic ${DETECTOR_PATH}/eic
    
    [[ "$?" == "0" ]]  ||  exit 1
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    ln -s -f ${DETECTOR_PREFIX}/${BEAMLINE_CONFIG}/${BEAMLINE_CONFIG} ${DETECTOR_PATH}/${BEAMLINE_CONFIG}
    
    [[ "$?" == "0" ]]  ||  exit 1
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    popd
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    ## =============================================================================
    ## Step 2: Compile and install the detector definition
    echo "Building and installing the ${JUGGLER_DETECTOR} package"
    
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    mkdir -p ${DETECTOR_PREFIX}/${JUGGLER_DETECTOR}_build
    pushd ${DETECTOR_PREFIX}/${JUGGLER_DETECTOR}_build
    cmake ${DETECTOR_PATH} -DCMAKE_INSTALL_PREFIX=${LOCAL_PREFIX} -DCMAKE_CXX_STANDARD=17 && make -j30 install || exit 1
    popd
    rm -rf ${DETECTOR_PREFIX}/${JUGGLER_DETECTOR}_build
    
    mkdir -p ${DETECTOR_PREFIX}/${BEAMLINE_CONFIG}_build
    pushd ${DETECTOR_PREFIX}/${BEAMLINE_CONFIG}_build
    cmake ${DETECTOR_PREFIX}/${BEAMLINE_CONFIG} -DCMAKE_INSTALL_PREFIX=${LOCAL_PREFIX} -DCMAKE_CXX_STANDARD=17 && make -j30 install || exit 1
    popd
    rm -rf ${DETECTOR_PREFIX}/${BEAMLINE_CONFIG}_build
    
    
    
    Whitney Armstrong's avatar
    Whitney Armstrong committed
    
    ## =============================================================================
    ## Step 3: That's all!
    echo "Detector build/install complete!"