CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RefHolder_.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefHolder__h
2 #define DataFormats_Common_RefHolder__h
4 
8 #include <memory>
9 #include <typeinfo>
10 
11 namespace edm {
12  namespace reftobase {
13  //------------------------------------------------------------------
14  // Class template RefHolder<REF>
15  //------------------------------------------------------------------
16 
17  template <class REF>
18  class RefHolder : public RefHolderBase {
19  public:
20  RefHolder();
21  explicit RefHolder(REF const& ref);
22  void swap(RefHolder& other);
23  ~RefHolder() override;
24  RefHolderBase* clone() const override;
25 
26  ProductID id() const override;
27  size_t key() const override;
28  bool isEqualTo(RefHolderBase const& rhs) const override;
29  bool fillRefIfMyTypeMatches(RefHolderBase& fillme, std::string& msg) const override;
30  REF const& getRef() const;
31  void setRef(REF const& r);
32  std::unique_ptr<RefVectorHolderBase> makeVectorHolder() const override;
33  EDProductGetter const* productGetter() const override;
34 
37  bool isAvailable() const override { return ref_.isAvailable(); }
38 
39  bool isTransient() const override { return ref_.isTransient(); }
40 
41  //Needed for ROOT storage
43  private:
44  void const* pointerToType(std::type_info const& iToType) const override;
45  REF ref_;
46  };
47 
48  //------------------------------------------------------------------
49  // Implementation of RefHolder<REF>
50  //------------------------------------------------------------------
51 
52  template <class REF>
53  RefHolder<REF>::RefHolder() : RefHolderBase(), ref_() {}
54 
55  template <class REF>
56  RefHolder<REF>::RefHolder(REF const& ref) : RefHolderBase(), ref_(ref) {}
57 
58  template <class REF>
60 
61  template <class REF>
63  return new RefHolder(ref_);
64  }
65 
66  template <class REF>
68  return ref_.id();
69  }
70 
71  template <class REF>
72  bool RefHolder<REF>::isEqualTo(RefHolderBase const& rhs) const {
73  RefHolder const* h(dynamic_cast<RefHolder const*>(&rhs));
74  return h && (getRef() == h->getRef());
75  }
76 
77  template <class REF>
79  RefHolder* h = dynamic_cast<RefHolder*>(&fillme);
80  bool conversion_worked = (h != nullptr);
81  if (conversion_worked)
82  h->setRef(ref_);
83  else
84  msg = typeid(REF).name();
85  return conversion_worked;
86  }
87 
88  template <class REF>
89  inline REF const& RefHolder<REF>::getRef() const {
90  return ref_;
91  }
92 
93  template <class REF>
95  return ref_.productGetter();
96  }
97 
98  template <class REF>
99  inline void RefHolder<REF>::swap(RefHolder& other) {
100  std::swap(ref_, other.ref_);
101  }
102 
103  template <class REF>
104  inline void RefHolder<REF>::setRef(REF const& r) {
105  ref_ = r;
106  }
107 
108  template <class REF>
109  void const* RefHolder<REF>::pointerToType(std::type_info const& iToType) const {
110  typedef typename REF::value_type contained_type;
111  if (iToType == typeid(contained_type)) {
112  return ref_.get();
113  }
114  return pointerToBase(iToType, ref_.get());
115  }
116  } // namespace reftobase
117 } // namespace edm
118 
119 #endif
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
bool isAvailable() const override
Definition: RefHolder_.h:37
void const * pointerToType(std::type_info const &iToType) const override
Definition: RefHolder_.h:109
REF const & getRef() const
Definition: RefHolder_.h:89
std::unique_ptr< RefVectorHolderBase > makeVectorHolder() const override
Definition: RefHolder.h:14
#define CMS_CLASS_VERSION(_version_)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool isTransient() const override
Definition: RefHolder_.h:39
ProductID id() const override
Definition: RefHolder_.h:67
RefHolderBase * clone() const override
Definition: RefHolder_.h:62
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: RefHolder_.h:78
void setRef(REF const &r)
Definition: RefHolder_.h:104
tuple msg
Definition: mps_check.py:285
EDProductGetter const * productGetter() const override
Definition: RefHolder_.h:94
bool isEqualTo(RefHolderBase const &rhs) const override
Definition: RefHolder_.h:72
ProductIndex id() const
Definition: ProductID.h:35
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:47
void swap(RefHolder &other)
Definition: RefHolder_.h:99
def template
Definition: svgfig.py:521
size_t key() const override
Definition: RefHolder.h:26