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 
19  template <class REF>
20  class RefHolder : public RefHolderBase {
21  public:
22  RefHolder();
23  explicit RefHolder(REF const& ref);
24  void swap(RefHolder& other);
25  ~RefHolder() override;
26  RefHolderBase* clone() const override;
27 
28  ProductID id() const override;
29  size_t key() const override;
30  bool isEqualTo(RefHolderBase const& rhs) const override;
32  std::string& msg) const override;
33  REF const& getRef() const;
34  void setRef(REF const& r);
35  std::unique_ptr<RefVectorHolderBase> makeVectorHolder() const override;
36  EDProductGetter const* productGetter() const override;
37 
40  bool isAvailable() const override { return ref_.isAvailable(); }
41 
42  bool isTransient() const override { return ref_.isTransient(); }
43 
44  //Needed for ROOT storage
46  private:
47  void const* pointerToType(std::type_info const& iToType) const override;
48  REF ref_;
49  };
50 
51  //------------------------------------------------------------------
52  // Implementation of RefHolder<REF>
53  //------------------------------------------------------------------
54 
55  template <class REF>
56  RefHolder<REF>::RefHolder() :
57  RefHolderBase(), ref_()
58  { }
59 
60  template <class REF>
61  RefHolder<REF>::RefHolder(REF const& ref) :
62  RefHolderBase(), ref_(ref)
63  { }
64 
65  template <class REF>
67  { }
68 
69  template <class REF>
72  {
73  return new RefHolder(ref_);
74  }
75 
76  template <class REF>
77  ProductID
79  {
80  return ref_.id();
81  }
82 
83  template <class REF>
84  bool
86  {
87  RefHolder const* h(dynamic_cast<RefHolder const*>(&rhs));
88  return h && (getRef() == h->getRef());
89  }
90 
91  template <class REF>
92  bool
94  std::string& msg) const
95  {
96  RefHolder* h = dynamic_cast<RefHolder*>(&fillme);
97  bool conversion_worked = (h != nullptr);
98  if (conversion_worked)
99  h->setRef(ref_);
100  else
101  msg = typeid(REF).name();
102  return conversion_worked;
103  }
104 
105  template <class REF>
106  inline
107  REF const&
109  {
110  return ref_;
111  }
112 
113  template<class REF>
115  return ref_.productGetter();
116  }
117 
118  template <class REF>
119  inline
120  void
122  {
123  std::swap(ref_, other.ref_);
124  }
125 
126  template <class REF>
127  inline
128  void
130  {
131  ref_ = r;
132  }
133 
134  template <class REF>
135  void const*
136  RefHolder<REF>::pointerToType(std::type_info const& iToType) const {
137  typedef typename REF::value_type contained_type;
138  if(iToType == typeid(contained_type)) {
139  return ref_.get();
140  }
141  return pointerToBase(iToType, ref_.get());
142  }
143  } // namespace reftobase
144 }
145 
146 #endif
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool isAvailable() const override
Definition: RefHolder_.h:40
RefHolderBase * clone() const override
Definition: RefHolder_.h:71
REF const & getRef() const
Definition: RefHolder_.h:108
std::unique_ptr< RefVectorHolderBase > makeVectorHolder() const override
Definition: RefHolder.h:14
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
void const * pointerToType(std::type_info const &iToType) const override
Definition: RefHolder_.h:136
EDProductGetter const * productGetter() const override
Definition: RefHolder_.h:114
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
bool isTransient() const override
Definition: RefHolder_.h:42
void setRef(REF const &r)
Definition: RefHolder_.h:129
tuple msg
Definition: mps_check.py:277
HLT enums.
bool isEqualTo(RefHolderBase const &rhs) const override
Definition: RefHolder_.h:85
bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: RefHolder_.h:93
ProductID id() const override
Definition: RefHolder_.h:78
size_t key() const override
Definition: RefHolder.h:27
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:50
void swap(RefHolder &other)
Definition: RefHolder_.h:121