/cvmfs/atlas.cern.ch/repo/sw/ASG/AnalysisBase/2.4.31/AthContainers/AthContainers/ConstDataVector.h File Reference

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

#include "AthContainers/DataVector.h"
#include "SGTools/ClassID_traits.h"
#include "AthContainers/ConstDataVector.icc"

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

namespace  SG
 

Constructor from a payload object.



Detailed Description

DataVector adapter that acts like it holds const pointers.

Author:
scott snyder <snyder@bnl.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) );
  ConstDataVector<DataVector<T> >* v_out =
    new ConstDataVector<DataVector<T> > (SG::VIEW_ELEMENTS);
  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.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 1 Dec 2017 for RootCore Packages by  doxygen 1.6.1