CMS 3D CMS Logo

RefToBaseVector.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefToBaseVector_h
2 #define DataFormats_Common_RefToBaseVector_h
3 
11 #include <algorithm>
12 #include <memory>
13 #include <utility>
14 #include <vector>
15 
16 namespace edm {
17  template <typename T>
18  class RefToBase;
19  template <typename T>
20  class View;
21  template <typename C>
22  class Handle;
23  class EDProductGetter;
24  namespace reftobase {
25  template <typename T>
26  class BaseVectorHolder;
27  class RefVectorHolderBase;
28  } // namespace reftobase
29 
30  template <class T>
31  class RefToBaseVector {
32  public:
34  typedef T member_type;
38 
41  template <class REFV>
42  explicit RefToBaseVector(REFV const&);
43  template <typename C>
44  explicit RefToBaseVector(Handle<C> const&);
45  RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p);
47  void swap(RefToBaseVector& other);
48 
50 
51  //void reserve(size_type n);
52  void clear();
53 
54  value_type at(size_type idx) const;
56  bool isValid() const { return holder_ != nullptr; }
57  bool isInvalid() const { return holder_ == nullptr; }
58  bool empty() const;
59  size_type size() const;
60  //size_type capacity() const;
61  ProductID id() const;
62  EDProductGetter const* productGetter() const;
63  const_iterator begin() const;
64  const_iterator end() const;
65 
66  void push_back(const RefToBase<T>&);
67 
68  void fillView(std::vector<void const*>& pointers, FillViewHelperVector& helpers) const;
69  std::unique_ptr<reftobase::RefVectorHolderBase> vectorHolder() const;
70 
73  bool isAvailable() const { return holder_->isAvailable(); }
74 
75  //Needed for ROOT storage
77 
78  private:
80  };
81 } // namespace edm
82 
83 #include "DataFormats/Common/interface/RefToBase.h"
89 
90 namespace edm {
91  template <class T>
93  a.swap(b);
94  }
95 
96  template <class T>
97  inline bool operator==(RefToBaseVector<T> const& a, RefToBaseVector<T> const& b) {
98  if (a.isInvalid() && b.isInvalid())
99  return true;
100  if (a.isInvalid() || b.isInvalid())
101  return false;
102  return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin());
103  }
104 
105  //--------------------------------------------------------------------
106  // Implementation of RefToBaseVector<T>
107  //--------------------------------------------------------------------
108 
109  template <class T>
111 
112  template <class T>
113  template <class REFV>
114  inline RefToBaseVector<T>::RefToBaseVector(const REFV& iRef) : holder_(new reftobase::VectorHolder<T, REFV>(iRef)) {}
115 
116  template <class T>
118  : holder_(iOther.holder_ ? iOther.holder_->clone() : nullptr) {}
119 
120  template <class T>
121  inline RefToBaseVector<T>::RefToBaseVector(std::shared_ptr<reftobase::RefVectorHolderBase> p)
122  : holder_(new reftobase::IndirectVectorHolder<T>(p)) {}
123 
124  template <class T>
126  RefToBaseVector temp(iRHS);
127  this->swap(temp);
128  return *this;
129  }
130 
131  template <class T>
133  std::swap(holder_, other.holder_);
134  }
135 
136  template <class T>
138  delete holder_;
139  }
140 
141  template <class T>
143  if (holder_ == nullptr)
144  Exception::throwThis(
145  errors::InvalidReference, "Trying to dereference null RefToBaseVector<T> in method: at(", idx, ")\n");
146  return holder_->at(idx);
147  }
148 
149  template <class T>
151  return at(idx);
152  }
153 
154  template <class T>
155  inline bool RefToBaseVector<T>::empty() const {
156  return holder_ ? holder_->empty() : true;
157  }
158 
159  template <class T>
161  return holder_ ? holder_->size() : 0;
162  }
163 
164  template <class T>
166  if (holder_ != nullptr)
167  holder_->clear();
168  }
169 
170  template <class T>
172  return holder_ ? holder_->id() : ProductID();
173  }
174 
175  template <class T>
177  return holder_ ? holder_->productGetter() : nullptr;
178  }
179 
180  template <class T>
182  return holder_ ? holder_->begin() : const_iterator();
183  }
184 
185  template <class T>
187  return holder_ ? holder_->end() : const_iterator();
188  }
189 
190  template <typename T>
191  void RefToBaseVector<T>::fillView(std::vector<void const*>& pointers, FillViewHelperVector& helpers) const {
192  pointers.reserve(this->size());
193  helpers.reserve(this->size());
194  for (const_iterator i = begin(), e = end(); i != e; ++i) {
195  RefToBase<T> ref = *i;
196  member_type const* address = ref.isNull() ? nullptr : &*ref;
197  pointers.push_back(address);
198  helpers.push_back(FillViewHelperVector::value_type(ref.id(), ref.key()));
199  }
200  }
201 
202  // NOTE: the following implementation has unusual signature!
203  template <typename T>
204  inline void fillView(RefToBaseVector<T> const& obj,
205  ProductID const&,
206  std::vector<void const*>& pointers,
208  obj.fillView(pointers, helpers);
209  }
210 
211  template <typename T>
213  static bool const value = true;
214  };
215 
216  template <typename T>
218  if (holder_ == nullptr) {
219  std::unique_ptr<reftobase::BaseVectorHolder<T> > p = r.holder_->makeVectorHolder();
220  holder_ = p.release();
221  }
222  holder_->push_back(r.holder_);
223  }
224 
225  template <typename T>
226  std::unique_ptr<reftobase::RefVectorHolderBase> RefToBaseVector<T>::vectorHolder() const {
227  return holder_ ? holder_->vectorHolder() : std::unique_ptr<reftobase::RefVectorHolderBase>();
228  }
229 } // namespace edm
230 
233 
234 namespace edm {
235 
236  template <typename T>
237  template <typename C>
239  : holder_(new reftobase::VectorHolder<
240  T,
241  RefVector<C, typename refhelper::ValueTrait<C>::value, typename refhelper::FindTrait<C, T>::value> >(
242  h.id())) {}
243 
244 } // namespace edm
245 #endif
edm::RefToBaseVector::end
const_iterator end() const
Definition: RefToBaseVector.h:186
edm::RefToBase::isNull
bool isNull() const
Checks for null.
Definition: RefToBase.h:295
edm::FillViewHelperVector
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
Definition: FillViewHelperVector.h:30
Handle.h
mps_fire.i
i
Definition: mps_fire.py:428
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::RefToBaseVector::empty
bool empty() const
Definition: RefToBaseVector.h:155
edm::RefToBase::key
size_t key() const
Definition: RefToBase.h:219
sistrip::View
View
Definition: ConstantsForView.h:26
edm::reftobase::BaseVectorHolder::size
virtual size_type size() const =0
edm::RefToBaseVector::swap
void swap(RefToBaseVector &other)
Definition: RefToBaseVector.h:132
Handle
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::RefToBaseVector::~RefToBaseVector
~RefToBaseVector()
Definition: RefToBaseVector.h:137
edm::reftobase::BaseVectorHolder
Definition: BaseHolder.h:16
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
IndirectVectorHolder.h
edm::RefToBaseVector::productGetter
EDProductGetter const * productGetter() const
Definition: RefToBaseVector.h:176
edm::reftobase::BaseVectorHolder::id
virtual ProductID id() const =0
edm::RefVector
Definition: EDProductfwd.h:27
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::RefToBaseVector::operator=
RefToBaseVector & operator=(RefToBaseVector const &iRHS)
Definition: RefToBaseVector.h:125
edm::RefToBaseVector::operator[]
value_type operator[](size_type idx) const
Definition: RefToBaseVector.h:150
edm::reftobase::BaseVectorHolder::size_type
size_t size_type
Definition: BaseVectorHolder.h:17
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
EDMException.h
edm::EDProductGetter
Definition: EDProductGetter.h:41
RefVectorHolder.h
FillViewHelperVector.h
edm::reftobase::BaseVectorHolder::empty
virtual bool empty() const =0
edm::RefToBaseVector::push_back
void push_back(const RefToBase< T > &)
Definition: RefToBaseVector.h:217
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
edm::RefToBaseVector::id
ProductID id() const
Definition: RefToBaseVector.h:171
edm::RefToBaseVector::isValid
bool isValid() const
Definition: RefToBaseVector.h:56
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
edm::fillView
void fillView(RefToBaseVector< T > const &obj, ProductID const &, std::vector< void const * > &pointers, FillViewHelperVector &helpers)
Definition: RefToBaseVector.h:204
mps_fire.end
end
Definition: mps_fire.py:242
reco::Track
Definition: Track.h:27
edm::RefToBaseVector::size_type
holder_type::size_type size_type
Definition: RefToBaseVector.h:36
ProductID.h
edm::reftobase::BaseVectorHolder::const_iterator
Definition: BaseVectorHolder.h:54
trackingPlots.other
other
Definition: trackingPlots.py:1460
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
h
b
double b
Definition: hdecay.h:118
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
edm::RefToBaseVector::const_iterator
holder_type::const_iterator const_iterator
Definition: RefToBaseVector.h:37
a
double a
Definition: hdecay.h:119
clear
void clear(HadCaloObj &c)
Definition: data.h:124
EDProductGetter
RefVector.h
edm::RefToBaseVector::at
value_type at(size_type idx) const
Definition: RefToBaseVector.h:142
helpers
Definition: makeCompositeCandidate.h:8
RefToBaseVector
RefToBase
value
Definition: value.py:1
edm::reftobase::BaseVectorHolder::push_back
virtual void push_back(BaseHolder< T > const *)=0
edm::reftobase::BaseVectorHolder::vectorHolder
virtual std::unique_ptr< RefVectorHolderBase > vectorHolder() const =0
edm::refcoreimpl::productGetter
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
Definition: refcore_implementation.h:72
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
edm::RefToBaseVector::isInvalid
bool isInvalid() const
Definition: RefToBaseVector.h:57
edm::RefToBaseVector
Definition: EDProductfwd.h:29
edm::RefToBaseVector::RefToBaseVector
RefToBaseVector()
Definition: RefToBaseVector.h:110
edm::RefToBase::id
ProductID id() const
Definition: RefToBase.h:214
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::RefToBaseVector::size
size_type size() const
Definition: RefToBaseVector.h:160
edm::reftobase::BaseVectorHolder::productGetter
virtual EDProductGetter const * productGetter() const =0
CMS_CLASS_VERSION.h
VectorHolder.h
edm::RefToBaseVector::holder_type
reftobase::BaseVectorHolder< T > holder_type
Definition: RefToBaseVector.h:35
gen::C
C
Definition: PomwigHadronizer.cc:78
edm::RefToBaseVector::value_type
RefToBase< T > value_type
Definition: RefToBaseVector.h:33
edm::reftobase::BaseVectorHolder::end
virtual const_iterator end() const =0
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
edm::RefToBaseVector::fillView
void fillView(std::vector< void const * > &pointers, FillViewHelperVector &helpers) const
Definition: RefToBaseVector.h:191
edm::RefToBaseVector::holder_
holder_type * holder_
Definition: RefToBaseVector.h:79
edm::RefToBase
Definition: AssociativeIterator.h:54
edm::RefToBaseVector::isAvailable
bool isAvailable() const
Definition: RefToBaseVector.h:73
edm::RefToBaseVector::begin
const_iterator begin() const
Definition: RefToBaseVector.h:181
edm::reftobase::BaseVectorHolder::isAvailable
virtual bool isAvailable() const =0
traits.h
operator[]
T operator[](int i) const
Definition: extBasic3DVector.h:222
edm::RefToBaseVector::clear
void clear()
Definition: RefToBaseVector.h:165
edm::RefToBaseVector::member_type
T member_type
Definition: RefToBaseVector.h:34
cond::serialization::equal
bool equal(const T &first, const T &second)
Definition: Equal.h:32
edm::RefToBaseVector::vectorHolder
std::unique_ptr< reftobase::RefVectorHolderBase > vectorHolder() const
Definition: RefToBaseVector.h:226
edm::has_fillView
Definition: traits.h:114
edm::ProductID
Definition: ProductID.h:27
edm::swap
void swap(RefToBaseVector< T > &a, RefToBaseVector< T > &b)
Definition: RefToBaseVector.h:92
edm::reftobase::BaseVectorHolder::begin
virtual const_iterator begin() const =0
edm::reftobase::BaseVectorHolder::clear
virtual void clear()=0
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edm::reftobase::BaseVectorHolder::at
virtual const base_ref_type at(size_type idx) const =0