ATLAS Offline Software
Loading...
Searching...
No Matches
TritonTracccTrackMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8
11
12#include <vecmem/memory/host_memory_resource.hpp>
13#include <vecmem/utils/copy.hpp>
14
15#include <chrono>
16#include <exception>
17#include <memory>
18
20{
21 ATH_CHECK(m_tracccCellsKey.initialize());
22 ATH_CHECK(m_measurementsKey.initialize());
23 ATH_CHECK(m_clustersKey.initialize());
24 ATH_CHECK(m_tracksKey.initialize());
25
26 ATH_CHECK(m_hostMR.retrieve());
28
29 return StatusCode::SUCCESS;
30}
31
32StatusCode TritonTracccTrackMaker::execute(const EventContext& ctx) const
33{
34 // The recorded buffers come from the (caching, shared) host memory
35 // resource; the temporary host containers use a plain one, since the
36 // jagged cluster collection alone is ~10^5 small allocations
37 vecmem::memory_resource& mr = m_hostMR->mr();
38 vecmem::host_memory_resource tmp_mr;
39 // everything here lives in host memory
40 vecmem::copy copy;
41
42 // Serialize the cells produced by RDOtoTracccCellConverterAlg
43 auto cells_handle = SG::makeHandle(m_tracccCellsKey, ctx);
44 ATH_CHECK(cells_handle.isValid());
45
46 traccc::edm::silicon_cell_collection::host cells{tmp_mr};
47 copy(*cells_handle, cells)->wait();
48
49 std::vector<uint8_t> cells_buffer;
50 TracccTriton::serialize(cells, cells_buffer);
51 ATH_MSG_DEBUG("Serialized " << cells.size() << " traccc cells into "
52 << cells_buffer.size() << " bytes");
53
54 // Run the reconstruction on the server
55 auto traccc_start = std::chrono::high_resolution_clock::now();
56 TracccTritonResult result;
57 ATH_CHECK(m_tracccTrackingTool->getTracks(cells_buffer, result));
58 auto traccc_end = std::chrono::high_resolution_clock::now();
59 std::chrono::duration<double, std::milli> traccc_time = traccc_end - traccc_start;
60 ATH_MSG_INFO("Traccc total inference time: " << traccc_time.count() << " ms");
61
62 // Deserialize what came back
63 traccc::edm::measurement_collection::host measurements{tmp_mr};
64 traccc::edm::silicon_cluster_collection::host clusters{tmp_mr};
65 traccc_track_container::host tracks{tmp_mr};
66 TracccTriton::deserialize(result.measurements.data(),
67 result.measurements.size(), measurements);
68 TracccTriton::deserialize(result.clusters.data(),
69 result.clusters.size(), clusters);
70 TracccTriton::deserialize(result.tracks.data(), result.tracks.size(),
71 tracks.tracks);
72 TracccTriton::deserialize(result.trackStates.data(),
73 result.trackStates.size(), tracks.states);
74 ATH_MSG_DEBUG("Received " << measurements.size() << " measurements, "
75 << clusters.size() << " clusters, " << tracks.tracks.size()
76 << " tracks and " << tracks.states.size() << " track states");
77
78 // Record output as host buffers
79 constexpr auto h2h = vecmem::copy::type::host_to_host;
80
81 auto measurementsHandle = SG::makeHandle(m_measurementsKey, ctx);
82 ATH_CHECK(measurementsHandle.record(
83 std::make_unique<traccc::edm::measurement_collection::buffer>(
84 copy.to(vecmem::get_data(measurements), mr, nullptr, h2h))));
85
86 auto clustersHandle = SG::makeHandle(m_clustersKey, ctx);
87 ATH_CHECK(clustersHandle.record(
88 std::make_unique<traccc::edm::silicon_cluster_collection::buffer>(
89 copy.to(vecmem::get_data(clusters), mr, &mr, h2h))));
90
91 auto tracksBuffer = std::make_unique<traccc_track_container::buffer>();
92 tracksBuffer->tracks = copy.to(vecmem::get_data(tracks.tracks), mr, &mr, h2h);
93 tracksBuffer->states = copy.to(vecmem::get_data(tracks.states), mr, nullptr, h2h);
94 tracksBuffer->measurements = *measurementsHandle;
95 auto tracksHandle = SG::makeHandle(m_tracksKey, ctx);
96 ATH_CHECK(tracksHandle.record(std::move(tracksBuffer)));
97
98 return StatusCode::SUCCESS;
99}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_INFO(x,...)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
Byte (de)serialization of vecmem SoA host containers, used to ship traccc EDM collections between the...
SG::WriteHandleKey< traccc::edm::silicon_cluster_collection::buffer > m_clustersKey
SG::WriteHandleKey< traccc_track_container::buffer > m_tracksKey
ToolHandle< AthDevice::IMemoryResourceTool > m_hostMR
virtual StatusCode execute(const EventContext &ctx) const override
SG::WriteHandleKey< traccc::edm::measurement_collection::buffer > m_measurementsKey
SG::ReadHandleKey< traccc::edm::silicon_cell_collection::const_view > m_tracccCellsKey
virtual StatusCode initialize() override
ToolHandle< ITracccTritonTool > m_tracccTrackingTool
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void serialize(const vecmem::edm::host< vecmem::edm::schema< VARTYPES... >, INTERFACE > &container, std::vector< std::uint8_t > &out)
Append container to out in the format described above.
void deserialize(const std::uint8_t *data, std::size_t size, vecmem::edm::host< vecmem::edm::schema< VARTYPES... >, INTERFACE > &container)
Fill container from size bytes at data.
The (serialized) traccc EDM collections returned by the server.