From adcc239b1338240c7637f47c1c44d6809b26e2cb Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Wed, 9 Aug 2023 12:37:26 -0500
Subject: [PATCH] fix: allow gaudirun return code 4 (ScheduledStop)

---
 benchmarks/clustering/full_cal_clusters.sh           | 5 +++--
 benchmarks/far_forward/far_forward_protons.sh        | 5 +++--
 benchmarks/far_forward/run_zdc.sh                    | 5 +++--
 benchmarks/imaging_ecal/run_emcal_barrel.sh          | 5 +++--
 benchmarks/imaging_ecal/run_emcal_barrel_pion_rej.sh | 5 +++--
 benchmarks/imaging_ecal/run_imcal_pion0.sh           | 5 +++--
 benchmarks/rich/forward_hadrons.sh                   | 5 +++--
 benchmarks/track_finding/multiple_tracks.sh          | 5 +++--
 benchmarks/track_fitting/single_tracks.sh            | 5 +++--
 benchmarks/tracking/central_electrons.sh             | 5 +++--
 benchmarks/tracking/central_pions.sh                 | 5 +++--
 benchmarks/tracking/multiple_tracks.sh               | 5 +++--
 benchmarks/tracking/run_tracking_benchmarks.py       | 2 +-
 13 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/benchmarks/clustering/full_cal_clusters.sh b/benchmarks/clustering/full_cal_clusters.sh
index 2feb65ae..00c4d0c8 100644
--- a/benchmarks/clustering/full_cal_clusters.sh
+++ b/benchmarks/clustering/full_cal_clusters.sh
@@ -122,8 +122,9 @@ mkdir -p results
 # Run Juggler
 FULL_CAL_OPTION_DIR=benchmarks/clustering/options
 gaudirun.py ${FULL_CAL_OPTION_DIR}/full_cal_reco.py
-if [[ "$?" -ne "0" ]] ; then
-  echo "ERROR running digitization (juggler)"
+status=$?
+if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+  echo "ERROR running juggler, got $status"
   exit 1
 fi
 
diff --git a/benchmarks/far_forward/far_forward_protons.sh b/benchmarks/far_forward/far_forward_protons.sh
index acd693d6..0ac8b16c 100644
--- a/benchmarks/far_forward/far_forward_protons.sh
+++ b/benchmarks/far_forward/far_forward_protons.sh
@@ -98,8 +98,9 @@ if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   # Need to figure out how to pass file name to juggler from the commandline
   gaudirun.py benchmarks/far_forward/options/far_forward_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/far_forward/run_zdc.sh b/benchmarks/far_forward/run_zdc.sh
index e9dc1666..e0285576 100644
--- a/benchmarks/far_forward/run_zdc.sh
+++ b/benchmarks/far_forward/run_zdc.sh
@@ -117,8 +117,9 @@ rootls -t ${JUGGLER_SIM_FILE}
 if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   gaudirun.py benchmarks/far_forward/options/zdc_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/imaging_ecal/run_emcal_barrel.sh b/benchmarks/imaging_ecal/run_emcal_barrel.sh
index 11318440..76f0fdf3 100644
--- a/benchmarks/imaging_ecal/run_emcal_barrel.sh
+++ b/benchmarks/imaging_ecal/run_emcal_barrel.sh
@@ -108,8 +108,9 @@ CB_EMCAL_OPTION_DIR=benchmarks/imaging_ecal/options
 # Run Juggler
 gaudirun.py ${CB_EMCAL_OPTION_DIR}/hybrid_cluster.py
 # gaudirun.py ${CB_EMCAL_OPTION_DIR}/imaging_topocluster.py
-if [[ "$?" -ne "0" ]] ; then
-  echo "ERROR running juggler"
+status=$?
+if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+  echo "ERROR running juggler, got $status"
   exit 1
 fi
 
diff --git a/benchmarks/imaging_ecal/run_emcal_barrel_pion_rej.sh b/benchmarks/imaging_ecal/run_emcal_barrel_pion_rej.sh
index 96a7752a..53bf8f1e 100755
--- a/benchmarks/imaging_ecal/run_emcal_barrel_pion_rej.sh
+++ b/benchmarks/imaging_ecal/run_emcal_barrel_pion_rej.sh
@@ -109,8 +109,9 @@ CB_EMCAL_OPTION_DIR=benchmarks/imaging_ecal/options
 # Run Juggler
 gaudirun.py ${CB_EMCAL_OPTION_DIR}/hybrid_cluster.py
 # gaudirun.py ${CB_EMCAL_OPTION_DIR}/imaging_topocluster.py
-if [[ "$?" -ne "0" ]] ; then
-  echo "ERROR running juggler"
+status=$?
+if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+  echo "ERROR running juggler, got $status"
   exit 1
 fi
 
