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::CaloCluster > edm::PtrVector< 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 (const PtrVectorBase &)
 
 PtrVectorBase (ProductID const &productID, void const *prodPtr=nullptr, EDProductGetter const *prodGetter=nullptr)
 
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 (std::vector< void const * >::const_iterator const iIt) const
 
template<typename TPtr >
TPtr makePtr (unsigned long iIndex) 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

◆ key_type

typedef unsigned long edm::PtrVectorBase::key_type

Definition at line 34 of file PtrVectorBase.h.

◆ size_type

Definition at line 35 of file PtrVectorBase.h.

Constructor & Destructor Documentation

◆ PtrVectorBase() [1/3]

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

Definition at line 37 of file PtrVectorBase.h.

40  : core_(productID, prodPtr, prodGetter, false), indicies_(), cachedItems_(nullptr) {}

◆ PtrVectorBase() [2/3]

edm::PtrVectorBase::PtrVectorBase ( const PtrVectorBase iOther)

Definition at line 39 of file PtrVectorBase.cc.

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  }

References utilities::cache(), and cachedItems_.

◆ ~PtrVectorBase()

edm::PtrVectorBase::~PtrVectorBase ( )
virtual

Definition at line 37 of file PtrVectorBase.cc.

37 { delete cachedItems_.load(); }

References cachedItems_.

◆ PtrVectorBase() [3/3]

edm::PtrVectorBase::PtrVectorBase ( )
protected

Definition at line 35 of file PtrVectorBase.cc.

35 : cachedItems_(nullptr) {}

Member Function Documentation

◆ capacity()

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

Capacity of the RefVector.

Definition at line 76 of file PtrVectorBase.h.

76 { return indicies_.capacity(); }

References indicies_.

◆ checkCachedItems()

bool edm::PtrVectorBase::checkCachedItems ( ) const
private

Definition at line 156 of file PtrVectorBase.cc.

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  }

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

Referenced by void_begin(), and void_end().

◆ clear()

void edm::PtrVectorBase::clear ( void  )
inline

◆ empty()

bool edm::PtrVectorBase::empty ( ) const
inline

Is the RefVector empty.

Definition at line 70 of file PtrVectorBase.h.

70 { return indicies_.empty(); }

References indicies_.

Referenced by Multi5x5BremRecoveryClusterAlgo::makeIslandSuperClusters(), and ReducedEGProducer::relinkCaloClusters().

◆ emptyCache()

const std::vector< void const * > & edm::PtrVectorBase::emptyCache ( )
staticprivate

Definition at line 186 of file PtrVectorBase.cc.

186 { return s_emptyCache; }

References edm::s_emptyCache.

Referenced by void_begin(), and void_end().

◆ getProduct_()

void edm::PtrVectorBase::getProduct_ ( ) const
private

Definition at line 105 of file PtrVectorBase.cc.

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  }

References cms::cuda::assert(), cachedItems_, Exception, hasCache(), indicies_, dqmdumpme::k, edm::errors::LogicError, product(), productGetter(), and typeInfo().

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

◆ hasCache()

bool edm::PtrVectorBase::hasCache ( ) const
inline

Definition at line 63 of file PtrVectorBase.h.

63 { return cachedItems_; }

References cachedItems_.

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

◆ id()

ProductID edm::PtrVectorBase::id ( ) const
inline

Accessor for product ID.

Definition at line 58 of file PtrVectorBase.h.

58 { return core_.id(); }

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

Referenced by checkCachedItems().

◆ isAvailable()

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.

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  }

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

◆ isNonnull()

bool edm::PtrVectorBase::isNonnull ( ) const
inline

Checks for non-null.

Definition at line 52 of file PtrVectorBase.h.

52 { return core_.isNonnull(); }

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

Referenced by isNull().

◆ isNull()

bool edm::PtrVectorBase::isNull ( ) const
inline

Checks for null.

Definition at line 48 of file PtrVectorBase.h.

48 { return !isNonnull(); }

References isNonnull().

Referenced by operator!().

◆ isTransient()

bool edm::PtrVectorBase::isTransient ( ) const
inline

Definition at line 102 of file PtrVectorBase.h.

102 { return core_.isTransient(); }

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

Referenced by makePtr().

◆ makePtr() [1/2]

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.

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  }

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

◆ makePtr() [2/2]

template<typename TPtr >
TPtr edm::PtrVectorBase::makePtr ( unsigned long  iIndex) const
inlineprotected

Definition at line 130 of file PtrVectorBase.h.

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  }

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

◆ operator!()

bool edm::PtrVectorBase::operator! ( ) const
inline

Checks for null.

Definition at line 55 of file PtrVectorBase.h.

55 { return isNull(); }

References isNull().

◆ operator=()

PtrVectorBase& edm::PtrVectorBase::operator= ( const PtrVectorBase )
privatedelete

◆ operator==()

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

Definition at line 170 of file PtrVectorBase.cc.

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  }

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

◆ product()

void const* edm::PtrVectorBase::product ( ) const
inline

Definition at line 104 of file PtrVectorBase.h.

104 { return nullptr; }

Referenced by getProduct_().

◆ productGetter()

EDProductGetter const* edm::PtrVectorBase::productGetter ( ) const
inline

◆ push_back_base()

void edm::PtrVectorBase::push_back_base ( RefCore const &  core,
key_type  iKey,
void const *  iData 
)
protected

