Warning, file /eic-opticks/tests/test_frontend_repeated_runs.py was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 """Exercise run-end event cleanup after hit output succeeds or cannot open."""
0002 import os
0003 from pathlib import Path
0004 import re
0005 import subprocess
0006 import sys
0007 import tempfile
0008
0009
0010 def main():
0011 binary, geometry, config_dir, mode = sys.argv[1:]
0012 env = os.environ.copy()
0013 env["G4FORCENUMBEROFTHREADS"] = "1"
0014 env["SIMPHONY_CONFIG_DIR"] = config_dir
0015
0016 with tempfile.TemporaryDirectory(dir=Path.cwd()) as directory:
0017 work = Path(directory)
0018 macro = work / "two_runs.mac"
0019 macro.write_text(
0020 "/run/initialize\n"
0021 "/process/optical/scintillation/setStackPhotons false\n"
0022 "/process/optical/cerenkov/setStackPhotons false\n"
0023 "/run/beamOn 1\n/run/beamOn 1\n"
0024 )
0025 output = work / "opticks_hits_output.txt"
0026 if mode == "output_failure":
0027 output.mkdir()
0028 result = subprocess.run(
0029 [binary, "-g", geometry, "-c", "dev", "-m", str(macro)],
0030 cwd=work, env=env, text=True, stdout=subprocess.PIPE,
0031 stderr=subprocess.STDOUT, timeout=90,
0032 )
0033 Path("run.log").write_text(result.stdout)
0034 assert result.returncode == 0, result.stdout
0035 counts = re.findall(r"Opticks: NumHits:\s+(\d+)", result.stdout)
0036 assert len(counts) == 2 and all(int(n) > 0 for n in counts), result.stdout
0037 if mode == "output_failure":
0038 assert result.stdout.count("Error opening output file!") == 2, result.stdout
0039 else:
0040 assert output.is_file() and output.stat().st_size > 0
0041 print(f"{Path(binary).name}: two runs passed ({mode}), hits={counts}")
0042
0043
0044 if __name__ == "__main__":
0045 main()