Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-08 08:36:30

0001 #!/usr/bin/env bash
0002 set -euo pipefail
0003 
0004 # BNL setup, launched from the normal tcsh login/submit session.
0005 # Bash executes this installer and the EIC wrapper; it is not a second
0006 # interactive environment. Condor stays on the host. yall-run is installed
0007 # for the host Python used to create and submit queued campaigns; the
0008 # wrapper-free local LFHCal example runs the checked-out Yall source directly
0009 # with the EIC Python.
0010 # Software is installed in the current folder (or --prefix PATH).
0011 
0012 install_root=$PWD
0013 while (($#)); do
0014     case "$1" in
0015         --prefix)
0016             if [[ $# -lt 2 || -z "$2" ]]; then
0017                 echo "--prefix requires an installation directory." >&2
0018                 exit 2
0019             fi
0020             install_root=$2
0021             shift 2
0022             ;;
0023         -h|--help)
0024             echo "Usage: bash bootstrap-yall-integration.sh [--prefix PATH]"
0025             echo "Default destination: the current working directory."
0026             exit 0
0027             ;;
0028         *)
0029             echo "Unknown argument: $1 (use --help)." >&2
0030             exit 2
0031             ;;
0032     esac
0033 done
0034 
0035 YALL_REPO_URL=${YALL_REPO_URL:-"https://github.com/paulnord/yall-run.git"}
0036 LFHCAL_REPO_URL=${LFHCAL_REPO_URL:-"https://github.com/eic/epic-lfhcal-tbana.git"}
0037 YALL_BRANCH=${YALL_BRANCH:-main}
0038 LFHCAL_BRANCH=${LFHCAL_BRANCH:-main}
0039 LFHCAL_BUILD_JOBS=${LFHCAL_BUILD_JOBS:-2}
0040 
0041 say() { printf '\n==> %s\n' "$*"; }
0042 need() {
0043     command -v "$1" >/dev/null 2>&1 || {
0044         echo "Required command not found: $1. Use the normal BNL submit shell." >&2
0045         exit 1
0046     }
0047 }
0048 update_checkout() {
0049     local url=$1 branch=$2 dir=$3
0050     if [[ -d "$dir/.git" ]]; then
0051         say "Updating $(basename "$dir") ($branch)"
0052         git -C "$dir" fetch origin
0053         git -C "$dir" switch "$branch"
0054         git -C "$dir" pull --ff-only
0055     else
0056         say "Cloning $(basename "$dir") ($branch)"
0057         git clone --branch "$branch" "$url" "$dir"
0058     fi
0059 }
0060 
0061 need git
0062 need curl
0063 need python3
0064 need tcsh
0065 need condor_submit
0066 need condor_submit_dag
0067 
0068 mkdir -p -- "$install_root"
0069 LFHCAL_HOME=$(cd -- "$install_root" && pwd -P)
0070 YALL_DIR="$LFHCAL_HOME/yall-run"
0071 LFHCAL_DIR="$LFHCAL_HOME/epic-lfhcal-tbana"
0072 EIC_SHELL="$LFHCAL_HOME/eic-shell"
0073 YALL_USER_BIN="$(python3 -m site --user-base)/bin"
0074 
0075 # Keep one user-editable storage file. Never overwrite existing settings.
0076 # Raw input is shared; only the user's work tree is created by activation.
0077 if [[ ! -f "$LFHCAL_HOME/site-env.tcsh" ]]; then
0078     cat > "$LFHCAL_HOME/site-env.tcsh" <<'EOF'
0079 # BNL storage defaults. Change these paths here when needed.
0080 # LFHCAL_DATA is the directory directly containing Run*.h2g.
0081 if (! $?LFHCAL_DATA) setenv LFHCAL_DATA "/gpfs01/star/pwg/pnord/eic/2026TBdata/raw"
0082 if (! $?LFHCAL_WORK) setenv LFHCAL_WORK "/gpfs01/star/scratch/`id -un`/lfhcal"
0083 EOF
0084 fi
0085 
0086 cat > "$LFHCAL_HOME/activate.tcsh" <<EOF
0087 # Source from the normal BNL tcsh session. This does not enter eic-shell.
0088 unset LFHCAL_HOME LFHCAL_REPO YALL_RUN_REPO EIC_SHELL
0089 setenv LFHCAL_HOME "${LFHCAL_HOME}"
0090 setenv LFHCAL_REPO "${LFHCAL_DIR}"
0091 setenv YALL_RUN_REPO "${YALL_DIR}"
0092 setenv EIC_SHELL "${EIC_SHELL}"
0093 setenv PATH "${YALL_USER_BIN}:\$PATH"
0094 rehash
0095 set _lfhcal_activate_rc = 1
0096 source "${LFHCAL_HOME}/site-env.tcsh"
0097 if (\$status == 0) then
0098     # Read access only: never create or write into the shared raw-data tree.
0099     if (! -d "\$LFHCAL_DATA" || ! -r "\$LFHCAL_DATA" || ! -x "\$LFHCAL_DATA") then
0100         echo "WARNING: shared raw data are not readable: \$LFHCAL_DATA"
0101         echo "Check access with Paul, or set LFHCAL_DATA to readable raw data before analysis."
0102     endif
0103     # -p also creates /gpfs01/star/scratch/<username> when it is missing.
0104     mkdir -p "\$LFHCAL_WORK/campaigns"
0105     if (\$status != 0) then
0106         echo "Cannot create work directories: \$LFHCAL_WORK"
0107         echo "Check scratch permissions or edit ${LFHCAL_HOME}/site-env.tcsh."
0108     else if (! -w "\$LFHCAL_WORK" || ! -w "\$LFHCAL_WORK/campaigns") then
0109         echo "Work directories are not writable: \$LFHCAL_WORK"
0110     else
0111         echo "Raw input: \$LFHCAL_DATA"
0112         echo "Work root: \$LFHCAL_WORK"
0113         set _lfhcal_activate_rc = 0
0114     endif
0115 endif
0116 # Keep this last, outside every conditional. Do not exit a sourcing shell.
0117 /bin/test "\$_lfhcal_activate_rc" -eq 0
0118 EOF
0119 
0120 say "Preparing BNL scratch directories"
0121 # Execute the same setup users will source, including any local overrides.
0122 # A child tcsh does not change the caller's interactive shell.
0123 tcsh -f "$LFHCAL_HOME/activate.tcsh"
0124 
0125 say "Installation root: $LFHCAL_HOME"
0126 if [[ ! -x "$EIC_SHELL" ]]; then
0127     say "Installing eic-shell"
0128     (
0129         cd "$LFHCAL_HOME"
0130         curl --fail --silent --show-error --location https://get.epic-eic.org | bash
0131     )
0132     if [[ ! -x "$EIC_SHELL" && -x "$LFHCAL_HOME/eic-env/eic-shell" ]]; then
0133         ln -s "$LFHCAL_HOME/eic-env/eic-shell" "$EIC_SHELL"
0134     fi
0135 fi
0136 if [[ ! -x "$EIC_SHELL" ]]; then
0137     echo "eic-shell was not found at $EIC_SHELL after installation." >&2
0138     exit 1
0139 fi
0140 
0141 update_checkout "$YALL_REPO_URL" "$YALL_BRANCH" "$YALL_DIR"
0142 update_checkout "$LFHCAL_REPO_URL" "$LFHCAL_BRANCH" "$LFHCAL_DIR"
0143 git -C "$LFHCAL_DIR" submodule update --init --recursive
0144 
0145 say "Installing yall-run for this user with the host Python"
0146 python3 -m pip install --user -e "$YALL_DIR"
0147 
0148 say "Configuring LFHCal inside eic-shell"
0149 "$LFHCAL_DIR/tools/run-in-eic-shell.sh" "$EIC_SHELL" \
0150     cmake -S "$LFHCAL_DIR/NewStructure" -B "$LFHCAL_DIR/NewStructure/build"
0151 say "Building LFHCal"
0152 "$LFHCAL_DIR/tools/run-in-eic-shell.sh" "$EIC_SHELL" \
0153     cmake --build "$LFHCAL_DIR/NewStructure/build" -j"$LFHCAL_BUILD_JOBS"
0154 
0155 say "Smoke tests (no batch jobs submitted)"
0156 "$LFHCAL_DIR/tools/run-in-eic-shell.sh" "$EIC_SHELL" root-config --version
0157 "$YALL_USER_BIN/yall-run" --help >/dev/null
0158 # Exercise the same source-checkout setup used interactively by lfhcal-simple.
0159 "$LFHCAL_DIR/tools/run-in-eic-shell.sh" "$EIC_SHELL" \
0160     /bin/bash -lc "cd '$LFHCAL_DIR/examples/yall/lfhcal-simple' && source ./env-eic.sh >/dev/null && yall-run --version"
0161 test -x "$LFHCAL_DIR/NewStructure/build/Convert"
0162 test -x "$LFHCAL_DIR/NewStructure/build/DataPrep"
0163 if [[ -f "$LFHCAL_DIR/examples/yall/check_shared_conversions.py" ]]; then
0164     python3 "$LFHCAL_DIR/examples/yall/check_shared_conversions.py" -v
0165 fi
0166 
0167 say "Ready"
0168 printf 'Install root: %s\n' "$LFHCAL_HOME"
0169 printf 'Host command: %s/yall-run\n' "$YALL_USER_BIN"
0170 printf '\nIn your normal tcsh session:\n  source "%s/activate.tcsh"\n' "$LFHCAL_HOME"
0171 printf 'For lfhcal-simple, enter eic-shell and source env-eic.sh; it runs Yall directly from the checkout.\n'
0172 printf 'Return to the host for Condor examples such as scan-set-1.\n'
0173 printf 'Instructions: %s/examples/yall/SETUP.md\n' "$LFHCAL_DIR"