From 9f37fa2fcd7dfb08696e80491d197567bde6c324 Mon Sep 17 00:00:00 2001
From: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
Date: Sun, 3 Mar 2024 15:05:49 -0500
Subject: [PATCH] Snakefile: add warmup job to avoid parallel gdml downloads
 (#14)

This is needed to facilitate running benchmarks where downloads may
happen.

https://github.com/eic/epic/pull/588
fails in
https://eicweb.phy.anl.gov/EIC/benchmarks/detector_benchmarks/-/jobs/2627824

This is similar to https://github.com/eic/physics_benchmarks/pull/5
---
 Snakefile                        | 15 +++++++++++++++
 benchmarks/backgrounds/Snakefile |  5 +++--
 benchmarks/ecal_gaps/Snakefile   |  1 +
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Snakefile b/Snakefile
index d72b6952..62c31acd 100644
--- a/Snakefile
+++ b/Snakefile
@@ -21,6 +21,21 @@ include: "benchmarks/backgrounds/Snakefile"
 include: "benchmarks/barrel_ecal/Snakefile"
 include: "benchmarks/ecal_gaps/Snakefile"
 
+
+rule warmup_run:
+    output:
+        "warmup/{DETECTOR_CONFIG}.edm4hep.root",
+    message: "Ensuring that calibrations/fieldmaps are available for {wildcards.DETECTOR_CONFIG}"
+    shell: """
+ddsim \
+  --runType batch \
+  --numberOfEvents 1 \
+  --compactFile "$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml" \
+  --outputFile "{output}" \
+  --enableGun
+"""
+
+
 rule matplotlibrc:
     output:
         ".matplotlibrc",
diff --git a/benchmarks/backgrounds/Snakefile b/benchmarks/backgrounds/Snakefile
index f8991097..300e38b0 100644
--- a/benchmarks/backgrounds/Snakefile
+++ b/benchmarks/backgrounds/Snakefile
@@ -34,7 +34,8 @@ rule backgrounds_get_DIS:
 
 rule backgrounds_sim:
     input:
-        "input/backgrounds/{NAME}.hepmc",
+        hepmc="input/backgrounds/{NAME}.hepmc",
+        warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
     output:
         "sim_output/{DETECTOR_CONFIG}/backgrounds/{NAME}.edm4hep.root",
     log:
@@ -50,7 +51,7 @@ ddsim \
   -v WARNING \
   --numberOfEvents {params.N_EVENTS} \
   --compactFile $DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml \
-  --inputFiles {input} \
+  --inputFiles {input.hepmc} \
   --outputFile {output}
 """
 
diff --git a/benchmarks/ecal_gaps/Snakefile b/benchmarks/ecal_gaps/Snakefile
index 2cf76ec8..a312ac1e 100644
--- a/benchmarks/ecal_gaps/Snakefile
+++ b/benchmarks/ecal_gaps/Snakefile
@@ -4,6 +4,7 @@ import os
 rule ecal_gaps_sim:
     input:
         steering_file=provider.remote(remote_path("EPIC/EVGEN/SINGLE/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.steer")),
+        warmup="warmup/{DETECTOR_CONFIG}.edm4hep.root",
     output:
         "sim_output/{DETECTOR_CONFIG}/{PARTICLE}/{ENERGY}/{PHASE_SPACE}/{PARTICLE}_{ENERGY}_{PHASE_SPACE}.{INDEX}.edm4hep.root",
     log:
-- 
GitLab