test
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 size_t keyForIndex(size_t idx) const;
37 
38  //Needed for ROOT storage
40 
41  private:
43 
44  public:
45  struct const_iterator_imp_specific : public const_iterator_imp {
46  typedef ptrdiff_t difference_type;
48  explicit const_iterator_imp_specific(typename REFV::const_iterator const& it) : i (it) { }
51  void increase() { ++i; }
52  void decrease() { --i; }
53  void increase(difference_type d) { i += d; }
54  void decrease(difference_type d) { i -= d; }
55  bool equal_to(const_iterator_imp const* o) const { return i == dc(o); }
56  bool less_than(const_iterator_imp const* o) const { return i < dc(o); }
57  void assign(const_iterator_imp const* o) { i = dc(o); }
58  std::shared_ptr<RefHolderBase> deref() const;
59  difference_type difference(const_iterator_imp const* o) const { return i - dc(o); }
60  private:
61  typename REFV::const_iterator const& dc(const_iterator_imp const* o) const {
62  if (o == 0) {
64  "In RefVectorHolder trying to dereference a null pointer\n");
65  }
67  if (oo == 0) {
69  "In RefVectorHolder trying to cast iterator to wrong type\n");
70  }
71  return oo->i;
72  }
73  typename REFV::const_iterator i;
74  };
75 
77 
79  return const_iterator(new const_iterator_imp_specific(refs_.begin()));
80  }
81  const_iterator end() const {
82  return const_iterator(new const_iterator_imp_specific(refs_.end()));
83  }
84 
87  virtual bool isAvailable() const { return refs_.isAvailable(); }
88 
89  private:
90  virtual std::shared_ptr<reftobase::RefHolderBase> refBase(size_t idx) const;
91  REFV refs_;
92  };
93 
94  //
95  // implementations for RefVectorHolder<REFV>
96  //
97 
98  template <typename REFV>
99  inline
101  this->RefVectorHolderBase::swap(other);
102  refs_.swap(other.refs_);
103  }
104 
105  template <typename REFV>
106  inline
109  this->swap(temp);
110  return *this;
111  }
112 
113  template<typename REFV>
114  inline
116  return refs_.empty();
117  }
118 
119  template<typename REFV>
120  inline
122  return refs_.size();
123  }
124 
125  template<typename REFV>
126  inline
128  return refs_.clear();
129  }
130 
131  template<typename REFV>
132  inline
134  typename REFV::size_type s = n;
135  refs_.reserve(s);
136  }
137 
138  template<typename REFV>
139  inline
141  return refs_.id();
142  }
143 
144  template<typename REFV>
145  inline
147  return refs_.productGetter();
148  }
149 
150  template<typename REFV>
151  inline
153  return new RefVectorHolder<REFV>(*this);
154  }
155 
156  template<typename REFV>
157  inline
159  return new RefVectorHolder<REFV>(id());
160  }
161 
162  template<typename REFV>
163  inline
164  void RefVectorHolder<REFV>::setRefs(REFV const& refs) {
165  refs_ = refs;
166  }
167 
168  template <typename REFV>
169  inline
171  return refs_[idx].key();
172  }
173 
174  // Free swap function
175  template <typename REFV>
176  inline
177  void
179  lhs.swap(rhs);
180  }
181  }
182 }
183 
185 
186 namespace edm {
187  namespace reftobase {
188 
189  template<typename REFV>
191  typedef typename REFV::value_type REF;
192  RefHolder<REF> const* rh = dynamic_cast<RefHolder<REF> const*>(h);
193  if(rh == 0) {
195  "RefVectorHolder: attempting to cast a RefHolderBase "
196  "to an invalid type.\nExpected: ",
197  typeid(REF).name(),
198  "\n");
199  }
200  refs_.push_back(rh->getRef());
201  }
202 
203  template <typename REFV>
204  std::shared_ptr<RefHolderBase>
206  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(refs_[idx]));
207  }
208 
209  template<typename REFV>
210  std::shared_ptr<RefHolderBase>
212  return std::shared_ptr<RefHolderBase>(std::make_shared<RefHolder<typename REFV::value_type> >(*i));
213  }
214  }
215 }
216 
217 #endif
RefVectorHolderBase::const_iterator const_iterator
int i
Definition: DBlmapReader.cc:9
virtual RefVectorHolder< REFV > * cloneEmpty() const
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void swap(RefVectorHolderBase &)
difference_type difference(const_iterator_imp const *o) const
virtual EDProductGetter const * productGetter() const
REF const & getRef() const
Definition: RefHolder_.h:109
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="")
tuple d
Definition: ztail.py:151
void setRefs(REFV const &refs)
virtual RefVectorHolder< REFV > * clone() const
virtual void push_back(RefHolderBase const *r)
virtual void reserve(size_type n)
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
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
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:116