ATLAS Offline Software
Loading...
Searching...
No Matches
JaggedVecConversions.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
3 */
10
11
13
14
15namespace SG { namespace detail {
16
17
25void JaggedVecProxyBase::resize1 (size_t elt_index, index_type n_new)
26{
27 int n_old = elt (elt_index).size (elt_index);
28 adjust1 (elt_index, n_old, static_cast<int>(n_new) - n_old);
29}
30
31
41void JaggedVecProxyBase::adjust1 (size_t elt_index, index_type index, int n_add)
42{
43 // Return right away if there's nothing to do.
44 if (n_add == 0) return;
45
46 // Find the IAuxTypeVector for the payload variable.
47 IAuxTypeVector* linkedVec;
48 if (m_linkedVec.index() == 0) {
49 // We already have it.
50 linkedVec = std::get<0>(m_linkedVec);
51 }
52 else {
53 // Look it up from the container.
54 SG::auxid_t auxid = std::get<1>(m_linkedVec);
55 linkedVec = m_container.getStore()->linkedVector (auxid);
56
57 // Remember it to possibly use again.
58 m_linkedVec = linkedVec;
59 }
60
61 // Indices from the element that we're modifying.
62 Elt_t& e = elt(elt_index);
63 size_t beg = e.begin(elt_index);
64 size_t end = e.end();
65
66 // Backfill trailing zeros up to the current element if needed.
67 if (end == 0 && m_elts.back().end() == 0) {
68 if (size_t npayload = linkedVec->getDataSpan().size) {
69 Elt_t::Shift shift (npayload);
70 size_t i = elt_index;
71 while (m_elts[i].end() == 0) {
72 if (i == 0) break;
73 --i;
74 }
75 if (m_elts[i].end() != 0) {
76 std::fill (m_elts.data()+i+1, m_elts.data()+elt_index+1, Elt_t(m_elts[i].end()));
77 beg = end = npayload;
78 }
79 }
80 }
81
82 // Shift the payload items.
83 if (!linkedVec->shift (beg+index, n_add)) {
84 m_container.clearCache (linkedVec->auxid());
85 }
86
87 // Adjust the indices in the jagged vector elements.
88 // First the element that we're modifying...
89 e = JaggedVecEltBase (end + n_add);
90 // .. then the remaining elements
92 for (auto pos = m_elts.begin() + elt_index+1; pos < m_elts.end(); ++pos)
93 {
94 if (pos->end() == 0 && (pos-1)->end() == linkedVec->getDataSpan().size) {
95 // Stop if we get to trailing zeros to avoid N^2 behavior.
96 break;
97 }
98 shift (*pos);
99 }
100}
101
102
103} } // namespace SG::detail
Conversions for accessing jagged vector variables.
Abstract interface for manipulating vectors of arbitrary types.
auxid_t auxid() const
Return the auxid of the variable this vector represents.
virtual bool shift(size_t pos, ptrdiff_t offs)=0
Shift the elements of the vector.
const AuxDataSpanBase & getDataSpan() const
Return a reference to a description of this vector's start+size.
Describe one element of a jagged vector (base class).
size_t size(size_t elt_ndx) const
Return the number of items in this range.
typename Elt_t::index_type index_type
Type used for indexing into a jagged vector.
SG::JaggedVecEltBase Elt_t
Type of a jagged vector element.
Elt_t & elt(size_t elt_index) noexcept
Return one jagged vector element (non-const).
void adjust1(size_t elt_index, index_type index, int n_add)
Add or remove payload items from one jagged vector element.
std::variant< IAuxTypeVector *, SG::auxid_t > m_linkedVec
Elt_span m_elts
The elements of the jagged vector.
void resize1(size_t elt_index, index_type n_new)
Resize one jagged vector element.
AuxVectorData & m_container
The container holding the variable.
Forward declaration.
SG::auxid_t auxid() const
Return the aux id for this variable.
virtual void shift(size_t pos, ptrdiff_t offs) override
Shift the elements of the container.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
Definition index.py:1
size_t size
The length of the variable's vector.
Definition AuxDataSpan.h:57
Helper to shift indices.