CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefVectorHolder.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVectorHolder_h
2 #define DataFormats_Common_RefVectorHolder_h
3 
9 
10 namespace edm {
11  namespace reftobase {
12  class RefHolderBase;
13  template <typename REF> class RefHolder;
14 
15  template<typename REFV>
17  public:
19  }
20  RefVectorHolder(REFV const& refs) : RefVectorHolderBase(), refs_(refs) {
21  }
22  explicit RefVectorHolder(ProductID const& iId) : RefVectorHolderBase(), refs_(iId) {
23  }
24  virtual ~RefVectorHolder() { }
25  void swap(RefVectorHolder& other);
27  virtual bool empty() const;
28  virtual size_type size() const;
29  virtual void clear();
30  virtual void push_back(RefHolderBase const* r);
31  virtual void reserve(size_type n);
32  virtual ProductID id() const;
33  virtual EDProductGetter const* productGetter() const;
34  virtual RefVectorHolder<REFV> * clone() const;
35  virtual RefVectorHolder<REFV> * cloneEmpty() const;
36  void setRefs(REFV const& refs);
37  virtual void reallyFillView(void const*, ProductID const&, std::vector<void const*> &);
38  virtual size_t keyForIndex(size_t idx) const;
39 
40  //Needed for ROOT storage
42 
43  private:
45 
46  public:
47  struct const_iterator_imp_specific : public const_iterator_imp {
48  typedef ptrdiff_t difference_type;
50  explicit const_iterator_imp_specific(typename REFV::const_iterator const& it) : i (it) { }
53  void increase() { ++i; }
54  void decrease() { --i; }
55  void increase(difference_type d) { i += d; }
56  void decrease(difference_type d) { i -= d; }
57  bool equal_to(const_iterator_imp const* o) const { return i == dc(o); }
58  bool less_than(const_iterator_imp const* o) const { return i < dc(o); }
59  void assign(const_iterator_imp const* o) { i = dc(o); }
60  std::shared_ptr<RefHolderBase> deref() const;
61  difference_type difference(const_iterator_imp const* o) const { return i - dc(o); }
62  private:
63  typename REFV::const_iterator const& dc(const_iterator_imp const* o) const {
64  if (o == 0) {
66  "In RefVectorHolder trying to dereference a null pointer\n");
67  }
69  if (oo == 0) {
71  "In RefVectorHolder trying to cast iterator to wrong type\n");
72  }
73  return oo->i;
74  }
75  typename REFV::const_iterator i;
76  };
77 
79 
81  return const_iterator(new const_iterator_imp_specific(refs_.begin()));
82  }
83  const_iterator end() const {
84  return const_iterator(new const_iterator_imp_specific(refs_.end()));
85  }
86  virtual void const* product() const {
87  return refs_.product();
88  }
89 
92  virtual bool isAvailable() const { return refs_.isAvailable(); }
93 
94  private:
95  virtual std::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const;
96  REFV refs_;
97  };
98 
99  //
100  // implementations for RefVectorHolder<REFV>
101  //
102 
103  template <typename REFV>
104  inline
106  this->RefVectorHolderBase::swap(other);
107  refs_.swap(other.refs_);
108  }
109 
110  template <typename REFV>
111  inline
114  this->swap(temp);
115  return *this;
116  }
117 
118  template<typename REFV>
119  inline
121  return refs_.empty();
122  }
123 
124  template<typename REFV>
125  inline
127  return refs_.size();
128  }
129 
130  template<typename REFV>
131  inline
133  return refs_.clear();
134  }
135 
136  template<typename REFV>
137  inline
139  typename REFV::size_type s = n;
140  refs_.reserve(s);
141  }
142 
143  template<typename REFV>
144  inline
146  return refs_.id();
147  }
148 
149  template<typename REFV>
150  inline
152  return refs_.productGetter();
153  }
154 
155  template<typename REFV>
156  inline
158  return new RefVectorHolder<REFV>(*this);
159  }
160 
161  template<typename REFV>
162  inline
164  return new RefVectorHolder<REFV>(id());
165  }
166 
167  template<typename REFV>
168  inline
169  void RefVectorHolder<REFV>::setRefs(REFV const& refs) {
170  refs_ = refs;
171  }
172 
173  template <typename REFV>
174  inline
176  return refs_[idx].key();
177  }
178 
179  // Free swap function
180  template <typename REFV>
181  inline
182  void
184  lhs.swap(rhs);
185  }
186  }
187 }
188 
190 
191 namespace edm {
192  namespace reftobase {
193 
194  template<typename REFV>
196  typedef typename REFV::value_type REF;
197  RefHolder<REF> const* rh = dynamic_cast<RefHolder<REF> const*>(h);
198  if(rh == 0) {
200  "RefVectorHolder: attempting to cast a RefHolderBase "
201  "to an invalid type.\nExpected: ",
202  typeid(REF).name(),
203  "\n");
204  }
205  refs_.push_back(rh->getRef());
206  }
207 
208  template <typename REFV>
209  std::shared_ptr<RefHolderBase>
211 #ifdef __GCCXML__
212  return std::shared_ptr<RefHolderBase>(new RefHolder<typename REFV::value_type>(refs_[idx]));
213 #else
214  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(refs_[idx]));
215 #endif
216  }
217 
218  template<typename REFV>
219  std::shared_ptr<RefHolderBase>
221 #ifdef __GCCXML__
222  return std::shared_ptr<RefHolderBase>(new RefHolder<typename REFV::value_type>(*i));
223 #else
224  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(*i));
225 #endif
226  }
227  }
228 }
229 
232 #include "boost/mpl/if.hpp"
233 
234 namespace edm {
235  namespace reftobase {
236  template<typename REFV>
238  static void reallyFillView(RefVectorHolder<REFV>&, void const*, ProductID const&, std::vector<void const*>&) {
240  "The product type ",
241  typeid(typename REFV::collection_type).name(),
242  "\ndoes not support Views\n");
243  }
244  };
245 
246  template<typename REFV>
248  static void reallyFillView(RefVectorHolder<REFV>& rvh, void const* prod, ProductID const& id , std::vector<void const*> & pointers) {
249  typedef typename REFV::collection_type collection;
250  collection const* product = static_cast<collection const*>(prod);
251  detail::reallyFillView(*product, id, pointers, rvh);
252  }
253  };
254 
255  template<typename REFV>
256  void RefVectorHolder<REFV>::reallyFillView(void const* iProd, ProductID const& iId , std::vector<void const*> & oPointers) {
257  typedef
261  maybe_filler::reallyFillView(*this, iProd, iId, oPointers);
262  }
263  }
264 }
265 
266 #endif
RefVectorHolderBase::const_iterator const_iterator
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
virtual RefVectorHolder< REFV > * cloneEmpty() const
void swap(RefVectorHolderBase &)
difference_type difference(const_iterator_imp const *o) const
virtual EDProductGetter const * productGetter() const
REF const & getRef() const
Definition: RefHolder_.h:107
void reallyFillView(COLLECTION const &coll, ProductID const &id, std::vector< void const * > &ptrs, helper_vector &helpers)
Definition: FillView.h:49
bool less_than(const_iterator_imp const *o) const
RefVectorHolder & operator=(RefVectorHolder const &rhs)
virtual ProductID id() const
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
uint16_t size_type
bool equal_to(const_iterator_imp const *o) const
virtual size_type size() const
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
void setRefs(REFV const &refs)
static void reallyFillView(RefVectorHolder< REFV > &, void const *, ProductID const &, std::vector< void const * > &)
virtual RefVectorHolder< REFV > * clone() const
virtual void reallyFillView(void const *, ProductID const &, std::vector< void const * > &)
virtual void push_back(RefHolderBase const *r)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual void reserve(size_type n)
Container::value_type value_type
RefVectorHolder(ProductID const &iId)
const_iterator end() const
const_iterator begin() const
const_iterator_imp_specific(typename REFV::const_iterator const &it)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void swap(RefVectorHolder &other)
string const
Definition: compareJSON.py:14
std::shared_ptr< RefHolderBase > deref() const
virtual bool isAvailable() const
#define private
Definition: FWFileEntry.h:17
static void reallyFillView(RefVectorHolder< REFV > &rvh, void const *prod, ProductID const &id, std::vector< void const * > &pointers)
virtual size_t keyForIndex(size_t idx) const
REFV::const_iterator const & dc(const_iterator_imp const *o) const
ProductIndex id() const
Definition: ProductID.h:38
virtual std::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) const
virtual void const * product() const
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:117