CMS 3D CMS Logo

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