CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
edm::PtrVectorBase Class Reference

#include <PtrVectorBase.h>

Inheritance diagram for edm::PtrVectorBase:
edm::PtrVector< T > edm::PtrVector< CaloCluster > edm::PtrVector< CaloTower > edm::PtrVector< Candidate > edm::PtrVector< reco::BaseTau > edm::PtrVector< reco::BasicJet > edm::PtrVector< reco::CaloCluster > edm::PtrVector< reco::CaloJet > edm::PtrVector< reco::Candidate > edm::PtrVector< reco::CastorJetID > edm::PtrVector< reco::FFTBasicJet > edm::PtrVector< reco::FFTCaloJet > edm::PtrVector< reco::FFTGenJet > edm::PtrVector< reco::FFTJPTJet > edm::PtrVector< reco::FFTPFJet > edm::PtrVector< reco::FFTTrackJet > edm::PtrVector< reco::GenJet > edm::PtrVector< reco::GsfElectron > edm::PtrVector< reco::Jet > edm::PtrVector< reco::JetID > edm::PtrVector< reco::JPTJet > edm::PtrVector< reco::MET > edm::PtrVector< reco::Muon > edm::PtrVector< reco::PFCandidate > edm::PtrVector< reco::PFClusterJet > edm::PtrVector< reco::PFJet > edm::PtrVector< reco::PFTau > edm::PtrVector< reco::Photon > edm::PtrVector< reco::reco::PFCluster > edm::PtrVector< reco::TrackJet >

Public Types

typedef unsigned long key_type
 
typedef key_type size_type
 

Public Member Functions

size_type capacity () const
 Capacity of the RefVector. More...
 
void clear ()
 Clear the PtrVector. More...
 
bool empty () const
 Is the RefVector empty. More...
 
bool hasCache () const
 
ProductID id () const
 Accessor for product ID. More...
 
bool isAvailable () const
 
bool isNonnull () const
 Checks for non-null. More...
 
bool isNull () const
 Checks for null. More...
 
bool isTransient () const
 
bool operator! () const
 Checks for null. More...
 
bool operator== (PtrVectorBase const &iRHS) const
 
void const * product () const
 
EDProductGetter const * productGetter () const
 Accessor for product getter. More...
 
 PtrVectorBase (ProductID const &productID, void const *prodPtr=0, EDProductGetter const *prodGetter=0)
 
void reserve (size_type n)
 Reserve space for RefVector. More...
 
void setProductGetter (EDProductGetter *iGetter) const
 
size_type size () const
 Size of the RefVector. More...
 
virtual ~PtrVectorBase ()
 

Protected Member Functions

template<typename TPtr >
TPtr makePtr (unsigned long iIndex) const
 
template<typename TPtr >
TPtr makePtr (std::vector< void const * >::const_iterator const iIt) const
 
 PtrVectorBase ()
 
void push_back_base (RefCore const &core, key_type iKey, void const *iData)
 
void swap (PtrVectorBase &other)
 swap More...
 
std::vector< void const * >
::const_iterator 
void_begin () const
 
std::vector< void const * >
::const_iterator 
void_end () const
 

Private Member Functions

void checkCachedItems () const
 
void getProduct_ () const
 
virtual std::type_info const & typeInfo () const
 

Private Attributes

std::vector< void const * > cachedItems_
 
RefCore core_
 
std::vector< key_typeindicies_
 

Detailed Description

Description: Base class for PtrVector

Usage: This class defines the common behavior for the PtrVector template class instances

Definition at line 32 of file PtrVectorBase.h.

Member Typedef Documentation

typedef unsigned long edm::PtrVectorBase::key_type

Definition at line 35 of file PtrVectorBase.h.

Definition at line 36 of file PtrVectorBase.h.

Constructor & Destructor Documentation

edm::PtrVectorBase::PtrVectorBase ( ProductID const &  productID,
void const *  prodPtr = 0,
EDProductGetter const *  prodGetter = 0 
)
inlineexplicit

Definition at line 38 of file PtrVectorBase.h.

39  :
40  core_(productID, prodPtr, prodGetter, false), indicies_() {}
std::vector< key_type > indicies_
edm::PtrVectorBase::~PtrVectorBase ( )
virtual

Definition at line 37 of file PtrVectorBase.cc.

