Skip to content

Commit 7a07215

Browse files
committed
Accelerate spacepoint IO code
This commit drastically speeds up some of our IO code for spacepoints by using a map instead of a vector.
1 parent daa38f3 commit 7a07215

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

io/src/csv/read_spacepoints.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// System include(s).
1919
#include <ranges>
2020
#include <stdexcept>
21+
#include <unordered_map>
2122

2223
namespace traccc::io::csv {
2324

@@ -36,13 +37,14 @@ void read_spacepoints(edm::spacepoint_collection::host& spacepoints,
3637
// Measurement hit id reader
3738
auto mhid_reader =
3839
io::csv::make_measurement_hit_id_reader(meas_hit_map_filename);
39-
std::vector<traccc::io::csv::measurement_hit_id> measurement_hit_ids;
40+
std::unordered_map<std::size_t, traccc::io::csv::measurement_hit_id>
41+
measurement_hit_ids;
4042
traccc::io::csv::measurement_hit_id io_mh_id;
4143
while (mhid_reader.read(io_mh_id)) {
4244
if (sort_measurements) {
4345
io_mh_id.measurement_id = new_idx_map[io_mh_id.measurement_id];
4446
}
45-
measurement_hit_ids.push_back(io_mh_id);
47+
measurement_hit_ids.insert({io_mh_id.hit_id, io_mh_id});
4648
}
4749

4850
// Construct the hit reader object.
@@ -55,14 +57,12 @@ void read_spacepoints(edm::spacepoint_collection::host& spacepoints,
5557
// Find the index of the measurement that this hit/spacepoint belongs
5658
// to. Which may not be valid, as some simulated hits are not associated
5759
// with a measurement.
58-
auto const measurement_id_it = std::ranges::find_if(
59-
measurement_hit_ids.begin(), measurement_hit_ids.end(),
60-
[&](const measurement_hit_id& mh_id) {
61-
return mh_id.hit_id == spacepoints.size();
62-
});
60+
auto const measurement_id_it =
61+
measurement_hit_ids.find(spacepoints.size());
6362
const unsigned int measurement_index =
6463
(measurement_id_it != measurement_hit_ids.end())
65-
? static_cast<unsigned int>(measurement_id_it->measurement_id)
64+
? static_cast<unsigned int>(
65+
measurement_id_it->second.measurement_id)
6666
: static_cast<unsigned int>(-1);
6767

6868
// Create a new spacepoint for the SoA container.

0 commit comments

Comments
 (0)