CMS 3D CMS Logo

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< C > edm::PtrVector< CaloCluster > edm::PtrVector< CaloTower > edm::PtrVector< Candidate > edm::PtrVector< l1t::HGCalCluster > edm::PtrVector< l1t::HGCalTriggerCell > 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::PFCandidate > edm::PtrVector< reco::PFClusterJet > edm::PtrVector< reco::PFJet > edm::PtrVector< reco::Photon > edm::PtrVector< reco::reco::BasicCluster > 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=nullptr, EDProductGetter const *prodGetter=nullptr)
 
 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 &)=delete
 
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 = nullptr,
EDProductGetter const *  prodGetter = nullptr 
)
inlineexplicit

Definition at line 38 of file PtrVectorBase.h.

References PtrVectorBase(), and ~PtrVectorBase().

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 42 of file PtrVectorBase.cc.

References helperFunctions::cache(), and cachedItems_.

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

Definition at line 38 of file PtrVectorBase.cc.

References cachedItems_.

Referenced by PtrVectorBase().

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

Definition at line 35 of file PtrVectorBase.cc.

Referenced by product(), and PtrVectorBase().

35  : cachedItems_(nullptr) {
36  }
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 167 of file PtrVectorBase.cc.

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

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

167  {
168  auto tmp = cachedItems_.load();
169  if(not tmp) { return false;}
170  for(auto item : *tmp) {
171  if(item == nullptr) {
172  throw Exception(errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product with ProductID "
173  << id() << "\n";
174  }
175  }
176  return true;
177  }
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 198 of file PtrVectorBase.cc.

References edm::s_emptyCache.

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

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

Definition at line 115 of file PtrVectorBase.cc.

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

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

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

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

64 { return cachedItems_; }
std::atomic< std::vector< void const * > * > cachedItems_
ProductID edm::PtrVectorBase::id ( ) const
inline
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 92 of file PtrVectorBase.cc.

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

Referenced by hasCache().

92  {
93  if(indicies_.empty()) {
94  return core_.isAvailable();
95  }
96  if(!hasCache()) {
97  if(!id().isValid() || productGetter() == nullptr) {
98  return false;
99  }
100  getProduct_();
101  }
102  auto tmpCachedItems = cachedItems_.load();
103  for(auto ptr : *tmpCachedItems) {
104  if(ptr == nullptr) {
105  return false;
106  }
107  }
108  return true;
109  }
void getProduct_() const
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
bool isAvailable() const
Definition: RefCore.cc:169
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:74
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:106
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 getProduct_(), 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 )
privatedelete

Referenced by typeInfo().

bool edm::PtrVectorBase::operator== ( PtrVectorBase const &  iRHS) const

Definition at line 180 of file PtrVectorBase.cc.

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

Referenced by clear().

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

References trackingPlots::other, PtrVectorBase(), push_back_base(), and swap().

Referenced by getProduct_().

95  {
96  return nullptr;
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(), makePtr(), PATObjectCrossLinker::matchElectronToPhoton(), and PATObjectCrossLinker::matchOneToMany().

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

Definition at line 70 of file PtrVectorBase.cc.

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

Referenced by product().

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

swap

Definition at line 63 of file PtrVectorBase.cc.

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

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

63  {
64  core_.swap(other.core_);
65  indicies_.swap(other.indicies_);
66  other.cachedItems_.store(cachedItems_.exchange(other.cachedItems_.load()));
67  }
void swap(RefCore &) noexcept
Definition: RefCore.h:157
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_().

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_().

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