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 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 include: "benchmarks/backgrounds/Snakefile"
0075 include: "benchmarks/backwards_ecal/Snakefile"
0076 include: "benchmarks/barrel_ecal/Snakefile"
0077 include: "benchmarks/beamline/Snakefile"
0078 include: "benchmarks/calo_pid/Snakefile"
0079 include: "benchmarks/ecal_gaps/Snakefile"
0080 include: "benchmarks/far_forward_dvcs/Snakefile"
0081 include: "benchmarks/lowq2_reconstruction/Snakefile"
0082 include: "benchmarks/material_scan/Snakefile"
0083 include: "benchmarks/secondary_vertexing_dis/Snakefile"
0084 include: "benchmarks/tracking_performances/Snakefile"
0085 include: "benchmarks/tracking_performances_dis/Snakefile"
0086 include: "benchmarks/lfhcal/Snakefile"
0087 include: "benchmarks/zdc_lyso/Snakefile"
0088 include: "benchmarks/zdc_neutron/Snakefile"
0089 include: "benchmarks/insert_muon/Snakefile"
0090 include: "benchmarks/irt/Snakefile"
0091 include: "benchmarks/zdc_lambda/Snakefile"
0092 include: "benchmarks/zdc_photon/Snakefile"
0093 include: "benchmarks/zdc_pi0/Snakefile"
0094 include: "benchmarks/zdc_sigma/Snakefile"
0095 include: "benchmarks/insert_neutron/Snakefile"
0096 include: "benchmarks/insert_tau/Snakefile"
0097 include: "benchmarks/femc_electron/Snakefile"
0098 include: "benchmarks/femc_photon/Snakefile"
0099 include: "benchmarks/femc_pi0/Snakefile"
0100 include: "benchmarks/nhcal_acceptance/Snakefile"
0101 include: "benchmarks/nhcal_basic_distribution/Snakefile"
0102 include: "benchmarks/nhcal_sampling_fraction/Snakefile"
0103 include: "benchmarks/nhcal_dimuon_photoproduction/Snakefile"
0104 include: "benchmarks/nhcal_pion_rejection/Snakefile"
0105 
0106 use_s3 = config["remote_provider"].lower() == "s3"
0107 use_xrootd = config["remote_provider"].lower() == "xrootd"
0108 
0109 
0110 def get_remote_path(path):
0111     if use_s3:
0112         return f"s3https://eics3.sdcc.bnl.gov:9000/eictest/{path}"
0113     elif use_xrootd:
0114         return f"root://dtn2304.jlab.org:8443//jlab-osdf-ro/eic/EPIC/volatile/{path}"
0115     else:
0116         raise runtime_exception('Unexpected value for config["remote_provider"]: {config["remote_provider"]}')
0117 
0118 
0119 localrules: fetch_epic
0120 
0121 rule fetch_epic:
0122     output:
0123         filepath="EPIC/{PATH}"
0124     params:
0125         # wildcards are not included in hash for caching, we need to add them as params
0126         PATH=lambda wildcards: wildcards.PATH
0127     cache: True
0128     retries: 3
0129     singularity: EIC_SINGULARITY_CONTAINER,
0130     shell: """
0131 xrdcp --debug 2 root://dtn2304.jlab.org:8443//jlab-osdf-ro/eic/EPIC/volatile/{wildcards.PATH} {output.filepath}
0132 """ if use_xrootd else """
0133 mc cp S3/eictest/EPIC/{wildcards.PATH} {output.filepath}
0134 """ if use_s3 else f"""
0135 echo 'Unexpected value for config["remote_provider"]: {config["remote_provider"]}'
0136 exit 1
0137 """
0138 
0139 
0140 rule warmup_run:
0141     output:
0142         "warmup.edm4hep.root",
0143     message: "Ensuring that calibrations/fieldmaps are available"
0144     singularity: EIC_SINGULARITY_CONTAINER,
0145     shell: """
0146 set -m # monitor mode to prevent lingering processes
0147 exec ddsim \
0148   --runType batch \
0149   --numberOfEvents 1 \
0150   --compactFile "$DETECTOR_PATH/epic_ip6.xml" \
0151   --outputFile "{output}" \
0152   --enableGun
0153 """
0154 
0155 
0156 rule matplotlibrc:
0157     output:
0158         ".matplotlibrc",
0159     run:
0160         with open(output[0], "wt") as fp:
0161             fp.write("backend: Agg\n")
0162             # interactive mode prevents plt.show() from blocking
0163             fp.write("interactive : True\n")
0164 
0165 
0166 rule org2py:
0167     input:
0168         notebook=lambda wildcards: workflow.source_path(f"{wildcards.NOTEBOOK}.org"),
0169         converter=workflow.source_path("benchmarks/common/org2py.awk"),
0170     output:
0171         "{NOTEBOOK}.org2py.py",
0172     singularity: EIC_SINGULARITY_CONTAINER,
0173     shell:
0174         """
0175 awk -f {input.converter} {input.notebook} > {output}
0176 """
0177 
0178 
0179 rule metadata:
0180     output:
0181         "results/metadata.json"
0182     shell:
0183         """
0184 cat > {output} <<EOF
0185 {{
0186   "CI_COMMIT_REF_NAME": "${{CI_COMMIT_REF_NAME:-}}",
0187   "CI_COMMIT_SHA": "${{CI_COMMIT_SHA:-}}",
0188   "CI_PIPELINE_ID": "${{CI_PIPELINE_ID:-}}",
0189   "CI_PIPELINE_SOURCE": "${{CI_PIPELINE_SOURCE:-}}",
0190   "CI_PROJECT_ID": "${{CI_PROJECT_ID:-}}",
0191   "GITHUB_REPOSITORY": "${{GITHUB_REPOSITORY:-}}",
0192   "GITHUB_SHA": "${{GITHUB_SHA:-}}",
0193   "GITHUB_PR": "${{GITHUB_PR:-}}",
0194   "PIPELINE_NAME": $(echo "${{PIPELINE_NAME:-}}" | jq -Rs .)
0195 }}
0196 EOF
0197 # validate JSON
0198 jq '.' {output}
0199 """