From 9989c7e97fd0be62063f52180d65d27774bfaee3 Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Wed, 27 Sep 2023 07:43:55 +0000
Subject: [PATCH] Fix to be generic and common to all detectors again.

---
 README.md             |  6 +++---
 bin/build_detector.sh | 27 +++++++++++++++++++++++++++
 bin/env.sh            | 24 +++++++++++++++++++++++-
 bin/print_env.sh      |  3 +++
 4 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md
index 665466a..0634618 100644
--- a/README.md
+++ b/README.md
@@ -5,9 +5,9 @@
 ## Overview
 
 Code common to:
- - `detector_benchmarks`
- - `reconstruction_benchmarks`
- - `physics_benchmarks`
+ - [`detector_benchmarks`](https://eicweb.phy.anl.gov/eic/benchmarks/detector_benchmarks/)
+ - [`reconstruction_benchmarks`](https://eicweb.phy.anl.gov/eic/benchmarks/reconstruction_benchmarks/)
+ - [`physics_benchmarks`](https://eicweb.phy.anl.gov/eic/benchmarks/physics_benchmarks/)
 
 
 ## Usage
diff --git a/bin/build_detector.sh b/bin/build_detector.sh
index 97cbc96..424eaa2 100755
--- a/bin/build_detector.sh
+++ b/bin/build_detector.sh
@@ -48,6 +48,33 @@ fi
 rm -rf "${DETECTOR}/.git"
 
 popd
+
+if [ "${BEAMLINE}" ]; then 
+  pushd ${DETECTOR_PREFIX}
+  ## We need an up-to-date copy of the detector
+  ## start clean to avoid issues...
+  if [ -d "${BEAMLINE}" ]; then
+    echo "cleaning up ${BEAMLINE}" 
+    mv "${BEAMLINE}" "$(mktemp)-${BEAMLINE}"
+  fi
+  echo "Fetching ${BEAMLINE}"
+  if [ -n "${BEAMLINE_DEPLOY_TOKEN_USERNAME:-}" -a -n "${BEAMLINE_DEPLOY_TOKEN_PASSWORD:-}" ]; then
+    DEPLOY_TOKEN="${BEAMLINE_DEPLOY_TOKEN_USERNAME}:${BEAMLINE_DEPLOY_TOKEN_PASSWORD}@"
+    echo "Deploy token for ${BEAMLINE_DEPLOY_TOKEN_USERNAME} is masked in the next line."
+  else
+    DEPLOY_TOKEN=""
+  fi
+  echo "git clone -b ${BEAMLINE_VERSION} --depth 1 ${BEAMLINE_REPOSITORYURL:-https://eicweb.phy.anl.gov/EIC/detectors/${BEAMLINE}.git} ${BEAMLINE}"
+  git clone -b ${BEAMLINE_VERSION} --depth 1 ${BEAMLINE_REPOSITORYURL:-https://${DEPLOY_TOKEN}eicweb.phy.anl.gov/EIC/detectors/${BEAMLINE}.git} ${BEAMLINE}
+  [[ "$?" == "0" ]]  ||  exit 1
+  rm -rf "${BEAMLINE}/.git"
+
+  ln -s -f ${DETECTOR_PREFIX}/${BEAMLINE}/${BEAMLINE} ${DETECTOR_PATH}/${BEAMLINE}
+  [[ "$?" == "0" ]]  ||  exit 1
+  popd
+fi
+
+
 ## =============================================================================
 ## Step 2: Compile and install the detector definition
 echo "Building and installing the ${DETECTOR} package"
diff --git a/bin/env.sh b/bin/env.sh
index e1c9e1f..c1418ec 100755
--- a/bin/env.sh
+++ b/bin/env.sh
@@ -5,6 +5,8 @@
 ## The script defines the following environment variables that are meant to
 ## be overriden by the Gitlab continuous integration (CI)
 ##
+##  - BEAMLINE:         compact detector files for the interaciton point beamline
+##  - BEAMLINE_VERSION: compact detector files for the interaciton point beamline
 ##  - DETECTOR:                detector package to be used for the benchmark
 ##  - DETECTOR_CONFIG:         detector package config to be used for the benchmark
 ##  - DETECTOR_VERSION:        detector package to be used for the benchmark
@@ -44,7 +46,10 @@ if [ ! -n  "${DETECTOR_VERSION}" ] ; then
 fi
 
 if [ ! -n  "${DETECTOR_REPOSITORYURL}" ] ; then
-  export DETECTOR_REPOSITORYURL="https://github.com/eic/${DETECTOR}.git"
+  export DETECTOR_REPOSITORYURL="https://eicweb.phy.anl.gov/EIC/detectors/${DETECTOR}.git"
+  if [ "${DETECTOR}" == "epic" ] ; then
+    export DETECTOR_REPOSITORYURL="https://github.com/eic/${DETECTOR}.git"
+  fi
 fi
 
 ## Number of events that will be processed by the reconstruction
@@ -53,6 +58,20 @@ if [ ! -n  "${BENCHMARK_N_EVENTS}" ] ; then
 fi
 export JUGGLER_N_EVENTS=${BENCHMARK_N_EVENTS}
 
+# optionally use a BEAMLINE repository
+if [ "${BEAMLINE}" ] ; then
+
+  if [ ! -n  "${BEAMLINE_VERSION}" ] ; then 
+    export BEAMLINE_VERSION="master"
+  fi
+
+  if [ ! -n  "${BEAMLINE_REPOSITORYURL}" ] ; then 
+    export BEAMLINE_REPOSITORYURL="https://eicweb.phy.anl.gov/EIC/detectors/${BEAMLINE}.git"
+  fi
+fi
+
+
+
 ## Maximum number of threads or processes a single pipeline should use
 ## (this is not enforced, but the different pipeline scripts should use
 ##  this to guide the number of parallel processes or threads they 
@@ -109,6 +128,9 @@ echo "DETECTOR=${DETECTOR}" >> .env
 echo "DETECTOR_CONFIG=${DETECTOR_CONFIG}" >> .env
 echo "DETECTOR_VERSION=${DETECTOR_VERSION}" >> .env
 echo "DETECTOR_REPOSITORYURL=${DETECTOR_REPOSITORYURL}" >> .env
+echo "BEAMLINE=${BEAMLINE}" >> .env
+echo "BEAMLINE_VERSION=${BEAMLINE_VERSION}" >> .env
+echo "BEAMLINE_REPOSITORYURL=${BEAMLINE_REPOSITORYURL}" >> .env
 echo "BENCHMARK_N_EVENTS=${BENCHMARK_N_EVENTS}" >> .env
 echo "BENCHMARK_N_THREADS=${BENCHMARK_N_THREADS}" >> .env
 echo "BENCHMARK_RNG_SEED=${BENCHMARK_RNG_SEED}" >> .env
diff --git a/bin/print_env.sh b/bin/print_env.sh
index 01de021..d47bc11 100755
--- a/bin/print_env.sh
+++ b/bin/print_env.sh
@@ -4,6 +4,9 @@ echo "JUGGLER_TAG:                ${JUGGLER_TAG}"
 echo "DETECTOR:                   ${DETECTOR}"
 echo "DETECTOR_CONFIG:            ${DETECTOR_CONFIG}"
 echo "DETECTOR_VERSION:           ${DETECTOR_VERSION}"
+echo "BEAMLINE:                   ${BEAMLINE}"
+echo "BEAMLINE_CONFIG:            ${BEAMLINE_CONFIG}"
+echo "BEAMLINE_VERSION:           ${BEAMLINE_VERSION}"
 echo "DETECTOR_PREFIX:            ${DETECTOR_PREFIX}"
 echo "DETECTOR_PATH:              ${DETECTOR_PATH}"
 echo "BENCHMARK_N_EVENTS:         ${BENCHMARK_N_EVENTS}"
-- 
GitLab