42 using size_type = traccc::edm::spacepoint_collection::buffer::size_type;
43 constexpr unsigned int invalidIndex = std::numeric_limits<unsigned int>::max();
48 std::vector<unsigned int> clusterToMeas;
49 for (
unsigned int measIdx = 0; measIdx < measToCluster->size(); ++measIdx) {
50 const unsigned int clusterIdx = (*measToCluster)[measIdx];
51 if (clusterIdx == invalidIndex)
continue;
52 if (clusterIdx >= clusterToMeas.size()) clusterToMeas.resize(clusterIdx + 1, invalidIndex);
53 clusterToMeas[clusterIdx] = measIdx;
56 std::vector<SG::ReadHandle<xAOD::SpacePointContainer>> spacePointHandles =
58 size_type nSpacePoints = 0;
59 for (
auto& handle : spacePointHandles) {
61 nSpacePoints += handle->size();
64 << spacePointHandles.size() <<
" containers");
66 std::pmr::memory_resource* hostMR =
m_MRs->hostMR();
68 auto spHostBuffer = std::make_unique<traccc::edm::spacepoint_collection::buffer>(
69 nSpacePoints, hostMR ? *hostMR :
m_MRs->mainMR());
70 hostCopy->setup(*spHostBuffer)->wait();
73 traccc::edm::spacepoint_collection::device spacepoints{*spHostBuffer};
75 auto spToContainer = std::make_unique<std::vector<unsigned int>>(nSpacePoints, invalidIndex);
76 auto spToIndex = std::make_unique<std::vector<unsigned int>>(nSpacePoints, invalidIndex);
80 if (m ==
nullptr || m->index() >= clusterToMeas.size())
return invalidIndex;
81 return clusterToMeas[m->index()];
85 size_type spIndex = 0;
86 for (
unsigned int c = 0; c < spacePointHandles.size(); ++c) {
88 for (
unsigned int j = 0; j < container.size(); ++j) {
91 if (xmeas.empty() || xmeas.front() ==
nullptr) {
93 <<
"' has no associated measurements");
94 return StatusCode::FAILURE;
99 spacePointType =
type;
100 }
else if (
type != spacePointType) {
102 <<
"' is of a different type than the previous space points, "
103 <<
"all input space points must be either pixel or strip");
104 return StatusCode::FAILURE;
107 const unsigned int idx1 = measurementIndexOf(xmeas[0]);
108 const unsigned int idx2 = (xmeas.size() > 1) ? measurementIndexOf(xmeas[1])
109 : traccc::edm::spacepoint_collection::device::INVALID_MEASUREMENT_INDEX;
110 if (idx1 == invalidIndex || (xmeas.size() > 1 && idx2 == invalidIndex)) {
113 return StatusCode::FAILURE;
116 auto sp = spacepoints.at(spIndex);
117 sp.measurement_index_1() = idx1;
118 sp.measurement_index_2() = idx2;
119 sp.global() = {xsp->
x(), xsp->
y(), xsp->
z()};
123 (*spToContainer)[spIndex] = c;
124 (*spToIndex)[spIndex] = j;
132 auto spDeviceBuffer = std::make_unique<traccc::edm::spacepoint_collection::buffer>(
133 spHostBuffer->capacity(),
m_MRs->mainMR());
136 deviceCopy->setup(*spDeviceBuffer)->ignore();
137 (*deviceCopy)(*spHostBuffer, *spDeviceBuffer)->wait();
138 ATH_CHECK(spHandle.record(std::move(spDeviceBuffer)));
140 ATH_CHECK(spHandle.record(std::move(spHostBuffer)));
143 ATH_CHECK(spToContainerHandle.record(std::move(spToContainer)));
145 ATH_CHECK(spToIndexHandle.record(std::move(spToIndex)));
149 ATH_MSG_DEBUG(
"Wrote " << nSpacePoints <<
" spacepoints to '"
151 return StatusCode::SUCCESS;