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< CaloCluster > edm::PtrVector< Candidate > edm::PtrVector< reco::reco::BasicCluster > edm::PtrVector< reco::reco::PFCluster >

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 34 of file PtrVectorBase.h.

Definition at line 35 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 37 of file PtrVectorBase.h.

References PtrVectorBase(), and ~PtrVectorBase().

40  : 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 39 of file PtrVectorBase.cc.

References utilities::cache(), and cachedItems_.

40  : core_(iOther.core_), indicies_(iOther.indicies_), cachedItems_(nullptr) {
41  auto cache = iOther.cachedItems_.load();
42  if (cache) {
43  cachedItems_.store(new std::vector<void const*>(*cache));
44  }
45  }
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
def cache(function)
Definition: utilities.py:3
edm::PtrVectorBase::~PtrVectorBase ( )
virtual

Definition at line 37 of file PtrVectorBase.cc.

References cachedItems_.

Referenced by PtrVectorBase().

37 { delete cachedItems_.load(); }
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) {}
std::atomic< std::vector< void const * > * > cachedItems_

Member Function Documentation

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

Capacity of the RefVector.

Definition at line 76 of file PtrVectorBase.h.

References indicies_.

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

Definition at line 156 of file PtrVectorBase.cc.

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

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

156  {
157  auto tmp = cachedItems_.load();
158  if (not tmp) {
159  return false;
160  }
161  for (auto item : *tmp) {
162  if (item == nullptr) {
164  << "Asked for data from a PtrVector which refers to a non-existent product with ProductID " << id() << "\n";
165  }
166  }
167  return true;
168  }
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:58
std::atomic< std::vector< void const * > * > cachedItems_
tmp
align.sh
Definition: createJobs.py:716
void edm::PtrVectorBase::clear ( void  )
inline
bool edm::PtrVectorBase::empty ( ) const
inline
const std::vector< void const * > & edm::PtrVectorBase::emptyCache ( )
staticprivate

Definition at line 186 of file PtrVectorBase.cc.

References edm::s_emptyCache.

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

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

Definition at line 105 of file PtrVectorBase.cc.

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

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

