From e39baba0ec783fce2a6f71db27995597305e000d Mon Sep 17 00:00:00 2001
From: Whitney Armstrong <warmstrong@anl.gov>
Date: Mon, 7 Jun 2021 19:04:06 +0000
Subject: [PATCH] Fix the benchmarks

- The CI was updated
- a few scripts needed tweaked.
---
 .gitlab-ci.yml                                |  2 +-
 benchmarks/clustering/barrel_clusters.sh      | 23 ++------
 benchmarks/clustering/config.yml              |  5 +-
 benchmarks/ecal/config.yml                    | 59 ++++++-------------
 benchmarks/ecal/emcal_pi0s.sh                 |  2 +-
 .../ecal/options/crystal_calorimeter_reco.py  |  8 +--
 benchmarks/imaging_ecal/config.yml            | 30 ++--------
 .../options/imaging_topocluster.py            |  2 +-
 benchmarks/imaging_ecal/run_emcal_barrel.sh   | 52 +++++++++++++---
 benchmarks/rich/config.yml                    |  8 +--
 10 files changed, 84 insertions(+), 107 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3224176e..dbcc78e1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -65,7 +65,7 @@ include:
 
 final_report:
   stage: finish
-  #needs: ["ecal_1_emcal_crystal_electrons", "tracking_central_electrons","clustering:results"]
+  needs: ["ecal_collect", "tracking_central_electrons","clustering:results"]
   script:
     # disabled while we address ACTS issues
     #- mkdir -p results/views && cd results/views && bash ../../bin/download_views
diff --git a/benchmarks/clustering/barrel_clusters.sh b/benchmarks/clustering/barrel_clusters.sh
index 6e701cc3..4d671c8b 100644
--- a/benchmarks/clustering/barrel_clusters.sh
+++ b/benchmarks/clustering/barrel_clusters.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-./util/print_env.sh
+print_env.sh
 
 ## To run the reconstruction, we need the following global variables:
 ## - JUGGLER_INSTALL_PREFIX:   Install prefix for Juggler (simu/recon)
@@ -10,7 +10,8 @@
 ##
 ## You can ready options/env.sh for more in-depth explanations of the variables
 ## and how they can be controlled.
-source options/env.sh
+
+# deprecated
 export JUGGLER_DETECTOR_PATH=${DETECTOR_PATH}
 
 if [[ ! -n  "${JUGGLER_N_EVENTS}" ]] ; then 
@@ -30,21 +31,8 @@ export JUGGLER_REC_FILE="rec_${JUGGLER_FILE_NAME_TAG}.root"
 echo "JUGGLER_N_EVENTS = ${JUGGLER_N_EVENTS}"
 echo "JUGGLER_DETECTOR = ${JUGGLER_DETECTOR}"
 
-### Build the detector constructors.
-#git clone https://eicweb.phy.anl.gov/EIC/detectors/${JUGGLER_DETECTOR}.git
-#git clone https://eicweb.phy.anl.gov/EIC/detectors/accelerator.git
-#pushd ${JUGGLER_DETECTOR}
-#ln -s ../accelerator/eic
-#popd
-#mkdir ${JUGGLER_DETECTOR}/build
-#pushd ${JUGGLER_DETECTOR}/build
-#cmake ../. -DCMAKE_INSTALL_PREFIX=/usr/local && make -j30 install
-#popd
-
 root -b -q "benchmarks/clustering/scripts/gen_central_electrons.cxx(${JUGGLER_N_EVENTS}, \"${JUGGLER_FILE_NAME_TAG}.hepmc\")"
 
-#pushd ${JUGGLER_DETECTOR}
-#ls -l
 ### run geant4 simulations
 npsim --runType batch \
       --part.minimalKineticEnergy 1000*GeV  \
@@ -59,14 +47,13 @@ if [[ "$?" -ne "0" ]] ; then
 fi
 
 # Need to figure out how to pass file name to juggler from the commandline
-xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv gaudirun.py benchmarks/clustering/options/fullcaloclustering.py
+gaudirun.py benchmarks/clustering/options/fullcalo_clustering.py
 if [[ "$?" -ne "0" ]] ; then
   echo "ERROR running juggler"
   exit 1
 fi
 
