CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  ~Holder() override;
24  BaseHolder<T>* clone() const override;
25 
26  T const* getPtr() const override;
27  ProductID id() const override;
28  size_t key() const override;
29  bool isEqualTo(BaseHolder<T> const& rhs) const override;
30  REF const& getRef() const;
31 
32  bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const override;
33 
34  std::unique_ptr<RefHolderBase> holder() const override {
35  return std::unique_ptr<RefHolderBase>(new RefHolder<REF>(ref_));
36  }
37  std::unique_ptr<BaseVectorHolder<T> > makeVectorHolder() const override;
38  EDProductGetter const* productGetter() const override;
39 
42  bool isAvailable() const override { return ref_.isAvailable(); }
43 
44  bool isTransient() const override { return ref_.isTransient(); }
45 
46  //Used by ROOT storage
48 
49  private:
50  REF ref_;
51  };
52 
53  //------------------------------------------------------------------
54  // Implementation of Holder<T,REF>
55  //------------------------------------------------------------------
56 
57  template <class T, class REF>
58  inline Holder<T, REF>::Holder() : BaseHolder<T>(), ref_() {}
59 
60  template <class T, class REF>
61  inline Holder<T, REF>::Holder(Holder const& other) : BaseHolder<T>(other), ref_(other.ref_) {}
62 
63  template <class T, class REF>
64  inline Holder<T, REF>::Holder(REF const& r) : BaseHolder<T>(), ref_(r) {}
65 
66  template <class T, class REF>
68  Holder temp(rhs);
69  swap(temp);
70  return *this;
71  }
72 
73  template <class T, class REF>
74  inline void Holder<T, REF>::swap(Holder& other) {
75  std::swap(ref_, other.ref_);
76  }
77 
78  template <class T, class REF>
80 
81  template <class T, class REF>
83  return new Holder(*this);
84  }
85 
86  template <class T, class REF>
87  inline T const* Holder<T, REF>::getPtr() const {
88  return ref_.operator->();
89  }
90 
91  template <class T, class REF>
92  inline ProductID Holder<T, REF>::id() const {
93  return ref_.id();
94  }
95 
96  template <class T, class REF>
97  inline bool Holder<T, REF>::isEqualTo(BaseHolder<T> const& rhs) const {
98  Holder const* h = dynamic_cast<Holder const*>(&rhs);
99  return h && (getRef() == h->getRef());
100  // if (h == 0) return false;
101  // return getRef() == h->getRef();
102  }
103 
104  template <class T, class REF>
105  inline REF const& Holder<T, REF>::getRef() const {
106  return ref_;
107  }
108 
109  template <class T, class REF>
111  return ref_.productGetter();
112  }
113 
114  template <class T, class REF>
116  RefHolder<REF>* h = dynamic_cast<RefHolder<REF>*>(&fillme);
117  bool conversion_worked = (h != nullptr);
118 
119  if (conversion_worked)
120  h->setRef(ref_);
121  else
122  msg = typeid(REF).name();
123 
124  return conversion_worked;
125  }
126 
127  } // namespace reftobase
128 } // namespace edm
129 
132 
133 namespace edm {
134  namespace reftobase {
135 
136  template <typename T, typename REF>
137  std::unique_ptr<BaseVectorHolder<T> > Holder<T, REF>::makeVectorHolder() const {
138  typedef typename HolderToVectorTrait<T, REF>::type helper;
139  return helper::makeVectorHolder();
140  }
141  } // namespace reftobase
142 } // namespace edm
143 
145 
146 namespace edm {
147  namespace reftobase {
148 
149  template <class T, class REF>
150  inline size_t Holder<T, REF>::key() const {
151  typedef typename RefKeyTrait<REF>::type helper;
152  return helper::key(ref_);
153  }
154 
155  } // namespace reftobase
156 } // namespace edm
157 #endif
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
std::unique_ptr< BaseVectorHolder< T > > makeVectorHolder() const override
Definition: Holder.h:137
Holder & operator=(Holder const &rhs)
Definition: Holder.h:67
REF const & getRef() const
Definition: Holder.h:105
EDProductGetter const * productGetter() const override
Definition: Holder.h:110
std::unique_ptr< RefHolderBase > holder() const override
Definition: Holder.h:34
#define CMS_CLASS_VERSION(_version_)
bool isTransient() const override
Definition: Holder.h:44
void swap(Holder &other)
Definition: Holder.h:74
BaseHolder< T > * clone() const override
Definition: Holder.h:82
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: Holder.h:115
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
tuple key
prepare the HTCondor submission files and eventually submit them
bool isAvailable() const override
Definition: Holder.h:42
~Holder() override
Definition: Holder.h:79
void setRef(REF const &r)
Definition: RefHolder_.h:104
T const * getPtr() const override
Definition: Holder.h:87
tuple msg
Definition: mps_check.py:285
ProductID id() const override
Definition: Holder.h:92
bool isEqualTo(BaseHolder< T > const &rhs) const override
Definition: Holder.h:97
ProductIndex id() const
Definition: ProductID.h:35
size_t key() const override
Definition: Holder.h:150
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
long double T
def template
Definition: svgfig.py:521
void swap(BaseHolder< T > &lhs, BaseHolder< T > &rhs)
Definition: BaseHolder.h:111