CMS 3D CMS Logo

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 
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  RefVectorBase(RefVectorBase&& rhs) noexcept
41  : product_(std::move(rhs.product_)),
42  keys_(std::move(rhs.keys_)),
43  memberPointersHolder_(std::move(rhs.memberPointersHolder_)) {}
44 
46  RefVectorBase temp(rhs);
47  this->swap(temp);
48  return *this;
49  }
51  product_ = std::move(rhs.product_);
52  keys_ = std::move(rhs.keys_);
53  memberPointersHolder_ = std::move(rhs.memberPointersHolder_);
54  return *this;
55  }
56 
57  explicit RefVectorBase(ProductID const& productID,
58  void const* prodPtr = nullptr,
59  EDProductGetter const* prodGetter = nullptr)
60  : product_(productID, prodPtr, prodGetter, false), keys_() {}
61 
63  ~RefVectorBase() noexcept {}
64 
66  RefCore const& refCore() const { return product_; }
67 
68  void const* cachedMemberPointer(size_type idx) const {
69  return memberPointers().empty() ? nullptr : memberPointers()[idx];
70  }
71 
73  keys_type const& keys() const { return keys_; }
74 
76  bool empty() const { return keys_.empty(); }
77 
79  size_type size() const { return keys_.size(); }
80 
81  void pushBack(RefCore const& product, KEY const& key) {
82  product_.pushBackRefItem(product);
83  if (product.productPtr() != nullptr) {
84  if (memberPointers().empty()) {
85  memberPointersHolder_.memberPointers().resize(keys_.size(), nullptr);
86  }
87  memberPointersHolder_.memberPointers().push_back(product.productPtr());
88  keys_.push_back(key);
89  return;
90  } else {
91  if (!memberPointers().empty()) {
92  memberPointersHolder_.memberPointers().push_back(nullptr);
93  }
94  keys_.push_back(key);
95  }
96  }
97 
99  size_type capacity() const { return keys_.capacity(); }
100 
102  void reserve(size_type n) { keys_.reserve(n); }
103 
105  typename keys_type::iterator eraseAtIndex(size_type index) {
107  return keys_.erase(keys_.begin() + index);
108  }
109 
111  void clear() {
112  keys_.clear();
114  product_ = RefCore();
115  }
116 
118  void swap(RefVectorBase<KEY>& other) noexcept {
119  product_.swap(other.product_);
120  keys_.swap(other.keys_);
121  memberPointersHolder_.memberPointers().swap(other.memberPointersHolder_.memberPointers());
122  }
123 
124  //Needed for ROOT storage
126 
127  private:
129 
133  };
134 
136  template <typename KEY>
137  bool operator==(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
138  return lhs.refCore() == rhs.refCore() && lhs.keys() == rhs.keys();
139  }
140 
142  template <typename KEY>
143  bool operator!=(RefVectorBase<KEY> const& lhs, RefVectorBase<KEY> const& rhs) {
144  return !(lhs == rhs);
145  }
146 
148  template <typename KEY>
150  a.swap(b);
151  }
152 
153 } // namespace edm
154 #endif
constexpr bool operator==(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
void swap(RefCore &) noexcept
Definition: RefCore.h:149
std::vector< void const * > const & memberPointers() const
void swap(RefVectorBase< KEY > &other) noexcept
swap two vectors
void clear()
clear the vector
std::vector< KEY > keys_type
Definition: RefVectorBase.h:33
#define CMS_CLASS_VERSION(_version_)
bool empty() const
Is vector empty?
Definition: RefVectorBase.h:76
void const * productPtr() const
Definition: RefCore.h:51
uint16_t size_type
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
RefVectorBase(RefVectorBase &&rhs) noexcept
Definition: RefVectorBase.h:40
~RefVectorBase() noexcept
Destructor.
Definition: RefVectorBase.h:63
std::vector< void const * > & memberPointers()
Definition: RefVectorBase.h:24
keys_type::size_type size_type
Definition: RefVectorBase.h:35
key
prepare the HTCondor submission files and eventually submit them
std::vector< void const * > const & memberPointers() const
Definition: RefVectorBase.h:23
constexpr bool operator!=(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
RefVectorBase()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefVectorBase.h:37
size_type capacity() const
Capacity of vector.
Definition: RefVectorBase.h:99
RefVectorMemberPointersHolder memberPointersHolder_
void pushBack(RefCore const &product, KEY const &key)
Definition: RefVectorBase.h:81
std::vector< void const * > memberPointers_
Definition: RefVectorBase.h:27
RefVectorBase & operator=(RefVectorBase const &rhs)
Definition: RefVectorBase.h:45
RefVectorBase(RefVectorBase const &rhs)
Definition: RefVectorBase.h:38
double b
Definition: hdecay.h:120
RefVectorBase(ProductID const &productID, void const *prodPtr=nullptr, EDProductGetter const *prodGetter=nullptr)
Definition: RefVectorBase.h:57
void const * cachedMemberPointer(size_type idx) const
Definition: RefVectorBase.h:68
HLT enums.
double a
Definition: hdecay.h:121
RefVectorBase & operator=(RefVectorBase &&rhs) noexcept
Definition: RefVectorBase.h:50
void pushBackRefItem(RefCore const &productToBeInserted)
Definition: RefCore.cc:215
keys_type::iterator eraseAtIndex(size_type index)
erase an element from the vector
void reserve(size_type n)
Reserve space for vector.
RefCore const & refCore() const
Accessor for product ID and product getter.
Definition: RefVectorBase.h:66
def move(src, dest)
Definition: eostools.py:511
keys_type const & keys() const
Accessor for vector of keys and pointers.
Definition: RefVectorBase.h:73
size_type size() const
Size of vector.
Definition: RefVectorBase.h:79