diff --git a/benchmarks/imaging_ecal/run_imcal_pion0.sh b/benchmarks/imaging_ecal/run_imcal_pion0.sh
index 2c9ff8dd..902bb9f4 100644
--- a/benchmarks/imaging_ecal/run_imcal_pion0.sh
+++ b/benchmarks/imaging_ecal/run_imcal_pion0.sh
@@ -103,8 +103,9 @@ mkdir -p results
 CB_EMCAL_OPTION_DIR=benchmarks/imaging_ecal/options
 # Run Juggler
 gaudirun.py ${CB_EMCAL_OPTION_DIR}/imaging_2dcluster.py
-if [[ "$?" -ne "0" ]] ; then
-  echo "ERROR running juggler"
+status=$?
+if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+  echo "ERROR running juggler, got $status"
   exit 1
 fi
 
diff --git a/benchmarks/rich/forward_hadrons.sh b/benchmarks/rich/forward_hadrons.sh
index edbda5e9..a2193fdc 100644
--- a/benchmarks/rich/forward_hadrons.sh
+++ b/benchmarks/rich/forward_hadrons.sh
@@ -73,8 +73,9 @@ fi
 
 # @TODO changeable simulation file name and detector xml file name
 gaudirun.py benchmarks/rich/options/rich_reco.py
-if [[ "$?" -ne "0" ]] ; then
-  echo "ERROR running juggler"
+status=$?
+if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+  echo "ERROR running juggler, got $status"
   exit 1
 fi
 
diff --git a/benchmarks/track_finding/multiple_tracks.sh b/benchmarks/track_finding/multiple_tracks.sh
index fc1c19c1..923c8b2c 100644
--- a/benchmarks/track_finding/multiple_tracks.sh
+++ b/benchmarks/track_finding/multiple_tracks.sh
@@ -82,8 +82,9 @@ if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   # Need to figure out how to pass file name to juggler from the commandline
   gaudirun.py benchmarks/track_finding/options/track_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/track_fitting/single_tracks.sh b/benchmarks/track_fitting/single_tracks.sh
index 89b8f2cc..50c0578c 100644
--- a/benchmarks/track_fitting/single_tracks.sh
+++ b/benchmarks/track_fitting/single_tracks.sh
@@ -85,8 +85,9 @@ if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   # Need to figure out how to pass file name to juggler from the commandline
   gaudirun.py benchmarks/track_fitting/options/track_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/tracking/central_electrons.sh b/benchmarks/tracking/central_electrons.sh
index d3c3cace..b5a1219b 100644
--- a/benchmarks/tracking/central_electrons.sh
+++ b/benchmarks/tracking/central_electrons.sh
@@ -99,8 +99,9 @@ if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   # Need to figure out how to pass file name to juggler from the commandline
   gaudirun.py benchmarks/tracking/options/track_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/tracking/central_pions.sh b/benchmarks/tracking/central_pions.sh
index 587ec115..fe0e5c17 100644
--- a/benchmarks/tracking/central_pions.sh
+++ b/benchmarks/tracking/central_pions.sh
@@ -98,8 +98,9 @@ if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   # Need to figure out how to pass file name to juggler from the commandline
   gaudirun.py benchmarks/tracking/options/track_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/tracking/multiple_tracks.sh b/benchmarks/tracking/multiple_tracks.sh
index 11500869..398d6855 100644
--- a/benchmarks/tracking/multiple_tracks.sh
+++ b/benchmarks/tracking/multiple_tracks.sh
@@ -99,8 +99,9 @@ if [[ -z "${ANALYSIS_ONLY}" ]] ;
 then
   # Need to figure out how to pass file name to juggler from the commandline
   gaudirun.py benchmarks/tracking/options/track_reconstruction.py
-  if [[ "$?" -ne "0" ]] ; then
-    echo "ERROR running juggler"
+  status=$?
+  if [[ "$status" -ne "0" && "$status" -ne "4" ]] ; then
+    echo "ERROR running juggler, got $status"
     exit 1
   fi
 fi
diff --git a/benchmarks/tracking/run_tracking_benchmarks.py b/benchmarks/tracking/run_tracking_benchmarks.py
index 0cb70daa..b450e199 100755
--- a/benchmarks/tracking/run_tracking_benchmarks.py
+++ b/benchmarks/tracking/run_tracking_benchmarks.py
@@ -83,7 +83,7 @@ if 'rec' in procs:
 
     rec_cmd = ['gaudirun.py', os.path.join(sdir, 'options', option_script)]
     return_code = subprocess.run(rec_cmd).returncode
-    if return_code is not None and return_code != 0:
+    if return_code is not None and return_code < 0:
         print('ERROR running juggler ({})!'.format(rec_cmd))
         exit(1)
     process = subprocess.run(['rootls', '-t', rec_file], check=True)
-- 
GitLab