CMS 3D CMS Logo

Holder.h
Go to the documentation of this file.
1 
2 #ifndef DataFormats_Common_Holder_h
3 #define DataFormats_Common_Holder_h
8 #include <memory>
9 
10 namespace edm {
11  namespace reftobase {
12  //------------------------------------------------------------------
13  // Class template Holder<T,REF>
14  //------------------------------------------------------------------
15 
16  template <class T, class REF>
17  class Holder : public BaseHolder<T> {
18  public:
19  Holder();
20  Holder(Holder const& other);
21  explicit Holder(REF const& iRef);
22  Holder& operator= (Holder const& rhs);
23  void swap(Holder& other);
24  virtual ~Holder();
25  virtual BaseHolder<T>* clone() const override;
26 
27  virtual T const* getPtr() const override;
28  virtual ProductID id() const override;
29  virtual size_t key() const override;
30  virtual bool isEqualTo(BaseHolder<T> const& rhs) const override;
31  REF const& getRef() const;
32 
33  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
34  std::string& msg) const override;
35 
36  virtual std::unique_ptr<RefHolderBase> holder() const override {
37  return std::unique_ptr<RefHolderBase>( new RefHolder<REF>( ref_ ) );
38  }
39  virtual std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
40  virtual EDProductGetter const* productGetter() const override;
41 
44  virtual bool isAvailable() const override { return ref_.isAvailable(); }
45 
46  virtual bool isTransient() const override { return ref_.isTransient(); }
47 
48  //Used by ROOT storage
50 
51  private:
52  REF ref_;
53  };
54 
55  //------------------------------------------------------------------
56  // Implementation of Holder<T,REF>
57  //------------------------------------------------------------------
58 
59  template <class T, class REF>
60  inline
61  Holder<T,REF>::Holder() : BaseHolder<T>(),
62  ref_()
63  { }
64 
65  template <class T, class REF>
66  inline
68  ref_(other.ref_)
69  { }
70 
71  template <class T, class REF>
72  inline
73  Holder<T,REF>::Holder(REF const& r) : BaseHolder<T>(),
74  ref_(r)
75  { }
76 
77  template <class T, class REF>
78  inline
81  {
82  Holder temp(rhs);
83  swap(temp);
84  return *this;
85  }
86 
87  template <class T, class REF>
88  inline
89  void
91  {
92  std::swap(ref_, other.ref_);
93  }
94 
95  template <class T, class REF>
96  inline
98  { }
99 
100  template <class T, class REF>
101  inline
104  {
105  return new Holder(*this);
106  }
107 
108  template <class T, class REF>
109  inline
110  T const*
112  {
113  return ref_.operator->();
114  }
115 
116  template <class T, class REF>
117  inline
118  ProductID
120  {
121  return ref_.id();
122  }
123 
124  template <class T, class REF>
125  inline
126  bool
128  {
129  Holder const* h = dynamic_cast<Holder const*>(&rhs);
130  return h && (getRef() == h->getRef());
131  // if (h == 0) return false;
132  // return getRef() == h->getRef();
133  }
134 
135  template <class T, class REF>
136  inline
137  REF const&
139  {
140  return ref_;
141  }
142 
143  template <class T, class REF>
144  inline
146  return ref_.productGetter();
147  }
148 
149  template <class T, class REF>
150  bool
152  std::string& msg) const
153  {
154  RefHolder<REF>* h = dynamic_cast<RefHolder<REF>*>(&fillme);
155  bool conversion_worked = (h != 0);
156 
157  if (conversion_worked)
158  h->setRef(ref_);
159  else
160  msg = typeid(REF).name();
161 
162  return conversion_worked;
163  }
164 
165  }
166 }
167 
170 
171 namespace edm {
172  namespace reftobase {
173 
174  template <typename T, typename REF>
175  std::unique_ptr<BaseVectorHolder<T> > Holder<T,REF>::makeVectorHolder() const {
176  typedef typename HolderToVectorTrait<T, REF>::type helper;
177  return helper::makeVectorHolder();
178  }
179  }
180 }
181 
183 
184 namespace edm {
185  namespace reftobase {
186 
187  template <class T, class REF>
188  inline
189  size_t
191  {
192  typedef typename RefKeyTrait<REF>::type helper;
193  return helper::key( ref_ );
194  }
195 
196  }
197 }
198 #endif
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: Holder.h:151
virtual bool isAvailable() const override
Definition: Holder.h:44
virtual bool isEqualTo(BaseHolder< T > const &rhs) const override
Definition: Holder.h:127
Definition: helper.py:1
Holder & operator=(Holder const &rhs)
Definition: Holder.h:80
virtual std::unique_ptr< RefHolderBase > holder() const override
Definition: Holder.h:36
virtual EDProductGetter const * productGetter() const override
Definition: Holder.h:145
REF const & getRef() const
Definition: Holder.h:138
virtual T const * getPtr() const override
Definition: Holder.h:111
virtual size_t key() const override
Definition: Holder.h:190
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
void swap(Holder &other)
Definition: Holder.h:90
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
virtual ~Holder()
Definition: Holder.h:97
virtual BaseHolder< T > * clone() const override
Definition: Holder.h:103
void setRef(REF const &r)
Definition: RefHolder_.h:129
virtual std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
Definition: Holder.h:175
HLT enums.
long double T
virtual ProductID id() const override
Definition: Holder.h:119
virtual bool isTransient() const override
Definition: Holder.h:46