ATLAS Offline Software
DVLInfo.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_TOOLS_DVLINFO_H
14 #define ATHCONTAINERS_TOOLS_DVLINFO_H
15 
16 
19 #include <typeinfo>
20 #include <cstddef>
21 #include <type_traits>
22 
23 
24 
25 namespace DataModel_detail {
26 
27 
32 {
33 public:
35  virtual ~DVLIteratorBase() {}
36 
37 
46  virtual const void* next() = 0;
47 };
48 
49 
50 /*
51  * @brief Holder to implement conversion copies for @c DataVector/@c DataList.
52  *
53  * In some cases, we want to convert @c DataVector<A> to @c DataVector<B>,
54  * where the two @c DataVector classes are not related by inheritance,
55  * but where @c A and @c B are. In such a case, we can make a new view
56  * container for @c DataVector<B> and fill it with the pointers
57  * from @c DataVector<A> (suitably converted). In order for this
58  * to work with the conversion machinery in SGTools, we must be able
59  * to do this given only the @c type_info for @c DataVector<B>.
60  * Thus, we build a registry of @c DVLInfo objects, indexed
61  * by the @c type_info; the @c DVLInfo objects have virtual methods
62  * to build the new container and to fill it. (Everything said here
63  * for @c DataVector also applies to @c DataList.)
64  *
65  * Note: these objects should only be allocated statically.
66  */
68 {
69 public:
78  DVLInfoBase (const std::type_info& tinfo,
79  const std::type_info& elt_tinfo);
80 
81 
83  virtual ~DVLInfoBase() {}
84 
85 
89  const std::type_info& tinfo() const;
90 
91 
95  CLID clid() const;
96 
97 
102  const std::type_info& elt_tinfo() const;
103 
104 
110  virtual void* make (size_t nreserve) const = 0;
111 
112 
119  virtual void push (void* cont_p, void* elt_p) const = 0;
120 
121 
126  virtual size_t size (void* cont_p) const = 0;
127 
128 
133  virtual void clear (void* cont_p) const = 0;
134 
135 
140  virtual void del (void* cont_p) const = 0;
141 
142 
147  virtual void* clone (void* cont_p) const = 0;
148 
149 
154  virtual DVLIteratorBase* iterator (const void* cont_p) const = 0;
155 
156 
161  virtual SG::AuxVectorBase* base (void* cont_p) const = 0;
162 
163 
169  static DVLInfoBase* find (const std::type_info& tinfo);
170 
171 
177  static DVLInfoBase* find (CLID clid);
178 
179 
180 private:
182  const std::type_info& m_tinfo;
183 
185  const std::type_info& m_elt_tinfo;
186 };
187 
188 
195 template <class T>
197  : public DVLIteratorBase
198 {
199 public:
200  typedef typename T::const_iterator base_iterator;
201 
202 
209 
210 
219  virtual const void* next();
220 
221 
222 private:
223  typename T::const_iterator m_it;
224  typename T::const_iterator m_end;
225 };
226 
227 
228 /*
229  * @brief Per-container @c DVLInfo.
230  *
231  * One instance of this class is instantiated for each
232  * @c DataVector/@c DataList class.
233  */
234 template <class T>
235 class DVLInfo
236  : public DVLInfoBase
237 {
238 public:
240  typedef T Container;
241 
244 
245 
252 
253 
259  virtual void* make (size_t nreserve) const;
260 
261 
268  virtual void push (void* cont_p, void* elt_p) const;
269 
270 
275  virtual size_t size (void* cont_p) const;
276 
277 
282  virtual void clear (void* cont_p) const;
283 
284 
289  virtual void del (void* cont_p) const;
290 
291 
296  virtual void* clone (void* cont_p) const;
297 
298 
303  virtual DVLIteratorBase* iterator (const void* cont_p) const;
304 
305 
310  virtual SG::AuxVectorBase* base (void* cont_p) const;
311 
312 
320  static const std::type_info* initHelper();
321 };
322 
323 
334 template <class T>
335 void* dvl_convert (const T& src,
336  const DVLInfoBase& targ_info);
337 
338 
350 template <class T>
351 void* dvl_convert (const T& src,
352  const std::type_info& targ_tinfo,
353  DVLInfoBase*& targ_info);
354 
355 
367 template <class T>
368 void* dvl_convert (const T& src,
369  CLID clid,
370  DVLInfoBase*& targ_info);
371 
372 
382 template <class T>
383 void dvl_update (const T& src,
384  void* target,
385  const DVLInfoBase* targ_info);
386 
387 
388 
389 } // namespace DataModel_detail
390 
391 
393 
394 
395 #endif // not ATHCONTAINERS_TOOLS_DVLINFO_H
DataModel_detail::DVLInfoBase::clear
virtual void clear(void *cont_p) const =0
Erase the elements in the container.
ClassID.h
Standalone helpers.
DataModel_detail::DVLInfo::base
virtual SG::AuxVectorBase * base(void *cont_p) const
Return a pointer to the container base.
DVLInfo.icc
DataModel_detail::DVLInfoBase::tinfo
const std::type_info & tinfo() const
Return the type_info for the container.
DataModel_detail::DVLInfo::size
virtual size_t size(void *cont_p) const
Return the size of the container.
DataModel_detail::DVLInfoBase::make
virtual void * make(size_t nreserve) const =0
Construct a new container.
DataModel_detail::DVLInfoBase::DVLInfoBase
DVLInfoBase(const std::type_info &tinfo, const std::type_info &elt_tinfo)
Constructor.
Definition: DVLInfo.cxx:59
DataModel_detail::DVLIterator
Implementation for iterator helper.
Definition: DVLInfo.h:198
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
DataModel_detail::DVLIteratorBase::next
virtual const void * next()=0
Return the next element from the container.
DataModel_detail::DVLInfo::DVLInfo
DVLInfo()
Constructor.
DataModel_detail::DVLInfo::del
virtual void del(void *cont_p) const
Delete a container.
AuxVectorBase.h
Manage index tracking and synchronization of auxiliary data.
SG::AuxVectorBase
Manage index tracking and synchronization of auxiliary data.
Definition: AuxVectorBase.h:98
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
DataModel_detail::DVLInfo::make
virtual void * make(size_t nreserve) const
Construct a new container.
DataModel_detail::DVLInfo::Elt
std::remove_const< typename Container::base_value_type >::type Elt
The container's element type (with pointer and any const removed).
Definition: DVLInfo.h:243
DataModel_detail::DVLInfoBase::clid
CLID clid() const
Return the CLID for the container.
Definition: DVLInfo.cxx:117
DataModel_detail::DVLInfoBase
Definition: DVLInfo.h:68
DataModel_detail::DVLInfoBase::m_tinfo
const std::type_info & m_tinfo
The type_info of the container.
Definition: DVLInfo.h:182
DataModel_detail::DVLInfo::push
virtual void push(void *cont_p, void *elt_p) const
Push a new pointer into the container.
DataModel_detail::DVLInfoBase::iterator
virtual DVLIteratorBase * iterator(const void *cont_p) const =0
Return a new iterator object.
DataModel_detail::DVLInfoBase::size
virtual size_t size(void *cont_p) const =0
Return the size of the container.
DataModel_detail::DVLIterator::base_iterator
T::const_iterator base_iterator
Definition: DVLInfo.h:200
DataModel_detail::DVLInfoBase::clone
virtual void * clone(void *cont_p) const =0
Copy a container.
DataModel_detail::DVLIterator::DVLIterator
DVLIterator(const base_iterator &beg, const base_iterator &end)
Constructor.
DataModel_detail::DVLInfoBase::m_elt_tinfo
const std::type_info & m_elt_tinfo
The type_info of the container's element.
Definition: DVLInfo.h:185
DataModel_detail::DVLInfo::Container
T Container
Container type.
Definition: DVLInfo.h:240
DataModel_detail::DVLInfo::initHelper
static const std::type_info * initHelper()
Helper to create the DVLInfo static instance.
DataModel_detail::DVLInfo::clone
virtual void * clone(void *cont_p) const
Copy a container.
DataModel_detail::DVLInfoBase::find
static DVLInfoBase * find(const std::type_info &tinfo)
Find the DVLInfo for the container tinfo.
Definition: DVLInfo.cxx:76
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
DataModel_detail::dvl_update
void dvl_update(const T &src, void *target, const DVLInfoBase *targ_info)
Update the elements in the target container from the source.
DataModel_detail
Definition: CompareAndPrint.h:15
DataModel_detail::dvl_convert
void * dvl_convert(const T &src, const DVLInfoBase &targ_info)
Perform DataVector/DataList conversion copying.
DataModel_detail::DVLIteratorBase::~DVLIteratorBase
virtual ~DVLIteratorBase()
Destructor.
Definition: DVLInfo.h:35
DataModel_detail::DVLInfo::iterator
virtual DVLIteratorBase * iterator(const void *cont_p) const
Return a new iterator object.
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
copySelective.target
string target
Definition: copySelective.py:37
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DataModel_detail::DVLIterator::m_it
T::const_iterator m_it
Definition: DVLInfo.h:223
DataModel_detail::DVLInfoBase::elt_tinfo
const std::type_info & elt_tinfo() const
Return the type_info for the container's element.
DataModel_detail::DVLInfoBase::base
virtual SG::AuxVectorBase * base(void *cont_p) const =0
Return a pointer to the container base.
DataModel_detail::DVLInfo::clear
virtual void clear(void *cont_p) const
Erase the elements in the container.
DataModel_detail::DVLInfo
Definition: DVLInfo.h:237
DataModel_detail::DVLInfoBase::~DVLInfoBase
virtual ~DVLInfoBase()
Destructor.
Definition: DVLInfo.h:83
DataModel_detail::DVLIteratorBase
Helper to iterate over a DV container.
Definition: DVLInfo.h:32
DataModel_detail::DVLIterator::m_end
T::const_iterator m_end
Definition: DVLInfo.h:224
DataModel_detail::DVLInfoBase::del
virtual void del(void *cont_p) const =0
Delete a container.
DataModel_detail::DVLIterator::next
virtual const void * next()
Return the next element from the container.
DataModel_detail::DVLInfoBase::push
virtual void push(void *cont_p, void *elt_p) const =0
Push a new pointer into the container.