CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefHolder_.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefHolder__h
2 #define DataFormats_Common_RefHolder__h
4 
10 #include <memory>
11 #include <typeinfo>
12 
13 namespace edm {
14  namespace reftobase {
15  //------------------------------------------------------------------
16  // Class template RefHolder<REF>
17  //------------------------------------------------------------------
18 
19 
20  template <class REF>
21  class RefHolder : public RefHolderBase {
22  public:
23  RefHolder();
24  explicit RefHolder(REF const& ref);
25  void swap(RefHolder& other);
26  virtual ~RefHolder();
27  virtual RefHolderBase* clone() const override;
28 
29  virtual ProductID id() const override;
30  virtual size_t key() const override;
31  virtual bool isEqualTo(RefHolderBase const& rhs) const override;
32  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
33  std::string& msg) const override;
34  REF const& getRef() const;
35  void setRef(REF const& r);
36  virtual std::auto_ptr<RefVectorHolderBase> makeVectorHolder() const override;
37  virtual EDProductGetter const* productGetter() const override;
38 
41  virtual bool isAvailable() const override { return ref_.isAvailable(); }
42 
43  virtual bool isTransient() const override { return ref_.isTransient(); }
44 
45  //Needed for ROOT storage
47  private:
48  virtual void const* pointerToType(std::type_info const& iToType) const override;
49  REF ref_;
50  };
51 
52  //------------------------------------------------------------------
53  // Implementation of RefHolder<REF>
54  //------------------------------------------------------------------
55 
56  template <class REF>
57  RefHolder<REF>::RefHolder() :
58  RefHolderBase(), ref_()
59  { }
60 
61  template <class REF>
62  RefHolder<REF>::RefHolder(REF const& ref) :
63  RefHolderBase(), ref_(ref)
64  { }
65 
66  template <class REF>
68  { }
69 
70  template <class REF>
73  {
74  return new RefHolder(ref_);
75  }
76 
77  template <class REF>
78  ProductID
80  {
81  return ref_.id();
82  }
83 
84  template <class REF>
85  bool
87  {
88  RefHolder const* h(dynamic_cast<RefHolder const*>(&rhs));
89  return h && (getRef() == h->getRef());
90  }
91 
92  template <class REF>
93  bool
95  std::string& msg) const
96  {
97  RefHolder* h = dynamic_cast<RefHolder*>(&fillme);
98  bool conversion_worked = (h != 0);
99  if (conversion_worked)
100  h->setRef(ref_);
101  else
102  msg = typeid(REF).name();
103  return conversion_worked;
104  }
105 
106  template <class REF>
107  inline
108  REF const&
110  {
111  return ref_;
112  }
113 
114  template<class REF>
116  return ref_.productGetter();
117  }
118 
119  template <class REF>
120  inline
121  void
123  {
124  std::swap(ref_, other.ref_);
125  }
126 
127  template <class REF>
128  inline
129  void
131  {
132  ref_ = r;
133  }
134 
135  template <class REF>
136  void const*
137  RefHolder<REF>::pointerToType(std::type_info const& iToType) const {
138  typedef typename REF::value_type contained_type;
139  if(iToType == typeid(contained_type)) {
140  return ref_.get();
141  }
142  return pointerToBase(iToType, ref_.get());
143  }
144  } // namespace reftobase
145 }
146 
147 #endif
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual void const * pointerToType(std::type_info const &iToType) const override
Definition: RefHolder_.h:137
REF const & getRef() const
Definition: RefHolder_.h:109
virtual bool isTransient() const override
Definition: RefHolder_.h:43
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual bool isAvailable() const override
Definition: RefHolder_.h:41
virtual ProductID id() const override
Definition: RefHolder_.h:79
virtual RefHolderBase * clone() const override
Definition: RefHolder_.h:72
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const override
Definition: RefHolder_.h:94
void setRef(REF const &r)
Definition: RefHolder_.h:130
string const
Definition: compareJSON.py:14
virtual std::auto_ptr< RefVectorHolderBase > makeVectorHolder() const override
Definition: RefHolder.h:14
virtual EDProductGetter const * productGetter() const override
Definition: RefHolder_.h:115
virtual bool isEqualTo(RefHolderBase const &rhs) const override
Definition: RefHolder_.h:86
ProductIndex id() const
Definition: ProductID.h:38
void const * pointerToBase(std::type_info const &baseTypeInfo, T const *address)
Definition: OffsetToBase.h:49
void swap(RefHolder &other)
Definition: RefHolder_.h:122
def template
Definition: svgfig.py:520
virtual size_t key() const override
Definition: RefHolder.h:27