ATLAS Offline Software
Loading...
Searching...
No Matches
TracccSeedConverterAlg.cxx
Go to the documentation of this file.
1/*
2Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
8
9#include <stdexcept>
10
11namespace ActsTrk {
12
14{
15 ATH_MSG_DEBUG("Initializing.");
16
17 ATH_CHECK(m_hostMR.retrieve());
18 ATH_CHECK(m_copy.retrieve());
19
20 ATH_CHECK(m_inputSPKey.initialize());
21 ATH_CHECK(m_inputSeedsKey.initialize());
22 ATH_CHECK(m_inputSPDeviceKey.initialize());
24
25 ATH_CHECK(m_outputSeedsKey.initialize());
26
27 ATH_MSG_DEBUG("Successfully initialized");
28 return StatusCode::SUCCESS;
29}
30
31
32StatusCode TracccSeedConverterAlg::execute(const EventContext& ctx) const
33{
34 // ---- Retrieve HOST RESIDENT spacepoints (always needed) ----
35 // These are made during the TracccMeasurementConverterAlg therefore the pixel meas index in PixelCluster container
36 // is the same as the pixel spacepoint index in the SpacePoint container
37 auto spacepoints = SG::makeHandle(m_inputSPKey, ctx);
38 ATH_MSG_DEBUG("Read SPs from " << m_inputSPKey.key());
39 ATH_CHECK(spacepoints.isValid());
40
41 // ---- Retrieve mapping from traccc measurement index to pixel spacepoint index (always needed) ----
42 auto measMap = SG::makeHandle(m_inputMeasToPixelSPKey, ctx);
43 ATH_CHECK(measMap.isValid());
44
45 // ---- Retrieve DEVICE resident traccc spacepoints ----
46 // these are made on the GPU, therefore the spacepoint points to measurement index
47 // in the traccc measurement collection on the device,
48 // (reminder: pixel and strip measurements are in the same collection on the device)
49 // which is the NOT the same index in the PixelCluster container
50
51 auto traccc_spacepoints = SG::makeHandle(m_inputSPDeviceKey, ctx);
52 ATH_CHECK(traccc_spacepoints.isValid());
53
54 auto copy = m_copy->copy(ctx);
55
56 traccc::edm::spacepoint_collection::buffer traccc_spacepoints_buffer{
57 copy->get_size(*traccc_spacepoints), m_hostMR->mr()};
58 copy->setup(traccc_spacepoints_buffer)->ignore();
59 (*copy)(*traccc_spacepoints, traccc_spacepoints_buffer)->wait();
60
61 traccc::edm::spacepoint_collection::const_device traccc_sp(
62 traccc_spacepoints_buffer);
63
64 // ---- Retrieve DEVICE resident traccc seeds ----
65 auto seeds = SG::makeHandle(m_inputSeedsKey, ctx);
66 ATH_MSG_DEBUG("Read seeds from " << m_inputSeedsKey.key());
67 ATH_CHECK(seeds.isValid());
68
69 traccc::edm::seed_collection::buffer traccc_seeds_buffer{
70 copy->get_size(*seeds), m_hostMR->mr()};
71 copy->setup(traccc_seeds_buffer)->ignore();
72 (*copy)(*seeds, traccc_seeds_buffer)->wait();
73
74 traccc::edm::seed_collection::const_device traccc_seeds(
75 traccc_seeds_buffer);
76
77 ATH_MSG_DEBUG("Read " << traccc_seeds.size() << " seeds and " << spacepoints->size() << " spacepoints from device and host, respectively.");
78 m_nSP += spacepoints->size();
79 m_nSeeds += traccc_seeds.size();
80
81 // -- Write HOST resident ACTS seed container ----
84
85 ATH_CHECK(seedHandle.record(std::make_unique<ActsTrk::SeedContainer>()));
86 ActsTrk::SeedContainer* seedPtrs = seedHandle.ptr();
87
88 for (size_t st = 0; st < traccc_seeds.size(); ++st) {
89
90 const auto& seed = traccc_seeds.at(st);
91 std::vector<unsigned int> sp_traccc_index{
92 seed.bottom_index(), seed.middle_index(), seed.top_index()};
93
94 std::vector<unsigned int> sp_host_index{
95 std::numeric_limits<unsigned int>::max(),
96 std::numeric_limits<unsigned int>::max(),
97 std::numeric_limits<unsigned int>::max()};
98
99 ATH_MSG_VERBOSE("Traccc seed " << st << " with spacepoints: ");
100 for (int sp = 0; sp < 3; sp++) {
101 const auto& sp_traccc = traccc_sp.at(sp_traccc_index[sp]);
102 const unsigned int measIdx = sp_traccc.measurement_index_1();
103 const unsigned int hostIdx = (*measMap)[measIdx];
104 ATH_CHECK(hostIdx != std::numeric_limits<unsigned int>::max());
105
106 sp_host_index[sp] = hostIdx;
107
108 const auto& sp_host = spacepoints->at(hostIdx);
109 ATH_MSG_VERBOSE(sp_traccc.x() << "," << sp_traccc.y()
110 << "," << sp_traccc.z());
111 ATH_MSG_VERBOSE(sp_host->globalPosition().x() << "," << sp_host->globalPosition().y()
112 << "," << sp_host->globalPosition().z());
113 }
114
115 seedPtrs->push_back(
116 std::array{spacepoints->at(sp_host_index[0]),
117 spacepoints->at(sp_host_index[1]),
118 spacepoints->at(sp_host_index[2])},
119 0.f, 0.f);
120 }
121
122 ATH_MSG_DEBUG(" Seed Container " << m_outputSeedsKey.key()
123 << " created with " << seedPtrs->size() << " seeds");
124
125 return StatusCode::SUCCESS;
126}
127
129{
130 ATH_MSG_DEBUG("Finalizing.");
131
132 ATH_MSG_DEBUG("Received " << m_nSP << " spacepoints and " << m_nSeeds << " seeds.");
133
134 ATH_MSG_DEBUG("Successfully finalized");
135 return StatusCode::SUCCESS;
136}
137
138} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_VERBOSE(x,...)
static Double_t sp
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
ToolHandle< AthDevice::IMemoryResourceTool > m_hostMR
ToolHandle< AthDevice::ICopyTool > m_copy
virtual StatusCode initialize() override
Function initializing the algorithm.
std::atomic< int > m_nSP
The object counters for debug prints in finalize method {.
virtual StatusCode execute(const EventContext &ctx) const override
Function executing the algorithm.
SG::ReadHandleKey< xAOD::SpacePointContainer > m_inputSPKey
virtual StatusCode finalize() override
Function finalizing the algorthm.
SG::ReadHandleKey< traccc::edm::spacepoint_collection::buffer > m_inputSPDeviceKey
SG::ReadHandleKey< traccc::edm::seed_collection::buffer > m_inputSeedsKey
SG::WriteHandleKey< ActsTrk::SeedContainer > m_outputSeedsKey
SG::ReadHandleKey< std::vector< unsigned int > > m_inputMeasToPixelSPKey
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Seed push_back(SpacePointRange spacePoints, float quality, float vertexZ)
std::size_t size() const noexcept