-#pwd
-#mkdir -p results/clustering
+mkdir -p results/clustering
 
 #root -b -q "benchmarks/clustering/scripts/barrel_clusters.cxx(\"${JUGGLER_REC_FILE}\")"
 
diff --git a/benchmarks/clustering/config.yml b/benchmarks/clustering/config.yml
index 2cc7fc28..76aab71d 100644
--- a/benchmarks/clustering/config.yml
+++ b/benchmarks/clustering/config.yml
@@ -1,13 +1,12 @@
 clustering:process :
-  allow_failure: true
+  extends: .rec_benchmark
   stage: process
   timeout: 8 hour
-  needs: ["common:detector"]
   script:
     - bash benchmarks/clustering/barrel_clusters.sh
 
 clustering:results:
-  allow_failure: true
+  extends: .rec_benchmark
   stage: collect
   needs: ["clustering:process"]
   script:
diff --git a/benchmarks/ecal/config.yml b/benchmarks/ecal/config.yml
index 87060f13..0632b5cb 100644
--- a/benchmarks/ecal/config.yml
+++ b/benchmarks/ecal/config.yml
@@ -1,65 +1,42 @@
-ecal_1_emcal_crystal_electrons:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
+emcal_crystal_electrons:
+  extends: .rec_benchmark
   stage: process
-  needs: ["common:detector"]
   timeout: 8 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
-        #allow_failure: true
   script:
     - bash benchmarks/ecal/emcal_electrons.sh
 
-ecal_2_emcal_crystal_pi0s:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
-  timeout: 12 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
+emcal_crystal_pi0s:
+  extends: .rec_benchmark
   stage: run
-  #allow_failure: true
+  timeout: 12 hours
   script:
     - bash benchmarks/ecal/emcal_pi0s.sh
 
-ecal_3_emcal_barrel_electrons:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+emcal_barrel_electrons:
+  extends: .rec_benchmark
   timeout: 48 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
-  #allow_failure: true
   script:
     - bash benchmarks/ecal/run_emcal_barrel_electrons.sh
 
-ecal_4_emcal_barrel_pions:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+emcal_barrel_pions:
+  extends: .rec_benchmark
   timeout: 48 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
-  #allow_failure: true
   script:
     - bash benchmarks/ecal/run_emcal_barrel_pions.sh
 
-## Not fully yet...
 full_emcal_barrel_electrons:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+  extends: .rec_benchmark
   timeout: 48 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
-  #allow_failure: true
   script:
     - bash benchmarks/ecal/full_emcal_electrons.sh
+
+ecal_collect:
+  stage: collect
+  needs:
+    - ["emcal_crystal_electrons", "emcal_crystal_pi0s", "emcal_barrel_electrons", "emcal_barrel_pions", "full_emcal_barrel_electrons"]
+  script:
+    - echo "Done collecting artifacts."
+
diff --git a/benchmarks/ecal/emcal_pi0s.sh b/benchmarks/ecal/emcal_pi0s.sh
index fd09b8d8..bed60cd5 100644
--- a/benchmarks/ecal/emcal_pi0s.sh
+++ b/benchmarks/ecal/emcal_pi0s.sh
@@ -58,7 +58,7 @@ if [[ "$?" -ne "0" ]] ; then
 fi
 
 # Need to figure out how to pass file name to juggler from the commandline
-xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv gaudirun.py benchmarks/ecal/options/crystal_calorimeter_reco.py
+gaudirun.py benchmarks/ecal/options/crystal_calorimeter_reco.py
 if [[ "$?" -ne "0" ]] ; then
   echo "ERROR running juggler"
   exit 1
diff --git a/benchmarks/ecal/options/crystal_calorimeter_reco.py b/benchmarks/ecal/options/crystal_calorimeter_reco.py
index 7892b0fb..51b2cf17 100644
--- a/benchmarks/ecal/options/crystal_calorimeter_reco.py
+++ b/benchmarks/ecal/options/crystal_calorimeter_reco.py
@@ -32,7 +32,7 @@ if "JUGGLER_N_EVENTS" in os.environ :
   n_events = str(os.environ["JUGGLER_N_EVENTS"])
 
 geo_service  = GeoSvc("GeoSvc", detectors=["{}/{}.xml".format(detector_path,detector_name)])
