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.20 2009/11/04 15:30:20 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 
48 
49 namespace edm {
50 
51  template <typename C>
52  class RefProd {
53  public:
54  typedef C product_type;
55  typedef C value_type;
56 
58  RefProd() : product_() {}
59 
61  explicit RefProd(Handle<C> const& handle) :
62  product_(handle.id(), handle.product(), 0, false) {
64  }
65 
67  explicit RefProd(OrphanHandle<C> const& handle) :
68  product_(handle.id(), handle.product(), 0, false) {
70  }
71 
73  // An exception will be thrown if an attempt is made to persistify
74  // any object containing this RefProd. Also, in the future work will
75  // be done to throw an exception if an attempt is made to put any object
76  // containing this RefProd into an event(or run or lumi).
77  RefProd(C const* product) :
78  product_(ProductID(), product, 0, true) {
79  checkTypeAtCompileTime(product);
80  }
81 
83  // An exception will be thrown if an attempt is made to persistify
84  // any object containing this RefProd. Also, in the future work will
85  // be done to throw an exception if an attempt is made to put any object
86  // containing this RefProd into an event(or run or lumi).
87  explicit RefProd(TestHandle<C> const& handle) :
88  product_(handle.id(), handle.product(), 0, true) {
90  }
91 
93  template <typename T, typename F>
94  explicit RefProd(Ref<C, T, F> const& ref);
95 
97  template <typename T, typename F>
98  explicit RefProd(RefVector<C, T, F> const& ref);
99 
100  // Constructor for those users who do not have a product handle,
101  // but have a pointer to a product getter (such as the EventPrincipal).
102  // prodGetter will ususally be a pointer to the event principal.
103  RefProd(ProductID const& productID, EDProductGetter const* prodGetter) :
104  product_(productID, 0, mustBeNonZero(prodGetter, "RefProd", productID), false) {
105  }
106 
108  ~RefProd() {}
109 
111  product_type const& operator*() const;
112 
114  product_type const* operator->() const;
115 
118  product_type const* get() const {
119  return isNull() ? 0 : this->operator->();
120  }
121 
124  product_type const* product() const {
125  return isNull() ? 0 : this->operator->();
126  }
127 
128  RefCore const& refCore() const {
129  return product_;
130  }
131 
133  bool isNull() const {return !isNonnull();}
134 
136  bool isNonnull() const {return product_.isNonnull();}
137 
139  bool operator!() const {return isNull();}
140 
142  ProductID id() const {return product_.id();}
143 
146 
148  bool hasCache() const {return product_.productPtr() != 0;}
149 
151  bool hasProductCache() const {return hasCache();}
152 
155  bool isAvailable() const {return product_.isAvailable();}
156 
158  bool isTransient() const {return product_.isTransient();}
159 
160  void swap(RefProd<C> &);
161 
162  //Needed for ROOT storage
164 
165  private:
166  // Compile time check that the argument is a C* or C const*
167  // or derived from it.
169 
171  };
172 }
173 
176 
177 namespace edm {
178  template<typename C, typename T, typename F>
179  class RefVector;
180 
182  template <typename C>
183  template <typename T, typename F>
184  inline
186  product_(ref.id(), ref.hasProductCache() ? ref.product() : 0, ref.productGetter(), ref.isTransient())
187  { }
188 
190  template <typename C>
191  template <typename T, typename F>
192  inline
194  product_(ref.id(), ref.hasProductCache() ? ref.product() : 0, ref.productGetter(), ref.isTransient())
195  { }
196 
198  template <typename C>
199  inline
200  C const& RefProd<C>::operator*() const {
201  return *(edm::template getProduct<C>(product_));
202  }
203 
205  template <typename C>
206  inline
207  C const* RefProd<C>::operator->() const {
208  return edm::template getProduct<C>(product_);
209  }
210 
211 
212  template<typename C>
213  inline
214  void RefProd<C>::swap(RefProd<C> & other) {
215  std::swap(product_, other.product_);
216  }
217 
218  template <typename C>
219  inline
220  bool
221  operator== (RefProd<C> const& lhs, RefProd<C> const& rhs) {
222  return lhs.refCore() == rhs.refCore();
223  }
224 
225  template <typename C>
226  inline
227  bool
228  operator!= (RefProd<C> const& lhs, RefProd<C> const& rhs) {
229  return !(lhs == rhs);
230  }
231 
232  template <typename C>
233  inline
234  bool
235  operator< (RefProd<C> const& lhs, RefProd<C> const& rhs) {
236  return (lhs.refCore() < rhs.refCore());
237  }
238 
239  template<typename C>
240  inline
241  void swap(edm::RefProd<C> const& lhs, edm::RefProd<C> const& rhs ) {
242  lhs.swap(rhs);
243  }
244 }
245 
247 
248 namespace edm {
249  namespace reftobase {
250 
251  template <typename T>
253  static std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() {
254  Exception::throwThis(errors::InvalidReference, "attempting to make a BaseVectorHolder<T> from a RefProd<C>.\n");
255  return std::auto_ptr<BaseVectorHolder<T> >();
256  }
257  static std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() {
258  Exception::throwThis(errors::InvalidReference, "attempting to make a RefVectorHolderBase from a RefProd<C>.\n");
259  return std::auto_ptr<RefVectorHolderBase>();
260  }
261  };
262 
263  template<typename C, typename T>
266  };
267 
269  static std::auto_ptr<RefVectorHolderBase> makeVectorHolder() {
270  Exception::throwThis(errors::InvalidReference, "attempting to make a BaseVectorHolder<T> from a RefProd<C>.\n");
271  return std::auto_ptr<RefVectorHolderBase>();
272  }
273  static std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() {
274  Exception::throwThis(errors::InvalidReference, "attempting to make a RefVectorHolderBase from a RefProd<C>.\n");
275  return std::auto_ptr<RefVectorHolderBase>();
276  }
277  };
278 
279  template<typename C>
282  };
283 
284  }
285 }
286 
287 #endif
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:74
static std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder()
Definition: RefProd.h:253
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
bool operator!() const
Checks for null.
Definition: RefProd.h:139
RefProd()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefProd.h:58
RefProd(OrphanHandle< C > const &handle)
General purpose constructor from orphan handle.
Definition: RefProd.h:67
T const * product() const
Definition: TestHandle.h:61
bool isNull() const
Checks for null.
Definition: RefProd.h:133
C product_type
Definition: RefProd.h:54
bool hasProductCache() const
Checks if product is in memory.
Definition: RefProd.h:151
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
bool operator==(const CaloTower &t1, const CaloTower &t2)
Definition: CaloTower.h:211
#define CMS_CLASS_VERSION(_version_)
bool isNonnull() const
Definition: RefCore.h:37
product_type const * operator->() const
Member dereference operator.
Definition: RefProd.h:207
~RefProd()
Destructor.
Definition: RefProd.h:108
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:148
RefProd(ProductID const &productID, EDProductGetter const *prodGetter)
Definition: RefProd.h:103
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefProd.h:145
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
static std::auto_ptr< RefVectorHolderBase > makeVectorHolder()
Definition: RefProd.h:269
void const * productPtr() const
Definition: RefCore.h:26
bool isAvailable() const
Definition: RefCore.cc:103
tuple handle
Definition: patZpeak.py:22
void swap(RefProd< C > &)
Definition: RefProd.h:214
bool isTransient() const
Checks if this RefProd is transient (i.e. not persistable).
Definition: RefProd.h:158
static std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder()
Definition: RefProd.h:273
void checkTypeAtCompileTime(C const *ptr)
Definition: RefProd.h:168
bool isAvailable() const
Definition: RefProd.h:155
static std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder()
Definition: RefProd.h:257
RefCore product_
Definition: RefProd.h:170
RefCore const & refCore() const
Definition: RefProd.h:128
edm::RefProd< Container > RefProd
product_type const & operator*() const
Dereference operator.
Definition: RefProd.h:200
T const * product() const
Definition: OrphanHandle.h:61
string const
Definition: compareJSON.py:14
T const * product() const
Definition: Handle.h:74
EDProductGetter const * productGetter() const
Definition: RefCore.h:47
ProductID id() const
Definition: RefCore.h:23
#define private
Definition: FWFileEntry.h:18
RefProd(TestHandle< C > const &handle)
General purpose constructor from test handle.
Definition: RefProd.h:87
bool isTransient() const
Definition: RefCore.h:64
product_type const * product() const
Definition: RefProd.h:124
bool isNonnull() const
Checks for non-null.
Definition: RefProd.h:136
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:142
RefProd(Handle< C > const &handle)
General purpose constructor from handle.
Definition: RefProd.h:61
long double T
RefProd(C const *product)
Constructor for ref to object that is not in an event.
Definition: RefProd.h:77
edm::RefVector< Container > RefVector
def template
Definition: svgfig.py:520
C value_type
Definition: RefProd.h:55