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
edm::RefCore
Definition: RefCore.h:21
edm::RefVectorBase
Definition: EDProductfwd.h:31
edm::RefCore::swap
void swap(RefCore &) noexcept
Definition: RefCore.h:149
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::RefVectorBase::refCore
RefCore const & refCore() const
Accessor for product ID and product getter.
Definition: RefVectorBase.h:66
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
watchdog.const
const
Definition: watchdog.py:83
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::RefVectorBase::swap
void swap(RefVectorBase< KEY > &other) noexcept
swap two vectors
Definition: RefVectorBase.h:118
edm::RefVectorBase::clear
void clear()
clear the vector
Definition: RefVectorBase.h:111
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
edm::RefVectorBase::empty
bool empty() const
Is vector empty?
Definition: RefVectorBase.h:76
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::RefVectorBase::RefVectorBase
RefVectorBase(RefVectorBase &&rhs) noexcept
Definition: RefVectorBase.h:40
edm::RefVectorMemberPointersHolder::RefVectorMemberPointersHolder
RefVectorMemberPointersHolder()
Definition: RefVectorBase.h:22
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
edm::RefVectorBase::keys_type
std::vector< KEY > keys_type
Definition: RefVectorBase.h:33
trackingPlots.other
other
Definition: trackingPlots.py:1460
edm::RefVectorBase::RefVectorBase
RefVectorBase()
Default constructor needed for reading from persistent store. Not for direct use.
Definition: RefVectorBase.h:37
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
b
double b
Definition: hdecay.h:118
edm::RefVectorBase::~RefVectorBase
~RefVectorBase() noexcept
Destructor.
Definition: RefVectorBase.h:63
edm::RefVectorBase::product_
RefCore product_
Definition: RefVectorBase.h:130
edm::RefVectorBase::size_type
keys_type::size_type size_type
Definition: RefVectorBase.h:35
edm::RefVectorBase::RefVectorBase
RefVectorBase(ProductID const &productID, void const *prodPtr=nullptr, EDProductGetter const *prodGetter=nullptr)
Definition: RefVectorBase.h:57
a
double a
Definition: hdecay.h:119
EDProductGetter
edm::RefVectorBase::key_type
KEY key_type
Definition: RefVectorBase.h:34
edm::RefVectorBase::cachedMemberPointer
void const * cachedMemberPointer(size_type idx) const
Definition: RefVectorBase.h:68
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::RefVectorBase::pushBack
void pushBack(RefCore const &product, KEY const &key)
Definition: RefVectorBase.h:81
edm::RefVectorBase::reserve
void reserve(size_type n)
Reserve space for vector.
Definition: RefVectorBase.h:102
edm::RefVectorBase::memberPointersHolder_
RefVectorMemberPointersHolder memberPointersHolder_
Definition: RefVectorBase.h:132
edm::RefCore::productPtr
void const * productPtr() const
Definition: RefCore.h:51
edm::RefCore::pushBackRefItem
void pushBackRefItem(RefCore const &productToBeInserted)
Definition: RefCore.cc:215
edm::RefVectorBase::RefVectorBase
RefVectorBase(RefVectorBase const &rhs)
Definition: RefVectorBase.h:38
edm::RefVectorBase::capacity
size_type capacity() const
Capacity of vector.
Definition: RefVectorBase.h:99
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CMS_CLASS_VERSION.h
edm::RefVectorBase::operator=
RefVectorBase & operator=(RefVectorBase const &rhs)
Definition: RefVectorBase.h:45
edm::RefVectorMemberPointersHolder::memberPointers
std::vector< void const * > const & memberPointers() const
Definition: RefVectorBase.h:23
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::RefVectorMemberPointersHolder
Definition: RefVectorBase.h:20
edm::RefVectorBase::size
size_type size() const
Size of vector.
Definition: RefVectorBase.h:79
RefCore.h
edm::RefVectorBase::operator=
RefVectorBase & operator=(RefVectorBase &&rhs) noexcept
Definition: RefVectorBase.h:50
edm::RefVectorMemberPointersHolder::memberPointers
std::vector< void const * > & memberPointers()
Definition: RefVectorBase.h:24
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::RefVectorBase::keys_
keys_type keys_
Definition: RefVectorBase.h:131
edm::RefVectorBase::keys
keys_type const & keys() const
Accessor for vector of keys and pointers.
Definition: RefVectorBase.h:73
EDProductfwd.h
edm::RefVectorBase::eraseAtIndex
keys_type::iterator eraseAtIndex(size_type index)
erase an element from the vector
Definition: RefVectorBase.h:105
edm::ProductID
Definition: ProductID.h:27
edm::RefVectorMemberPointersHolder::memberPointers_
std::vector< void const * > memberPointers_
Definition: RefVectorBase.h:27
edm::RefVectorBase::memberPointers
std::vector< void const * > const & memberPointers() const
Definition: RefVectorBase.h:128