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...
 
PtrVectorBaseoperator= (const PtrVectorBase &)=delete
 
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
 
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) {}
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_

◆ PtrVectorBase() [2/3]

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

◆ ~PtrVectorBase()

edm::PtrVectorBase::~PtrVectorBase ( )
virtual

Definition at line 37 of file PtrVectorBase.cc.

References cachedItems_.

37 { delete cachedItems_.load(); }
std::atomic< std::vector< void const * > * > cachedItems_

◆ PtrVectorBase() [3/3]

edm::PtrVectorBase::PtrVectorBase ( )
protected

Definition at line 35 of file PtrVectorBase.cc.

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

Member Function Documentation

◆ capacity()

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

Capacity of the RefVector.

Definition at line 78 of file PtrVectorBase.h.

References indicies_.

78 { return indicies_.capacity(); }
std::vector< key_type > indicies_

◆ checkCachedItems()

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 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  }
std::atomic< std::vector< void const * > * > cachedItems_
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:60
tmp
align.sh
Definition: createJobs.py:716

◆ clear()

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

◆ empty()

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

Is the RefVector empty.

Definition at line 72 of file PtrVectorBase.h.

References indicies_.

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

72 { return indicies_.empty(); }
std::vector< key_type > indicies_

◆ emptyCache()

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

Definition at line 186 of file PtrVectorBase.cc.

References edm::s_emptyCache.

Referenced by void_begin(), and void_end().

186 { return s_emptyCache; }
static const std::vector< void const * > s_emptyCache

◆ getProduct_()

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

Definition at line 105 of file PtrVectorBase.cc.

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

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  }
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:63
assert(be >=bs)
void const * product() const
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
virtual std::type_info const & typeInfo() const
bool hasCache() const
Definition: PtrVectorBase.h:65

◆ hasCache()

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

Definition at line 65 of file PtrVectorBase.h.

References cachedItems_.

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

65 { return cachedItems_; }
std::atomic< std::vector< void const * > * > cachedItems_

◆ id()

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

Accessor for product ID.

Definition at line 60 of file PtrVectorBase.h.

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

Referenced by checkCachedItems().

60 { return core_.id(); }
ProductID id() const
Definition: RefCore.h:48

◆ 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.

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

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  }
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:63
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
bool isAvailable() const
Definition: RefCore.cc:146
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_
void getProduct_() const
bool hasCache() const
Definition: PtrVectorBase.h:65

◆ isNonnull()

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

Checks for non-null.

Definition at line 54 of file PtrVectorBase.h.

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

Referenced by isNull().

54 { return core_.isNonnull(); }
bool isNonnull() const
Definition: RefCore.h:71

◆ isNull()

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

Checks for null.

Definition at line 50 of file PtrVectorBase.h.

References isNonnull().

Referenced by operator!().

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

◆ isTransient()

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

Definition at line 104 of file PtrVectorBase.h.

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

Referenced by makePtr().

104 { return core_.isTransient(); }
bool isTransient() const
Definition: RefCore.h:105

◆ makePtr() [1/2]

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

Definition at line 132 of file PtrVectorBase.h.

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

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

◆ makePtr() [2/2]

template<typename TPtr >
TPtr edm::PtrVectorBase::makePtr ( std::vector< void const *>::const_iterator const  iIt) const
inlineprotected

Definition at line 144 of file PtrVectorBase.h.

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

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

◆ operator!()

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

Checks for null.

Definition at line 57 of file PtrVectorBase.h.

References isNull().

57 { return isNull(); }
bool isNull() const
Checks for null.
Definition: PtrVectorBase.h:50

◆ operator=()

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

◆ operator==()

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

Definition at line 170 of file PtrVectorBase.cc.

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

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_

◆ product()

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

Definition at line 106 of file PtrVectorBase.h.

Referenced by getProduct_().

106 { return nullptr; }

◆ 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.

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

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

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:165
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_

◆ reserve()

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

Reserve space for RefVector.

Definition at line 95 of file PtrVectorBase.h.

References cachedItems_, indicies_, and dqmiodumpmetadata::n.

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

95  {
96  indicies_.reserve(n);
97  if (cachedItems_) {
98  (*cachedItems_).reserve(n);
99  }
100  }
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_

◆ setProductGetter()

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

Definition at line 102 of file PtrVectorBase.h.

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

102 { core_.setProductGetter(iGetter); }
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:156

◆ 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.

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

Referenced by edm::PtrVector< reco::CaloCluster >::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:149
std::vector< key_type > indicies_
std::atomic< std::vector< void const * > * > cachedItems_

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

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

Referenced by getProduct_().

159  {
160  assert(false);
161  return typeid(void);
162  }
assert(be >=bs)
TEMPL(T2) struct Divides void
Definition: Factorize.h:24

◆ void_begin()

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

Definition at line 116 of file PtrVectorBase.h.

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

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

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

◆ void_end()

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

Definition at line 123 of file PtrVectorBase.h.

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

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

123  {
124  getProduct_();
125  if (not checkCachedItems()) {
126  return emptyCache().end();
127  }
128  return (*cachedItems_).end();
129  }
bool checkCachedItems() const
static const std::vector< void const * > & emptyCache()
void getProduct_() const

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