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 
7 #include "Reflex/Object.h"
8 #include "Reflex/Type.h"
10 #include <memory>
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  virtual ~RefHolder();
26  virtual RefHolderBase* clone() const;
27 
28  virtual ProductID id() const;
29  virtual size_t key() const;
30  virtual bool isEqualTo(RefHolderBase const& rhs) const;
31  virtual bool fillRefIfMyTypeMatches(RefHolderBase& fillme,
32  std::string& msg) const;
33  REF const& getRef() const;
34  void setRef(REF const& r);
35  virtual std::auto_ptr<RefVectorHolderBase> makeVectorHolder() const;
36  virtual EDProductGetter const* productGetter() const;
37  virtual bool hasProductCache() const;
38  virtual void const * product() const;
39 
42  virtual bool isAvailable() const { return ref_.isAvailable(); }
43 
44  //Needed for ROOT storage
46  private:
47  virtual void const* pointerToType(Reflex::Type const& iToType) const;
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 != 0);
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>
120  return ref_.hasProductCache();
121  }
122 
123  template<class REF>
124  void const * RefHolder<REF>::product() const {
125  return ref_.product();
126  }
127 
128  template <class REF>
129  inline
130  void
132  {
133  std::swap(ref_, other.ref_);
134  }
135 
136  template <class REF>
137  inline
138  void
140  {
141  ref_ = r;
142  }
143 
144  template <class REF>
145  void const*
147  {
148  typedef typename REF::value_type contained_type;
149  static const Reflex::Type s_type(Reflex::Type::ByTypeInfo(typeid(contained_type)));
150 
151  // The const_cast below is needed because
152  // Object's constructor requires a pointer to
153  // non-const void, although the implementation does not, of
154  // course, modify the object to which the pointer points.
155  Reflex::Object obj(s_type, const_cast<void*>(static_cast<const void*>(ref_.get())));
156  if ( s_type == iToType ) return obj.Address();
157  Reflex::Object cast = obj.CastObject(iToType);
158  return cast.Address(); // returns void*, after pointer adjustment
159  }
160  } // namespace reftobase
161 }
162 
163 #endif
helper::MatcherGetRef< C >::ref_type getRef(const Handle< C > &c, size_t k)
Definition: getRef.h:28
REF const & getRef() const
Definition: RefHolder_.h:108
virtual ProductID id() const
Definition: RefHolder_.h:78
virtual bool hasProductCache() const
Definition: RefHolder_.h:119
virtual RefHolderBase * clone() const
Definition: RefHolder_.h:71
#define CMS_CLASS_VERSION(_version_)
virtual bool isAvailable() const
Definition: RefHolder_.h:42
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Container::value_type value_type
virtual EDProductGetter const * productGetter() const
Definition: RefHolder_.h:114
virtual void const * product() const
Definition: RefHolder_.h:124
virtual bool fillRefIfMyTypeMatches(RefHolderBase &fillme, std::string &msg) const
Definition: RefHolder_.h:93
virtual std::auto_ptr< RefVectorHolderBase > makeVectorHolder() const
Definition: RefHolder.h:14
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void setRef(REF const &r)
Definition: RefHolder_.h:139
virtual void const * pointerToType(Reflex::Type const &iToType) const
Definition: RefHolder_.h:146
string const
Definition: compareJSON.py:14
#define private
Definition: FWFileEntry.h:18
virtual bool isEqualTo(RefHolderBase const &rhs) const
Definition: RefHolder_.h:85
virtual size_t key() const
Definition: RefHolder.h:27
ProductIndex id() const
Definition: ProductID.h:38
void swap(RefHolder &other)
Definition: RefHolder_.h:131
def template
Definition: svgfig.py:520