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 | Static 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::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::PFClusterJet > edm::PtrVector< reco::PFJet > 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)
 
 PtrVectorBase (const PtrVectorBase &)
 
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

bool checkCachedItems () const
 
void getProduct_ () const
 
PtrVectorBaseoperator= (const PtrVectorBase &)
 
virtual std::type_info const & typeInfo () const
 

Static Private Member Functions

static const std::vector< void
const * > & 
emptyCache ()
 

Private Attributes

std::atomic< 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.

40  :
41  core_(productID, prodPtr, prodGetter, false), indicies_(), cachedItems_(nullptr) {}
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
edm::PtrVectorBase::PtrVectorBase ( const PtrVectorBase iOther)

Definition at line 41 of file PtrVectorBase.cc.

References cachedItems_.

41  :
42  core_(iOther.core_),
43  indicies_(iOther.indicies_),
44  cachedItems_(nullptr)
45  {
46  auto cache = iOther.cachedItems_.load();
47  if(cache) {
48  cachedItems_.store( new std::vector<void const*>(*cache));
49  }
50  }
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
edm::PtrVectorBase::~PtrVectorBase ( )
virtual

Definition at line 37 of file PtrVectorBase.cc.

References cachedItems_.

37  {
38  delete cachedItems_.load();
39  }
std::atomic< std::vector< void const * > * > cachedItems_
edm::PtrVectorBase::PtrVectorBase ( )
protected

Definition at line 34 of file PtrVectorBase.cc.

34  : cachedItems_(nullptr) {
35  }
std::atomic< std::vector< void const * > * > cachedItems_

Member Function Documentation

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

Capacity of the RefVector.

Definition at line 77 of file PtrVectorBase.h.

References indicies_.

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

Definition at line 166 of file PtrVectorBase.cc.

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

Referenced by void_begin(), and void_end().

