Warning, /detector_benchmarks/Snakefile is written in an unsupported language. File is not indexed.
0001 configfile: "snakemake.yml"
0002
0003 import functools
0004 import re
0005 import os
0006 from snakemake.logging import logger
0007
0008 shell.prefix(
0009 f"source {config['DETECTOR_PREFIX']}/bin/thisepic.sh {config['DETECTOR_CONFIG']}; "
0010 f"export ROOT_MAX_THREADS={config['BENCHMARK_N_THREADS']}; "
0011 )
0012
0013
0014 EIC_SINGULARITY_CONTAINER = os.getenv("EIC_SINGULARITY_CONTAINER", "/cvmfs/eic.opensciencegrid.org/singularity/eicweb/eic_xl:nightly")
0015
0016
0017 rule compile_analysis:
0018 input:
0019 lambda wildcards: f"{wildcards.PATH}/{wildcards.FILENAME}.cxx",
0020 output:
0021 "{PATH}/{FILENAME}_cxx.d",
0022 "{PATH}/{FILENAME}_cxx.so",
0023 "{PATH}/{FILENAME}_cxx_ACLiC_dict_rdict.pcm",
0024 singularity: EIC_SINGULARITY_CONTAINER,
0025 shell:
0026 """
0027 root -l -b -q -e '.L {input}+'
0028 """
0029
0030
0031 @functools.cache
0032 def get_spack_package_hash(package_name):
0033 import json
0034 try:
0035 ver_info = json.loads(subprocess.check_output(["spack", "find", "--json", package_name]))
0036 return ver_info[0]["hash"]
0037 except FileNotFoundError as e:
0038 logger.warning("Spack is not installed")
0039 return ""
0040 except subprocess.CalledProcessError as e:
0041 print(e)
0042 return ""
0043
0044
0045 @functools.cache
0046 def find_epic_libraries():
0047 import ctypes.util
0048 # if library is not found (not avaliable) we return an empty list to let DAG still evaluate
0049 libs = []
0050 lib = ctypes.util.find_library("epic")
0051 if lib is not None:
0052 libs.append(config["DETECTOR_PREFIX"] + "/lib/" + lib)
0053 return libs
0054
0055
0056 @functools.cache
0057 def gun_energy(energy):
0058 """Convert an energy wildcard such as "500MeV" to a DD4hep expression such as "500*MeV"."""
0059 m = re.fullmatch(r"([0-9.]+)([kMGT]?eV)", energy)
0060 if m is None:
0061 raise ValueError(f"Cannot parse energy {energy!r}")
0062 return f"{m.group(1)}*{m.group(2)}"
0063
0064
0065 @functools.cache
0066 def gun_theta_range(phase_space):
0067 """Convert a phase space wildcard such as "130to177deg" to its (min, max) polar angle in degrees."""
0068 m = re.fullmatch(r"([0-9.]+)to([0-9.]+)deg", phase_space)
0069 if m is None:
0070 raise ValueError(f"Cannot parse phase space {phase_space!r}")
0071 return m.group(1), m.group(2)
0072
0073
0074 def stable_seed(*parts):
0075 """Derive a reproducible, nonzero 31-bit random seed from strings such as wildcard values."""
0076 import zlib
0077 return zlib.crc32("_".join(map(str, parts)).encode()) % (2**31 - 1) + 1
0078
0079
0080 include: "benchmarks/backgrounds/Snakefile"
0081 include: "benchmarks/backwards_ecal/Snakefile"
0082 include: "benchmarks/barrel_ecal/Snakefile"
0083 include: "benchmarks/beamline/Snakefile"
0084 include: "benchmarks/calo_pid/Snakefile"
0085 include: "benchmarks/ecal_gaps/Snakefile"
0086 include: "benchmarks/far_forward_dvcs/Snakefile"
0087 include: "benchmarks/lowq2_reconstruction/Snakefile"
0088 include: "benchmarks/material_scan/Snakefile"
0089 include: "benchmarks/secondary_vertexing_dis/Snakefile"
0090 include: "benchmarks/tracking_performances/Snakefile"
0091 include: "benchmarks/tracking_performances_dis/Snakefile"
0092 include: "benchmarks/lfhcal/Snakefile"
0093 include: "benchmarks/zdc_lyso/Snakefile"
0094 include: "benchmarks/zdc_neutron/Snakefile"
0095 include: "benchmarks/insert_muon/Snakefile"
0096 include: "benchmarks/irt/Snakefile"
0097 include: "benchmarks/zdc_lambda/Snakefile"
0098 include: "benchmarks/zdc_photon/Snakefile"
0099 include: "benchmarks/zdc_pi0/Snakefile"
0100 include: "benchmarks/zdc_sigma/Snakefile"
0101 include: "benchmarks/insert_neutron/Snakefile"
0102 include: "benchmarks/insert_tau/Snakefile"
0103 include: "benchmarks/femc_electron/Snakefile"
0104 include: "benchmarks/femc_photon/Snakefile"
0105 include: "benchmarks/femc_pi0/Snakefile"
0106 include: "benchmarks/nhcal_acceptance/Snakefile"
0107 include: "benchmarks/nhcal_basic_distribution/Snakefile"
0108 include: "benchmarks/nhcal_sampling_fraction/Snakefile"
0109 include: "benchmarks/nhcal_dimuon_photoproduction/Snakefile"
0110 include: "benchmarks/nhcal_pion_rejection/Snakefile"
0111
0112 use_s3 = config["remote_provider"].lower() == "s3"
0113 use_xrootd = config["remote_provider"].lower() == "xrootd"
0114
0115
0116 def get_remote_path(path):
0117 if use_s3:
0118 return f"s3https://eics3.sdcc.bnl.gov:9000/eictest/{path}"
0119 elif use_xrootd:
0120 return f"root://dtn2304.jlab.org:8443//jlab-osdf-ro/eic/EPIC/volatile/{path}"
0121 else:
0122 raise runtime_exception('Unexpected value for config["remote_provider"]: {config["remote_provider"]}')
0123
0124
0125 localrules: fetch_epic
0126
0127 rule fetch_epic:
0128 output:
0129 filepath="EPIC/{PATH}"
0130 params:
0131 # wildcards are not included in hash for caching, we need to add them as params
0132 PATH=lambda wildcards: wildcards.PATH
0133 cache: True
0134 retries: 3
0135 singularity: EIC_SINGULARITY_CONTAINER,
0136 shell: """
0137 xrdcp --debug 2 root://dtn2304.jlab.org:8443//jlab-osdf-ro/eic/EPIC/volatile/{wildcards.PATH} {output.filepath}
0138 """ if use_xrootd else """
0139 mc cp S3/eictest/EPIC/{wildcards.PATH} {output.filepath}
0140 """ if use_s3 else f"""
0141 echo 'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
0142 exit 1
0143 """
0144
0145
0146 rule warmup_run:
0147 output:
0148 "warmup.edm4hep.root",
0149 message: "Ensuring that calibrations/fieldmaps are available"
0150 singularity: EIC_SINGULARITY_CONTAINER,
0151 shell: """
0152 set -m # monitor mode to prevent lingering processes
0153 exec ddsim \
0154 --runType batch \
0155 --numberOfEvents 1 \
0156 --compactFile "$DETECTOR_PATH/epic_ip6.xml" \
0157 --outputFile "{output}" \
0158 --enableGun
0159 """
0160
0161
0162 rule matplotlibrc:
0163 output:
0164 ".matplotlibrc",
0165 run:
0166 with open(output[0], "wt") as fp:
0167 fp.write("backend: Agg\n")
0168 # interactive mode prevents plt.show() from blocking
0169 fp.write("interactive : True\n")
0170
0171
0172 rule org2py:
0173 input:
0174 notebook=lambda wildcards: workflow.source_path(f"{wildcards.NOTEBOOK}.org"),
0175 converter=workflow.source_path("benchmarks/common/org2py.awk"),
0176 output:
0177 "{NOTEBOOK}.org2py.py",
0178 singularity: EIC_SINGULARITY_CONTAINER,
0179 shell:
0180 """
0181 awk -f {input.converter} {input.notebook} > {output}
0182 """
0183
0184
0185 rule metadata:
0186 output:
0187 "results/metadata.json"
0188 shell:
0189 """
0190 cat > {output} <<EOF
0191 {{
0192 "CI_COMMIT_REF_NAME": "${{CI_COMMIT_REF_NAME:-}}",
0193 "CI_COMMIT_SHA": "${{CI_COMMIT_SHA:-}}",
0194 "CI_PIPELINE_ID": "${{CI_PIPELINE_ID:-}}",
0195 "CI_PIPELINE_SOURCE": "${{CI_PIPELINE_SOURCE:-}}",
0196 "CI_PROJECT_ID": "${{CI_PROJECT_ID:-}}",
0197 "GITHUB_REPOSITORY": "${{GITHUB_REPOSITORY:-}}",
0198 "GITHUB_SHA": "${{GITHUB_SHA:-}}",
0199 "GITHUB_PR": "${{GITHUB_PR:-}}",
0200 "PIPELINE_NAME": $(echo "${{PIPELINE_NAME:-}}" | jq -Rs .)
0201 }}
0202 EOF
0203 # validate JSON
0204 jq '.' {output}
0205 """
0206
0207
0208 # Rules whose cache key includes one of these params would only fill the cache with outputs no
0209 # later pipeline can retrieve (e.g. EICRECON_HASH when testing an EICrecon change)
0210 _cache_exclude_params = set(os.environ.get("BENCHMARKS_CACHE_EXCLUDE_PARAMS", "").split())
0211 for _rule in workflow.rules:
0212 if _cache_exclude_params & set(_rule.params.keys()):
0213 # older Snakemake (e.g. 9.6) keeps the cache directive in workflow.cache_rules, newer in rule.cache
0214 if hasattr(_rule, "cache"):
0215 _rule.cache = None
0216 else:
0217 workflow.cache_rules.pop(_rule.name, None)