ATLAS Offline Software
JaggedVecConversions.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef ATHCONTAINERS_JAGGEDVECCONVERSIONS_H
14 #define ATHCONTAINERS_JAGGEDVECCONVERSIONS_H
15 
16 
24 #include "CxxUtils/concepts.h"
25 #include "CxxUtils/ranges.h"
26 #include <variant>
27 #include <cassert>
28 #include <stdexcept>
29 
30 
31 // For unit testing.
34 
35 
36 namespace SG { namespace detail {
37 
38 
47 template <class PAYLOAD_T>
49 {
50 public:
52  using Payload_t = PAYLOAD_T;
53 
56 
59 
60 
68 
69 
74  const element_type operator() (const JaggedVecEltBase& elt) const;
75 
76 
77 private:
80 
83 };
84 
85 
86 //****************************************************************************
87 
88 
96 {
97 public:
100 
102  using Elt_span = std::span<Elt_t>;
103 
105  using index_type = typename Elt_t::index_type;
106 
107 
115  AuxVectorData& container,
116  SG::auxid_t auxid);
117 
118 
123  Elt_t& elt (size_t elt_index) noexcept;
124 
125 
130  const Elt_t& elt (size_t elt_index) const noexcept;
131 
132 
140  void resize1 (size_t elt_index, index_type n_new);
141 
142 
152  void adjust1 (size_t elt_index, index_type index, int n_add);
153 
154 
155 private:
158 
161 
162  // Holds either a pointer to the @c IAuxTypeVector the variable ID.
163  std::variant<IAuxTypeVector*, SG::auxid_t> m_linkedVec;
164 };
165 
166 
167 //****************************************************************************
168 
169 
176  : public std::ranges::view_base
177 {
178 public:
186  AuxVectorData& container,
187  SG::auxid_t auxid);
188 
189 
190 protected:
191  friend void ::test_JaggedVecProxyValBase(); // For unit testing.
192 
195 };
196 
197 
204  : public std::ranges::view_base
205 {
206 public:
212 
213 
214 protected:
215  friend void ::test_JaggedVecProxyRefBase(); // For unit testing.
216 
219 };
220 
221 
222 //****************************************************************************
223 
224 
248 template <class PAYLOAD_T, class BASE>
250  : public BASE
251 {
252 public:
254  using Payload_t = PAYLOAD_T;
256 
259  using index_type = typename Elt_t::index_type;
261  static_assert (sizeof (Elt_t) == sizeof (SG::JaggedVecElt<Payload_t>));
262 
265  using value_type = std::remove_cv_t<element_type>;
266  using size_type = std::size_t;
267  using difference_type = std::ptrdiff_t;
269  using const_pointer = const element_type*;
272 
274  using iterator = pointer;
276  using reverse_iterator = std::reverse_iterator<iterator>;
277  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
278 
279 
292  {
294  nonnull_iterator (std::nullptr_t) = delete;
295  nonnull_iterator (int) = delete;
296  operator iterator() { return m_it; }
298  };
299 
300 
309  JaggedVecProxyT (size_t elt_index,
311  const AuxDataSpanBase& elts,
312  AuxVectorData& container,
313  SG::auxid_t auxid);
314 
315 
322  JaggedVecProxyT (size_t elt_index,
325 
329  size_t size() const noexcept;
330 
331 
335  bool empty() const noexcept;
336 
337 
342  reference operator[] (size_t i) noexcept;
343 
344 
349  const_reference operator[] (size_t i) const noexcept;
350 
351 
356  reference at (size_t i);
357 
358 
364 
365 
369  reference front() noexcept;
370 
371 
376 
377 
381  reference back() noexcept;
382 
383 
388 
389 
393  iterator begin() noexcept;
394 
395 
399  iterator end() noexcept;
400 
401 
406 
407 
412 
413 
418 
419 
424 
425 
430 
431 
435  reverse_iterator rend() noexcept;
436 
437 
442 
443 
448 
449 
454 
455 
460 
461 
466  template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
467  JaggedVecProxyT& operator= (const RANGE& range);
468 
469 
474 
475 
479  template <class VALLOC>
480  operator std::vector<Payload_t, VALLOC>() const;
481 
482 
488 
489 
493  void clear();
494 
495 
502  void resize (size_t n, const Payload_t& x = Payload_t());
503 
504 
510 
511 
517 
518 
525 
526 
533 
534 
541 
542 
549 
550 
558 
559 
566  void insert (index_type pos, size_t n, const Payload_t& x);
567 
568 
575  template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
576  void insert (nonnull_iterator pos, ITERATOR first, ITERATOR last);
577 
578 
585  template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
586  void insert (index_type pos, ITERATOR first, ITERATOR last);
587 
588 
594  template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
596 
597 
603  template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
605 
606 
611  template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
612  void append_range (const RANGE& range);
613 
614 
618  void pop_back();
619 
620 
626  void assign (size_t n, const Payload_t& x);
627 
628 
634  template <CxxUtils::detail::InputValIterator<PAYLOAD_T> ITERATOR>
635  void assign (ITERATOR first, ITERATOR last);
636 
637 
642  template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
643  void assign_range (const RANGE& range);
644 
645 
646 private:
650  Elt_t& elt() noexcept;
651 
652 
656  const Elt_t& elt() const noexcept;
657 
658 
662  size_t elt_begin() const noexcept;
663 
664 
668  size_t elt_end() const noexcept;
669 
670 
672  size_t m_index;
673 
676 };
677 
678 
679 //****************************************************************************
680 
681 
691 template <class PAYLOAD_T>
693 {
694 public:
696  using Payload_t = PAYLOAD_T;
697 
700 
703 
704 
708 
709 
717  auxid_t auxid,
718  auxid_t linked_auxid);
719 
720 
725  const element_type operator() (const SG::JaggedVecEltBase& elt) const;
726 
727 
733 
734 
735 private:
738 
741 };
742 
743 
744 } } // namespace SG::detail
745 
746 
748 
749 
750 #endif // not ATHCONTAINERS_JAGGEDVECCONVERSIONS_H
SG::detail::JaggedVecProxyT::elt
Elt_t & elt() noexcept
Return a reference to this proxy's element.
base
std::string base
Definition: hcg.cxx:78
SG::detail::JaggedVecProxyT::insert_range
void insert_range(nonnull_iterator pos, const RANGE &range)
Insert a range of items into this jagged vector element.
SG::detail::JaggedVecProxyT::erase
void erase(nonnull_iterator pos)
Erase one item from this jagged vector element.
SG::detail::JaggedVecProxyT::cbegin
const_iterator cbegin() const noexcept
Return a (const) begin iterator.
SG::detail::JaggedVecProxyT
Proxy for jagged vectors.
Definition: JaggedVecConversions.h:251
SG::detail::JaggedVecProxyBase::adjust1
void adjust1(size_t elt_index, index_type index, int n_add)
Add or remove payload items from one jagged vector element.
Definition: JaggedVecConversions.cxx:41
SG::detail::JaggedVecProxyT::end
iterator end() noexcept
Return a (non-const) end iterator.
SG::detail::JaggedVecProxyBase::JaggedVecProxyBase
JaggedVecProxyBase(const AuxDataSpanBase &elts, AuxVectorData &container, SG::auxid_t auxid)
Constructor.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::detail::JaggedVecConstConverter
Helper: Make a span from a jagged vector element.
Definition: JaggedVecConversions.h:49
SG::detail::JaggedVecProxyT::elt_begin
size_t elt_begin() const noexcept
Return the begin payload index of this proxy's element.
SG::detail::JaggedVecProxyT::push_back
void push_back(const Payload_t &x)
Add an item to the end of this jagged vector element.
SG::detail::JaggedVecProxyT::element_type
Payload_t element_type
Standard type aliases.
Definition: JaggedVecConversions.h:264
SG::detail::JaggedVecProxyBase
Base class for jagged vector proxies.
Definition: JaggedVecConversions.h:96
SG::detail::JaggedVecProxyT::resize
void resize(size_t n, const Payload_t &x=Payload_t())
Resize this jagged vector element.
index
Definition: index.py:1
SG::detail::JaggedVecProxyT::JaggedVecProxyT
JaggedVecProxyT(size_t elt_index, Payload_span payload, const AuxDataSpanBase &elts, AuxVectorData &container, SG::auxid_t auxid)
Constructor.
SG::detail::JaggedVecProxyT::Elt_span
JaggedVecProxyBase::Elt_span Elt_span
Definition: JaggedVecConversions.h:260
SG::detail::JaggedVecProxyT::m_index
size_t m_index
Index of the element we're proxying.
Definition: JaggedVecConversions.h:672
SG::detail::JaggedVecConverter::m_payload
Payload_span m_payload
The span over the payload vector.
Definition: JaggedVecConversions.h:740
SG::detail::JaggedVecProxyT::size
size_t size() const noexcept
Return the size of this jagged vector element.
SG::detail::JaggedVecProxyT::asVector
std::vector< Payload_t > asVector() const
Convert this jagged vector element to a vector.
skel.it
it
Definition: skel.GENtoEVGEN.py:423
taskman.template
dictionary template
Definition: taskman.py:317
AuxDataSpan.h
Describe a range over an auxiliary variable, for low-overhead access.
SG::detail::JaggedVecProxyT::insert
void insert(nonnull_iterator pos, const Payload_t &x)
Insert an item into this jagged vector element.
SG::detail::JaggedVecProxyT::append_range
void append_range(const RANGE &range)
Append a range of items to the end of this jagged vector element.
SG::detail::JaggedVecConverter::m_base
JaggedVecProxyBase m_base
The proxy base information.
Definition: JaggedVecConversions.h:737
detail
Definition: extract_histogram_tag.cxx:14
reference
Definition: hcg.cxx:437
SG::detail::AuxDataSpan< Payload_t >
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
SG::detail::JaggedVecProxyT::rend
reverse_iterator rend() noexcept
Return a (non-const) end reverse iterator.
x
#define x
range_with_conv.h
Add to a range class conversions to containers.
SG::detail::JaggedVecProxyT::nonnull_iterator::nonnull_iterator
nonnull_iterator(std::nullptr_t)=delete
SG::detail::JaggedVecProxyBase::Elt_span
std::span< Elt_t > Elt_span
A span of elements.
Definition: JaggedVecConversions.h:102
IAuxTypeVector.h
Abstract interface for manipulating vectors of arbitrary types.
SG::detail::JaggedVecProxyT::const_iterator
const_pointer const_iterator
Definition: JaggedVecConversions.h:275
SG::JaggedVecEltBase
Describe one element of a jagged vector (base class).
Definition: JaggedVecImpl.h:52
CxxUtils::InputRangeOverT
concept InputRangeOverT
Concept for an input range over a given type.
Definition: ranges.h:27
SG::detail::JaggedVecProxyBase::m_elts
Elt_span m_elts
The elements of the jagged vector.
Definition: JaggedVecConversions.h:157
SG::detail::JaggedVecConverter
Helper: Make a span — either read-only or writable — from a jagged vector element.
Definition: JaggedVecConversions.h:693
SG::detail::JaggedVecProxyValBase
Adapter for holding the proxy base information by value.
Definition: JaggedVecConversions.h:177
SG::JaggedVecEltBase::index_type
uint32_t index_type
Type for the indices.
Definition: JaggedVecImpl.h:56
SG::detail::JaggedVecConstConverter::m_payload
const_Payload_span m_payload
The span over the payload vector.
Definition: JaggedVecConversions.h:82
SG::detail::JaggedVecProxyT::rbegin
reverse_iterator rbegin() noexcept
Return a (non-const) begin reverse iterator.
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::detail::JaggedVecProxyBase::m_container
AuxVectorData & m_container
The container holding the variable.
Definition: JaggedVecConversions.h:160
SG::detail::JaggedVecProxyBase::m_linkedVec
std::variant< IAuxTypeVector *, SG::auxid_t > m_linkedVec
Definition: JaggedVecConversions.h:163
SG::detail::JaggedVecConstConverter::Payload_t
PAYLOAD_T Payload_t
The type of the jagged vector payload.
Definition: JaggedVecConversions.h:52
SG::detail::JaggedVecProxyRefBase::m_base
JaggedVecProxyBase & m_base
The proxy base information.
Definition: JaggedVecConversions.h:218
SG::detail::JaggedVecProxyT::begin
iterator begin() noexcept
Return a (non-const) begin iterator.
SG::detail::JaggedVecProxyT::elt_end
size_t elt_end() const noexcept
Return the end payload index of this proxy's element.
SG::detail::AuxDataConstSpan< Payload_t >
lumiFormat.i
int i
Definition: lumiFormat.py:85
JaggedVecConversions.icc
beamspotman.n
n
Definition: beamspotman.py:731
SG::detail::JaggedVecProxyT::index_type
typename Elt_t::index_type index_type
Definition: JaggedVecConversions.h:259
vector
Definition: MultiHisto.h:13
SG::detail::JaggedVecProxyRefBase::JaggedVecProxyRefBase
JaggedVecProxyRefBase(JaggedVecProxyBase &base)
Constructor.
SG::detail::JaggedVecProxyT::const_pointer
const element_type * const_pointer
Definition: JaggedVecConversions.h:269
SG::detail::JaggedVecProxyT::front
reference front() noexcept
Return a reference to the first item in this element's payload.
CxxUtils
Definition: aligned_vector.h:29
SG::detail::JaggedVecProxyBase::elt
Elt_t & elt(size_t elt_index) noexcept
Return one jagged vector element (non-const).
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
AuxDataTraits.h
Allow customizing how aux data types are treated.
SG::detail::JaggedVecProxyT::assign_range
void assign_range(const RANGE &range)
Assign this jagged vector element from a range.
SG::detail::JaggedVecProxyBase::elt
const Elt_t & elt(size_t elt_index) const noexcept
Return one jagged vector element (const).
SG::detail::JaggedVecProxyT::Payload_t
PAYLOAD_T Payload_t
The payload type.
Definition: JaggedVecConversions.h:254
SG::detail::JaggedVecConstConverter::operator()
const element_type operator()(const JaggedVecEltBase &elt) const
Convert to a span.
SG::detail::JaggedVecProxyT::const_reference
const element_type & const_reference
Definition: JaggedVecConversions.h:271
AuxVectorData.h
Manage lookup of vectors of auxiliary data.
SG::detail::JaggedVecConstConverter::m_elts
const JaggedVecEltBase * m_elts
The vector of elements.
Definition: JaggedVecConversions.h:79
SG::detail::JaggedVecProxyBase::resize1
void resize1(size_t elt_index, index_type n_new)
Resize one jagged vector element.
Definition: JaggedVecConversions.cxx:25
SG::AuxDataSpanBase
Minimal span-like object describing the range of an auxiliary variable.
Definition: AuxDataSpan.h:39
SG::detail::JaggedVecProxyT::pop_back
void pop_back()
Remove the last item from this jagged vector element.
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
SG::detail::JaggedVecProxyT::at
reference at(size_t i)
Element access (non-const, bounds-checked).
SG::detail::JaggedVecConverter::Payload_t
PAYLOAD_T Payload_t
The type of the jagged vector payload.
Definition: JaggedVecConversions.h:696
SG::detail::JaggedVecProxyBase::index_type
typename Elt_t::index_type index_type
Type used for indexing into a jagged vector.
Definition: JaggedVecConversions.h:105
test_JaggedVecProxyRefBase
void test_JaggedVecProxyRefBase()
SG::detail::JaggedVecProxyT::nonnull_iterator::nonnull_iterator
nonnull_iterator(iterator it)
Definition: JaggedVecConversions.h:293
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
SG::detail::JaggedVecProxyT::assign
void assign(size_t n, const Payload_t &x)
Set this jagged vector element to a number of items.
SG::detail::JaggedVecProxyT::nonnull_iterator::m_it
iterator m_it
Definition: JaggedVecConversions.h:297
AuxTypes.h
Basic definitions for auxiliary types.
SG::detail::JaggedVecProxyT::size_type
std::size_t size_type
Definition: JaggedVecConversions.h:266
SG::detail::JaggedVecProxyT::empty
bool empty() const noexcept
Test if this jagged vector element is empty.
JaggedVecImpl.h
Definition of JaggedVecElt.
test_JaggedVecProxyValBase
void test_JaggedVecProxyValBase()
concepts.h
Compatibility helpers for using some pieces of C++20 concepts with older compilers.
SG::detail::JaggedVecProxyValBase::m_base
JaggedVecProxyBase m_base
The proxy base information.
Definition: JaggedVecConversions.h:194
SG::detail::JaggedVecProxyT::iterator
pointer iterator
Use pointers as iterators.
Definition: JaggedVecConversions.h:274
DeMoScan.first
bool first
Definition: DeMoScan.py:536
SG::detail::JaggedVecProxyT::nonnull_iterator::nonnull_iterator
nonnull_iterator(int)=delete
SG::JaggedVecElt
Describe one element of a jagged vector.
Definition: JaggedVecImpl.h:132
SG::detail::JaggedVecProxyT::clear
void clear()
Clear this jagged vector element.
SG::detail::JaggedVecProxyValBase::JaggedVecProxyValBase
JaggedVecProxyValBase(const AuxDataSpanBase &elts, AuxVectorData &container, SG::auxid_t auxid)
Constructor.
SG::detail::JaggedVecProxyT::crend
const_reverse_iterator crend() const noexcept
Return a (const) end reverse iterator.
CxxUtils::range_with_conv
Add to a range class conversions to containers.
Definition: range_with_conv.h:33
SG::detail::JaggedVecProxyT::const_reverse_iterator
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: JaggedVecConversions.h:277
SG::detail::JaggedVecProxyT::difference_type
std::ptrdiff_t difference_type
Definition: JaggedVecConversions.h:267
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:168
SG::detail::JaggedVecProxyT::cend
const_iterator cend() const noexcept
Return a (const) end iterator.
ranges.h
C++20 range helpers.
SG::detail::JaggedVecProxyT::nonnull_iterator
Helper for passing iterators.
Definition: JaggedVecConversions.h:292
SG::detail::JaggedVecProxyT::pointer
element_type * pointer
Definition: JaggedVecConversions.h:268
value_type
Definition: EDM_MasterSearch.h:11
SG::detail::JaggedVecProxyT::back
reference back() noexcept
Return a reference to the last item in this element's payload.
SG::detail::JaggedVecProxyRefBase
Adapter for holding the proxy base information by reference.
Definition: JaggedVecConversions.h:205
SG::detail::JaggedVecProxyT::m_payload
Payload_span m_payload
Reference to a span over the payload vector.
Definition: JaggedVecConversions.h:675
SG::detail::JaggedVecProxyT::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Definition: JaggedVecConversions.h:276
SG::detail::JaggedVecConverter::JaggedVecConverter
JaggedVecConverter(AuxVectorData &container, auxid_t auxid, auxid_t linked_auxid)
Constructor.
SG::detail::JaggedVecProxyT::crbegin
const_reverse_iterator crbegin() const noexcept
Return a (const) begin reverse iterator.
SG::detail::JaggedVecProxyBase::Elt_t
SG::JaggedVecEltBase Elt_t
Type of a jagged vector element.
Definition: JaggedVecConversions.h:99
SG::detail::JaggedVecProxyT::JaggedVecProxyT
JaggedVecProxyT(size_t elt_index, Payload_span payload, JaggedVecProxyBase &base)
Constructor.
SG::detail::JaggedVecConstConverter::JaggedVecConstConverter
JaggedVecConstConverter(const JaggedVecEltBase *elts, const_Payload_span payload)
Constructor.