105  {
106  if (hasCache()) {
107  return;
108  }
109  if (indicies_.empty()) {
110  return;
111  }
112  //NOTE: Another thread could be getting the data
113  auto tmpProductGetter = productGetter();
114  if (nullptr == tmpProductGetter) {
115  throw Exception(errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n";
116  }
117  WrapperBase const* product = tmpProductGetter->getIt(id());
118 
119  auto tmpCachedItems = std::make_unique<std::vector<void const*>>();
120 
121  if (product != nullptr) {
122  product->fillPtrVector(typeInfo(), indicies_, *tmpCachedItems);
123 
124  std::vector<void const*>* expected = nullptr;
125  if (cachedItems_.compare_exchange_strong(expected, tmpCachedItems.get())) {
126  //we were the first thread to change the value
127  tmpCachedItems.release();
128  }
129 
130  return;
131  }
132 
133  tmpCachedItems->resize(indicies_.size(), nullptr);
134 
135  std::vector<unsigned int> thinnedKeys;
136  thinnedKeys.assign(indicies_.begin(), indicies_.end());
137  std::vector<WrapperBase const*> wrappers(indicies_.size(), nullptr);
138  tmpProductGetter->getThinnedProducts(id(), wrappers, thinnedKeys);
139  unsigned int nWrappers = wrappers.size();
140  assert(wrappers.size() == indicies_.size());
141  assert(wrappers.size() == tmpCachedItems->size());
142  for (unsigned k = 0; k < nWrappers; ++k) {
143  if (wrappers[k] != nullptr) {
144  wrappers[k]->setPtr(typeInfo(), thinnedKeys[k], (*tmpCachedItems)[k]);
145  }
146  }
147  {
148  std::vector<void const*>* expected = nullptr;
149  if (cachedItems_.compare_exchange_strong(expected, tmpCachedItems.get())) {
150  //we were the first thread to change the value
151  tmpCachedItems.release();
152  }
153  }
154  }
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:63
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:61
void const * product() const
bool edm::PtrVectorBase::hasCache ( ) const
inline

Definition at line 63 of file PtrVectorBase.h.

References cachedItems_, and isAvailable().

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

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

Accessor for product ID.

Definition at line 58 of file PtrVectorBase.h.

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

Referenced by checkCachedItems().

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

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

Referenced by hasCache().

83  {
84  if (indicies_.empty()) {
85  return core_.isAvailable();
86  }
87  if (!hasCache()) {
88  if (!id().isValid() || productGetter() == nullptr) {
89  return false;
90  }
91  getProduct_();
92  }
93  auto tmpCachedItems = cachedItems_.load();
94  for (auto ptr : *tmpCachedItems) {
95  if (ptr == nullptr) {
96  return false;
97  }
98  }
99  return true;
100  }
void getProduct_() const
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
bool isAvailable() const
Definition: RefCore.cc:145
bool hasCache() const
Definition: PtrVectorBase.h:63
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:61
bool edm::PtrVectorBase::isNonnull ( ) const
inline

Checks for non-null.

Definition at line 52 of file PtrVectorBase.h.

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

Referenced by isNull().

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

Checks for null.

Definition at line 48 of file PtrVectorBase.h.

References isNonnull().

Referenced by operator!().

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

Definition at line 102 of file PtrVectorBase.h.

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

Referenced by makePtr().

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

Definition at line 130 of file PtrVectorBase.h.

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

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

Definition at line 142 of file PtrVectorBase.h.

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

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

Checks for null.

Definition at line 55 of file PtrVectorBase.h.

References isNull().

55 { return isNull(); }
bool isNull() const
Checks for null.
Definition: PtrVectorBase.h:48
PtrVectorBase& edm::PtrVectorBase::operator= ( const PtrVectorBase )
privatedelete

Referenced by typeInfo().

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

Definition at line 170 of file PtrVectorBase.cc.

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

Referenced by clear().

170  {
171  if (core_ != iRHS.core_) {
172  return false;
173  }
174  if (indicies_.size() != iRHS.indicies_.size()) {
175  return false;
176  }
177  return std::equal(indicies_.begin(), indicies_.end(), iRHS.indicies_.begin());
178  }
bool equal(const T &first, const T &second)
Definition: Equal.h:32
std::vector< key_type > indicies_
void const* edm::PtrVectorBase::product ( ) const
inline

Definition at line 104 of file PtrVectorBase.h.

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

Referenced by getProduct_().

104 { return nullptr; }
EDProductGetter const* edm::PtrVectorBase::productGetter ( ) const
inline

Accessor for product getter.

Definition at line 61 of file PtrVectorBase.h.

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

Referenced by getProduct_(), isAvailable(), makePtr(), PATObjectCrossLinker::matchElectronToPhoton(), and PATObjectCrossLinker::matchOneToMany().

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

Definition at line 62 of file PtrVectorBase.cc.

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

Referenced by product().

62  {
63  core_.pushBackItem(core, false);
64  //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr?
65  if (not cachedItems_ and indicies_.empty()) {
66  cachedItems_.store(new std::vector<void const*>());
67  (*cachedItems_).reserve(indicies_.capacity());
68  }
69  auto tmpCachedItems = cachedItems_.load();
70  if (tmpCachedItems and (indicies_.size() == (*tmpCachedItems).size())) {
71  if (iData) {
72  tmpCachedItems->push_back(iData);
73  } else if (key_traits<key_type>::value == iKey) {
74  tmpCachedItems->push_back(nullptr);
75  } else {
76  delete tmpCachedItems;
77  cachedItems_.store(nullptr);
78  }
79  }
80  indicies_.push_back(iKey);
81  }
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:164
static const key_type value
Definition: traits.h:34
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 93 of file PtrVectorBase.h.

References cachedItems_, and indicies_.

Referenced by convertToPFCandidatePtr(), Multi5x5SuperClusterProducer::getClusterPtrVector(), and HGCalLayerClusterProducer::produce().

93  {
94  indicies_.reserve(n);
95  if (cachedItems_) {
96  (*cachedItems_).reserve(n);
97  }
98  }
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
void edm::PtrVectorBase::setProductGetter ( EDProductGetter iGetter) const
inline

Definition at line 100 of file PtrVectorBase.h.

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

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

swap

Definition at line 56 of file PtrVectorBase.cc.

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

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

56  {
57  core_.swap(other.core_);
58  indicies_.swap(other.indicies_);
59  other.cachedItems_.store(cachedItems_.exchange(other.cachedItems_.load()));
60  }
void swap(RefCore &) noexcept
Definition: RefCore.h:147
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
virtual std::type_info const& edm::PtrVectorBase::typeInfo ( ) const
inlineprivatevirtual

Reimplemented in edm::PtrVector< T >, edm::PtrVector< CaloCluster >, edm::PtrVector< Candidate >, edm::PtrVector< reco::reco::BasicCluster >, and edm::PtrVector< reco::reco::PFCluster >.

Definition at line 157 of file PtrVectorBase.h.

References checkCachedItems(), emptyCache(), and operator=().

Referenced by getProduct_().

157  {
158  assert(false);
159  return typeid(void);
160  }
std::vector<void const*>::const_iterator edm::PtrVectorBase::void_begin ( ) 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().begin();
118  }
119  return (*cachedItems_).begin();
120  }
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 121 of file PtrVectorBase.h.

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

121  {
122  getProduct_();
123  if (not checkCachedItems()) {
124  return emptyCache().end();
125  }
126  return (*cachedItems_).end();
127  }
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