Skip to content

Commit 8a4e6f3

Browse files
committed
Fix dependency handling in test097b_ccmod_coincidences.py
1 parent c3d6d5a commit 8a4e6f3

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

opengate/tests/src/external/coresi/test097b_ccmod_coincidences.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4+
import os
5+
import subprocess
6+
47
from opengate.utility import g4_units
58
import opengate.tests.utility as utility
69
from opengate.actors.coincidences import *
710
import opengate.contrib.compton_camera.macaco as macaco
811
import opengate.contrib.compton_camera.coresi_helpers as ch
912

10-
if __name__ == "__main__":
1113

14+
def main(dependency="test097a_ccmod_simulation.py"):
1215
# get tests paths
1316
paths = utility.get_default_test_paths(
1417
__file__, gate_folder="", output_folder="test097_coresi_ccmod"
1518
)
1619
output_folder = paths.output
17-
data_folder = paths.data
1820

1921
# units
20-
mm = g4_units.mm
21-
cm = g4_units.cm
2222
ns = g4_units.ns
2323

24-
# compute the coincidences
2524
scatt_file = output_folder / "ThrScatt.root"
2625
abs_file = output_folder / "ThrAbs.root"
26+
27+
# The test needs the output of the simulation step.
28+
# When this script is launched via the opengate_tests suite, the
29+
# dependency="test097a_ccmod_simulation.py" signature on main() is used by
30+
# the runner to schedule test097a before test097b. The fallback below is
31+
# only for standalone execution of this script.
32+
if not scatt_file.exists() or not abs_file.exists():
33+
subdir = os.path.dirname(__file__)
34+
print(f"Missing input singles files, running {dependency} first.")
35+
subprocess.call(["python", paths.current / subdir / dependency])
36+
37+
if not scatt_file.exists() or not abs_file.exists():
38+
utility.test_ok(
39+
False,
40+
exceptions=[
41+
f"Required input files were not created: {scatt_file.name}, {abs_file.name}"
42+
],
43+
)
44+
45+
# compute the coincidences
2746
print(f"Computing coincidences from {scatt_file.name} and {abs_file.name}")
2847
merge_file = output_folder / "singles.root"
2948
coinc_file = output_folder / "coincidences.root"
@@ -65,3 +84,17 @@
6584
data_filename = output_folder / "coincidences.dat"
6685
ch.coresi_convert_root_data(cones_filename, "cones", data_filename)
6786
print(f"Data file: {data_filename.name}")
87+
88+
is_ok = (
89+
merge_file.exists()
90+
and coinc_file.exists()
91+
and cones_filename.exists()
92+
and data_filename.exists()
93+
and len(coincidences) > 0
94+
and len(data_cones) > 0
95+
)
96+
utility.test_ok(is_ok)
97+
98+
99+
if __name__ == "__main__":
100+
main()

0 commit comments

Comments
 (0)