CMS 3D CMS Logo

VectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_VectorHolder_h
2 #define DataFormats_Common_VectorHolder_h
6 #include <memory>
7 
8 namespace edm {
9  namespace reftobase {
10 
11  class RefVectorHolderBase;
12 
13  template <class T, class REFV>
14  class VectorHolder : public BaseVectorHolder<T> {
15  public:
17  typedef typename base_type::size_type size_type;
21  typedef REFV ref_vector_type;
22 
25 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
26  VectorHolder(VectorHolder&& rh) noexcept : base_type(std::forward(rh)), refVector_(std::move(rh.refVector_)) {}
27 #endif
28 
29  explicit VectorHolder(const ref_vector_type& iRefVector) : base_type(), refVector_(iRefVector) {}
30  explicit VectorHolder(const ProductID& iId) : base_type(), refVector_(iId) {}
31  ~VectorHolder() noexcept override {}
32  base_type* clone() const override { return new VectorHolder(*this); }
33  base_type* cloneEmpty() const override { return new VectorHolder(refVector_.id()); }
34  base_ref_type const at(size_type idx) const override { return base_ref_type(refVector_.at(idx)); }
35  bool empty() const override { return refVector_.empty(); }
36  size_type size() const override { return refVector_.size(); }
37  //size_type capacity() const { return refVector_.capacity(); }
38  //void reserve(size_type n) { refVector_.reserve(n); }
39  void clear() override { refVector_.clear(); }
40  ProductID id() const override { return refVector_.id(); }
41  EDProductGetter const* productGetter() const override { return refVector_.productGetter(); }
42  void swap(VectorHolder& other) noexcept {
44  refVector_.swap(other.refVector_);
45  }
47  VectorHolder temp(rhs);
48  this->swap(temp);
49  return *this;
50  }
51 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
52  VectorHolder& operator=(VectorHolder&& rhs) noexcept {
53  base_type::operator=(std::forward(rhs));
54  refVector_ = std::move(rhs.refVector_);
55  return *this;
56  }
57 #endif
58 
59  const_iterator begin() const override {
61  }
62  const_iterator end() const override { return const_iterator(new const_iterator_imp_specific(refVector_.end())); }
63  void push_back(const BaseHolder<T>* r) override {
64  typedef Holder<T, typename REFV::value_type> holder_type;
65  const holder_type* h = dynamic_cast<const holder_type*>(r);
66  if (h == nullptr)
68  "In VectorHolder<T, REFV> trying to push_back wrong reference type");
69  refVector_.push_back(h->getRef());
70  }
71  std::unique_ptr<RefVectorHolderBase> vectorHolder() const override {
72  return std::unique_ptr<RefVectorHolderBase>(new RefVectorHolder<REFV>(refVector_));
73  }
74 
77  bool isAvailable() const override { return refVector_.isAvailable(); }
78 
79  //Used by ROOT storage
81 
82  private:
84 
86 
87  // the following structure is public
88  // to allow dictionary to compile
89  public:
91  typedef ptrdiff_t difference_type;
93  explicit const_iterator_imp_specific(const typename REFV::const_iterator& it) : i(it) {}
96  void increase() override { ++i; }
97  void decrease() override { --i; }
98  void increase(difference_type d) override { i += d; }
99  void decrease(difference_type d) override { i -= d; }
100  bool equal_to(const const_iterator_imp* o) const override { return i == dc(o); }
101  bool less_than(const const_iterator_imp* o) const override { return i < dc(o); }
102  void assign(const const_iterator_imp* o) override { i = dc(o); }
103  base_ref_type deref() const override { return base_ref_type(*i); }
104  difference_type difference(const const_iterator_imp* o) const override { return i - dc(o); }
105 
106  private:
107  const typename ref_vector_type::const_iterator& dc(const const_iterator_imp* o) const {
108  if (o == nullptr)
110  "In RefToBaseVector<T> trying to dereference a null pointer");
111  const const_iterator_imp_specific* oo = dynamic_cast<const const_iterator_imp_specific*>(o);
112  if (oo == nullptr)
114  "In RefToBaseVector<T> trying to cast iterator to wrong type ");
115  return oo->i;
116  }
117  typename ref_vector_type::const_iterator i;
118  };
119  };
120 
121  // Free swap function
122  template <typename T, typename REFV>
123  inline void swap(VectorHolder<T, REFV>& lhs, VectorHolder<T, REFV>& rhs) noexcept {
124  lhs.swap(rhs);
125  }
126  } // namespace reftobase
127 } // namespace edm
128 
129 #endif
edm::reftobase::VectorHolder::base_type
BaseVectorHolder< T > base_type
Definition: VectorHolder.h:16
mps_fire.i
i
Definition: mps_fire.py:428
edm::reftobase::VectorHolder::const_iterator_imp_specific::const_iterator_imp_specific
const_iterator_imp_specific(const typename REFV::const_iterator &it)
Definition: VectorHolder.h:93
edm::reftobase::VectorHolder::const_iterator_imp_specific::assign
void assign(const const_iterator_imp *o) override
Definition: VectorHolder.h:102
edm::reftobase::VectorHolder::const_iterator_imp_specific::dc
const ref_vector_type::const_iterator & dc(const const_iterator_imp *o) const
Definition: VectorHolder.h:107
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::reftobase::VectorHolder::const_iterator_imp_specific::~const_iterator_imp_specific
~const_iterator_imp_specific() override
Definition: VectorHolder.h:94
edm::reftobase::VectorHolder::const_iterator_imp_specific::increase
void increase(difference_type d) override
Definition: VectorHolder.h:98
edm::reftobase::VectorHolder::refVector_
ref_vector_type refVector_
Definition: VectorHolder.h:85
edm::reftobase::VectorHolder::const_iterator_imp_specific::difference
difference_type difference(const const_iterator_imp *o) const override
Definition: VectorHolder.h:104
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::reftobase::BaseVectorHolder
Definition: BaseHolder.h:16
edm::reftobase::VectorHolder::begin
const_iterator begin() const override
Definition: VectorHolder.h:59
edm::reftobase::VectorHolder::const_iterator_imp_specific::equal_to
bool equal_to(const const_iterator_imp *o) const override
Definition: VectorHolder.h:100
edm::reftobase::VectorHolder::operator=
VectorHolder & operator=(VectorHolder const &rhs)
Definition: VectorHolder.h:46
edm::reftobase::VectorHolder::const_iterator_imp_specific::decrease
void decrease(difference_type d) override
Definition: VectorHolder.h:99
edm::reftobase::VectorHolder::swap
void swap(VectorHolder &other) noexcept
Definition: VectorHolder.h:42
edm::reftobase::VectorHolder::const_iterator_imp_specific::i
ref_vector_type::const_iterator i
Definition: VectorHolder.h:117
edm::reftobase::VectorHolder::const_iterator_imp_specific::difference_type
ptrdiff_t difference_type
Definition: VectorHolder.h:91
edm::reftobase::VectorHolder::const_iterator_imp_specific::less_than
bool less_than(const const_iterator_imp *o) const override
Definition: VectorHolder.h:101
edm::reftobase::VectorHolder::VectorHolder
VectorHolder(VectorHolder const &rh)
Definition: VectorHolder.h:24
edm::reftobase::VectorHolder::const_iterator_imp_specific::clone
const_iterator_imp_specific * clone() const override
Definition: VectorHolder.h:95
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::reftobase::VectorHolder::clear
void clear() override
Definition: VectorHolder.h:39
edm::reftobase::VectorHolder::VectorHolder
VectorHolder(const ProductID &iId)
Definition: VectorHolder.h:30
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
edm::reftobase::BaseVectorHolder::size_type
size_t size_type
Definition: BaseVectorHolder.h:17
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
edm::reftobase::BaseVectorHolder::swap
void swap(BaseVectorHolder &)
Definition: BaseVectorHolder.h:33
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::reftobase::VectorHolder::const_iterator_imp_specific::increase
void increase() override
Definition: VectorHolder.h:96
edm::reftobase::BaseHolder
Definition: BaseHolder.h:29
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
trackingPlots.other
other
Definition: trackingPlots.py:1467
edm::reftobase::VectorHolder::ref_vector_type
REFV ref_vector_type
Definition: VectorHolder.h:21
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
h
edm::reftobase::VectorHolder::push_back
void push_back(const BaseHolder< T > *r) override
Definition: VectorHolder.h:63
Holder.h
edm::reftobase::VectorHolder::const_iterator
base_type::const_iterator const_iterator
Definition: VectorHolder.h:20
edm::reftobase::VectorHolder
Definition: EDProductfwd.h:55
edm::reftobase::VectorHolder::VectorHolder
VectorHolder()
Definition: VectorHolder.h:23
edm::reftobase::Holder
Definition: EDProductfwd.h:45
edm::reftobase::VectorHolder::end
const_iterator end() const override
Definition: VectorHolder.h:62
edm::reftobase::VectorHolder::isAvailable
bool isAvailable() const override
Definition: VectorHolder.h:77
edm::reftobase::BaseVectorHolder::element_type
T element_type
Definition: BaseVectorHolder.h:18
edm::reftobase::VectorHolder::at
const base_ref_type at(size_type idx) const override
Definition: VectorHolder.h:34
edm::reftobase::BaseVectorHolder::const_iterator_imp::difference_type
ptrdiff_t difference_type
Definition: BaseVectorHolder.h:39
edm::reftobase::VectorHolder::cloneEmpty
base_type * cloneEmpty() const override
Definition: VectorHolder.h:33
edm::reftobase::VectorHolder::base_ref_type
base_type::base_ref_type base_ref_type
Definition: VectorHolder.h:19
edm::reftobase::VectorHolder::size
size_type size() const override
Definition: VectorHolder.h:36
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::reftobase::VectorHolder::const_iterator_imp_specific::const_iterator_imp_specific
const_iterator_imp_specific()
Definition: VectorHolder.h:92
edm::reftobase::swap
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111
eostools.move
def move(src, dest)
Definition: eostools.py:511
CMS_CLASS_VERSION.h
edm::reftobase::VectorHolder::clone
base_type * clone() const override
Definition: VectorHolder.h:32
BaseVectorHolder.h
edm::reftobase::VectorHolder::const_iterator_imp_specific
Definition: VectorHolder.h:90
edm::reftobase::VectorHolder::const_iterator_imp_specific::deref
base_ref_type deref() const override
Definition: VectorHolder.h:103
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
edm::reftobase::VectorHolder::const_iterator_imp_specific::decrease
void decrease() override
Definition: VectorHolder.h:97
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::reftobase::VectorHolder::element_type
base_type::element_type element_type
Definition: VectorHolder.h:18
edm::reftobase::VectorHolder::empty
bool empty() const override
Definition: VectorHolder.h:35
ztail.d
d
Definition: ztail.py:151
edm::reftobase::VectorHolder::~VectorHolder
~VectorHolder() noexcept override
Definition: VectorHolder.h:31
edm::reftobase::BaseVectorHolder::const_iterator_imp
Definition: BaseVectorHolder.h:38
edm::reftobase::VectorHolder::VectorHolder
VectorHolder(const ref_vector_type &iRefVector)
Definition: VectorHolder.h:29
edm::reftobase::RefVectorHolder
Definition: RefVectorHolder.h:16
edm::reftobase::VectorHolder::vectorHolder
std::unique_ptr< RefVectorHolderBase > vectorHolder() const override
Definition: VectorHolder.h:71
edm::reftobase::VectorHolder::id
ProductID id() const override
Definition: VectorHolder.h:40
edm::ProductID
Definition: ProductID.h:27
edm::reftobase::VectorHolder::productGetter
EDProductGetter const * productGetter() const override
Definition: VectorHolder.h:41
edm::reftobase::VectorHolder::size_type
base_type::size_type size_type
Definition: VectorHolder.h:17