CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Holder.h
Go to the documentation of this file.
1 
2 #ifndef DataFormats_Common_Holder_h
3 #define DataFormats_Common_Holder_h
7 #include <memory>
8 
9 namespace edm {
10  namespace reftobase {
11  //------------------------------------------------------------------
12  // Class template Holder<T,REF>
13  //------------------------------------------------------------------
14 
15  template <class T, class REF>
16  class Holder : public BaseHolder<T> {
17  public:
18  Holder();
19  Holder(Holder const& other);
20  explicit Holder(REF const& iRef);
21  Holder& operator= (Holder const& rhs);
22  void swap(Holder& other);
23  virtual ~Holder();
24  virtual BaseHolder<T>* clone() const;
25 
26  virtual T const* getPtr() const;
27  virtual ProductID id() const;
28  virtual size_t key() const;
29  virtual bool isEqualTo(BaseHolder<T> const& rhs) const;
30  REF const& getRef() const;
31 
32  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
33  std::string& msg) const;
34 
35  virtual std::auto_ptr<RefHolderBase> holder() const {
36  return std::auto_ptr<RefHolderBase>( new RefHolder<REF>( ref_ ) );
37  }
38  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const;
39  virtual std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() const;
40  virtual EDProductGetter const* productGetter() const;
41  virtual bool hasProductCache() const;
42  virtual void const * product() const;
43 
46  virtual bool isAvailable() const { return ref_.isAvailable(); }
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
67  Holder<T,REF>::Holder(Holder const& other) : BaseHolder<T>(other),
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  inline
152  return ref_.hasProductCache();
153  }
154 
155  template <class T, class REF>
156  inline
157  void const * Holder<T,REF>::product() const {
158  return ref_.product();
159  }
160 
161  template <class T, class REF>
162  bool
164  std::string& msg) const
165  {
166  RefHolder<REF>* h = dynamic_cast<RefHolder<REF>*>(&fillme);
167  bool conversion_worked = (h != 0);
168 
169  if (conversion_worked)
170  h->setRef(ref_);
171  else
172  msg = typeid(REF).name();
173 
174  return conversion_worked;
175  }
176 
177  }
178 }
179 
182 
183 namespace edm {
184  namespace reftobase {
185 
186  template <typename T, typename REF>
187  std::auto_ptr<BaseVectorHolder<T> > Holder<T,REF>::makeVectorHolder() const {
188  typedef typename HolderToVectorTrait<T, REF>::type helper;
189  return helper::makeVectorHolder();
190  }
191 
192  template <typename T, typename REF>
193  std::auto_ptr<RefVectorHolderBase> Holder<T,REF>::makeVectorBaseHolder() const {
194  typedef typename HolderToVectorTrait<T, REF>::type helper;
195  return helper::makeVectorBaseHolder();
196  }
197 
198  }
199 }
200 
202 
203 namespace edm {
204  namespace reftobase {
205 
206  template <class T, class REF>
207  inline
208  size_t
210  {
211  typedef typename RefKeyTrait<REF>::type helper;
212  return helper::key( ref_ );
213  }
214 
215  }
216 }
217 #endif
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
virtual EDProductGetter const * productGetter() const
Definition: Holder.h:145
Holder & operator=(Holder const &rhs)
Definition: Holder.h:80
virtual void const * product() const
Definition: Holder.h:157
REF const & getRef() const
Definition: Holder.h:138
virtual size_t key() const
Definition: Holder.h:209
#define CMS_CLASS_VERSION(_version_)
void swap(Holder &other)
Definition: Holder.h:90
virtual T const * getPtr() const
Definition: Holder.h:111
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual std::auto_ptr< RefHolderBase > holder() const
Definition: Holder.h:35
virtual std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder() const
Definition: Holder.h:193
virtual BaseHolder< T > * clone() const
Definition: Holder.h:103
virtual ~Holder()
Definition: Holder.h:97
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void setRef(REF const &r)
Definition: RefHolder_.h:139
virtual std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder() const
Definition: Holder.h:187
string const
Definition: compareJSON.py:14
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const
Definition: Holder.h:163
#define private
Definition: FWFileEntry.h:18
list key
Definition: combine.py:13
virtual bool hasProductCache() const
Definition: Holder.h:151
ProductIndex id() const
Definition: ProductID.h:38
virtual bool isEqualTo(BaseHolder< T > const &rhs) const
Definition: Holder.h:127
long double T
virtual bool isAvailable() const
Definition: Holder.h:46
def template
Definition: svgfig.py:520
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:117
virtual ProductID id() const
Definition: Holder.h:119