ATLAS Offline Software
Classes | Namespaces
ConstDataVector.h File Reference

DataVector adapter that acts like it holds const pointers. More...

#include "AthContainers/DataVector.h"
#include "AthLinks/ElementLink.h"
#include <initializer_list>
#include "AthenaKernel/ClassID_traits.h"
#include "AthContainers/ConstDataVector.icc"
Include dependency graph for ConstDataVector.h:

Go to the source code of this file.

Classes

class  ConstDataVector< DV >
 DataVector adapter that acts like it holds const pointers. More...
 
struct  ClassID_traits< ConstDataVector< DV > >
 Specialize ClassID_traits for ConstDataVector so that they will be automatically made const when recorded in StoreGate. More...
 
class  SG::DVLConstDataVectorBucket< DV >
 DataBucket class for ConstDataVector. More...
 
struct  SG::DataBucketTrait< ConstDataVector< DV >, U >
 Metafunction to find the proper DataBucket class for the first template argument. More...
 
class  SG::BaseInfo< ConstDataVector< DV > >
 Let the BaseInfo for ConstDataVector forward to that of the base DataVector. More...
 

Namespaces

 SG
 Forward declaration.
 

Detailed Description

DataVector adapter that acts like it holds const pointers.

Author
scott snyder snyde.nosp@m.r@bn.nosp@m.l.gov
Date
Sep, 2011 A DataVector<T> acts as a container of T*. This means, though, that one cannot put a const T* into a DataVector<T>. However, one sometimes wants to do that. A typical case is that one retrieves a const DataVector from StoreGate, filters the contents, and then stores them in a new DataVector. Recall that a const DataVector will return const T*. So the pointers one gets from a const DataVector cannot be inserted into another DataVector. (The root cause of this is that we don't want to have to deal with distinct DataVector<T> and DataVector<const T> types, and thus DataVector [and StoreGate] don't have standard const semantics.)

To solve this, we introduce the template class ConstDataVector<DV>. The template argument should be a DataVector class or something that derives from one. (The reason the template argument is the DataVector class rather than the element type T is to allow for types that derive from DataVector.) ConstDataVector<DV> derives from DV, but privately — so it is a DV, but clients cannot use it as a DV. Instead, we provide only methods that retrieve const pointers. Further, the insertion methods will take const rather than non-const pointers.

There are two ways (short of casting) to convert a ConstDataVector<DV> to a const DV. The asDataVector method will directly do this conversion. Also, if the object is recorded in StoreGate, it will automatically be made const, so a retrieval will get a const DV. A ConstDataVector should not convert to a non-const DV.

So, for example, filtering might look something like this:

const DataVector<T>* v_in = 0;
CHECK( sg->retrieve (v_in) );
CHECK( sg->record (v_out, "key") );
for (const T* t : *v_in) {
if (filter (t))
v_out->push_back (t);
}

Note that if you are not recording the result in StoreGate, it may well be preferable to just use a std::vector<const T*> rather than ConstDataVector.

Definition in file ConstDataVector.h.

SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
covarianceTool.filter
filter
Definition: covarianceTool.py:514
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
DataVector< T >
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35