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 
8 
9 namespace edm {
10  namespace reftobase {
11  class RefHolderBase;
12  template <typename REF> class RefHolder;
13 
14  template<typename REFV>
16  public:
18  }
19  RefVectorHolder(REFV const& refs) : RefVectorHolderBase(), refs_(refs) {
20  }
21  explicit RefVectorHolder(ProductID const& iId) : RefVectorHolderBase(), refs_(iId) {
22  }
23  virtual ~RefVectorHolder() { }
24  void swap(RefVectorHolder& other);
26  virtual bool empty() const;
27  virtual size_type size() const;
28  virtual void clear();
29  virtual void push_back(RefHolderBase const* r);
30  virtual void reserve(size_type n);
31  virtual ProductID id() const;
32  virtual EDProductGetter const* productGetter() const;
33  virtual RefVectorHolder<REFV> * clone() const;
34  virtual RefVectorHolder<REFV> * cloneEmpty() const;
35  void setRefs(REFV const& refs);
36  virtual void reallyFillView(void const*, ProductID const&, std::vector<void const*> &);
37  virtual size_t keyForIndex(size_t idx) const;
38 
39  //Needed for ROOT storage
41 
42  private:
44 
45  public:
46  struct const_iterator_imp_specific : public const_iterator_imp {
47  typedef ptrdiff_t difference_type;
49  explicit const_iterator_imp_specific(typename REFV::const_iterator const& it) : i (it) { }
52  void increase() { ++i; }
53  void decrease() { --i; }
54  void increase(difference_type d) { i += d; }
55  void decrease(difference_type d) { i -= d; }
56  bool equal_to(const_iterator_imp const* o) const { return i == dc(o); }
57  bool less_than(const_iterator_imp const* o) const { return i < dc(o); }
58  void assign(const_iterator_imp const* o) { i = dc(o); }
59  boost::shared_ptr<RefHolderBase> deref() const;
60  difference_type difference(const_iterator_imp const* o) const { return i - dc(o); }
61  private:
62  typename REFV::const_iterator const& dc(const_iterator_imp const* o) const {
63  if (o == 0) {
65  "In RefVectorHolder trying to dereference a null pointer\n");
66  }
68  if (oo == 0) {
70  "In RefVectorHolder trying to cast iterator to wrong type\n");
71  }
72  return oo->i;
73  }
74  typename REFV::const_iterator i;
75  };
76 
78 
80  return const_iterator(new const_iterator_imp_specific(refs_.begin()));
81  }
82  const_iterator end() const {
83  return const_iterator(new const_iterator_imp_specific(refs_.end()));
84  }
85  virtual void const* product() const {
86  return refs_.product();
87  }
88 
91  virtual bool isAvailable() const { return refs_.isAvailable(); }
92 
93  private:
94  virtual boost::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const;
95  REFV refs_;
96  };
97 
98  //
99  // implementations for RefVectorHolder<REFV>
100  //
101 
102  template <typename REFV>
103  inline
105  this->RefVectorHolderBase::swap(other);
106  refs_.swap(other.refs_);
107  }
108 
109  template <typename REFV>
110  inline
113  this->swap(temp);
114  return *this;
115  }
116 
117  template<typename REFV>
118  inline
120  return refs_.empty();
121  }
122 
123  template<typename REFV>
124  inline
126  return refs_.size();
127  }
128 
129  template<typename REFV>
130  inline
132  return refs_.clear();
133  }
134 
135  template<typename REFV>
136  inline
138  typename REFV::size_type s = n;
139  refs_.reserve(s);
140  }
141 
142  template<typename REFV>
143  inline
145  return refs_.id();
146  }
147 
148  template<typename REFV>
149  inline
151  return refs_.productGetter();
152  }
153 
154  template<typename REFV>
155  inline
157  return new RefVectorHolder<REFV>(*this);
158  }
159 
160  template<typename REFV>
161  inline
163  return new RefVectorHolder<REFV>(id());
164  }
165 
166  template<typename REFV>
167  inline
168  void RefVectorHolder<REFV>::setRefs(REFV const& refs) {
169  refs_ = refs;
170  }
171 
172  template <typename REFV>
173  inline
175  return refs_[idx].key();
176  }
177 
178  // Free swap function
179  template <typename REFV>
180  inline
181  void
183  lhs.swap(rhs);
184  }
185  }
186 }
187 
189 
190 namespace edm {
191  namespace reftobase {
192 
193  template<typename REFV>
195  typedef typename REFV::value_type REF;
196  RefHolder<REF> const* rh = dynamic_cast<RefHolder<REF> const*>(h);
197  if(rh == 0) {
199  "RefVectorHolder: attempting to cast a RefHolderBase "
200  "to an invalid type.\nExpected: ",
201  typeid(REF).name(),
202  "\n");
203  }
204  refs_.push_back(rh->getRef());
205  }
206 
207  template <typename REFV>
208  boost::shared_ptr<RefHolderBase>
210  return boost::shared_ptr<RefHolderBase>(new RefHolder<typename REFV::value_type>(refs_[idx]));
211  }
212 
213  template<typename REFV>
214  boost::shared_ptr<RefHolderBase> RefVectorHolder<REFV>::const_iterator_imp_specific::deref() const {
215  return boost::shared_ptr<RefHolderBase>(new RefHolder<typename REFV::value_type>(*i));
216  }
217 
218  }
219 }
220 
223 #include "boost/mpl/if.hpp"
224 
225 namespace edm {
226  namespace reftobase {
227  template<typename REFV>
229  static void reallyFillView(RefVectorHolder<REFV>&, void const*, ProductID const&, std::vector<void const*>&) {
231  "The product type ",
232  typeid(typename REFV::collection_type).name(),
233  "\ndoes not support Views\n");
234  }
235  };
236 
237  template<typename REFV>
239  static void reallyFillView(RefVectorHolder<REFV>& rvh, void const* prod, ProductID const& id , std::vector<void const*> & pointers) {
240  typedef typename REFV::collection_type collection;
241  collection const* product = static_cast<collection const*>(prod);
242  detail::reallyFillView(*product, id, pointers, rvh);
243  }
244  };
245 
246  template<typename REFV>
247  void RefVectorHolder<REFV>::reallyFillView(void const* iProd, ProductID const& iId , std::vector<void const*> & oPointers) {
248  typedef
252  maybe_filler::reallyFillView(*this, iProd, iId, oPointers);
253  }
254  }
255 }
256 
257 #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_)
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 * > &)
boost::shared_ptr< RefHolderBase > deref() 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
virtual boost::shared_ptr< reftobase::RefHolderBase > refBase(size_t idx) 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
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 void const * product() const
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:117