ATLAS Offline Software
DataVectorWithAlloc.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-2025 CERN for the benefit of the ATLAS collaboration.
4  */
48 #ifndef ATHCONTAINERS_DATAVECTORWITHALLOC_H
49 #define ATHCONTAINERS_DATAVECTORWITHALLOC_H
50 
51 
56 #include <type_traits>
57 
64 template <class DV, class ALLOC>
66  : private DV
67 {
68 public:
70  typedef typename DV::size_type size_type;
71  typedef typename DV::difference_type difference_type;
72  typedef typename DV::allocator_type allocator_type;
73  typedef typename DV::base_value_type base_value_type;
74  typedef typename DV::BaseContainer BaseContainer;
75  typedef typename DV::DVL_BASE DVL_BASE;
76  typedef typename DV::const_iterator const_iterator;
77  typedef typename DV::const_reverse_iterator const_reverse_iterator;
78  typedef typename DV::value_type value_type;
79  typedef typename DV::const_value_type const_value_type;
80  typedef typename DV::reference reference;
81  typedef typename DV::const_reference const_reference;
82  typedef typename DV::pointer pointer;
83  typedef typename DV::const_pointer const_pointer;
84 
86  typedef ALLOC elt_allocator_type;
87 
88  // Not necessarily DV; DV may be an intermediate class.
90 
92  // cppcheck-suppress duplInheritedMember
93  static const bool has_virtual = DV::has_virtual;
94 
98 
101 
104  typedef typename std::reverse_iterator<iterator>
106 
107  typedef std::true_type isSequence;
108 
110  static constexpr bool must_own = true;
111 
114  using DV::size;
115  using DV::max_size;
116  using DV::resize;
117  using DV::capacity;
118  using DV::empty;
119  using DV::pop_back;
120  using DV::sort;
121  using DV::ownPolicy;
122  using DV::trackIndices;
123  using DV::testInsert;
124  using DV::getConstStore;
125  using DV::setStore;
126  using DV::setConstStore;
127  using DV::setNonConstStore;
128  using DV::hasNonConstStore;
129  using DV::cbegin;
130  using DV::cend;
131  using DV::crbegin;
132  using DV::crend;
133  using DV::do_cast;
134 
135 
139  using DV::begin;
140  using DV::end;
141  using DV::rbegin;
142  using DV::rend;
143  using DV::front;
144  using DV::back;
145  using DV::operator[];
146  using DV::at;
147 
148 
149  //========================================================================
152 
153 private:
157  class UPDeleter
158  {
159  public:
160  UPDeleter() noexcept;
162  void operator() (value_type p);
164  private:
166  };
167 
168 
169 public:
176  class Ptr
177  {
178  using base_ptr = std::unique_ptr<base_value_type, UPDeleter>;
179  public:
180  using pointer = typename base_ptr::pointer;
181  using element_type = typename base_ptr::element_type;
182 
183  Ptr() = default;
184  Ptr(std::nullptr_t) noexcept;
185  Ptr(Ptr&&) = default;
186  operator bool() const noexcept;
187  Ptr& operator= (Ptr&&) noexcept = default;
188  Ptr& operator= (std::nullptr_t) noexcept;
189  void swap (Ptr& other) noexcept;
190  pointer get() const noexcept;
191  typename std::add_lvalue_reference<base_value_type>::type operator*() const;
192  pointer operator->() const noexcept;
193  bool operator== (const Ptr& other) const noexcept;
194  bool operator< (const Ptr& other) const noexcept;
195  bool operator== (std::nullptr_t) const noexcept;
196  bool operator!= (std::nullptr_t) const noexcept;
197 
198 
199  private:
200  // Methods to build a Ptr from a bare pointer or to release a Ptr
201  // to a bare pointer can only be called by the container itself.
202  friend class DataVectorWithAlloc;
203  Ptr (pointer p, UPDeleter&& d) noexcept;
204  pointer release() noexcept;
205  // We're trying to insert this pointer into a container using
206  // heap other_heap. Ensure that that's the same heap we're using;
207  // raise an exception if not.
208  void checkHeap (const elt_allocator_type* other_heap) const;
209 
211  base_ptr m_ptr;
212  };
213 
214 
215  using unique_type = Ptr;
216 
217 
222  : public std::unique_ptr<DataVectorWithAlloc>
223  {
224  public:
225  using Base = std::unique_ptr<DataVectorWithAlloc>;
226  using Base::Base;
227  operator std::unique_ptr<const DV> () && noexcept
228  {
229  return std::unique_ptr<const DV>(this->release()->asDataVector());
230  }
231  };
232 
233 
249  {
251  }
252 
253 
255  //========================================================================
258 
259 
265 
266 
276  elt_allocator_type&& eltAlloc = elt_allocator_type());
277 
278 
279  // Don't allow copying.
282 
283 
294 
295 
306 
307 
312 
313 
318 
319 
324 
325 
327  //========================================================================
330 
331 
339 
340 
347 
348 
350  //========================================================================
353 
354 
365 
366 
377 
378 
388 
389 
399 
400 
402  //========================================================================
405 
406 
416  iterator begin() noexcept;
417 
418 
428  iterator end() noexcept;
429 
430 
441 
442 
452  reverse_iterator rend() noexcept;
453 
454 
456  //========================================================================
459 
460 
471 
472 
484 
485 
498 
499 
509  iterator insert(iterator position, Ptr pElem);
510 
511 
524  iterator emplace(iterator position, Ptr pElem);
525 
526 
528  //========================================================================
531 
532 
541 
542 
553 
554 
560  // cppcheck-suppress duplInheritedMember
561  void clear();
562 
563 
565  //========================================================================
568 
569 
581 
582 
590  static void iter_swap (iterator a, iterator b);
591 
592 
594  //========================================================================
597 
598 
599 
615  void swapElement (size_type index, Ptr newElem, Ptr& oldElem);
616 
617 
633  void swapElement (iterator pos, Ptr newElem, Ptr& oldElem);
634 
635 
640 
641 
648  static
650 
651 
658 
659 
666  const SG::AuxVectorBase& auxbase() const;
667 
668 
674  template <class... Args>
676 
677 
679  //========================================================================
682 
683 
694  bool operator< (const DataVectorWithAlloc& b) const;
695 
697  bool operator> (const DataVectorWithAlloc& b) const;
698 
700  bool operator<= (const DataVectorWithAlloc& b) const;
701 
703  bool operator>= (const DataVectorWithAlloc& b) const;
704 
705 
715  bool operator== (const DataVectorWithAlloc& b) const;
716 
718  bool operator!= (const DataVectorWithAlloc& b) const;
719 
720 
721 
722 private:
724  //========================================================================
727 
728 
731 
732 
741 
742 
748  static
750 
751 
758 
759 
766 
767 
772  : public DV::Deleter
773  {
774  public:
775  using Base = typename DV::Deleter;
776  using value_type = typename Base::value_type;
777  using PtrVector = typename Base::PtrVector;
780  virtual void doDelete (value_type p) override;
781  virtual void doDelete (typename PtrVector::iterator first,
782  typename PtrVector::iterator last) override;
783 
784 
785  private:
787  };
788 
789 
792 };
793 
794 
796 template <class DV, class ALLOC>
797 void swap (DataVectorWithAlloc<DV, ALLOC>& a, DataVectorWithAlloc<DV, ALLOC>& b)
798 {
799  a.swap (b);
800 }
801 
802 
803 
804 #ifndef XAOD_STANDALONE
805 
807 
812 template <class DV, class ALLOC>
814  : public ClassID_traits<DV>
815 {
816 public:
817  static constexpr bool s_isConst = true;
818 };
819 
820 
821 namespace SG {
822 
823 
833 template <class DV, class ALLOC>
835  : public DVLDataBucket<DV>
836 {
837 public:
843 
844 
850 };
851 
852 
860 template <class DV, class ALLOC, class U>
862 {
864  static void init() { DV::dvlinfo(); }
865 };
866 
867 
872 template <class DV, class ALLOC>
873 class BaseInfo<DataVectorWithAlloc<DV, ALLOC> >
874  : public BaseInfo<DV>
875 {
876 };
877 
878 
879 } // namespace SG
880 
881 
882 #endif // not XAOD_STANDALONE
883 
884 
886 
887 
888 #endif // not ATHCONTAINERS_DATAVECTORWITHALLOC_H
DataVectorWithAlloc::const_reference
DV::const_reference const_reference
Definition: DataVectorWithAlloc.h:81
DataVectorWithAlloc::Ptr::Ptr
Ptr(Ptr &&)=default
DataVectorWithAlloc::base_data_vector
DataVector< base_value_type > base_data_vector
Definition: DataVectorWithAlloc.h:89
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
DataVectorWithAlloc::has_virtual
static const bool has_virtual
This needs to be forwarded from the base as well.
Definition: DataVectorWithAlloc.h:93
DataVectorWithAlloc::UPDeleter
Internal helper to serve as a deleter for our unique_ptr class.
Definition: DataVectorWithAlloc.h:158
DataVectorWithAlloc::ContainerUniquePtr
Helper for unique_ptr conversions.
Definition: DataVectorWithAlloc.h:223
DataVectorWithAlloc::auxbase
const SG::AuxVectorBase & auxbase() const
Convert to AuxVectorBase.
PlotCalibFromCool.dv
dv
Definition: PlotCalibFromCool.py:762
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
DataVectorWithAlloc::insert
iterator insert(iterator position, Ptr pElem)
Add a new element to the collection.
DataVectorWithAlloc::ElementProxy
DataModel_detail::ElementProxy< DataVectorWithAlloc > ElementProxy
This type is used to proxy lvalue accesses to DataVector elements, in order to handle ownership.
Definition: DataVectorWithAlloc.h:97
DataVectorWithAlloc::rend
reverse_iterator rend() noexcept
Return a reverse_iterator pointing at the beginning of the collection.
DataVectorWithAlloc::size_type
DV::size_type size_type
Basic types, forwarded from the base.
Definition: DataVectorWithAlloc.h:70
DataVectorWithAlloc::push_new
size_type push_new(size_type n)
Create and add a number of new elements to the end of the container.
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
DataVectorWithAlloc::UPDeleter::UPDeleter
UPDeleter() noexcept
DataVectorWithAlloc::begin
iterator begin() noexcept
Return an iterator pointing at the beginning of the collection.
DataVectorWithAlloc::rbegin
reverse_iterator rbegin() noexcept
Return a reverse_iterator pointing past the end of the collection.
DataVectorWithAlloc::value_type
DV::value_type value_type
Definition: DataVectorWithAlloc.h:78
index
Definition: index.py:1
hist_file_dump.d
d
Definition: hist_file_dump.py:142
DataVectorWithAlloc::HeapDeleter::heap
elt_allocator_type & heap() noexcept
DataVectorWithAlloc::push_back
value_type push_back(Ptr pElem)
Add an element to the end of the collection.
DataVectorWithAlloc
DataVector using a custom allocator for the elements.
Definition: DataVectorWithAlloc.h:67
SG::DVLDataVectorWithAllocBucket::DVLDataVectorWithAllocBucket
DVLDataVectorWithAllocBucket(std::unique_ptr< DataVectorWithAlloc< DV, ALLOC > > data)
Constructor from a payload object.
DataVectorWithAlloc::elt_allocator
elt_allocator_type & elt_allocator()
Return the underlying allocator.
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:407
DataVectorWithAlloc::emplace_back
value_type emplace_back(Ptr pElem)
Add an element to the end of the collection.
taskman.template
dictionary template
Definition: taskman.py:314
DataVectorWithAlloc::to_my_iterator
iterator to_my_iterator(typename DV::iterator it)
Convert an iterator of the base DataVector to a DataVectorWithAlloc::iterator.
DataVectorWithAlloc::iter_swap
static void iter_swap(iterator a, iterator b)
Swap the referents of two DataVector iterators.
DataVectorWithAlloc::const_iterator
DV::const_iterator const_iterator
Definition: DataVectorWithAlloc.h:76
DataVectorWithAlloc::DataVectorWithAlloc
DataVectorWithAlloc(elt_allocator_type &&eltAlloc=elt_allocator_type())
Default constructor.
SG::DVLDataVectorWithAllocBucket::DVLDataVectorWithAllocBucket
DVLDataVectorWithAllocBucket(DataVectorWithAlloc< DV, ALLOC > *data)
Constructor from a payload object.
DataVectorWithAllocFwd.h
DataVectorWithAlloc::BaseContainer
DV::BaseContainer BaseContainer
Definition: DataVectorWithAlloc.h:74
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
DataVectorWithAlloc::front
ElementProxy front()
Access the first element in the collection as an lvalue.
Args
Definition: test_lwtnn_fastgraph.cxx:12
DataVectorWithAlloc::reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
Standard reverse_iterator.
Definition: DataVectorWithAlloc.h:105
DataVectorWithAlloc::back
ElementProxy back()
Access the last element in the collection as an lvalue.
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
DataVectorWithAlloc::at
ElementProxy at(size_type n)
Access an element, as an lvalue.
columnar::rend
auto rend() const noexcept
Definition: ObjectRange.h:164
DataVectorWithAlloc::const_value_type
DV::const_value_type const_value_type
Definition: DataVectorWithAlloc.h:79
SG::DataBucketTrait< DataVectorWithAlloc< DV, ALLOC >, U >::type
SG::DVLDataVectorWithAllocBucket< DV, ALLOC > type
Definition: DataVectorWithAlloc.h:863
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
DataVectorWithAlloc::isSequence
std::true_type isSequence
Definition: DataVectorWithAlloc.h:107
DataVectorWithAlloc::DataVectorWithAlloc
DataVectorWithAlloc(size_type n, elt_allocator_type &&eltAlloc=elt_allocator_type())
Sized constructor.
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
DataVectorWithAlloc::const_reverse_iterator
DV::const_reverse_iterator const_reverse_iterator
Definition: DataVectorWithAlloc.h:77
DataVectorWithAlloc::make_unique
static ContainerUniquePtr make_unique()
Helper for unique_ptr conversions.
Definition: DataVectorWithAlloc.h:248
DataVectorWithAlloc::emplace
iterator emplace(iterator position, Ptr pElem)
Add a new element to the collection.
DataModel_detail::iterator
(Non-const) Iterator class for DataVector/DataList.
Definition: DVLIterator.h:184
DataVectorWithAlloc::operator=
DataVectorWithAlloc & operator=(const DataVectorWithAlloc &rhs)=delete
lumiFormat.i
int i
Definition: lumiFormat.py:85
DataVectorWithAlloc::DataVectorWithAlloc
DataVectorWithAlloc(DataVectorWithAlloc &&rhs)
Move constructor.
DataVectorWithAlloc::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
ClassID_traits.h
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
beamspotman.n
n
Definition: beamspotman.py:727
DataVectorWithAlloc::Ptr::pointer
typename base_ptr::pointer pointer
Definition: DataVectorWithAlloc.h:180
Base
maybeUnprotect.h
Hook for unprotecting an arena.
ClassID_traits
Default, invalid implementation of ClassID_traits.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:37
DataVectorWithAlloc::must_own
static constexpr bool must_own
If true, then this type must own its contents.
Definition: DataVectorWithAlloc.h:110
SG::BaseInfo
Provide an interface for finding inheritance information at run time.
Definition: Control/AthenaKernel/AthenaKernel/BaseInfo.h:751
DataVectorWithAlloc::iterator
DataModel_detail::iterator< DataVectorWithAlloc > iterator
The iterator for this type.
Definition: DataVectorWithAlloc.h:100
DataVectorWithAlloc::Ptr::Ptr
Ptr()=default
DataVectorWithAlloc::ContainerUniquePtr::Base
std::unique_ptr< DataVectorWithAlloc > Base
Definition: DataVectorWithAlloc.h:225
DataVectorWithAlloc::reference
DV::reference reference
Definition: DataVectorWithAlloc.h:80
DataVector
Derived DataVector<T>.
Definition: DataVector.h:795
DataVectorWithAlloc.icc
DataVectorWithAlloc::swap
void swap(DataVectorWithAlloc &rhs)
Swap this collection with another.
DataVectorWithAlloc::elt_allocator
const elt_allocator_type & elt_allocator() const
Return the underlying allocator.
DataModel_detail
Definition: CompareAndPrint.h:15
DataVectorWithAlloc::resortAux
void resortAux(iterator beg, iterator end)
Reset indices / reorder aux data after elements have been permuted.
DataVectorWithAlloc::to_base_iterator
static DV::iterator to_base_iterator(iterator it)
Convert a DataVectorWithAlloc::iterator to an iterator of the base DataVector.
DataVectorWithAlloc::fromDataVector
static const DataVectorWithAlloc * fromDataVector(const DV *dv)
Cast from a DataVector to a DataVectorWithAlloc.
python.EventInfoMgtInit.release
release
Definition: EventInfoMgtInit.py:23
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
DataVectorWithAlloc::Ptr::element_type
typename base_ptr::element_type element_type
Definition: DataVectorWithAlloc.h:181
DataVectorWithAlloc::to_element_proxy
ElementProxy to_element_proxy(typename BaseContainer::iterator i)
Convert an iterator of the base vector to an ElementProxy for the DataVectorWithAlloc.
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
DataVectorWithAlloc::allocator_type
DV::allocator_type allocator_type
Definition: DataVectorWithAlloc.h:72
DataVectorWithAlloc::DataVectorWithAlloc
DataVectorWithAlloc(const DataVectorWithAlloc &)=delete
DataVectorWithAlloc::base_value_type
DV::base_value_type base_value_type
Definition: DataVectorWithAlloc.h:73
SG::DataBucketTrait< DataVectorWithAlloc< DV, ALLOC >, U >::init
static void init()
Definition: DataVectorWithAlloc.h:864
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:193
DataVectorWithAlloc::Ptr::base_ptr
std::unique_ptr< base_value_type, UPDeleter > base_ptr
Definition: DataVectorWithAlloc.h:178
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
DataVectorWithAlloc::pointer
DV::pointer pointer
Definition: DataVectorWithAlloc.h:82
DataVectorWithAlloc::difference_type
DV::difference_type difference_type
Definition: DataVectorWithAlloc.h:71
DataVectorWithAlloc::erase
iterator erase(iterator position)
Remove element at a given position.
DataVectorWithAlloc::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
DataVectorWithAlloc::assignElement
void assignElement(typename BaseContainer::iterator pos, Ptr newElem)
Handle element assignment.
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
DataVectorWithAlloc::end
iterator end() noexcept
Return an iterator pointing past the end of the collection.
python.CaloAddPedShiftConfig.default
default
Definition: CaloAddPedShiftConfig.py:43
DataVectorWithAlloc::Ptr::Ptr
Ptr(std::nullptr_t) noexcept
DataVectorWithAlloc::clear
void clear()
Erase all the elements in the collection.
a
TList * a
Definition: liststreamerinfos.cxx:10
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
DataVectorWithAlloc::test2_assignelement1a
friend void test2_assignelement1a()
SG::DVLDataBucket
A DataBucket specialized for DataVector/DataList.
Definition: DVLDataBucket.h:49
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DataVectorWithAlloc::operator[]
ElementProxy operator[](size_type n)
Access an element, as an lvalue.
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:43
DataVectorWithAlloc::allocate
Ptr allocate(Args &&... args)
Allocate a new vector element.
DataVectorWithAlloc::shrink_to_fit
void shrink_to_fit()
Change the vector capacity to match the current size.
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
DataVectorWithAlloc::UPDeleter::heap
const elt_allocator_type * heap() const noexcept
DataVectorWithAlloc::Ptr
unique_ptr holding an element for this vector.
Definition: DataVectorWithAlloc.h:177
DataVectorWithAlloc::HeapDeleter::PtrVector
typename Base::PtrVector PtrVector
Definition: DataVectorWithAlloc.h:777
DataVectorWithAlloc::UPDeleter::m_heap
elt_allocator_type * m_heap
Definition: DataVectorWithAlloc.h:165
private
#define private
Definition: xAODTruthCnvAlg.h:20
DataVectorWithAlloc::swapElement
void swapElement(size_type index, Ptr newElem, Ptr &oldElem)
Swap one element out of the container.
DataVectorWithAlloc::elt_allocator_type
ALLOC elt_allocator_type
Type of the allocator use for vector elements.
Definition: DataVectorWithAlloc.h:86
DataModel_detail::ElementProxy
Proxy for lvalue access to DataVector/DataList elements.
Definition: ElementProxy.h:53
DataVectorWithAlloc::const_pointer
DV::const_pointer const_pointer
Definition: DataVectorWithAlloc.h:83
ArenaHeapSTLAllocator.h
STL-style allocator wrapper for ArenaHeapAllocator.
DataVectorWithAlloc::~DataVectorWithAlloc
virtual ~DataVectorWithAlloc()
Destructor.
columnar::rbegin
auto rbegin() const noexcept
Definition: ObjectRange.h:162
DataVectorWithAlloc::DVL_BASE
DV::DVL_BASE DVL_BASE
Definition: DataVectorWithAlloc.h:75
SG::DataBucketTrait
Metafunction to find the proper DataBucket class for T.
Definition: DataBucketTraitFwd.h:28
value_type
Definition: EDM_MasterSearch.h:11
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
SG::DVLDataVectorWithAllocBucket
DataBucket class for DataVectorWithAlloc.
Definition: DataVectorWithAlloc.h:836
xAOD::BaseContainer
DataVector< SG::AuxElement > BaseContainer
Definition: BaseContainer.h:7
DataVectorWithAlloc::HeapDeleter
Internal helper to delete vector elements.
Definition: DataVectorWithAlloc.h:773
DataVectorWithAlloc::HeapDeleter::HeapDeleter
HeapDeleter(elt_allocator_type &&heap)