ATLAS Offline Software
Loading...
Searching...
No Matches
RDOtoTracccCellConverterCommons.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
11#include <GaudiKernel/IMessageSvc.h>
12
13#include <algorithm>
14
15namespace ActsTrk {
16
19 : AthMessaging{"RDOtoTracccCellConverterCommons"}
20 , m_parent{parent}
21 , m_tracccCellsKey{&parent, "TracccCells", "", "Output traccc cell collection buffer"}
22 , m_hostMR{&parent, "HostMR", "", "The host memory resource tool to use"}
23 , m_deviceMR{&parent, "DeviceMR", "", "The device memory resource tool to use"}
24 , m_copiesTool{&parent, "CopiesTool", "", "Tool that provides host and device copy objects"}
25 , m_detDescSvc{&parent, "DetectorDescriptionSvc", "ActsTrk::JSONDeviceDetectorDescriptionProviderSvc"}
26 , m_hostCondObjectName{&parent, "HostConditionsObjectName", "",
27 "Traccc host conditions object"}
28 , m_CPUCellSorting{&parent, "CPUCellSorting", false,
29 "Whether to sort traccc cells on CPU or GPU"}
30 , m_UsePixelToTForCellActivation{&parent, "UsePixelToTForCellActivation", true,
31 "Use Pixel hit time over threshold value to set traccc cell activation value, otherwise defaults to 1"}
32{
33}
34
36{
37 ATH_CHECK(m_parent.detStore()->retrieve(m_pixelID, "PixelID"));
38 ATH_CHECK(m_parent.detStore()->retrieve(m_stripID, "SCT_ID"));
39
40 ATH_CHECK(m_hostMR.retrieve());
41 ATH_CHECK(m_tracccCellsKey.initialize());
42 ATH_CHECK(m_copiesTool.retrieve());
43
44 m_athenaToDetray = &m_detDescSvc->athenaToDetrayMap();
45 ATH_CHECK(m_parent.detStore()->retrieve(m_hostCond, m_hostCondObjectName.value()));
46
47 const auto& gids = m_hostCond->geometry_id();
48 m_DetrayIdToDetDescrIndexMap.reserve(gids.size());
49 for (unsigned int i = 0; i < gids.size(); ++i) {
50 m_DetrayIdToDetDescrIndexMap[gids[i].value()] = i;
51 }
52 ATH_MSG_INFO("Built detray→detcond map with "
53 << m_DetrayIdToDetDescrIndexMap.size() << " entries");
54
55 return StatusCode::SUCCESS;
56}
57
59{
60 //TODO: change to DEBUG once we figure how to set the log level of this class
61 // from that of the parent class
62 ATH_MSG_INFO("Read total number of pixel hits = " << m_nPix
63 << ", total number of strip hits = " << m_nStrip
64 << " and created total number of traccc cells = " << m_nCells
65 );
66 return StatusCode::SUCCESS;
67}
68
69traccc::edm::silicon_cell_collection::buffer RDOtoTracccCellConverterCommons::sortCells(
70 vecmem::copy const & host_copy
71 , traccc::edm::silicon_cell_collection::device const & cells
72) const
73{
74 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer{
75 cells.size(), m_hostMR->mr()};
76 host_copy.setup(sorted_cells_host_buffer)->wait();
77 traccc::edm::silicon_cell_collection::device sorted_cells{sorted_cells_host_buffer};
78 sort_traccc_soa(sorted_cells, cells);
79 return sorted_cells_host_buffer;
80}
81
83 EventContext const & ctx
84 , traccc::edm::silicon_cell_collection::buffer const & cells
85) const
86{
87 auto device_copy = m_copiesTool->deviceCopy(ctx);
88 auto traccc_cells_gpu_buffer = std::make_unique<traccc::edm::silicon_cell_collection::buffer>(
89 cells.capacity(), m_deviceMR->mr());
90
91 // We ignore() the setup and wait() on the copy to allow parallelism.
92 device_copy->setup(*traccc_cells_gpu_buffer)->ignore();
93 (*device_copy)(cells, *traccc_cells_gpu_buffer)->wait();
94
95 auto outputTracccCells = SG::makeHandle(m_tracccCellsKey, ctx);
96 ATH_CHECK(outputTracccCells.record(std::move(traccc_cells_gpu_buffer)));
97 return StatusCode::SUCCESS;
98}
99
101 traccc::edm::silicon_cell_collection::device & sorted_cells
102 , traccc::edm::silicon_cell_collection::device const & cells
103 )
104{
105 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
106
107 std::vector<size_type> indices(cells.size());
108 std::iota(indices.begin(), indices.end(), 0u);
109
110 // Sort the indices according to the cells.
111 std::sort(indices.begin(), indices.end(),
112 [&](size_type lhs, size_type rhs) {
113 return cells.at(lhs) < cells.at(rhs);
114 });
115
116 // Fill an output container with the sorted cells.
117 size_type s = 0;
118 for (size_type i : indices) {
119 sorted_cells.at(s++) = cells.at(i);
120 }
121}
122
123} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
An algorithm that can be simultaneously executed in multiple threads.
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...
void sort_traccc_soa(traccc::edm::silicon_cell_collection::device &sorted_cells, traccc::edm::silicon_cell_collection::device const &cells)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
std::unordered_map< uint64_t, unsigned int > m_DetrayIdToDetDescrIndexMap
ToolHandle< AthDevice::IMemoryResourceTool > m_deviceMR
const std::unordered_map< Identifier, uint64_t > * m_athenaToDetray
SG::WriteHandleKey< traccc::edm::silicon_cell_collection::buffer > m_tracccCellsKey
traccc::edm::silicon_cell_collection::buffer sortCells(vecmem::copy const &host_copy, traccc::edm::silicon_cell_collection::device const &cells) const
ToolHandle< AthDevice::ICopiesTool > m_copiesTool
ToolHandle< AthDevice::IMemoryResourceTool > m_hostMR
const traccc::detector_conditions_description::host * m_hostCond
StatusCode copyToGpuAndRecordToSG(EventContext const &ctx, traccc::edm::silicon_cell_collection::buffer const &cells) const
ServiceHandle< ActsTrk::IDeviceDetectorDescriptionProviderSvc > m_detDescSvc