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
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 GCC11_OVERRIDE;
26 
27  virtual T const* getPtr() const GCC11_OVERRIDE;
28  virtual ProductID id() const GCC11_OVERRIDE;
29  virtual size_t key() const GCC11_OVERRIDE;
30  virtual bool isEqualTo(BaseHolder<T> const& rhs) const GCC11_OVERRIDE;
31  REF const& getRef() const;
32 
33  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
34  std::string& msg) const GCC11_OVERRIDE;
35 
36  virtual std::auto_ptr<RefHolderBase> holder() const GCC11_OVERRIDE {
37  return std::auto_ptr<RefHolderBase>( new RefHolder<REF>( ref_ ) );
38  }
39  virtual std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() const GCC11_OVERRIDE;
41 
44  virtual bool isAvailable() const GCC11_OVERRIDE { return ref_.isAvailable(); }
45 
46  virtual bool isTransient() const GCC11_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
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  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::auto_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
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
#define GCC11_OVERRIDE
virtual EDProductGetter const * productGetter() const
Definition: Holder.h:145
Holder & operator=(Holder const &rhs)
Definition: Holder.h:80
REF const & getRef() const
Definition: Holder.h:138
virtual size_t key() const
Definition: Holder.h:190
virtual bool isTransient() const
Definition: Holder.h:46
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
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)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
virtual std::auto_ptr< RefHolderBase > holder() const
Definition: Holder.h:36
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
virtual BaseHolder< T > * clone() const
Definition: Holder.h:103
virtual ~Holder()
Definition: Holder.h:97
void setRef(REF const &r)
Definition: RefHolder_.h:129
virtual std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder() const
Definition: Holder.h:175
string const
Definition: compareJSON.py:14
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const
Definition: Holder.h:151
#define private
Definition: FWFileEntry.h:17
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:44
def template
Definition: svgfig.py:520
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:116
virtual ProductID id() const
Definition: Holder.h:119