CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PtrVectorBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Common
4 // Class : PtrVectorBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Oct 24 15:49:27 EDT 2007
11 //
12 
13 // user include files
19 
20 // system include files
21 #include <ostream>
22 
23 //
24 // constants, enums and typedefs
25 //
26 namespace edm {
27 //
28 // static data member definitions
29 //
30 
31 //
32 // constructor and destructor
33 //
35  }
36 
38  }
39 
40 //
41 // assignment operators
42 //
43 
44 //
45 // member functions
46 //
47 
49  void
51  core_.swap(other.core_);
52  indicies_.swap(other.indicies_);
53  cachedItems_.swap(other.cachedItems_);
54  }
55 
56  void
57  PtrVectorBase::push_back_base(RefCore const& core, key_type iKey, void const* iData) {
58  core_.pushBackItem(core, false);
59  //Did we already push a 'non-cached' Ptr into the container or is this a 'non-cached' Ptr?
60  if(indicies_.size() == cachedItems_.size()) {
61  if(iData) {
62  cachedItems_.push_back(iData);
63  } else if(key_traits<key_type>::value == iKey) {
64  cachedItems_.push_back(0);
65  } else {
66  cachedItems_.clear();
67  }
68  }
69  indicies_.push_back(iKey);
70  }
71 
72  bool
74  if(indicies_.empty()) {
75  return core_.isAvailable();
76  }
77  if(!hasCache()) {
78  if(!id().isValid() || productGetter() == nullptr) {
79  return false;
80  }
81  getProduct_();
82  }
83  for(auto ptr : cachedItems_) {
84  if(ptr == nullptr) {
85  return false;
86  }
87  }
88  return true;
89  }
90 
91 //
92 // const member functions
93 //
94  void
96  if(hasCache()) {
97  return;
98  }
99  if(indicies_.size() == 0) {
100  return;
101  }
102  if(0 == productGetter()) {
103  throw Exception(errors::LogicError) << "Tried to get data for a PtrVector which has no EDProductGetter\n";
104  }
105  WrapperBase const* product = productGetter()->getIt(id());
106 
107  if(product != nullptr) {
109  return;
110  }
111 
112  cachedItems_.resize(indicies_.size(), nullptr);
113 
114  std::vector<unsigned int> thinnedKeys;
115  thinnedKeys.assign(indicies_.begin(), indicies_.end());
116  std::vector<WrapperBase const*> wrappers(indicies_.size(), nullptr);
117  productGetter()->getThinnedProducts(id(), wrappers, thinnedKeys);
118  unsigned int nWrappers = wrappers.size();
119  assert(wrappers.size() == indicies_.size());
120  assert(wrappers.size() == cachedItems_.size());
121  for(unsigned k = 0; k < nWrappers; ++k) {
122  if (wrappers[k] != nullptr) {
123  wrappers[k]->setPtr(typeInfo(), thinnedKeys[k], cachedItems_[k]);
124  }
125  }
126  }
127 
128  void
130  for(auto item : cachedItems_) {
131  if(item == nullptr) {
132  throw Exception(errors::InvalidReference) << "Asked for data from a PtrVector which refers to a non-existent product with ProductID "
133  << id() << "\n";
134  }
135  }
136  }
137 
138  bool
140  if(core_ != iRHS.core_) {
141  return false;
142  }
143  if(indicies_.size() != iRHS.indicies_.size()){
144  return false;
145  }
146  return std::equal(indicies_.begin(),
147  indicies_.end(),
148  iRHS.indicies_.begin());
149  }
150 
151 //
152 // static member functions
153 //
154 }
void push_back_base(RefCore const &core, key_type iKey, void const *iData)
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:176
void swap(RefCore &)
Definition: RefCore.h:122
assert(m_qm.get())
void swap(PtrVectorBase &other)
swap
virtual std::type_info const & typeInfo() const
bool equal(const T &first, const T &second)
Definition: Equal.h:34
void getProduct_() const
virtual void getThinnedProducts(ProductID const &pid, std::vector< WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const =0
ProductID id() const
Accessor for product ID.
Definition: PtrVectorBase.h:56
bool isAvailable() const
std::vector< key_type > indicies_
bool isAvailable() const
Definition: RefCore.cc:155
virtual WrapperBase const * getIt(ProductID const &) const =0
bool operator==(PtrVectorBase const &iRHS) const
std::vector< void const * > cachedItems_
void fillPtrVector(std::type_info const &iToType, std::vector< unsigned long > const &iIndicies, std::vector< void const * > &oPtr) const
Definition: WrapperBase.cc:34
virtual ~PtrVectorBase()
bool hasCache() const
Definition: PtrVectorBase.h:61
unsigned long key_type
Definition: PtrVectorBase.h:35
void checkCachedItems() const
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: PtrVectorBase.h:59
void const * product() const
Definition: PtrVectorBase.h:90