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-2021 CERN for the benefit of the ATLAS collaboration.
4  */
48 #ifndef ATHCONTAINERS_DATAVECTORWITHALLOC_H
49 #define ATHCONTAINERS_DATAVECTORWITHALLOC_H
50 
51 
56 
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 boost::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 
485 
486 
496  iterator insert(iterator position, Ptr pElem);
497 
498 
511  iterator emplace(iterator position, Ptr pElem);
512 
513 
515  //========================================================================
518 
519 
528 
529 
540 
541 
547  // cppcheck-suppress duplInheritedMember
548  void clear();
549 
550 
552  //========================================================================
555 
556 
568 
569 
577  static void iter_swap (iterator a, iterator b);
578 
579 
581  //========================================================================
584 
585 
586 
602  void swapElement (size_type index, Ptr newElem, Ptr& oldElem);
603 
604 
620  void swapElement (iterator pos, Ptr newElem, Ptr& oldElem);
621 
622 
627 
628 
635  static
637 
638 
645 
646 
653  const SG::AuxVectorBase& auxbase() const;
654 
655 
661  template <class... Args>
663 
664 
666  //========================================================================
669 
670 
681  bool operator< (const DataVectorWithAlloc& b) const;
682 
684  bool operator> (const DataVectorWithAlloc& b) const;
685 
687  bool operator<= (const DataVectorWithAlloc& b) const;
688 
690  bool operator>= (const DataVectorWithAlloc& b) const;
691 
692 
702  bool operator== (const DataVectorWithAlloc& b) const;
703 
705  bool operator!= (const DataVectorWithAlloc& b) const;
706 
707 
708 
709 private:
711  //========================================================================
714 
715 
718 
719 
728 
729 
735  static
737 
738 
745 
746 
753 
754 
759  : public DV::Deleter
760  {
761  public:
762  using Base = typename DV::Deleter;
763  using value_type = typename Base::value_type;
764  using PtrVector = typename Base::PtrVector;
767  virtual void doDelete (value_type p) override;
768  virtual void doDelete (typename PtrVector::iterator first,
769  typename PtrVector::iterator last) override;
770 
771 
772  private:
774  };
775 
776 
779 };
780 
781 
783 template <class DV, class ALLOC>
784 void swap (DataVectorWithAlloc<DV, ALLOC>& a, DataVectorWithAlloc<DV, ALLOC>& b)
785 {
786  a.swap (b);
787 }
788 
789 
790 
791 #ifndef XAOD_STANDALONE
792 
794 
799 template <class DV, class ALLOC>
801  : public ClassID_traits<DV>
802 {
803 public:
804  BOOST_STATIC_CONSTANT(bool, s_isConst = true);
805 };
806 
807 
808 namespace SG {
809 
810 
820 template <class DV, class ALLOC>
822  : public DVLDataBucket<DV>
823 {
824 public:
830 
831 
837 };
838 
839 
847 template <class DV, class ALLOC, class U>
849 {
851  static void init() { DV::dvlinfo(); }
852 };
853 
854 
859 template <class DV, class ALLOC>
860 class BaseInfo<DataVectorWithAlloc<DV, ALLOC> >
861  : public BaseInfo<DV>
862 {
863 };
864 
865 
866 } // namespace SG
867 
868 
869 #endif // not XAOD_STANDALONE
870 
871 
873 
874 
875 #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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
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::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:137
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.
DataVectorWithAlloc::isSequence
boost::true_type isSequence
Definition: DataVectorWithAlloc.h:107
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
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:317
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:562
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.
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
DataVectorWithAlloc::at
ElementProxy at(size_type n)
Access an element, as an lvalue.
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:850
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
DataVectorWithAlloc::DataVectorWithAlloc
DataVectorWithAlloc(size_type n, elt_allocator_type &&eltAlloc=elt_allocator_type())
Sized constructor.
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:92
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:731
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:40
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:581
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:24
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
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:77
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:851
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:194
DataVectorWithAlloc::Ptr::base_ptr
std::unique_ptr< base_value_type, UPDeleter > base_ptr
Definition: DataVectorWithAlloc.h:178
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
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.
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DataVectorWithAlloc::operator[]
ElementProxy operator[](size_type n)
Access an element, as an lvalue.
ClassID_traits< DataVectorWithAlloc< DV, ALLOC > >::BOOST_STATIC_CONSTANT
BOOST_STATIC_CONSTANT(bool, s_isConst=true)
dq_make_web_display.reference
reference
Definition: dq_make_web_display.py:44
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:764
DataVectorWithAlloc::UPDeleter::m_heap
elt_allocator_type * m_heap
Definition: DataVectorWithAlloc.h:165
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
python.CaloScaleNoiseConfig.default
default
Definition: CaloScaleNoiseConfig.py:79
DataModel_detail::ElementProxy
Proxy for lvalue access to DataVector/DataList elements.
Definition: ElementProxy.h:26
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.
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:30
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:823
xAOD::BaseContainer
DataVector< SG::AuxElement > BaseContainer
Definition: BaseContainer.h:7
DataVectorWithAlloc::HeapDeleter
Internal helper to delete vector elements.
Definition: DataVectorWithAlloc.h:760
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
DataVectorWithAlloc::HeapDeleter::HeapDeleter
HeapDeleter(elt_allocator_type &&heap)