Definition at line 62 of file PtrVectorBase.cc.

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  }

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

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

◆ reserve()

void edm::PtrVectorBase::reserve ( size_type  n)
inline

Reserve space for RefVector.

Definition at line 93 of file PtrVectorBase.h.

93  {
94  indicies_.reserve(n);
95  if (cachedItems_) {
96  (*cachedItems_).reserve(n);
97  }
98  }

References cachedItems_, indicies_, and dqmiodumpmetadata::n.

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

◆ setProductGetter()

void edm::PtrVectorBase::setProductGetter ( EDProductGetter iGetter) const
inline

Definition at line 100 of file PtrVectorBase.h.

100 { core_.setProductGetter(iGetter); }

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

◆ size()

size_type edm::PtrVectorBase::size ( void  ) const
inline

◆ swap()

void edm::PtrVectorBase::swap ( PtrVectorBase other)
protected

swap

Definition at line 56 of file PtrVectorBase.cc.

56  {
57  core_.swap(other.core_);
58  indicies_.swap(other.indicies_);
59  other.cachedItems_.store(cachedItems_.exchange(other.cachedItems_.load()));
60  }

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

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

◆ typeInfo()

virtual std::type_info const& edm::PtrVectorBase::typeInfo ( ) const
inlineprivatevirtual

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

Definition at line 157 of file PtrVectorBase.h.

157  {
158  assert(false);
159  return typeid(void);
160  }

References cms::cuda::assert(), and funct::void.

Referenced by getProduct_().

◆ void_begin()

std::vector<void const*>::const_iterator edm::PtrVectorBase::void_begin ( ) const
inlineprotected

Definition at line 114 of file PtrVectorBase.h.

114  {
115  getProduct_();
116  if (not checkCachedItems()) {
117  return emptyCache().begin();
118  }
119  return (*cachedItems_).begin();
120  }

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

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

◆ void_end()

std::vector<void const*>::const_iterator edm::PtrVectorBase::void_end ( ) const
inlineprotected

Definition at line 121 of file PtrVectorBase.h.

121  {
122  getProduct_();
123  if (not checkCachedItems()) {
124  return emptyCache().end();
125  }
126  return (*cachedItems_).end();
127  }

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

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

Member Data Documentation

◆ cachedItems_

std::atomic<std::vector<void const*>*> edm::PtrVectorBase::cachedItems_
mutableprivate

◆ core_

RefCore edm::PtrVectorBase::core_
private

◆ indicies_

std::vector<key_type> edm::PtrVectorBase::indicies_
private
edm::RefCore::setProductGetter
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:156
edm::RefCore::swap
void swap(RefCore &) noexcept
Definition: RefCore.h:149
edm::PtrVectorBase::getProduct_
void getProduct_() const
Definition: PtrVectorBase.cc:105
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::PtrVectorBase::isNull
bool isNull() const
Checks for null.
Definition: PtrVectorBase.h:48
edm::errors::LogicError
Definition: EDMException.h:37
cms::cuda::assert
assert(be >=bs)
edm::PtrVectorBase::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:61
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::PtrVectorBase::product
void const * product() const
Definition: PtrVectorBase.h:104
edm::PtrVectorBase::checkCachedItems
bool checkCachedItems() const
Definition: PtrVectorBase.cc:156
edm::PtrVectorBase::isTransient
bool isTransient() const
Definition: PtrVectorBase.h:102
edm::RefCore::productGetter
EDProductGetter const * productGetter() const
Definition: RefCore.h:81
edm::PtrVectorBase::indicies_
std::vector< key_type > indicies_
Definition: PtrVectorBase.h:172
edm::PtrVectorBase::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: PtrVectorBase.h:52
edm::s_emptyCache
static const std::vector< void const * > s_emptyCache
Definition: PtrVectorBase.cc:184
trackingPlots.other
other
Definition: trackingPlots.py:1467
dqmdumpme.k
k
Definition: dqmdumpme.py:60
utilities.cache
def cache(function)
Definition: utilities.py:3
edm::PtrVectorBase::core_
RefCore core_
Definition: PtrVectorBase.h:171
edm::key_traits::value
static const key_type value
Definition: traits.h:34
edm::RefCore::isTransient
bool isTransient() const
Definition: RefCore.h:105
core
Definition: __init__.py:1
edm::RefCore::pushBackItem
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:165
edm::PtrVectorBase::cachedItems_
std::atomic< std::vector< void const * > * > cachedItems_
Definition: PtrVectorBase.h:173
edm::PtrVectorBase::emptyCache
static const std::vector< void const * > & emptyCache()
Definition: PtrVectorBase.cc:186
edm::RefCore::id
ProductID id() const
Definition: RefCore.h:48
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::PtrVectorBase::id
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:58
edm::PtrVectorBase::typeInfo
virtual std::type_info const & typeInfo() const
Definition: PtrVectorBase.h:157
Exception
Definition: hltDiff.cc:246
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
edm::PtrVectorBase::hasCache
bool hasCache() const
Definition: PtrVectorBase.h:63
edm::RefCore::isAvailable
bool isAvailable() const
Definition: RefCore.cc:146
cond::serialization::equal
bool equal(const T &first, const T &second)
Definition: Equal.h:32
edm::RefCore::isNonnull
bool isNonnull() const
Definition: RefCore.h:71