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