Back to home page

EIC code displayed by LXR

 
 

    


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