16 #include "ActsPodioEdm/Track.h"
17 #include "ActsPodioEdm/TrackCollection.h"
18 #include "ActsPodioEdm/TrackInfo.h"
22 #include <type_traits>
24 #include <podio/Frame.h>
28 class MutablePodioTrackContainer;
29 class ConstPodioTrackContainer;
59 template <
bool EnsureConst,
typename T>
62 using namespace Acts::HashedStringLiteral;
63 if constexpr (EnsureConst) {
64 static_assert(std::is_const_v<std::remove_reference_t<T>>,
68 using namespace Acts::HashedStringLiteral;
69 auto track = instance.m_collection->at(itrack);
70 std::conditional_t<EnsureConst,
const ActsPodioEdm::TrackInfo*,
71 ActsPodioEdm::TrackInfo*>
73 if constexpr (EnsureConst) {
74 dataPtr = &track.getData();
76 dataPtr = &track.data();
78 auto&
data = *dataPtr;
81 return &
data.tipIndex;
83 return data.parameters.data();
85 return data.covariance.data();
86 case "nMeasurements"_hash:
87 return &
data.nMeasurements;
94 case "nOutliers"_hash:
95 return &
data.nOutliers;
96 case "nSharedHits"_hash:
97 return &
data.nSharedHits;
99 auto it = instance.m_dynamic.find(key);
100 if (
it == instance.m_dynamic.end()) {
101 throw std::runtime_error(
"Unable to handle this component");
104 std::conditional_t<EnsureConst,
105 const podio_detail::ConstDynamicColumnBase*,
106 podio_detail::DynamicColumnBase*>
107 col =
it->second.get();
108 assert(col &&
"Dynamic column is null");
109 return col->get(itrack);
113 static void populateSurfaceBuffer(
114 const PodioUtil::ConversionHelper& helper,
115 const ActsPodioEdm::TrackCollection& collection,
116 std::vector<std::shared_ptr<const Surface>>& surfaces) noexcept {
117 surfaces.reserve(collection.size());
120 helper, track.getReferenceSurface()));
124 std::reference_wrapper<const PodioUtil::ConversionHelper> m_helper;
125 std::vector<std::shared_ptr<const Surface>>
m_surfaces;
132 m_collection{std::make_unique<ActsPodioEdm::TrackCollection>()} {
133 populateSurfaceBuffer(m_helper, *m_collection,
m_surfaces);
145 std::shared_ptr<const Surface>& ptr =
m_surfaces.at(itrack);
149 track.getReferenceSurface());
156 return PodioTrackContainerBase::component_impl<false>(*
this, key, itrack);
160 return PodioTrackContainerBase::component_impl<true>(*
this, key, itrack);
164 return m_dynamic.find(key) != m_dynamic.end();
167 std::size_t
size_impl()
const {
return m_collection->size(); }
175 std::shared_ptr<const Surface>
surface) {
176 auto track = m_collection->at(itrack);
177 track.setReferenceSurface(
186 auto track = m_collection->create();
189 for (
const auto& [key,
vec] : m_dynamic) {
192 return m_collection->size() - 1;
197 template <
typename T>
200 std::make_unique<podio_detail::DynamicColumn<T>>(key)});
204 return Parameters{m_collection->at(itrack).data().parameters.data()};
209 m_collection->at(itrack).getData().parameters.data()};
213 return Covariance{m_collection->at(itrack).data().covariance.data()};
218 m_collection->at(itrack).getData().covariance.data()};
222 void copyDynamicFrom_impl(
IndexType dstIdx,
237 frame.put(
std::move(m_collection),
"tracks" + s);
240 for (
const auto& [key, col] : m_dynamic) {
241 col->releaseInto(frame,
"tracks" + s +
"_extra__");
252 std::unique_ptr<podio_detail::DynamicColumnBase>>
261 const ActsPodioEdm::TrackCollection& collection)
263 populateSurfaceBuffer(m_helper, *m_collection,
m_surfaces);
266 ConstPodioTrackContainer(
const PodioUtil::ConversionHelper& helper,
267 const podio::Frame& frame,
273 std::vector<std::string> available = frame.getAvailableCollections();
274 if (std::find(available.begin(), available.end(), tracksKey) ==
276 throw std::runtime_error{
"Track collection '" + tracksKey +
277 "'not found in frame"};
280 const auto* collection = frame.get(tracksKey);
283 dynamic_cast<const ActsPodioEdm::TrackCollection*>(collection);
287 throw std::runtime_error{
"Unable to get collection " + tracksKey};
290 populateSurfaceBuffer(m_helper, *m_collection,
m_surfaces);
294 std::tuple<int32_t, int64_t, uint32_t, uint64_t, float, double>;
296 for (
const auto& col : available) {
298 std::size_t
p = col.find(prefix);
299 if (p == std::string::npos) {
303 const podio::CollectionBase* coll = frame.get(col);
305 std::unique_ptr<podio_detail::ConstDynamicColumnBase> up;
309 auto inner = [&](
auto arg) {
313 using T = decltype(arg);
315 dynamic_cast<const podio::UserDataCollection<T>*
>(coll);
316 if (dyn ==
nullptr) {
319 up = std::make_unique<podio_detail::ConstDynamicColumn<T>>(
323 ((inner(
args)), ...);
328 throw std::runtime_error{
"Dynamic column '" + dynName +
329 "' is not of allowed type"};
337 return PodioTrackContainerBase::component_impl<true>(*
this, key, itrack);
341 return m_dynamic.find(key) != m_dynamic.end();
344 std::size_t size_impl()
const {
return m_collection->size(); }
352 m_collection->at(itrack).getData().parameters.data()};
357 m_collection->at(itrack).getData().covariance.data()};
360 const ActsPodioEdm::TrackCollection& trackCollection() {
361 return *m_collection;
369 std::unique_ptr<podio_detail::ConstDynamicColumnBase>>