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
0056 use_s3 = config["remote_provider"].lower() == "s3"
0057 use_xrootd = config["remote_provider"].lower() == "xrootd"
0058
0059
0060 def get_remote_path(path):
0061 if use_s3:
0062 return f"s3https://eics3.sdcc.bnl.gov:9000/eictest/{path}"
0063 elif use_xrootd:
0064 return f"root://dtn-eic.jlab.org//volatile/eic/{path}"
0065 else:
0066 raise runtime_exception('Unexpected value for config["remote_provider"]: {config["remote_provider"]}')
0067
0068
0069 rule fetch_epic:
0070 output:
0071 filepath="EPIC/{PATH}"
0072 params:
0073 # wildcards are not included in hash for caching, we need to add them as params
0074 PATH=lambda wildcards: wildcards.PATH
0075 cache: True
0076 retries: 3
0077 shell: """
0078 xrdcp --debug 2 root://dtn-eic.jlab.org//volatile/eic/{output.filepath} {output.filepath}
0079 """ if use_xrootd else """
0080 mc cp S3/eictest/{output.filepath} {output.filepath}
0081 """ if use_s3 else f"""
0082 echo 'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
0083 exit 1
0084 """
0085
0086
0087 rule warmup_run:
0088 output:
0089 "warmup/{DETECTOR_CONFIG}.edm4hep.root",
0090 message: "Ensuring that calibrations/fieldmaps are available for {wildcards.DETECTOR_CONFIG}"
0091 shell: """
0092 set -m # monitor mode to prevent lingering processes
0093 exec ddsim \
0094 --runType batch \
0095 --numberOfEvents 1 \
0096 --compactFile "$DETECTOR_PATH/{wildcards.DETECTOR_CONFIG}.xml" \
0097 --outputFile "{output}" \
0098 --enableGun
0099 """
0100
0101
0102 rule matplotlibrc:
0103 output:
0104 ".matplotlibrc",
0105 run:
0106 with open(output[0], "wt") as fp:
0107 fp.write("backend: Agg\n")
0108 # interactive mode prevents plt.show() from blocking
0109 fp.write("interactive : True\n")
0110
0111
0112 rule org2py:
0113 input:
0114 notebook=workflow.basedir + "/{NOTEBOOK}.org",
0115 converter=workflow.source_path("benchmarks/common/org2py.awk"),
0116 output:
0117 "{NOTEBOOK}.py"
0118 shell:
0119 """
0120 awk -f {input.converter} {input.notebook} > {output}
0121 """
0122
0123
0124 rule metadata:
0125 output:
0126 "results/metadata.json"
0127 shell:
0128 """
0129 cat > {output} <<EOF
0130 {{
0131 "CI_COMMIT_REF_NAME": "${{CI_COMMIT_REF_NAME:-}}",
0132 "CI_COMMIT_SHA": "${{CI_COMMIT_SHA:-}}",
0133 "CI_PIPELINE_ID": "${{CI_PIPELINE_ID:-}}",
0134 "CI_PIPELINE_SOURCE": "${{CI_PIPELINE_SOURCE:-}}",
0135 "CI_PROJECT_ID": "${{CI_PROJECT_ID:-}}",
0136 "GITHUB_REPOSITORY": "${{GITHUB_REPOSITORY:-}}",
0137 "GITHUB_SHA": "${{GITHUB_SHA:-}}",
0138 "GITHUB_PR": "${{GITHUB_PR:-}}",
0139 "PIPELINE_NAME": "${{PIPELINE_NAME:-}}"
0140 }}
0141 EOF
0142 # validate JSON
0143 jq '.' {output}
0144 """