37  {
38  }
edm::PtrVectorBase::PtrVectorBase ( )
protected

Definition at line 34 of file PtrVectorBase.cc.

34  {
35  }

Member Function Documentation

size_type edm::PtrVectorBase::capacity ( ) const
inline

Capacity of the RefVector.

Definition at line 74 of file PtrVectorBase.h.

References indicies_.

74 {return indicies_.capacity();}
std::vector< key_type > indicies_
void edm::PtrVectorBase::checkCachedItems ( ) const
private

Definition at line 129 of file PtrVectorBase.cc.

References cachedItems_, edm::hlt::Exception, id(), and edm::errors::InvalidReference.

Referenced by void_begin(), and void_end().

129  {
130  for(auto item : cachedItems_) {
131  if(item == nullptr) {
132  throw Exception(errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product with ProductID "
133  << id() << "\n";
134  }
135  }
136  }
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:56
std::vector< void const * > cachedItems_
void edm::PtrVectorBase::clear ( void  )
inline
bool edm::PtrVectorBase::empty ( ) const
inline
void edm::PtrVectorBase::getProduct_ ( ) const
private

Definition at line 95 of file PtrVectorBase.cc.

References assert(), cachedItems_, edm::hlt::Exception, edm::WrapperBase::fillPtrVector(), edm::EDProductGetter::getIt(), edm::EDProductGetter::getThinnedProducts(), hasCache(), indicies_, relval_steps::k, edm::errors::LogicError, product(), productGetter(), and typeInfo().

Referenced by isAvailable(), void_begin(), and void_end().

95  {
96  if(hasCache()) {
97  return;
98  }
99  if(indicies_.size() == 0) {
100  return;
101  }
102  if(0 == productGetter()) {
103  throw Exception(errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n";
104  }
105  WrapperBase const* product = productGetter()->getIt(id());
106 
107  if(product != nullptr) {
109  return;
110  }
111 
112  cachedItems_.resize(indicies_.size(), nullptr);
113 
114  std::vector<unsigned int> thinnedKeys;
115  thinnedKeys.assign(indicies_.begin(), indicies_.end());
116  std::vector<WrapperBase const*> wrappers(indicies_.size(), nullptr);
117  productGetter()->getThinnedProducts(id(), wrappers, thinnedKeys);
118  unsigned int nWrappers = wrappers.size();
119  assert(wrappers.size() == indicies_.size());
120  assert(wrappers.size() == cachedItems_.size());
121  for(unsigned k = 0; k < nWrappers; ++k) {
122  if (wrappers[k] != nullptr) {
123  wrappers[k]->setPtr(typeInfo(), thinnedKeys[k], cachedItems_[k]);
124  }
125  }
126  }
assert(m_qm.get())
virtual std::type_info const & typeInfo() const
virtual void getThinnedProducts(ProductID const &pid, std::vector< WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const =0
std::vector< key_type > indicies_
virtual WrapperBase const * getIt(ProductID const &) const =0
std::vector< void const * > cachedItems_
void fillPtrVector(std::type_info const &iToType, std::vector< unsigned long > const &iIndicies, std::vector< void const * > &oPtr) const
Definition: WrapperBase.cc:34
bool hasCache() const
Definition: PtrVectorBase.h:61
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:59
void const * product() const
Definition: PtrVectorBase.h:90
bool edm::PtrVectorBase::hasCache ( ) const
inline

Definition at line 61 of file PtrVectorBase.h.

References cachedItems_.

Referenced by getProduct_(), isAvailable(), and makePtr().

61 { return !cachedItems_.empty(); }
std::vector< void const * > cachedItems_
ProductID edm::PtrVectorBase::id ( void  ) const
inline

Accessor for product ID.

Definition at line 56 of file PtrVectorBase.h.

References core_, and edm::RefCore::id().

Referenced by checkCachedItems(), pf2pat::TopProjectorAlgo< Top, Bottom >::printAncestors(), and pf2pat::TopProjectorAlgo< Top, Bottom >::processCollection().

56 {return core_.id();}
ProductID id() const
Definition: RefCore.h:29
bool edm::PtrVectorBase::isAvailable ( ) const

True if the data is in memory or is available in the Event No type checking is done.

Definition at line 73 of file PtrVectorBase.cc.

References cachedItems_, core_, getProduct_(), hasCache(), indicies_, edm::RefCore::isAvailable(), and productGetter().

73  {
74  if(indicies_.empty()) {
75  return core_.isAvailable();
76  }
77  if(!hasCache()) {
78  if(!id().isValid() || productGetter() == nullptr) {
79  return false;
80  }
81  getProduct_();
82  }
83  for(auto ptr : cachedItems_) {
84  if(ptr == nullptr) {
85  return false;
86  }
87  }
88  return true;
89  }
void getProduct_() const
std::vector< key_type > indicies_
bool isAvailable() const
Definition: RefCore.cc:155
std::vector< void const * > cachedItems_
bool hasCache() const
Definition: PtrVectorBase.h:61
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:59
bool edm::PtrVectorBase::isNonnull ( ) const
inline

Checks for non-null.

Definition at line 50 of file PtrVectorBase.h.

References core_, and edm::RefCore::isNonnull().

Referenced by isNull().

50 { return core_.isNonnull(); }
bool isNonnull() const
Definition: RefCore.h:43
bool edm::PtrVectorBase::isNull ( ) const
inline

Checks for null.

Definition at line 46 of file PtrVectorBase.h.

References isNonnull().

Referenced by operator!().

46 {return !isNonnull(); }
bool isNonnull() const
Checks for non-null.
Definition: PtrVectorBase.h:50
bool edm::PtrVectorBase::isTransient ( ) const
inline

Definition at line 88 of file PtrVectorBase.h.

References core_, and edm::RefCore::isTransient().

Referenced by makePtr().

88 {return core_.isTransient();}
bool isTransient() const
Definition: RefCore.h:75
template<typename TPtr >
TPtr edm::PtrVectorBase::makePtr ( unsigned long  iIndex) const
inlineprotected

Definition at line 114 of file PtrVectorBase.h.

References cachedItems_, hasCache(), indicies_, isTransient(), and productGetter().

114  {
115  if (isTransient()) {
116  return TPtr(reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
117  indicies_[iIndex]);
118  }
119  if (hasCache() && (cachedItems_[iIndex] != nullptr || productGetter() == nullptr)) {
120  return TPtr(this->id(),
121  reinterpret_cast<typename TPtr::value_type const*>(cachedItems_[iIndex]),
122  indicies_[iIndex]);
123  }
124  return TPtr(this->id(), indicies_[iIndex], productGetter());
125  }
bool isTransient() const
Definition: PtrVectorBase.h:88
std::vector< key_type > indicies_
std::vector< void const * > cachedItems_
bool hasCache() const
Definition: PtrVectorBase.h:61
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:59
template<typename TPtr >
TPtr edm::PtrVectorBase::makePtr ( std::vector< void const * >::const_iterator const  iIt) const
inlineprotected

Definition at line 128 of file PtrVectorBase.h.

References cachedItems_, hasCache(), indicies_, isTransient(), and productGetter().

128  {
129  if (isTransient()) {
130  return TPtr(reinterpret_cast<typename TPtr::value_type const*>(*iIt),
131  indicies_[iIt - cachedItems_.begin()]);
132  }
133  if (hasCache() && (*iIt != nullptr || productGetter() == nullptr)) {
134  return TPtr(this->id(),
135  reinterpret_cast<typename TPtr::value_type const*>(*iIt),
136  indicies_[iIt - cachedItems_.begin()]);
137  }
138  return TPtr(this->id(), indicies_[iIt - cachedItems_.begin()], productGetter());
139  }
bool isTransient() const
Definition: PtrVectorBase.h:88
std::vector< key_type > indicies_
std::vector< void const * > cachedItems_
bool hasCache() const
Definition: PtrVectorBase.h:61
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:59
bool edm::PtrVectorBase::operator! ( ) const
inline

Checks for null.

Definition at line 53 of file PtrVectorBase.h.

References isNull().

53 {return isNull();}
bool isNull() const
Checks for null.
Definition: PtrVectorBase.h:46
bool edm::PtrVectorBase::operator== ( PtrVectorBase const &  iRHS) const

Definition at line 139 of file PtrVectorBase.cc.

References core_, cond::serialization::equal(), and indicies_.

139  {
140  if(core_ != iRHS.core_) {
141  return false;
142  }
143  if(indicies_.size() != iRHS.indicies_.size()){
144  return false;
145  }
146  return std::equal(indicies_.begin(),
147  indicies_.end(),
148  iRHS.indicies_.begin());
149  }
bool equal(const T &first, const T &second)
Definition: Equal.h:34
std::vector< key_type > indicies_
void const* edm::PtrVectorBase::product ( ) const
inline

Definition at line 90 of file PtrVectorBase.h.

Referenced by getProduct_().

90  {
91  return 0;
92  }
EDProductGetter const* edm::PtrVectorBase::productGetter ( ) const
inline

Accessor for product getter.

Definition at line 59 of file PtrVectorBase.h.

References core_, and edm::RefCore::productGetter().

Referenced by getProduct_(), isAvailable(), and makePtr().

59 {return core_.productGetter();}
EDProductGetter const * productGetter() const
Definition: RefCore.h:53
void edm::PtrVectorBase::push_back_base ( RefCore const &  core,
key_type  iKey,
void const *  iData 
)
protected

Definition at line 57 of file PtrVectorBase.cc.

References cachedItems_, core_, indicies_, and edm::RefCore::pushBackItem().

Referenced by edm::PtrVector< reco::FFTJPTJet >::push_back().

57  {
58  core_.pushBackItem(core, false);
59  //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr?
60  if(indicies_.size() == cachedItems_.size()) {
61  if(iData) {
62  cachedItems_.push_back(iData);
63  } else if(key_traits<key_type>::value == iKey) {
64  cachedItems_.push_back(0);
65  } else {
66  cachedItems_.clear();
67  }
68  }
69  indicies_.push_back(iKey);
70  }
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:176
std::vector< key_type > indicies_
std::vector< void const * > cachedItems_
void edm::PtrVectorBase::reserve ( size_type  n)
inline

Reserve space for RefVector.

Definition at line 84 of file PtrVectorBase.h.

References cachedItems_, and indicies_.

84 {indicies_.reserve(n); cachedItems_.reserve(n);}
std::vector< key_type > indicies_
std::vector< void const * > cachedItems_
void edm::PtrVectorBase::setProductGetter ( EDProductGetter iGetter) const
inline

Definition at line 86 of file PtrVectorBase.h.

References core_, and edm::RefCore::setProductGetter().

86 { core_.setProductGetter(iGetter); }
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:161
size_type edm::PtrVectorBase::size ( void  ) const
inline
void edm::PtrVectorBase::swap ( PtrVectorBase other)
protected

swap

Definition at line 50 of file PtrVectorBase.cc.

References cachedItems_, core_, indicies_, and edm::RefCore::swap().

Referenced by edm::PtrVector< reco::FFTJPTJet >::swap().

50  {
51  core_.swap(other.core_);
52  indicies_.swap(other.indicies_);
53  cachedItems_.swap(other.cachedItems_);
54  }
void swap(RefCore &)
Definition: RefCore.h:122
std::vector< key_type > indicies_
std::vector< void const * > cachedItems_
virtual std::type_info const& edm::PtrVectorBase::typeInfo ( ) const
inlineprivatevirtual
std::vector<void const*>::const_iterator edm::PtrVectorBase::void_begin ( ) const
inlineprotected

Definition at line 102 of file PtrVectorBase.h.

References cachedItems_, checkCachedItems(), and getProduct_().

Referenced by edm::PtrVector< reco::FFTJPTJet >::begin().

102  {
103  getProduct_();
105  return cachedItems_.begin();
106  }
void getProduct_() const
std::vector< void const * > cachedItems_
void checkCachedItems() const
std::vector<void const*>::const_iterator edm::PtrVectorBase::void_end ( ) const
inlineprotected

Definition at line 107 of file PtrVectorBase.h.

References cachedItems_, checkCachedItems(), and getProduct_().

Referenced by edm::PtrVector< reco::FFTJPTJet >::end().

107  {
108  getProduct_();
110  return cachedItems_.end();
111  }
void getProduct_() const
std::vector< void const * > cachedItems_
void checkCachedItems() const

Member Data Documentation

std::vector<void const*> edm::PtrVectorBase::cachedItems_
mutableprivate
RefCore edm::PtrVectorBase::core_
private
std::vector<key_type> edm::PtrVectorBase::indicies_
private