diff --git a/algo/test/CMakeLists.txt b/algo/test/CMakeLists.txt index 298c38feaf4c7388e50c1a8a5742fcc9a5eaad97..151303f857990b667f1e672beca01287369a9259 100644 --- a/algo/test/CMakeLists.txt +++ b/algo/test/CMakeLists.txt @@ -20,3 +20,20 @@ AddBasicTest(_GTestDigiEventSelector) AddBasicTest(_GTestYamlConfig) AddBasicTest(_GTestPartitionedVector) AddBasicTest(_GTestPartitionedSpan) + +if (DEFINED ENV{RAW_DATA_PATH}) + set(RAW_DATA_PATH $ENV{RAW_DATA_PATH}) + + set(TEST_SCRIPT ${CMAKE_SOURCE_DIR}/algo/test/realdata_test.sh) + set(RECO_BIN ${EXECUTABLE_OUTPUT_PATH}/cbmreco) + set(PARAMS_DIR ${CMAKE_SOURCE_DIR}/parameters/online) + set(TSA_FILE ${RAW_DATA_PATH}/2391_firstTs.tsa) + + Add_Test( + NAME OnlineRecoCanProcessTimeslice + COMMAND ${TEST_SCRIPT} ${RECO_BIN} ${PARAMS_DIR} ${TSA_FILE} + ) + + set_tests_properties(OnlineRecoCanProcessTimeslice PROPERTIES TIMEOUT 600) + +endif() diff --git a/algo/test/realdata_test.sh b/algo/test/realdata_test.sh new file mode 100755 index 0000000000000000000000000000000000000000..da9d6715bde146dd5a7f9b7143762cb71e0f6097 --- /dev/null +++ b/algo/test/realdata_test.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +cbmreco_bin=$1 +parameter_dir=$2 +tsa_file=$3 + +reco_args=" \ + -p $parameter_dir \ + -i $tsa_file \ + -n1 \ + --steps Unpack DigiTrigger LocalReco \ +" + +script=$(readlink -f "$0") +function check_arg { + if [ -z "$1" ]; then + echo "Error: <$2> not specified." + echo "Usage: $script <cbmreco_bin> <parameter_dir> <tsa_file>" + exit 1 + fi +} + +function ensure_gt_zero { + local output="$1" + local pattern="$2" + + # Extract placeholders from the pattern, e.g. %1, %2, ..., %9 + # [[ $? == 1 ]] is a workaround for the following issue: + # grep returns 1 if no match is found, but set -e causes the script to exit in this case + placeholders=($(echo "$pattern" | grep -o '%[0-9]\+' || [[ $? == 1 ]])) + if [[ $? -ne 0 ]]; then + echo "Error: Failed to extract placeholders: $pattern" + exit 1 + fi + + if [ -z "${placeholders[*]}" ]; then + echo "Error: No placeholders found: $pattern" + exit 1 + fi + + # Replace placeholders with a regex that matches the value + sed_pattern=$pattern + for placeholder in "${placeholders[@]}"; do + sed_pattern="${sed_pattern//$placeholder/\\([0-9]\\+\\)}" + done + + for placeholder in "${placeholders[@]}"; do + # Use sed to extract the value for the current placeholder + # echo "Searching for $placeholder..." + id=$(echo "$placeholder" | grep -o '[0-9]\+') + value=$(echo "$output" | sed -n "s/.*$sed_pattern.*/\\$id/p") + if [ -n "$value" ] && [ "$value" -gt 0 ]; then + continue + else + echo "$pattern: FAIL ($placeholder is not greater than zero.)" + echo "Output:" + echo "$output" + exit 1 + fi + done + + echo "$pattern: OK" +} + +check_arg "$cbmreco_bin" "cbmreco_bin" +check_arg "$parameter_dir" "parameter_dir" +check_arg "$tsa_file" "tsa_file" + +# Run the reconstruction and capture the log +echo "Running '$cbmreco_bin $reco_args'" +log="$($cbmreco_bin $reco_args 2>&1)" +reco_ok=$? +echo "$log" +echo "==============================" +if [ $reco_ok -ne 0 ]; then + echo "Error: Reconstruction failed. Exit early." + exit 1 +fi + +# Check Digis +ensure_gt_zero "$log" "Timeslice contains %1 STS Digis" +ensure_gt_zero "$log" "Timeslice contains %1 TOF Digis" +ensure_gt_zero "$log" "Timeslice contains %1 BMON Digis" +ensure_gt_zero "$log" "Timeslice contains %1 MUCH Digis" +ensure_gt_zero "$log" "Timeslice contains %1 TRD Digis" +ensure_gt_zero "$log" "Timeslice contains %1 TRD2D Digis" +ensure_gt_zero "$log" "Timeslice contains %1 RICH Digis" + +# Check Events +ensure_gt_zero "$log" "Triggers: %1, events %2" + +# Check Hits +ensure_gt_zero "$log" "TS contains %1 TOF Hits" +ensure_gt_zero "$log" "Timeslice contains %1 STS hits and %2 STS clusters"