166  {
167  auto tmp = cachedItems_.load();
168  if(not tmp) { return false;}
169  for(auto item : *tmp) {
170  if(item == nullptr) {
171  throw Exception(errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product with ProductID "
172  << id() << "\n";
173  }
174  }
175  return true;
176  }
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:59
std::atomic< std::vector< void const * > * > cachedItems_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
void edm::PtrVectorBase::clear ( void  )
inline
bool edm::PtrVectorBase::empty ( ) const
inline
const std::vector< void const * > & edm::PtrVectorBase::emptyCache ( )
staticprivate

Definition at line 197 of file PtrVectorBase.cc.

References edm::s_emptyCache.

Referenced by void_begin(), and void_end().

197  {
198  return s_emptyCache;
199  }
static const std::vector< void const * > s_emptyCache
void edm::PtrVectorBase::getProduct_ ( ) const
private

Definition at line 114 of file PtrVectorBase.cc.

References assert(), cachedItems_, Exception, edm::WrapperBase::fillPtrVector(), hasCache(), indicies_, relval_2017::k, edm::errors::LogicError, product(), productGetter(), and typeInfo().

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

114  {
115  if(hasCache()) {
116  return;
117  }
118  if(indicies_.size() == 0) {
119  return;
120  }
121  //NOTE: Another thread could be getting the data
122  auto tmpProductGetter = productGetter();
123  if(nullptr == tmpProductGetter) {
124  throw Exception(errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n";
125  }
126  WrapperBase const* product = tmpProductGetter->getIt(id());
127 
128  auto tmpCachedItems = std::make_unique<std::vector<void const*>>();
129 
130  if(product != nullptr) {
131  product->fillPtrVector(typeInfo(), indicies_, *tmpCachedItems);
132 
133  std::vector<void const*>* expected = nullptr;
134  if(cachedItems_.compare_exchange_strong(expected, tmpCachedItems.get())) {
135  //we were the first thread to change the value
136  tmpCachedItems.release();
137  }
138 
139  return;
140  }
141 
142  tmpCachedItems->resize(indicies_.size(), nullptr);
143 
144  std::vector<unsigned int> thinnedKeys;
145  thinnedKeys.assign(indicies_.begin(), indicies_.end());
146  std::vector<WrapperBase const*> wrappers(indicies_.size(), nullptr);
147  tmpProductGetter->getThinnedProducts(id(), wrappers, thinnedKeys);
148  unsigned int nWrappers = wrappers.size();
149  assert(wrappers.size() == indicies_.size());
150  assert(wrappers.size() == tmpCachedItems->size());
151  for(unsigned k = 0; k < nWrappers; ++k) {
152  if (wrappers[k] != nullptr) {
153  wrappers[k]->setPtr(typeInfo(), thinnedKeys[k], (*tmpCachedItems)[k]);
154  }
155  }
156  {
157  std::vector<void const*>* expected = nullptr;
158  if(cachedItems_.compare_exchange_strong(expected, tmpCachedItems.get())) {
159  //we were the first thread to change the value
160  tmpCachedItems.release();
161  }
162  }
163  }
assert(m_qm.get())
virtual std::type_info const & typeInfo() const
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
bool hasCache() const
Definition: PtrVectorBase.h:64
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:62
void const * product() const
Definition: PtrVectorBase.h:95
bool edm::PtrVectorBase::hasCache ( ) const
inline

Definition at line 64 of file PtrVectorBase.h.

References cachedItems_.

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

64 { return cachedItems_; }
std::atomic< std::vector< void const * > * > cachedItems_
ProductID edm::PtrVectorBase::id ( ) const
inline

Accessor for product ID.

Definition at line 59 of file PtrVectorBase.h.

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

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

59 {return core_.id();}
ProductID id() const
Definition: RefCore.h:38
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 91 of file PtrVectorBase.cc.

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

91  {
92  if(indicies_.empty()) {
93  return core_.isAvailable();
94  }
95  if(!hasCache()) {
96  if(!id().isValid() || productGetter() == nullptr) {
97  return false;
98  }
99  getProduct_();
100  }
101  auto tmpCachedItems = cachedItems_.load();
102  for(auto ptr : *tmpCachedItems) {
103  if(ptr == nullptr) {
104  return false;
105  }
106  }
107  return true;
108  }
void getProduct_() const
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
bool isAvailable() const
Definition: RefCore.cc:168
bool hasCache() const
Definition: PtrVectorBase.h:64
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:62
bool edm::PtrVectorBase::isNonnull ( ) const
inline

Checks for non-null.

Definition at line 53 of file PtrVectorBase.h.

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

Referenced by isNull().

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

Checks for null.

Definition at line 49 of file PtrVectorBase.h.

References isNonnull().

Referenced by operator!().

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

Definition at line 93 of file PtrVectorBase.h.

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

Referenced by makePtr().

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

Definition at line 123 of file PtrVectorBase.h.

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

123  {
124  if (isTransient()) {
125  return TPtr(reinterpret_cast<typename TPtr::value_type const*>((*cachedItems_)[iIndex]),
126  indicies_[iIndex]);
127  }
128  if (hasCache() && ((*cachedItems_)[iIndex] != nullptr || productGetter() == nullptr)) {
129  return TPtr(this->id(),
130  reinterpret_cast<typename TPtr::value_type const*>((*cachedItems_)[iIndex]),
131  indicies_[iIndex]);
132  }
133  return TPtr(this->id(), indicies_[iIndex], productGetter());
134  }
bool isTransient() const
Definition: PtrVectorBase.h:93
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
bool hasCache() const
Definition: PtrVectorBase.h:64
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:62
template<typename TPtr >
TPtr edm::PtrVectorBase::makePtr ( std::vector< void const * >::const_iterator const  iIt) const
inlineprotected

Definition at line 137 of file PtrVectorBase.h.

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

137  {
138  if (isTransient()) {
139  return TPtr(reinterpret_cast<typename TPtr::value_type const*>(*iIt),
140  indicies_[iIt - (*cachedItems_).begin()]);
141  }
142  if (hasCache() && (*iIt != nullptr || productGetter() == nullptr)) {
143  return TPtr(this->id(),
144  reinterpret_cast<typename TPtr::value_type const*>(*iIt),
145  indicies_[iIt - (*cachedItems_).begin()]);
146  }
147  return TPtr(this->id(), indicies_[iIt - (*cachedItems_).begin()], productGetter());
148  }
bool isTransient() const
Definition: PtrVectorBase.h:93
std::vector< key_type > indicies_
bool hasCache() const
Definition: PtrVectorBase.h:64
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:62
bool edm::PtrVectorBase::operator! ( ) const
inline

Checks for null.

Definition at line 56 of file PtrVectorBase.h.

References isNull().

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

Definition at line 179 of file PtrVectorBase.cc.

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

179  {
180  if(core_ != iRHS.core_) {
181  return false;
182  }
183  if(indicies_.size() != iRHS.indicies_.size()){
184  return false;
185  }
186  return std::equal(indicies_.begin(),
187  indicies_.end(),
188  iRHS.indicies_.begin());
189  }
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 95 of file PtrVectorBase.h.

Referenced by getProduct_().

95  {
96  return 0;
97  }
EDProductGetter const* edm::PtrVectorBase::productGetter ( ) const
inline

Accessor for product getter.

Definition at line 62 of file PtrVectorBase.h.

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

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

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

Definition at line 69 of file PtrVectorBase.cc.

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

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

69  {
70  core_.pushBackItem(core, false);
71  //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr?
72  if(not cachedItems_ and indicies_.empty()) {
73  cachedItems_.store( new std::vector<void const*>());
74  (*cachedItems_).reserve(indicies_.capacity());
75  }
76  auto tmpCachedItems = cachedItems_.load();
77  if(tmpCachedItems and (indicies_.size() == (*tmpCachedItems).size())) {
78  if(iData) {
79  tmpCachedItems->push_back(iData);
80  } else if(key_traits<key_type>::value == iKey) {
81  tmpCachedItems->push_back(nullptr);
82  } else {
83  delete tmpCachedItems;
84  cachedItems_.store(nullptr);
85  }
86  }
87  indicies_.push_back(iKey);
88  }
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:193
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
void edm::PtrVectorBase::reserve ( size_type  n)
inline

Reserve space for RefVector.

Definition at line 88 of file PtrVectorBase.h.

References cachedItems_, and indicies_.

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

Definition at line 91 of file PtrVectorBase.h.

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

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

swap

Definition at line 62 of file PtrVectorBase.cc.

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

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

62  {
63  core_.swap(other.core_);
64  indicies_.swap(other.indicies_);
65  other.cachedItems_.store(cachedItems_.exchange(other.cachedItems_.load()));
66  }
void swap(RefCore &)
Definition: RefCore.h:146
std::vector< key_type > indicies_
std::atomic< 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 107 of file PtrVectorBase.h.

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

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

107  {
108  getProduct_();
109  if(not checkCachedItems()) {
110  return emptyCache().begin();
111  }
112  return (*cachedItems_).begin();
113  }
bool checkCachedItems() const
static const std::vector< void const * > & emptyCache()
void getProduct_() const
std::vector<void const*>::const_iterator edm::PtrVectorBase::void_end ( ) const
inlineprotected

Definition at line 114 of file PtrVectorBase.h.

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

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

114  {
115  getProduct_();
116  if(not checkCachedItems()) {
117  return emptyCache().end();
118  }
119  return (*cachedItems_).end();
120  }
bool checkCachedItems() const
static const std::vector< void const * > & emptyCache()
void getProduct_() const

Member Data Documentation

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