CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefVectorBase.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorBase_h
2 #define DataFormats_Common_RefVectorBase_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefVectorBase: Base class for a vector of interproduct references.
7 
8 
9 ----------------------------------------------------------------------*/
10 
14 #include <vector>
16 
17 namespace edm {
18 
19  class EDProductGetter;
20 
22  public:
24  std::vector<void const*> const& memberPointers() const { return memberPointers_; }
25  std::vector<void const*>& memberPointers() { return memberPointers_; }
26  private:
27  std::vector<void const*> memberPointers_;
28  };
29 
30  template <typename KEY>
31  class RefVectorBase {
32  public:
33  typedef std::vector<KEY > keys_type;
34  typedef KEY key_type;
35  typedef typename keys_type::size_type size_type;
40 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
41  RefVectorBase( RefVectorBase && rhs) noexcept : product_(std::move(rhs.product_)), keys_(std::move(rhs.keys_)),
43 #endif
44 
45  explicit RefVectorBase(ProductID const& productID, void const* prodPtr = 0,
46  EDProductGetter const* prodGetter = 0) :
47  product_(productID, prodPtr, prodGetter, false), keys_() {}
48 
51 
53  RefCore const& refCore() const {return product_;}
54 
55  void const* cachedMemberPointer(size_type idx) const {
56  return memberPointers().empty() ? nullptr : memberPointers()[idx];
57  }
58 
60  keys_type const& keys() const {return keys_;}
61 
63  bool empty() const {return keys_.empty();}
64 
66  size_type size() const {return keys_.size();}
67 
68  void pushBack(RefCore const& product, KEY const& key) {
69  product_.pushBackRefItem(product);
70  if(product.productPtr() != nullptr) {
71  if(memberPointers().empty()) {
72  memberPointersHolder_.memberPointers().resize(keys_.size(), nullptr);
73  }
74  memberPointersHolder_.memberPointers().push_back(product.productPtr());
75  keys_.push_back(key);
76  return;
77  } else {
78  if(!memberPointers().empty()) {
79  memberPointersHolder_.memberPointers().push_back(nullptr);
80  }
81  keys_.push_back(key);
82  }
83  }
84 
86  size_type capacity() const {return keys_.capacity();}
87 
89  void reserve(size_type n) {keys_.reserve(n);}
90 
92  typename keys_type::iterator eraseAtIndex(size_type index) {
94  return keys_.erase(keys_.begin() + index);
95  }
96 
98  void clear() {
99  keys_.clear();
101  product_ = RefCore();
102  }
103 
106  product_.swap(other.product_);
107  keys_.swap(other.keys_);
108  memberPointersHolder_.memberPointers().swap(other.memberPointersHolder_.memberPointers());
109  }
110 
113  RefVectorBase temp(rhs);
114  this->swap(temp);
115  return *this;
116  }
117 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
119  product_ = std::move(rhs.product_);
120  keys_ =std::move(rhs.keys_);
121  memberPointersHolder_ = std::move(rhs.memberPointersHolder_);
122  return *this;
123  }
124 #endif
125 
126  //Needed for ROOT storage
128 
129  private:
130 
131  std::vector<void const*> const& memberPointers() const { return memberPointersHolder_.memberPointers(); }
132 
136  };
137 
139  template<typename KEY>
140  bool
142  return lhs.refCore() == rhs.refCore() && lhs.keys() == rhs.keys();
143  }
144 
146  template<typename KEY>
147  bool
149  return !(lhs == rhs);
150  }
151 
153  template<typename KEY>
154  inline
155  void
157  a.swap(b);
158  }
159 
160 }
161 #endif
void const * cachedMemberPointer(size_type idx) const
Definition: RefVectorBase.h:55
void swap(RefCore &)
Definition: RefCore.h:157
RefVectorBase & operator=(RefVectorBase const &rhs)
Copy assignment.
RefVectorBase(RefVectorBase const &rhs)
Definition: RefVectorBase.h:38
bool empty() const
Is vector empty?
Definition: RefVectorBase.h:63
#define noexcept
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
keys_type::iterator eraseAtIndex(size_type index)
erase an element from the vector
Definition: RefVectorBase.h:92
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
uint16_t size_type
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
std::vector< void const * > const & memberPointers() const
Definition: RefVectorBase.h:24
void pushBack(RefCore const &product, KEY const &key)
Definition: RefVectorBase.h:68
RefVectorBase()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefVectorBase.h:37
RefVectorMemberPointersHolder memberPointersHolder_
std::vector< void const * > & memberPointers()
Definition: RefVectorBase.h:25
void swap(RefVectorBase< KEY > &other)
swap two vectors
size_type capacity() const
Capacity of vector.
Definition: RefVectorBase.h:86
std::vector< void const * > const & memberPointers() const
RefCore const & refCore() const
Accessor for product ID and product getter.
Definition: RefVectorBase.h:53
def move
Definition: eostools.py:510
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
void const * productPtr() const
Definition: RefCore.h:45
#define private
Definition: FWEveView.cc:22
void clear()
clear the vector
Definition: RefVectorBase.h:98
keys_type const & keys() const
Accessor for vector of keys and pointers.
Definition: RefVectorBase.h:60
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
~RefVectorBase()
Destructor.
Definition: RefVectorBase.h:50
std::vector< void const * > memberPointers_
Definition: RefVectorBase.h:27
RefVectorBase(ProductID const &productID, void const *prodPtr=0, EDProductGetter const *prodGetter=0)
Definition: RefVectorBase.h:45
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
double a
Definition: hdecay.h:121
keys_type::size_type size_type
Definition: RefVectorBase.h:35
void pushBackRefItem(RefCore const &productToBeInserted)
Definition: RefCore.cc:242
volatile std::atomic< bool > shutdown_flag false
size_type size() const
Size of vector.
Definition: RefVectorBase.h:66
std::vector< KEY > keys_type
Definition: RefVectorBase.h:33
void reserve(size_type n)
Reserve space for vector.
Definition: RefVectorBase.h:89