-podioevent   = EICDataSvc("EventDataSvc", inputs=[input_sim_file], OutputLevel=DEBUG)
+podioevent   = EICDataSvc("EventDataSvc", inputs=[input_sim_file], OutputLevel=INFO)
 
 from Configurables import PodioInput
 from Configurables import Jug__Base__InputCopier_dd4pod__Geant4ParticleCollection_dd4pod__Geant4ParticleCollection_ as MCCopier
@@ -48,8 +48,8 @@ from Configurables import Jug__Reco__ClusterRecoCoG as RecoCoG
 podioinput = PodioInput("PodioReader", collections=["mcparticles","CrystalEcalHits"], OutputLevel=DEBUG)
 
 ## copiers to get around input --> output copy bug. Note the "2" appended to the output collection.
-copier    = MCCopier("MCCopier", inputCollection="mcparticles", outputCollection="mcparticles2",OutputLevel=DEBUG) 
-calcopier = CalCopier("CalCopier", inputCollection="CrystalEcalHits", outputCollection="CrystalEcalHits2",OutputLevel=DEBUG) 
+copier    = MCCopier("MCCopier", inputCollection="mcparticles", outputCollection="mcparticles2",OutputLevel=INFO) 
+calcopier = CalCopier("CalCopier", inputCollection="CrystalEcalHits", outputCollection="CrystalEcalHits2",OutputLevel=INFO) 
 
 emcaldigi = CrystalEndcapsDigi("ecal_digi", 
         inputHitCollection="CrystalEcalHits", 
@@ -81,5 +81,5 @@ ApplicationMgr(
     EvtSel = 'NONE',
     EvtMax   = n_events,
     ExtSvc = [podioevent],
-    OutputLevel=DEBUG
+    OutputLevel=INFO
  )
diff --git a/benchmarks/imaging_ecal/config.yml b/benchmarks/imaging_ecal/config.yml
index 958d0d17..13b684f8 100644
--- a/benchmarks/imaging_ecal/config.yml
+++ b/benchmarks/imaging_ecal/config.yml
@@ -1,39 +1,21 @@
 imaging_ecal_electrons:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+  extends: .rec_benchmark
   timeout: 48 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
   script:
-    - bash benchmarks/imaging_ecal/run_emcal_barrel.sh -t emcal_barrel_electrons -p "electron" -n 1000
-      #allow_failure: true
+    - bash benchmarks/imaging_ecal/run_emcal_barrel.sh -t emcal_barrel_electrons -p "electron" -n 100
 
 imaging_ecal_photons:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+  extends: .rec_benchmark
   timeout: 48 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
   script:
-    - bash benchmarks/imaging_ecal/run_emcal_barrel.sh -t emcal_barrel_photons -p "photon" -n 1000
-      #allow_failure: true
+    - bash benchmarks/imaging_ecal/run_emcal_barrel.sh -t emcal_barrel_photons -p "photon" -n 100
 
 imaging_ecal_pions:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+  extends: .rec_benchmark
   timeout: 48 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
   script:
-    - bash benchmarks/imaging_ecal/run_emcal_barrel.sh -t emcal_barrel_pions -p "pion-" -n 1000
-      #allow_failure: true
+    - bash benchmarks/imaging_ecal/run_emcal_barrel.sh -t emcal_barrel_pions -p "pion-" -n 100
 
diff --git a/benchmarks/imaging_ecal/options/imaging_topocluster.py b/benchmarks/imaging_ecal/options/imaging_topocluster.py
index dde4426a..bdcda122 100644
--- a/benchmarks/imaging_ecal/options/imaging_topocluster.py
+++ b/benchmarks/imaging_ecal/options/imaging_topocluster.py
@@ -21,7 +21,7 @@ kwargs['sf'] = float(os.environ.get('CB_EMCAL_SAMP_FRAC', '1.0'))
 kwargs['input'] = os.environ.get('CB_EMCAL_SIM_FILE', '../topside/barrel_pion0_5GeV.root')
 kwargs['output'] = os.environ.get('CB_EMCAL_REC_FILE', 'barrel_pion0_5GeV_cluster.root')
 kwargs['compact'] = os.environ.get('CB_EMCAL_COMPACT_PATH', '../topside/test.xml')
-kwargs['nev'] = int(os.environ.get('CB_EMCAL_NUMEV', 10000))
+kwargs['nev'] = int(os.environ.get('CB_EMCAL_NUMEV', 100))
 
 if kwargs['nev'] < 1:
     f = ROOT.TFile(kwargs['input'])
diff --git a/benchmarks/imaging_ecal/run_emcal_barrel.sh b/benchmarks/imaging_ecal/run_emcal_barrel.sh
index 4157142e..ad7f7ed8 100644
--- a/benchmarks/imaging_ecal/run_emcal_barrel.sh
+++ b/benchmarks/imaging_ecal/run_emcal_barrel.sh
@@ -1,13 +1,51 @@
 #!/bin/bash
 
-while getopts t:p:n: flag
+print_env.sh
+
+function print_the_help {
+  echo "USAGE: ${0} -n <nevents> -t <nametag> -p <particle> "
+  echo "  OPTIONS: "
+  echo "    -n,--nevents     Number of eventsj"
+  echo "    -t,--nametag     name tag"
+  echo "    -p,--particle    particle type" 
+  echo "                     allowed types: pion0, pion+, pion-, kaon0, kaon+, kaon-, proton, neutron, electron, positron, photon"
+  exit 
+}
+
+POSITIONAL=()
+while [[ $# -gt 0 ]]
 do
-    case "${flag}" in
-        t) nametag=${OPTARG};;
-        p) particle=${OPTARG};;
-        n) export CB_EMCAL_NUMEV=${OPTARG};;
-    esac
+  key="$1"
+
+  case $key in
+    -h|--help)
+      shift # past argument
+      print_the_help
+      ;;
+    -t|--nametag)
+      nametag="$2"
+      shift # past argument
+      shift # past value
+      ;;
+    -p|--particle)
+      particle="$2"
+      shift # past argument
+      shift # past value
+      ;;
+    -n|--nevents)
+      export CB_EMCAL_NUMEV=${OPTARG}
+      shift # past argument
+      #shift # past value
+      ;;
+    *)    # unknown option
+      #POSITIONAL+=("$1") # save it in an array for later
+      echo "unknown option $1"
+      print_the_help
+      shift # past argument
+      ;;
+  esac
 done
