Skip to content

Commit 9558ecd

Browse files
committed
Remove the io roundtrip from the tests
1 parent 302ffa8 commit 9558ecd

19 files changed

+76
-229
lines changed

io/src/read_detector.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,23 @@ void read_detector(host_detector& detector, vecmem::memory_resource& mr,
5858
traccc::io::get_absolute_path(geometry_file));
5959

6060
// TODO: Update this
61-
if (header.detector == "Cylindrical detector from DD4hep blueprint") {
62-
::read_detector<odd_detector>(detector, mr, geometry_file,
63-
material_file, grid_file);
61+
if (header.detector == "telescope_detector") {
62+
::read_detector<traccc::telescope_detector>(detector, mr, geometry_file,
63+
material_file, grid_file);
64+
} else if (header.detector == "toy_detector") {
65+
::read_detector<traccc::toy_detector>(detector, mr, geometry_file,
66+
material_file, grid_file);
67+
} else if (header.detector ==
68+
"Cylindrical detector from DD4hep blueprint") {
69+
::read_detector<traccc::odd_detector>(detector, mr, geometry_file,
70+
material_file, grid_file);
6471
} else if (header.detector == "detray_detector") {
65-
::read_detector<itk_detector>(detector, mr, geometry_file,
66-
material_file, grid_file);
72+
::read_detector<traccc::itk_detector>(detector, mr, geometry_file,
73+
material_file, grid_file);
6774
} else {
6875
// TODO: Warning here
69-
::read_detector<default_detector>(detector, mr, geometry_file,
70-
material_file, grid_file);
76+
::read_detector<traccc::default_detector>(detector, mr, geometry_file,
77+
material_file, grid_file);
7178
}
7279
}
7380

