Warning, /detector_benchmarks/Snakefile is written in an unsupported language. File is not indexed.
0001 configfile: "snakemake.yml"
0002
0003 import functools
0004 import os
0005 from snakemake.logging import logger
0006
0007
0008 @functools.cache
0009 def get_spack_package_hash(package_name):
0010 import json
0011 try:
0012 ver_info = json.loads(subprocess.check_output(["spack", "find", "--json", package_name]))
0013 return ver_info[0]["package_hash"]
0014 except FileNotFoundError as e:
0015 logger.warning("Spack is not installed")
0016 return ""
0017 except subprocess.CalledProcessError as e:
0018 print(e)
0019 return ""
0020
0021
0022 @functools.cache
0023 def find_epic_libraries():
0024 import ctypes.util
0025 # if library is not found (not avaliable) we return an empty list to let DAG still evaluate
0026 libs = []
0027 lib = ctypes.util.find_library("epic")
0028 if lib is not None:
0029 libs.append(os.environ["DETECTOR_PATH"] + "/../../lib/" + lib)
0030 return libs
0031
0032
0033 include: "benchmarks/backgrounds/Snakefile"
0034 include: "benchmarks/backwards_ecal/Snakefile"
0035 include: "benchmarks/barrel_ecal/Snakefile"
0036 include: "benchmarks/beamline/Snakefile"
0037 include: "benchmarks/calo_pid/Snakefile"
0038 include: "benchmarks/ecal_gaps/Snakefile"
0039 include: "benchmarks/material_scan/Snakefile"
0040 include: "benchmarks/tracking_performances/Snakefile"
0041 include: "benchmarks/tracking_performances_dis/Snakefile"
0042 include: "benchmarks/lfhcal/Snakefile"
0043 include: "benchmarks/zdc_lyso/Snakefile"
0044 include: "benchmarks/zdc_neutron/Snakefile"
0045 include: "benchmarks/insert_muon/Snakefile"
0046 include: "benchmarks/zdc_lambda/Snakefile"
0047 include: "benchmarks/zdc_photon/Snakefile"
0048 include: "benchmarks/zdc_pi0/Snakefile"
0049 include: "benchmarks/zdc_sigma/Snakefile"
0050 include: "benchmarks/insert_neutron/Snakefile"
0051 include: "benchmarks/insert_tau/Snakefile"
0052 include: "benchmarks/femc_electron/Snakefile"
0053 include: "benchmarks/femc_photon/Snakefile"
0054 include: "benchmarks/femc_pi0/Snakefile"
0055 include: "benchmarks/nhcal_acceptance/Snakefile"
0056 include: "benchmarks/nhcal_basic_distribution/Snakefile"
0057
0058 use_s3 = config["remote_provider"].lower() == "s3"
0059 use_xrootd = config["remote_provider"].lower() == "xrootd"
0060
0061
0062 def get_remote_path(path):
0063 if use_s3:
0064 return f"s3https://eics3.sdcc.bnl.gov:9000/eictest/{path}"
0065 elif use_xrootd:
0066 return f"root://dtn-eic.jlab.org//volatile/eic/{path}"
0067 else:
0068 raise runtime_exception('Unexpected value for config["remote_provider"]: {config["remote_provider"]}')
0069
0070
0071 rule fetch_epic:
0072 output:
0073 filepath="EPIC/{PATH}"
0074 params:
0075 # wildcards are not included in hash for caching, we need to add them as params
0076 PATH=lambda wildcards: wildcards.PATH
0077 cache: True
0078 retries: 3
0079 shell: """
0080 xrdcp --debug 2 root://dtn-eic.jlab.org//volatile/eic/{output.filepath} {output.filepath}
0081 """ if use_xrootd else """
0082 mc cp S3/eictest/{output.filepath} {output.filepath}
0083 """ if use_s3 else f"""
0084 echo 'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
0085 exit 1
0086 """
0087
0088
0089 rule warmup_run:
0090 output:
0091 "warmup/{DETECTOR_CONFIG}.edm4hep.root",
0092 message: "Ensuring that calibrations/fieldmaps are available for {wildcards.DETECTOR_CONFIG}"
0093 shell: """
0094 set -m # monitor mode to prevent lingering processes
0095 exec ddsim \
0096 --runType batch \
0097 --numberOfEvents 1 \
0098 --compactFile "$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml" \
0099 --outputFile "{output}" \
0100 --enableGun
0101 """
0102
0103
0104 rule matplotlibrc:
0105 output:
0106 ".matplotlibrc",
0107 run:
0108 with open(output[0], "wt") as fp:
0109 fp.write("backend: Agg\n")
0110 # interactive mode prevents plt.show() from blocking
0111 fp.write("interactive : True\n")
0112
0113
0114 rule org2py:
0115 input:
0116 notebook=workflow.basedir + "/{NOTEBOOK}.org",
0117 converter=workflow.source_path("benchmarks/common/org2py.awk"),
0118 output:
0119 "{NOTEBOOK}.py"
0120 shell:
0121 """
0122 awk -f {input.converter} {input.notebook} > {output}
0123 """
0124
0125
0126 rule metadata:
0127 output:
0128 "results/metadata.json"
0129 shell:
0130 """
0131 cat > {output} <<EOF
0132 {{
0133 "CI_COMMIT_REF_NAME": "${{CI_COMMIT_REF_NAME:-}}",
0134 "CI_COMMIT_SHA": "${{CI_COMMIT_SHA:-}}",
0135 "CI_PIPELINE_ID": "${{CI_PIPELINE_ID:-}}",
0136 "CI_PIPELINE_SOURCE": "${{CI_PIPELINE_SOURCE:-}}",
0137 "CI_PROJECT_ID": "${{CI_PROJECT_ID:-}}",
0138 "GITHUB_REPOSITORY": "${{GITHUB_REPOSITORY:-}}",
0139 "GITHUB_SHA": "${{GITHUB_SHA:-}}",
0140 "GITHUB_PR": "${{GITHUB_PR:-}}",
0141 "PIPELINE_NAME": "${{PIPELINE_NAME:-}}"
0142 }}
0143 EOF
0144 # validate JSON
0145 jq '.' {output}
0146 """