105 lines
2.9 KiB
Bash
Executable File
105 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
echo "usage: ${MUSRSIM_COMPARE_COMMAND:-$0} <baseline-musrSim> <candidate-musrSim> [events]" >&2
|
|
echo "set MUSRSIM_ROOT_COMPARATOR if the comparator is not beside the candidate build" >&2
|
|
}
|
|
|
|
if [[ $# -lt 5 || $# -gt 6 ]]; then
|
|
usage
|
|
exit 2
|
|
fi
|
|
|
|
source_macro=$(realpath "$1")
|
|
run_id=$2
|
|
default_events=$3
|
|
baseline_binary=$(realpath "$4")
|
|
candidate_binary=$(realpath "$5")
|
|
events=${6:-$default_events}
|
|
|
|
if [[ ! -f "$source_macro" ]]; then
|
|
echo "source macro not found: $source_macro" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! -x "$baseline_binary" || ! -x "$candidate_binary" ]]; then
|
|
echo "both musrSim paths must be executable" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! "$run_id" =~ ^[1-9][0-9]*$ ]]; then
|
|
echo "run ID must be a positive integer" >&2
|
|
exit 2
|
|
fi
|
|
if [[ ! "$events" =~ ^[1-9][0-9]*$ ]]; then
|
|
echo "event count must be a positive integer" >&2
|
|
exit 2
|
|
fi
|
|
|
|
macro_directory=$(dirname "$source_macro")
|
|
|
|
if [[ -n ${MUSRSIM_ROOT_COMPARATOR:-} ]]; then
|
|
comparator=$(realpath "$MUSRSIM_ROOT_COMPARATOR")
|
|
else
|
|
candidate_directory=$(dirname "$candidate_binary")
|
|
comparator="$candidate_directory/tests/musrRootOutputCompare"
|
|
fi
|
|
if [[ ! -x "$comparator" ]]; then
|
|
echo "ROOT comparator not found at $comparator" >&2
|
|
echo "build the musrRootOutputCompare target or set MUSRSIM_ROOT_COMPARATOR" >&2
|
|
exit 2
|
|
fi
|
|
|
|
macro_name=$(basename "$source_macro" .mac)
|
|
work_directory=$(mktemp -d "${TMPDIR:-/tmp}/musrsim-${macro_name}-compare.XXXXXX")
|
|
trap 'rm -rf "$work_directory"' EXIT
|
|
mkdir -p "$work_directory/baseline" "$work_directory/candidate"
|
|
|
|
make_macro() {
|
|
local output_directory=$1
|
|
local output_macro=$2
|
|
awk -v events="$events" -v output_directory="$output_directory" -v run_id="$run_id" '
|
|
/^[[:space:]]*\/run\/beamOn[[:space:]]+/ {
|
|
++beam_on_count
|
|
print "/musr/command rootOutputDirectoryName " output_directory
|
|
print "/musr/run/runID " run_id
|
|
print "/run/beamOn " events
|
|
next
|
|
}
|
|
{ print }
|
|
END {
|
|
if (beam_on_count != 1) {
|
|
print "expected exactly one active /run/beamOn command" > "/dev/stderr"
|
|
exit 2
|
|
}
|
|
}
|
|
' "$source_macro" > "$output_macro"
|
|
}
|
|
|
|
run_version() {
|
|
local label=$1
|
|
local binary=$2
|
|
local output_directory="$work_directory/$label"
|
|
local macro="$work_directory/$label.mac"
|
|
local log="$work_directory/$label.log"
|
|
|
|
make_macro "$output_directory" "$macro"
|
|
if ! (cd "$macro_directory" && "$binary" "$macro") >"$log" 2>&1; then
|
|
echo "$label simulation failed; final log lines:" >&2
|
|
tail -40 "$log" >&2
|
|
exit 1
|
|
fi
|
|
|
|
local root_file="$output_directory/musr_${run_id}.root"
|
|
if [[ ! -f "$root_file" ]]; then
|
|
echo "$label simulation did not create $root_file" >&2
|
|
exit 1
|
|
fi
|
|
echo "$root_file"
|
|
}
|
|
|
|
baseline_output=$(run_version baseline "$baseline_binary")
|
|
candidate_output=$(run_version candidate "$candidate_binary")
|
|
|
|
"$comparator" "$baseline_output" "$candidate_output"
|