CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefProd.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefProd_h
2 #define DataFormats_Common_RefProd_h
3 
4 /*----------------------------------------------------------------------
5 
6 Ref: A template for an interproduct reference to a product.
7 
8 $Id: RefProd.h,v 1.19 2008/05/29 21:13:15 wmtan Exp $
9 
10 ----------------------------------------------------------------------*/
11 
12 /*----------------------------------------------------------------------
13 // This defines the public interface to the class RefProd<T>.
14 //
15 // ProductID productID is the product ID of the collection. (0 is invalid)
16 // RefProd<T> const& ref is another RefProd<T>
17 
18 // Constructors
19  RefProd(); // Default constructor
20  RefProd(RefProd<T> const& ref); // Copy constructor (default, not explicitly specified)
21 
22  RefProd(Handle<T> const& handle);
23  RefProd(ProductID pid, EDProductGetter const* prodGetter);
24 
25 // Destructor
26  virtual ~RefProd() {}
27 
28 // Operators and methods
29  RefProd<T>& operator=(RefProd<T> const&); // assignment (default, not explicitly specified)
30  T const& operator*() const; // dereference
31  T const* operator->() const; // member dereference
32  bool operator==(RefProd<T> const& ref) const; // equality
33  bool operator!=(RefProd<T> const& ref) const; // inequality
34  bool operator<(RefProd<T> const& ref) const; // ordering
35  bool isNonnull() const; // true if an object is referenced
36  bool isNull() const; // equivalent to !isNonnull()
37  bool operator!() const; // equivalent to !isNonnull()
38 ----------------------------------------------------------------------*/
39 
47 
48 namespace edm {
49 
50  template <typename C>
51  class RefProd {
52  public:
53  typedef C product_type;
54  typedef C value_type;
55 
57  RefProd() : product_() {}
58 
60  explicit RefProd(Handle<C> const& handle) :
61  product_(handle.id(), handle.product(), 0, false) {
63  }
64 
66  explicit RefProd(OrphanHandle<C> const& handle) :
67  product_(handle.id(), handle.product(), 0, false) {
69  }
70 
72  // An exception will be thrown if an attempt is made to persistify
73  // any object containing this RefProd. Also, in the future work will
74  // be done to throw an exception if an attempt is made to put any object
75  // containing this RefProd into an event(or run or lumi).
76  RefProd(C const* product) :
77  product_(ProductID(), product, 0, true) {
78  checkTypeAtCompileTime(product);
79  }
80 
82  // An exception will be thrown if an attempt is made to persistify
83  // any object containing this RefProd. Also, in the future work will
84  // be done to throw an exception if an attempt is made to put any object
85  // containing this RefProd into an event(or run or lumi).
86  explicit RefProd(TestHandle<C> const& handle) :
87  product_(handle.id(), handle.product(), 0, true) {
89  }
90 
92  template <typename T, typename F>
93  explicit RefProd(Ref<C, T, F> const& ref);
94 
96  template <typename T, typename F>
97  explicit RefProd(RefVector<C, T, F> const& ref);
98 
99  // Constructor for those users who do not have a product handle,
100  // but have a pointer to a product getter (such as the EventPrincipal).
101  // prodGetter will ususally be a pointer to the event principal.
102  RefProd(ProductID const& productID, EDProductGetter const* prodGetter) :
103  product_(productID, 0, mustBeNonZero(prodGetter, "RefProd", productID), false) {
104  }
105 
107  ~RefProd() {}
108 
110  product_type const& operator*() const;
111 
113  product_type const* operator->() const;
114 
117  product_type const* get() const {
118  return isNull() ? 0 : this->operator->();
119  }
120 
123  product_type const* product() const {
124  return isNull() ? 0 : this->operator->();
125  }
126 
127  RefCore const& refCore() const {
128  return product_;
129  }
130 
132  bool isNull() const {return !isNonnull();}
133 
135  bool isNonnull() const {return product_.isNonnull();}
136 
138  bool operator!() const {return isNull();}
139 
141  ProductID id() const {return product_.id();}
142 
145 
147  bool hasCache() const {return product_.productPtr() != 0;}
148 
150  bool hasProductCache() const {return hasCache();}
151 
154  bool isAvailable() const {return product_.isAvailable();}
155 
157  bool isTransient() const {return product_.isTransient();}
158 
159  void swap(RefProd<C> &);
160 
161  private:
162  // Compile time check that the argument is a C* or C const*
163  // or derived from it.
164  void checkTypeAtCompileTime(C const* ptr) {}
165 
167  };
168 }
169 
172 
173 namespace edm {
174  template<typename C, typename T, typename F>
175  class RefVector;
176 
178  template <typename C>
179  template <typename T, typename F>
180  inline
182  product_(ref.id(), ref.hasProductCache() ? ref.product() : 0, ref.productGetter(), ref.isTransient())
183  { }
184 
186  template <typename C>
187  template <typename T, typename F>
188  inline
190  product_(ref.id(), ref.hasProductCache() ? ref.product() : 0, ref.productGetter(), ref.isTransient())
191  { }
192 
194  template <typename C>
195  inline
196  C const& RefProd<C>::operator*() const {
197  return *(edm::template getProduct<C>(product_));
198  }
199 
201  template <typename C>
202  inline
203  C const* RefProd<C>::operator->() const {
204  return edm::template getProduct<C>(product_);
205  }
206 
207 
208  template<typename C>
209  inline
210  void RefProd<C>::swap(RefProd<C> & other) {
211  std::swap(product_, other.product_);
212  }
213 
214  template <typename C>
215  inline
216  bool
217  operator== (RefProd<C> const& lhs, RefProd<C> const& rhs) {
218  return lhs.refCore() == rhs.refCore();
219  }
220 
221  template <typename C>
222  inline
223  bool
224  operator!= (RefProd<C> const& lhs, RefProd<C> const& rhs) {
225  return !(lhs == rhs);
226  }
227 
228  template <typename C>
229  inline
230  bool
231  operator< (RefProd<C> const& lhs, RefProd<C> const& rhs) {
232  return (lhs.refCore() < rhs.refCore());
233  }
234 
235  template<typename C>
236  inline
237  void swap(edm::RefProd<C> const& lhs, edm::RefProd<C> const& rhs ) {
238  lhs.swap(rhs);
239  }
240 }
241 
243 
244 namespace edm {
245  namespace reftobase {
246 
247  template <typename T>
249  static std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() {
250  Exception::throwThis(errors::InvalidReference, "attempting to make a BaseVectorHolder<T> from a RefProd<C>.\n");
251  return std::auto_ptr<BaseVectorHolder<T> >();
252  }
253  static std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() {
254  Exception::throwThis(errors::InvalidReference, "attempting to make a RefVectorHolderBase from a RefProd<C>.\n");
255  return std::auto_ptr<RefVectorHolderBase>();
256  }
257  };
258 
259  template<typename C, typename T>
262  };
263 
265  static std::auto_ptr<RefVectorHolderBase> makeVectorHolder() {
266  Exception::throwThis(errors::InvalidReference, "attempting to make a BaseVectorHolder<T> from a RefProd<C>.\n");
267  return std::auto_ptr<RefVectorHolderBase>();
268  }
269  static std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() {
270  Exception::throwThis(errors::InvalidReference, "attempting to make a RefVectorHolderBase from a RefProd<C>.\n");
271  return std::auto_ptr<RefVectorHolderBase>();
272  }
273  };
274 
275  template<typename C>
278  };
279 
280  }
281 }
282 
283 #endif
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:74
static std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder()
Definition: RefProd.h:249
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
bool operator!() const
Checks for null.
Definition: RefProd.h:138
RefProd()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefProd.h:57
RefProd(OrphanHandle< C > const &handle)
General purpose constructor from orphan handle.
Definition: RefProd.h:66
T const * product() const
Definition: TestHandle.h:61
bool isNull() const
Checks for null.
Definition: RefProd.h:132
C product_type
Definition: RefProd.h:53
bool hasProductCache() const
Checks if product is in memory.
Definition: RefProd.h:150
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
bool operator==(const CaloTower &t1, const CaloTower &t2)
Definition: CaloTower.h:211
bool isNonnull() const
Definition: RefCore.h:31
product_type const * operator->() const
Member dereference operator.
Definition: RefProd.h:203
~RefProd()
Destructor.
Definition: RefProd.h:107
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:81
bool hasCache() const
Checks if product is in memory.
Definition: RefProd.h:147
RefProd(ProductID const &productID, EDProductGetter const *prodGetter)
Definition: RefProd.h:102
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefProd.h:144
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
static std::auto_ptr< RefVectorHolderBase > makeVectorHolder()
Definition: RefProd.h:265
void const * productPtr() const
Definition: RefCore.h:23
bool isAvailable() const
Definition: RefCore.cc:86
tuple handle
Definition: patZpeak.py:22
void swap(RefProd< C > &)
Definition: RefProd.h:210
bool isTransient() const
Checks if this RefProd is transient (i.e. not persistable).
Definition: RefProd.h:157
static std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder()
Definition: RefProd.h:269
void checkTypeAtCompileTime(C const *ptr)
Definition: RefProd.h:164
bool isAvailable() const
Definition: RefProd.h:154
static std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder()
Definition: RefProd.h:253
RefCore product_
Definition: RefProd.h:166
RefCore const & refCore() const
Definition: RefProd.h:127
edm::RefProd< Container > RefProd
product_type const & operator*() const
Dereference operator.
Definition: RefProd.h:196
T const * product() const
Definition: OrphanHandle.h:61
T const * product() const
Definition: Handle.h:74
EDProductGetter const * productGetter() const
Definition: RefCore.h:41
ProductID id() const
Definition: RefCore.h:21
RefProd(TestHandle< C > const &handle)
General purpose constructor from test handle.
Definition: RefProd.h:86
bool isTransient() const
Definition: RefCore.h:57
product_type const * product() const
Definition: RefProd.h:123
bool isNonnull() const
Checks for non-null.
Definition: RefProd.h:135
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:141
RefProd(Handle< C > const &handle)
General purpose constructor from handle.
Definition: RefProd.h:60
RefProd(C const *product)
Constructor for ref to object that is not in an event.
Definition: RefProd.h:76
edm::RefVector< Container > RefVector
def template
Definition: svgfig.py:520
C value_type
Definition: RefProd.h:54