2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/tools/PackedLinkConversions.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Conversions between PackedLink and ElementLink.
12 namespace SG { namespace detail {
17 * @param dlinks Span over DataLinks.
21 PackedLinkConstConverter<CONT>::PackedLinkConstConverter
22 (const const_DataLink_span& dlinks)
29 * @brief Transform a PackedLink to an ElementLink.
30 * @param plink The link to transform.
34 auto PackedLinkConstConverter<CONT>::operator()
35 (const PackedLinkBase& plink) const -> const value_type
37 unsigned int coll = plink.collection();
38 // We need to special-case this: if there were no non-null links,
39 // then the DataLink collection may not have been filled.
43 #ifdef XAOD_STANDALONE
44 return value_type (m_dlinks.at(coll).key(), plink.index());
46 return value_type (m_dlinks.at(coll), plink.index());
51 //****************************************************************************
56 * @param dlinks Span over DataLinks.
60 PackedLinkVectorConstConverter<CONT>::PackedLinkVectorConstConverter
61 (const const_DataLink_span& dlinks)
68 * @brief Transform a vector of PackedLinks to a span over ElementLinks.
69 * @param velt The vector to transform.
72 template <class VALLOC>
74 auto PackedLinkVectorConstConverter<CONT>::operator()
75 (const std::vector<PackedLink<CONT>, VALLOC>& velt) const -> value_type
77 return value_type (CxxUtils::make_span (velt), m_dlinks);
81 //****************************************************************************
86 * @param container Container holding the variables.
87 * @param auxid The ID of the PackedLink variable.
88 * @param linked_auxid The ID of the linked variable of DataLinks.
92 PackedLinkConverter<CONT>::PackedLinkConverter (AuxVectorData& container,
94 SG::auxid_t linked_auxid)
95 : m_container (container),
96 m_linkedVec (container, auxid),
97 m_dlinks (*container.getDataSpan (linked_auxid))
99 // cppcheck-suppress missingReturn; false positive
104 * @brief Convert a PackedLink to an ElementLink.
105 * @param plink The link to transform.
107 template <class CONT>
108 auto PackedLinkConverter<CONT>::operator() (const PackedLinkBase& plink) const
111 unsigned int coll = plink.collection();
112 // We need to special-case this: if there were no non-null links,
113 // then the DataLink collection may not have been filled.
117 #ifdef XAOD_STANDALONE
118 return value_type (m_dlinks.at(coll).key(), plink.index());
120 return value_type (static_cast<const DLink_t&>(m_dlinks.at(coll)), plink.index());
126 * @brief Convert an ElementLink to a PackedLink.
127 * @param pl The destination PackedLink.
128 * @param link The link to transform.
130 template <class CONT>
131 void PackedLinkConverter<CONT>::set (PackedLinkBase& pl, const value_type& link)
133 pl.setIndex (link.isDefault() ? 0 : link.index());
134 auto [dlindex, cacheValid] = PLVH::findCollection (m_linkedVec,
138 pl.setCollection (dlindex);
139 if (!cacheValid) m_container.clearCache (m_linkedVec->auxid());
144 * @brief Convert a range of ElementLinks to a vector of PackedLinks.
145 * @param plv The destination vector of PackedLinks.
146 * @param r The range of ElementLinks.
148 template <class CONT>
149 template <class VALLOC, ElementLinkRange<CONT> RANGE>
150 void PackedLinkConverter<CONT>::set (std::vector<PLink_t, VALLOC>& plv,
153 if (!PLVH::template assignVElt (plv, *m_linkedVec, m_dlinks, r)) {
154 m_container.clearCache (m_linkedVec->auxid());
160 * @brief Insert a range of ElementLinks into a vector of PackedLinks.
161 * @param plv The destination vector of PackedLinks.
162 * @param pos Position in the container at which to insert the range.
163 * @param r The range of ElementLinks.
165 template <class CONT>
166 template <class VALLOC, ElementLinkRange<CONT> RANGE>
167 void PackedLinkConverter<CONT>::insert (std::vector<PLink_t, VALLOC>& plv,
171 if (!PLVH::template insertVElt (plv, pos, *m_linkedVec, m_dlinks, r)) {
172 m_container.clearCache (m_linkedVec->auxid());
177 } } // namespace SG::detail