io/src/read_detector_description.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ void read_json_dd(traccc::silicon_detector_description::host& dd,
124124
const auto header = detray::io::detail::deserialize_json_header(
125125
traccc::io::get_absolute_path(geometry_file));
126126

127-
if (header.detector == "Cylindrical detector from DD4hep blueprint") {
127+
if (header.detector == "telescope_detector") {
128+
read_json_dd_impl<traccc::telescope_detector>(dd, detector, digi);
129+
} else if (header.detector == "toy_detector") {
130+
read_json_dd_impl<traccc::toy_detector>(dd, detector, digi);
131+
} else if (header.detector ==
132+
"Cylindrical detector from DD4hep blueprint") {
128133
read_json_dd_impl<traccc::odd_detector>(dd, detector, digi);
129134
} else if (header.detector == "detray_detector") {
130135
read_json_dd_impl<traccc::itk_detector>(dd, detector, digi);

tests/common/tests/kalman_fitting_momentum_resolution_test.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ void KalmanFittingMomentumResolutionTests::momentum_resolution_tests(
116116

117117
void KalmanFittingMomentumResolutionTests::SetUp() {
118118

119-
vecmem::host_memory_resource host_mr;
120-
121119
const scalar offset = std::get<10>(GetParam());
122120
const unsigned int n_planes = std::get<11>(GetParam());
123121
const scalar spacing = std::get<12>(GetParam());
@@ -151,13 +149,7 @@ void KalmanFittingMomentumResolutionTests::SetUp() {
151149
// Create telescope detector
152150
auto [det, name_map] = build_telescope_detector(host_mr, tel_cfg);
153151

154-
// Write detector file
155-
auto writer_cfg = detray::io::detector_writer_config{}
156-
.format(detray::io::format::json)
157-
.replace_files(true)
158-
.write_material(true)
159-
.path(std::get<0>(GetParam()));
160-
detray::io::write_detector(det, name_map, writer_cfg);
152+
detector.set<traccc::telescope_detector>(std::move(det));
161153
}
162154

163155
} // namespace traccc

tests/common/tests/kalman_fitting_momentum_resolution_test.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// Project include(s).
1111
#include "kalman_fitting_test.hpp"
1212
#include "test_detectors.hpp"
13-
14-
// Detray include(s).
15-
#include <detray/io/frontend/detector_writer.hpp>
13+
#include "traccc/geometry/host_detector.hpp"
1614

1715
namespace traccc {
1816

@@ -44,6 +42,12 @@ class KalmanFittingMomentumResolutionTests
4442
detray::material<scalar>, std::array<scalar, 2u>>> {
4543

4644
public:
45+
/// The host memory resource
46+
vecmem::host_memory_resource host_mr;
47+
48+
/// The polymorphic test detector
49+
traccc::host_detector detector;
50+
4751
/// Plane thickness
4852
static constexpr scalar thickness = 0.5f * traccc::unit<scalar>::mm;
4953

tests/common/tests/kalman_fitting_telescope_test.hpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// Project include(s).
1111
#include "kalman_fitting_test.hpp"
1212
#include "test_detectors.hpp"
13-
14-
// Detray include(s).
15-
#include <detray/io/frontend/detector_writer.hpp>
13+
#include "traccc/geometry/host_detector.hpp"
1614

1715
namespace traccc {
1816

@@ -54,6 +52,12 @@ class KalmanFittingTelescopeTests
5452
static constexpr detray::mask<detray::rectangle2D, traccc::default_algebra>
5553
rectangle{0u, 100000.f, 100000.f};
5654

55+
/// The host memory resource
56+
vecmem::host_memory_resource host_mr;
57+
58+
/// The polymorphic test detector
59+
traccc::host_detector detector;
60+
5761
/// Measurement smearing parameters
5862
static constexpr std::array<scalar, 2u> smearing{
5963
50 * traccc::unit<scalar>::um, 50 * traccc::unit<scalar>::um};
@@ -80,8 +84,6 @@ class KalmanFittingTelescopeTests
8084
protected:
8185
virtual void SetUp() override {
8286

83-
vecmem::host_memory_resource host_mr;
84-
8587
const scalar offset = std::get<10>(GetParam());
8688
const unsigned int n_planes = std::get<11>(GetParam());
8789
const scalar spacing = std::get<12>(GetParam());
@@ -103,13 +105,7 @@ class KalmanFittingTelescopeTests
103105
// Create telescope detector
104106
auto [det, name_map] = build_telescope_detector(host_mr, tel_cfg);
105107

106-
// Write detector file
107-
auto writer_cfg = detray::io::detector_writer_config{}
108-
.format(detray::io::format::json)
109-
.replace_files(true)
110-
.write_material(true)
111-
.path(std::get<0>(GetParam()));
112-
detray::io::write_detector(det, name_map, writer_cfg);
108+
detector.set<traccc::telescope_detector>(std::move(det));
113109
}
114110
};
115111

tests/common/tests/kalman_fitting_toy_detector_test.hpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// Project include(s).
1111
#include "kalman_fitting_test.hpp"
1212
#include "test_detectors.hpp"
13-
14-
// Detray include(s).
15-
#include <detray/io/frontend/detector_writer.hpp>
13+
#include "traccc/geometry/host_detector.hpp"
1614

1715
// System include(s)
1816
#include <array>
@@ -47,6 +45,12 @@ class KalmanFittingToyDetectorTests
4745
/// Number of endcap layers
4846
static constexpr inline unsigned int n_endcaps{7u};
4947

48+
/// The host memory resource
49+
vecmem::host_memory_resource host_mr;
50+
51+
/// The polymorphic test detector
52+
traccc::host_detector detector;
53+
5054
/// B field value and its type
5155
static constexpr vector3 B{0, 0, 2 * traccc::unit<scalar>::T};
5256

@@ -71,8 +75,6 @@ class KalmanFittingToyDetectorTests
7175

7276
protected:
7377
virtual void SetUp() override {
74-
vecmem::host_memory_resource host_mr;
75-
7678
detray::toy_det_config<scalar> toy_cfg{};
7779
toy_cfg.n_brl_layers(n_barrels).n_edc_layers(n_endcaps).do_check(false);
7880

@@ -81,14 +83,7 @@ class KalmanFittingToyDetectorTests
8183
detray::build_toy_detector<traccc::default_algebra>(host_mr,
8284
toy_cfg);
8385

84-
// Write detector file
85-
auto writer_cfg = detray::io::detector_writer_config{}
86-
.format(detray::io::format::json)
87-
.replace_files(true)
88-
.write_grids(true)
89-
.write_material(true)
90-
.path(std::get<0>(GetParam()));
91-
detray::io::write_detector(det, name_map, writer_cfg);
86+
detector.set<traccc::toy_detector>(std::move(det));
9287
}
9388
};
9489

tests/common/tests/kalman_fitting_wire_chamber_test.hpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
// Project include(s).
1111
#include "kalman_fitting_test.hpp"
1212
#include "test_detectors.hpp"
13-
14-
// Detray include(s).
15-
#include <detray/io/frontend/detector_writer.hpp>
13+
#include "traccc/geometry/host_detector.hpp"
1614

1715
// System include(s)
1816
#include <array>
@@ -47,6 +45,12 @@ class KalmanFittingWireChamberTests
4745
/// Half z of cylinder
4846
static const inline scalar half_z{2000.f * traccc::unit<scalar>::mm};
4947

48+
/// The host memory resource
49+
vecmem::host_memory_resource host_mr;
50+
51+
/// The polymorphic test detector
52+
traccc::host_detector detector;
53+
5054
/// B field value and its type
5155
static constexpr vector3 B{0, 0, 2 * traccc::unit<scalar>::T};
5256

@@ -82,8 +86,6 @@ class KalmanFittingWireChamberTests
8286

8387
protected:
8488
virtual void SetUp() override {
85-
vecmem::host_memory_resource host_mr;
86-
8789
detray::wire_chamber_config<scalar> wire_chamber_cfg;
8890
wire_chamber_cfg.n_layers(n_wire_layers);
8991
wire_chamber_cfg.half_z(half_z);
@@ -92,14 +94,7 @@ class KalmanFittingWireChamberTests
9294
auto [det, name_map] = build_wire_chamber<traccc::default_algebra>(
9395
host_mr, wire_chamber_cfg);
9496

95-
// Write detector file
96-
auto writer_cfg = detray::io::detector_writer_config{}
97-
.format(detray::io::format::json)
98-
.replace_files(true)
99-
.write_grids(true)
100-
.write_material(true)
101-
.path(std::get<0>(GetParam()));
102-
detray::io::write_detector(det, name_map, writer_cfg);
97+
detector.set<traccc::default_detector>(std::move(det));
10398
}
10499
};
105100

tests/cpu/test_ckf_combinatorics_telescope.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,11 @@ TEST_P(CpuCkfCombinatoricsTelescopeTests, Run) {
5151
const bool random_charge = std::get<9>(GetParam());
5252

5353
/*****************************
54-
* Build a telescope geometry
54+
* Build the magnetic field
5555
*****************************/
5656

57-
// Memory resources used by the application.
58-
vecmem::host_memory_resource host_mr;
59-
6057
// Read back detector file
6158
const std::string path = name + "/";
62-
traccc::host_detector detector;
63-
traccc::io::read_detector(
64-
detector, host_mr,
65-
std::filesystem::absolute(
66-
std::filesystem::path(path + "telescope_detector_geometry.json"))
67-
.native(),
68-
std::filesystem::absolute(
69-
std::filesystem::path(
70-
path + "telescope_detector_homogeneous_material.json"))
71-
.native());
7259

7360
const auto field = traccc::construct_const_bfield(std::get<13>(GetParam()));
7461

tests/cpu/test_ckf_sparse_tracks_telescope.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,26 +60,14 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {
6060
traccc::Logging::Level::INFO));
6161

6262
/*****************************
63-
* Build a telescope geometry
63+
* Build the magnetic field
6464
*****************************/
6565

66-
// Memory resources used by the application.
67-
vecmem::host_memory_resource host_mr;
6866
// Copy obejct
6967
vecmem::copy copy;
7068

7169
// Read back detector file
7270
const std::string path = name + "/";
73-
traccc::host_detector detector;
74-
traccc::io::read_detector(
75-
detector, host_mr,
76-
std::filesystem::absolute(
77-
std::filesystem::path(path + "telescope_detector_geometry.json"))
78-
.native(),
79-
std::filesystem::absolute(
80-
std::filesystem::path(
81-
path + "telescope_detector_homogeneous_material.json"))
82-
.native());
8371

8472
auto field = traccc::construct_const_bfield(std::get<13>(GetParam()));
8573

tests/cpu/test_kalman_fitter_hole_count.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,15 @@ TEST_P(KalmanFittingHoleCountTests, Run) {
5757
ASSERT_EQ(n_events, 1u);
5858

5959
/*****************************
60-
* Build a telescope geometry
60+
* Build the magnetic field
6161
*****************************/
6262

63-
// Memory resources used by the application.
64-
vecmem::host_memory_resource host_mr;
6563
// Copy obejct
6664
vecmem::copy copy;
6765

6866
// Read back detector file
6967
const std::string path = name + "/";
70-
traccc::host_detector detector;
71-
traccc::io::read_detector(
72-
detector, host_mr,
73-
std::filesystem::absolute(
74-
std::filesystem::path(path + "telescope_detector_geometry.json"))
75-
.native(),
76-
std::filesystem::absolute(
77-
std::filesystem::path(
78-
path + "telescope_detector_homogeneous_material.json"))
79-
.native());
68+
8069
auto field = traccc::construct_const_bfield(std::get<13>(GetParam()));
8170

8271
/***************************

0 commit comments

Comments
 (0)