+set -- "${POSITIONAL[@]}" # restore positional parameters
 
 export CB_EMCAL_COMPACT_PATH=${DETECTOR_PATH}/${JUGGLER_DETECTOR}.xml
 
@@ -70,7 +108,7 @@ CB_EMCAL_OPTION_DIR=benchmarks/imaging_ecal/options
 CB_EMCAL_SCRIPT_DIR=benchmarks/imaging_ecal/scripts
 
 # Run Juggler
-xenv -x ${JUGGLER_INSTALL_PREFIX}/Juggler.xenv gaudirun.py ${CB_EMCAL_OPTION_DIR}/imaging_topocluster.py
+gaudirun.py ${CB_EMCAL_OPTION_DIR}/imaging_topocluster.py
 # gaudirun.py ${CB_EMCAL_OPTION_DIR}/imaging_topocluster.py
 if [[ "$?" -ne "0" ]] ; then
   echo "ERROR running juggler"
diff --git a/benchmarks/rich/config.yml b/benchmarks/rich/config.yml
index dae1855d..3cc8b89f 100644
--- a/benchmarks/rich/config.yml
+++ b/benchmarks/rich/config.yml
@@ -1,14 +1,8 @@
 rich_job_x:
-  image: eicweb.phy.anl.gov:4567/eic/juggler/juggler:$JUGGLER_TAG
-  needs: ["common:detector"]
+  extends: .rec_benchmark
   timeout: 24 hours
-  artifacts:
-    expire_in: 20 weeks
-    paths:
-      - results/
   stage: run
   script:
     - bash benchmarks/rich/forward_hadrons.sh
-      #allow_failure: true
 
 
-- 
GitLab