CMS 3D CMS Logo

RefVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorHolder_h
2 #define DataFormats_Common_RefVectorHolder_h
3 
8 
9 namespace edm {
10  namespace reftobase {
11  class RefHolderBase;
12  template <typename REF>
13  class RefHolder;
14 
15  template <typename REFV>
17  public:
19  RefVectorHolder(REFV const& refs) : RefVectorHolderBase(), refs_(refs) {}
20  explicit RefVectorHolder(ProductID const& iId) : RefVectorHolderBase(), refs_(iId) {}
21  ~RefVectorHolder() override {}
22  void swap(RefVectorHolder& other);
24  bool empty() const override;
25  size_type size() const override;
26  void clear() override;
27  void push_back(RefHolderBase const* r) override;
28  void reserve(size_type n) override;
29  ProductID id() const override;
30  EDProductGetter const* productGetter() const override;
31  RefVectorHolder<REFV>* clone() const override;
32  RefVectorHolder<REFV>* cloneEmpty() const override;
33  void setRefs(REFV const& refs);
34  size_t keyForIndex(size_t idx) const override;
35 
36  //Needed for ROOT storage
38 
39  private:
41 
42  public:
44  typedef ptrdiff_t difference_type;
46  explicit const_iterator_imp_specific(typename REFV::const_iterator const& it) : i(it) {}
49  void increase() override { ++i; }
50  void decrease() override { --i; }
51  void increase(difference_type d) override { i += d; }
52  void decrease(difference_type d) override { i -= d; }
53  bool equal_to(const_iterator_imp const* o) const override { return i == dc(o); }
54  bool less_than(const_iterator_imp const* o) const override { return i < dc(o); }
55  void assign(const_iterator_imp const* o) override { i = dc(o); }
56  std::shared_ptr<RefHolderBase> deref() const override;
57  difference_type difference(const_iterator_imp const* o) const override { return i - dc(o); }
58 
59  private:
60  typename REFV::const_iterator const& dc(const_iterator_imp const* o) const {
61  if (o == nullptr) {
62  Exception::throwThis(errors::InvalidReference, "In RefVectorHolder trying to dereference a null pointer\n");
63  }
64  const_iterator_imp_specific const* oo = dynamic_cast<const_iterator_imp_specific const*>(o);
65  if (oo == nullptr) {
67  "In RefVectorHolder trying to cast iterator to wrong type\n");
68  }
69  return oo->i;
70  }
71  typename REFV::const_iterator i;
72  };
73 
75 
76  const_iterator begin() const override { return const_iterator(new const_iterator_imp_specific(refs_.begin())); }
77  const_iterator end() const override { return const_iterator(new const_iterator_imp_specific(refs_.end())); }
78 
81  bool isAvailable() const override { return refs_.isAvailable(); }
82 
83  private:
84  std::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const override;
85  REFV refs_;
86  };
87 
88  //
89  // implementations for RefVectorHolder<REFV>
90  //
91 
92  template <typename REFV>
94  this->RefVectorHolderBase::swap(other);
95  refs_.swap(other.refs_);
96  }
97 
98  template <typename REFV>
101  this->swap(temp);
102  return *this;
103  }
104 
105  template <typename REFV>
106  inline bool RefVectorHolder<REFV>::empty() const {
107  return refs_.empty();
108  }
109 
110  template <typename REFV>
112  return refs_.size();
113  }
114 
115  template <typename REFV>
117  return refs_.clear();
118  }
119 
120  template <typename REFV>
122  typename REFV::size_type s = n;
123  refs_.reserve(s);
124  }
125 
126  template <typename REFV>
128  return refs_.id();
129  }
130 
131  template <typename REFV>
133  return refs_.productGetter();
134  }
135 
136  template <typename REFV>
138  return new RefVectorHolder<REFV>(*this);
139  }
140 
141  template <typename REFV>
143  return new RefVectorHolder<REFV>(id());
144  }
145 
146  template <typename REFV>
147  inline void RefVectorHolder<REFV>::setRefs(REFV const& refs) {
148  refs_ = refs;
149  }
150 
151  template <typename REFV>
152  inline size_t RefVectorHolder<REFV>::keyForIndex(size_t idx) const {
153  return refs_[idx].key();
154  }
155 
156  // Free swap function
157  template <typename REFV>
159  lhs.swap(rhs);
160  }
161  } // namespace reftobase
162 } // namespace edm
163 
165 
166 namespace edm {
167  namespace reftobase {
168 
169  template <typename REFV>
171  typedef typename REFV::value_type REF;
172  RefHolder<REF> const* rh = dynamic_cast<RefHolder<REF> const*>(h);
173  if (rh == nullptr) {
175  "RefVectorHolder: attempting to cast a RefHolderBase "
176  "to an invalid type.\nExpected: ",
177  typeid(REF).name(),
178  "\n");
179  }
180  refs_.push_back(rh->getRef());
181  }
182 
183  template <typename REFV>
184  std::shared_ptr<RefHolderBase> RefVectorHolder<REFV>::refBase(size_t idx) const {
185  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(refs_[idx]));
186  }
187 
188  template <typename REFV>
189  std::shared_ptr<RefHolderBase> RefVectorHolder<REFV>::const_iterator_imp_specific::deref() const {
190  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(*i));
191  }
192  } // namespace reftobase
193 } // namespace edm
194 
195 #endif
edm::reftobase::RefVectorHolderBase::swap
void swap(RefVectorHolderBase &)
Definition: RefVectorHolderBase.h:18
edm::reftobase::RefVectorHolder::id
ProductID id() const override
Definition: RefVectorHolder.h:127
edm::reftobase::RefVectorHolder::isAvailable
bool isAvailable() const override
Definition: RefVectorHolder.h:81
mps_fire.i
i
Definition: mps_fire.py:428
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::dc
REFV::const_iterator const & dc(const_iterator_imp const *o) const
Definition: RefVectorHolder.h:60
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
RefVectorHolderBase.h
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::reftobase::RefVectorHolder::productGetter
EDProductGetter const * productGetter() const override
Definition: RefVectorHolder.h:132
edm::reftobase::RefVectorHolder::const_iterator_imp_specific
Definition: RefVectorHolder.h:43
edm
HLT enums.
Definition: AlignableModifier.h:19
h
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
Definition: L1TUtmAlgorithmRcd.h:4
edm::reftobase::RefVectorHolder::operator=
RefVectorHolder & operator=(RefVectorHolder const &rhs)
Definition: RefVectorHolder.h:99
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::difference_type
ptrdiff_t difference_type
Definition: RefVectorHolder.h:44
edm::reftobase::RefVectorHolderBase
Definition: RefVectorHolderBase.h:13
edm::reftobase::RefVectorHolder::reserve
void reserve(size_type n) override
Definition: RefVectorHolder.h:121
edm::reftobase::RefVectorHolder::RefVectorHolder
RefVectorHolder()
Definition: RefVectorHolder.h:18
watchdog.const
const
Definition: watchdog.py:83
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::reftobase::RefHolderBase
Definition: RefHolderBase.h:17
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
EDMException.h
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::less_than
bool less_than(const_iterator_imp const *o) const override
Definition: RefVectorHolder.h:54
edm::EDProductGetter
Definition: EDProductGetter.h:41
alignCSCRings.s
s
Definition: alignCSCRings.py:92
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::reftobase::RefHolder::getRef
REF const & getRef() const
Definition: RefHolder_.h:89
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::difference
difference_type difference(const_iterator_imp const *o) const override
Definition: RefVectorHolder.h:57
edm::reftobase::RefVectorHolder::begin
const_iterator begin() const override
Definition: RefVectorHolder.h:76
edm::reftobase::RefVectorHolder::clear
void clear() override
Definition: RefVectorHolder.h:116
ProductID.h
edm::reftobase::RefVectorHolderBase::const_iterator_imp
Definition: RefVectorHolderBase.h:31
trackingPlots.other
other
Definition: trackingPlots.py:1460
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
h
edm::reftobase::RefVectorHolder::setRefs
void setRefs(REFV const &refs)
Definition: RefVectorHolder.h:147
edm::reftobase::RefVectorHolder::~RefVectorHolder
~RefVectorHolder() override
Definition: RefVectorHolder.h:21
edm::reftobase::RefVectorHolder::keyForIndex
size_t keyForIndex(size_t idx) const override
Definition: RefVectorHolder.h:152
edm::reftobase::RefVectorHolderBase::const_iterator
Definition: RefVectorHolderBase.h:47
edm::reftobase::RefVectorHolder::RefVectorHolder
RefVectorHolder(ProductID const &iId)
Definition: RefVectorHolder.h:20
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::const_iterator_imp_specific
const_iterator_imp_specific(typename REFV::const_iterator const &it)
Definition: RefVectorHolder.h:46
edm::reftobase::RefVectorHolder::size
size_type size() const override
Definition: RefVectorHolder.h:111
edm::reftobase::RefVectorHolder::clone
RefVectorHolder< REFV > * clone() const override
Definition: RefVectorHolder.h:137
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::decrease
void decrease() override
Definition: RefVectorHolder.h:50
RefHolder.h
edm::reftobase::RefVectorHolderBase::size_type
size_t size_type
Definition: RefVectorHolderBase.h:16
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::deref
std::shared_ptr< RefHolderBase > deref() const override
Definition: RefVectorHolder.h:189
edm::reftobase::RefVectorHolder::empty
bool empty() const override
Definition: RefVectorHolder.h:106
edm::reftobase::RefVectorHolder::RefVectorHolder
RefVectorHolder(REFV const &refs)
Definition: RefVectorHolder.h:19
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::~const_iterator_imp_specific
~const_iterator_imp_specific() override
Definition: RefVectorHolder.h:47
edm::reftobase::RefVectorHolder::cloneEmpty
RefVectorHolder< REFV > * cloneEmpty() const override
Definition: RefVectorHolder.h:142
edm::reftobase::RefVectorHolder::swap
void swap(RefVectorHolder &other)
Definition: RefVectorHolder.h:93
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::increase
void increase() override
Definition: RefVectorHolder.h:49
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::assign
void assign(const_iterator_imp const *o) override
Definition: RefVectorHolder.h:55
edm::reftobase::RefHolder
Definition: EDProductfwd.h:50
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::reftobase::swap
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111
CMS_CLASS_VERSION.h
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::equal_to
bool equal_to(const_iterator_imp const *o) const override
Definition: RefVectorHolder.h:53
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::decrease
void decrease(difference_type d) override
Definition: RefVectorHolder.h:52
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::const_iterator_imp_specific
const_iterator_imp_specific()
Definition: RefVectorHolder.h:45
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::RefVectorHolder::end
const_iterator end() const override
Definition: RefVectorHolder.h:77
edm::reftobase::RefVectorHolder::push_back
void push_back(RefHolderBase const *r) override
Definition: RefVectorHolder.h:170
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::clone
const_iterator_imp_specific * clone() const override
Definition: RefVectorHolder.h:48
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::reftobase::RefVectorHolder::refs_
REFV refs_
Definition: RefVectorHolder.h:85
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::increase
void increase(difference_type d) override
Definition: RefVectorHolder.h:51
edm::reftobase::RefVectorHolder::const_iterator_imp_specific::i
REFV::const_iterator i
Definition: RefVectorHolder.h:71
ztail.d
d
Definition: ztail.py:151
edm::reftobase::RefVectorHolder
Definition: RefVectorHolder.h:16
edm::ProductID
Definition: ProductID.h:27
edm::reftobase::RefVectorHolder::const_iterator
RefVectorHolderBase::const_iterator const_iterator
Definition: RefVectorHolder.h:74
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35
edm::reftobase::RefVectorHolder::refBase
std::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) const override
Definition: RefVectorHolder.h:184