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>
15 
16 namespace edm {
17 
18  class EDProductGetter;
19 
21  public:
23  std::vector<void const*> const& memberPointers() const { return memberPointers_; }
24  std::vector<void const*>& memberPointers() { return memberPointers_; }
25  private:
26  std::vector<void const*> memberPointers_;
27  };
28 
29  template <typename KEY>
30  class RefVectorBase {
31  public:
32  typedef std::vector<KEY > keys_type;
33  typedef KEY key_type;
34  typedef typename keys_type::size_type size_type;
41 
43  RefVectorBase temp(rhs);
44  this->swap(temp);
45  return *this;
46  }
48  product_ = std::move(rhs.product_);
49  keys_ =std::move(rhs.keys_);
50  memberPointersHolder_ = std::move(rhs.memberPointersHolder_);
51  return *this;
52  }
53 
54 
55 
56  explicit RefVectorBase(ProductID const& productID, void const* prodPtr = 0,
57  EDProductGetter const* prodGetter = 0) :
58  product_(productID, prodPtr, prodGetter, false), keys_() {}
59 
60 
63 
65  RefCore const& refCore() const {return product_;}
66 
67  void const* cachedMemberPointer(size_type idx) const {
68  return memberPointers().empty() ? nullptr : memberPointers()[idx];
69  }
70 
72  keys_type const& keys() const {return keys_;}
73 
75  bool empty() const {return keys_.empty();}
76 
78  size_type size() const {return keys_.size();}
79 
80  void pushBack(RefCore const& product, KEY const& key) {
81  product_.pushBackRefItem(product);
82  if(product.productPtr() != nullptr) {
83  if(memberPointers().empty()) {
84  memberPointersHolder_.memberPointers().resize(keys_.size(), nullptr);
85  }
86  memberPointersHolder_.memberPointers().push_back(product.productPtr());
87  keys_.push_back(key);
88  return;
89  } else {
90  if(!memberPointers().empty()) {
91  memberPointersHolder_.memberPointers().push_back(nullptr);
92  }
93  keys_.push_back(key);
94  }
95  }
96 
98  size_type capacity() const {return keys_.capacity();}
99 
101  void reserve(size_type n) {keys_.reserve(n);}
102 
104  typename keys_type::iterator eraseAtIndex(size_type index) {
106  return keys_.erase(keys_.begin() + index);
107  }
108 
110  void clear() {
111  keys_.clear();
113  product_ = RefCore();
114  }
115 
118  product_.swap(other.product_);
119  keys_.swap(other.keys_);
120  memberPointersHolder_.memberPointers().swap(other.memberPointersHolder_.memberPointers());
121  }
122 
123 
124  //Needed for ROOT storage
126 
127  private:
128 
129  std::vector<void const*> const& memberPointers() const { return memberPointersHolder_.memberPointers(); }
130 
134  };
135 
137  template<typename KEY>
138  bool
140  return lhs.refCore() == rhs.refCore() && lhs.keys() == rhs.keys();
141  }
142 
144  template<typename KEY>
145  bool
147  return !(lhs == rhs);
148  }
149 
151  template<typename KEY>
152  inline
153  void
155  a.swap(b);
156  }
157 
158 }
159 #endif
void const * cachedMemberPointer(size_type idx) const
Definition: RefVectorBase.h:67
RefVectorBase & operator=(RefVectorBase const &rhs)
Definition: RefVectorBase.h:42
RefVectorBase(RefVectorBase const &rhs)
Definition: RefVectorBase.h:37
void swap(RefCore &) noexcept
Definition: RefCore.h:157
bool empty() const
Is vector empty?
Definition: RefVectorBase.h:75
#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
#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:23
void pushBack(RefCore const &product, KEY const &key)
Definition: RefVectorBase.h:80
RefVectorBase()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefVectorBase.h:36
RefVectorMemberPointersHolder memberPointersHolder_
std::vector< void const * > & memberPointers()
Definition: RefVectorBase.h:24
size_type capacity() const
Capacity of vector.
Definition: RefVectorBase.h:98
RefVectorBase & operator=(RefVectorBase &&rhs) noexcept
Definition: RefVectorBase.h:47
std::vector< void const * > const & memberPointers() const
RefCore const & refCore() const
Accessor for product ID and product getter.
Definition: RefVectorBase.h:65
def move
Definition: eostools.py:510
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
void const * productPtr() const
Definition: RefCore.h:52
void clear()
clear the vector
keys_type const & keys() const
Accessor for vector of keys and pointers.
Definition: RefVectorBase.h:72
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::vector< void const * > memberPointers_
Definition: RefVectorBase.h:26
RefVectorBase(RefVectorBase &&rhs) noexcept
Definition: RefVectorBase.h:39
RefVectorBase(ProductID const &productID, void const *prodPtr=0, EDProductGetter const *prodGetter=0)
Definition: RefVectorBase.h:56
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
~RefVectorBase() noexcept
Destructor.
Definition: RefVectorBase.h:62
double a
Definition: hdecay.h:121
keys_type::size_type size_type
Definition: RefVectorBase.h:34
void pushBackRefItem(RefCore const &productToBeInserted)
Definition: RefCore.cc:243
volatile std::atomic< bool > shutdown_flag false
size_type size() const
Size of vector.
Definition: RefVectorBase.h:78
std::vector< KEY > keys_type
Definition: RefVectorBase.h:32
void reserve(size_type n)
Reserve space for vector.
void swap(RefVectorBase< KEY > &other) noexcept
swap two vectors