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#include <cstddef>
15
16namespace ActsTrk {
17
20 : AthMessaging{"RDOtoTracccCellConverterCommons"}
21 , m_parent{parent}
22 , m_tracccCellsKey{&parent, "TracccCells", "", "Output traccc cell collection buffer"}
23 , m_hostMR{&parent, "HostMR", "", "The host memory resource tool to use"}
24 , m_deviceMR{&parent, "DeviceMR", "", "The device memory resource tool to use"}
25 , m_copiesTool{&parent, "CopiesTool", "", "Tool that provides host and device copy objects"}
26 , m_geoIdMappingObjectName{&parent, "GeoIdMappingObjectName", "",
27 "StoreGate name for the detray/acts/athena geo id mapping"}
28 , m_hostCondObjectName{&parent, "HostConditionsObjectName", "",
29 "Traccc host conditions object"}
30 , m_CPUCellSorting{&parent, "CPUCellSorting", false,
31 "Whether to sort traccc cells on CPU or GPU"}
32 , m_UsePixelToTForCellActivation{&parent, "UsePixelToTForCellActivation", true,
33 "Use Pixel hit time over threshold value to set traccc cell activation value, otherwise defaults to 1"}
34 , m_stripRDOTimeBinStr{&parent, "timeBins", "Allowed time bins pattern for Strip RDOs"}
35{
36}
37
39{
40 ATH_CHECK(m_parent.detStore()->retrieve(m_pixelID, "PixelID"));
41 ATH_CHECK(m_parent.detStore()->retrieve(m_stripID, "SCT_ID"));
42
43 ATH_CHECK(m_hostMR.retrieve());
44 ATH_CHECK(m_tracccCellsKey.initialize());
45 ATH_CHECK(m_copiesTool.retrieve());
46
47 ATH_CHECK(m_parent.detStore()->retrieve(m_geoIdMapping, m_geoIdMappingObjectName.value()));
48 ATH_CHECK(m_parent.detStore()->retrieve(m_hostCond, m_hostCondObjectName.value()));
49
50 ATH_MSG_INFO("Built detray→detcond map with "
51 << m_DetrayIdToDetDescrIndexMap.size() << " entries");
52
54
55 return StatusCode::SUCCESS;
56}
57
59{
60
61 const auto& gids = m_hostCond->geometry_id();
62 // NOTE: m_DetrayIdToDetDescrIndexMap is built once here;
63 // meaning it is only valid as long as the geometry does not change.
64 // if the job ever spans multiple IOVs with a
65 // genuinely different geometry_id() payload, this caching strategy
66 // would need to become IOV-aware instead.
67 const_cast<RDOtoTracccCellConverterCommons*>(this)->m_DetrayIdToDetDescrIndexMap.reserve(gids.size());
68 for (unsigned int i = 0; i < gids.size(); ++i) {
69 const_cast<RDOtoTracccCellConverterCommons*>(this)->m_DetrayIdToDetDescrIndexMap[gids[i].value()] = i;
70 }
71 ATH_MSG_INFO("Built detray→detcond map with "
72 << m_DetrayIdToDetDescrIndexMap.size() << " entries");
73
74 return StatusCode::SUCCESS;
75}
76
78{
79 //TODO: change to DEBUG once we figure how to set the log level of this class
80 // from that of the parent class
81 ATH_MSG_INFO("Read total number of pixel hits = " << m_nPix
82 << ", total number of strip hits = " << m_nStrip
83 << " and created total number of traccc cells = " << m_nCells
84 );
85 return StatusCode::SUCCESS;
86}
87
88traccc::edm::silicon_cell_collection::buffer RDOtoTracccCellConverterCommons::sortCells(
89 vecmem::copy const & host_copy
90 , traccc::edm::silicon_cell_collection::device const & cells
91) const
92{
93 traccc::edm::silicon_cell_collection::buffer sorted_cells_host_buffer{
94 cells.size(), m_hostMR->mr()};
95 host_copy.setup(sorted_cells_host_buffer)->wait();
96 traccc::edm::silicon_cell_collection::device sorted_cells{sorted_cells_host_buffer};
97 sort_traccc_soa(sorted_cells, cells);
98 return sorted_cells_host_buffer;
99}
100
102 EventContext const & ctx
103 , traccc::edm::silicon_cell_collection::buffer const & cells
104) const
105{
106 auto device_copy = m_copiesTool->deviceCopy(ctx);
107 auto traccc_cells_gpu_buffer = std::make_unique<traccc::edm::silicon_cell_collection::buffer>(
108 cells.capacity(), m_deviceMR->mr());
109
110 // We ignore() the setup and wait() on the copy to allow parallelism.
111 device_copy->setup(*traccc_cells_gpu_buffer)->ignore();
112 (*device_copy)(cells, *traccc_cells_gpu_buffer)->wait();
113
114 auto outputTracccCells = SG::makeHandle(m_tracccCellsKey, ctx);
115 ATH_CHECK(outputTracccCells.record(std::move(traccc_cells_gpu_buffer)));
116 return StatusCode::SUCCESS;
117}
118
120 traccc::edm::silicon_cell_collection::device & sorted_cells
121 , traccc::edm::silicon_cell_collection::device const & cells
122 )
123{
124 using size_type = traccc::edm::silicon_cell_collection::buffer::size_type;
125
126 std::vector<size_type> indices(cells.size());
127 std::iota(indices.begin(), indices.end(), 0u);
128
129 // Sort the indices according to the cells.
130 std::sort(indices.begin(), indices.end(),
131 [&](size_type lhs, size_type rhs) {
132 return cells.at(lhs) < cells.at(rhs);
133 });
134
135 // Fill an output container with the sorted cells.
136 size_type s = 0;
137 for (size_type i : indices) {
138 sorted_cells.at(s++) = cells.at(i);
139 }
140}
141
143{
144 static const size_t MAX_BINS = 2;
145 if (m_stripRDOTimeBinStr.size() > MAX_BINS) {
146 ATH_MSG_WARNING("Time bin string has excess characters");
147 }
148
149 for (size_t i = 0; i < MAX_BINS; ++i) {
150 switch (std::toupper(m_stripRDOTimeBinStr[i])) {
151 case 'X': m_stripRDOTimeBinBits[i] = -1; break;
152 case '0': m_stripRDOTimeBinBits[i] = 0; break;
153 case '1': m_stripRDOTimeBinBits[i] = 1; break;
154 default:
155 ATH_MSG_FATAL("Invalid time bin string: " << m_stripRDOTimeBinStr);
156 return StatusCode::FAILURE;
157 }
158 }
159 return StatusCode::SUCCESS;
160}
161
162bool RDOtoTracccCellConverterCommons::passTiming(const std::bitset<3>& timePattern) const
163{
164 // Convert the given timebin to a bit set and test each bit
165 // if bit is -1 (i.e. X) it always passes, otherwise require exact match of 0/1
166 // N.B. bitset has opposite order to the bit pattern we define
167 if (m_stripRDOTimeBinBits[0] != -1 and timePattern.test(2) != static_cast<bool>(m_stripRDOTimeBinBits[0])) return false;
168 if (m_stripRDOTimeBinBits[1] != -1 and timePattern.test(1) != static_cast<bool>(m_stripRDOTimeBinBits[1])) return false;
169 if (m_stripRDOTimeBinBits[2] != -1 and timePattern.test(0) != static_cast<bool>(m_stripRDOTimeBinBits[2])) return false;
170 return true;
171}
172
173} // namespace ActsTrk
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(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
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
bool passTiming(const std::bitset< 3 > &timePattern) 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