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 ----------------------------------------------------------------------*/
9 
10 /*----------------------------------------------------------------------
11 // This defines the public interface to the class RefProd<T>.
12 //
13 // ProductID productID is the product ID of the collection. (0 is invalid)
14 // RefProd<T> const& ref is another RefProd<T>
15 
16 // Constructors
17  RefProd(); // Default constructor
18  RefProd(RefProd<T> const& ref); // Copy constructor (default, not explicitly specified)
19 
20  RefProd(Handle<T> const& handle);
21  RefProd(ProductID pid, EDProductGetter const* prodGetter);
22 
23 // Destructor
24  virtual ~RefProd() {}
25 
26 // Operators and methods
27  RefProd<T>& operator=(RefProd<T> const&); // assignment (default, not explicitly specified)
28  T const& operator*() const; // dereference
29  T const* operator->() const; // member dereference
30  bool operator==(RefProd<T> const& ref) const; // equality
31  bool operator!=(RefProd<T> const& ref) const; // inequality
32  bool operator<(RefProd<T> const& ref) const; // ordering
33  bool isNonnull() const; // true if an object is referenced
34  bool isNull() const; // equivalent to !isNonnull()
35  bool operator!() const; // equivalent to !isNonnull()
36 ----------------------------------------------------------------------*/
37 
46 
47 namespace edm {
48 
49  template<typename C>
50  class RefProd {
51  public:
52  typedef C product_type;
53  typedef C value_type;
54 
56  RefProd() : product_() {}
57 
59  explicit RefProd(Handle<C> const& handle) :
60  product_(handle.id(), handle.product(), 0, false) {
62  }
63 
65  explicit RefProd(OrphanHandle<C> const& handle) :
66  product_(handle.id(), handle.product(), 0, false) {
68  }
69 
71  // An exception will be thrown if an attempt is made to persistify
72  // any object containing this RefProd. Also, in the future work will
73  // be done to throw an exception if an attempt is made to put any object
74  // containing this RefProd into an event(or run or lumi).
75  RefProd(C const* iProduct) :
76  product_(ProductID(), iProduct, 0, true) {
77  checkTypeAtCompileTime(iProduct);
78  }
79 
81  // An exception will be thrown if an attempt is made to persistify
82  // any object containing this RefProd. Also, in the future work will
83  // be done to throw an exception if an attempt is made to put any object
84  // containing this RefProd into an event(or run or lumi).
85  explicit RefProd(TestHandle<C> const& handle) :
86  product_(handle.id(), handle.product(), 0, true) {
88  }
89 
91  template<typename T, typename F>
92  explicit RefProd(Ref<C, T, F> const& ref);
93 
95  template<typename T, typename F>
96  explicit RefProd(RefVector<C, T, F> const& ref);
97 
98  // Constructor for those users who do not have a product handle,
99  // but have a pointer to a product getter (such as the EventPrincipal).
100  // prodGetter will ususally be a pointer to the event principal.
101  RefProd(ProductID const& productID, EDProductGetter const* prodGetter) :
102  product_(productID, 0, mustBeNonZero(prodGetter, "RefProd", productID), false) {
103  }
104 
106  ~RefProd() {}
107 
109  product_type const& operator*() const;
110 
112  product_type const* operator->() const;
113 
116  product_type const* get() const {
117  return isNull() ? 0 : this->operator->();
118  }
119 
122  product_type const* product() const {
123  return isNull() ? 0 : this->operator->();
124  }
125 
126  RefCore const& refCore() const {
127  return product_;
128  }
129 
131  bool isNull() const {return !isNonnull();}
132 
134  bool isNonnull() const {return product_.isNonnull();}
135 
137  bool operator!() const {return isNull();}
138 
140  ProductID id() const {return product_.id();}
141 
144 
146  bool hasCache() const {return product_.productPtr() != 0;}
147 
149  bool hasProductCache() const {return hasCache();}
150 
153  bool isAvailable() const {return product_.isAvailable();}
154 
156  bool isTransient() const {return product_.isTransient();}
157 
158  void swap(RefProd<C> &);
159 
160  //Needed for ROOT storage
162 
163  private:
164  // Compile time check that the argument is a C* or C const*
165  // or derived from it.
166  void checkTypeAtCompileTime(C const* /*ptr*/) {}
167 
169  };
170 }
171 
174 
175 namespace edm {
176  template<typename C, typename T, typename F>
177  class RefVector;
178 
180  template<typename C>
181  template<typename T, typename F>
182  inline
184  product_(ref.id(), ref.hasProductCache() ? ref.product() : 0, ref.productGetter(), ref.isTransient()) {
185  }
186 
188  template<typename C>
189  template<typename T, typename F>
190  inline
192  product_(ref.id(), ref.hasProductCache() ? ref.product() : 0, ref.productGetter(), ref.isTransient()) {
193  }
194 
196  template<typename C>
197  inline
198  C const& RefProd<C>::operator*() const {
199  return *(edm::template getProduct<C>(product_));
200  }
201 
203  template<typename C>
204  inline
205  C const* RefProd<C>::operator->() const {
206  return edm::template getProduct<C>(product_);
207  }
208 
209 
210  template<typename C>
211  inline
212  void RefProd<C>::swap(RefProd<C> & other) {
213  std::swap(product_, other.product_);
214  }
215 
216  template<typename C>
217  inline
218  bool
219  operator==(RefProd<C> const& lhs, RefProd<C> const& rhs) {
220  return lhs.refCore() == rhs.refCore();
221  }
222 
223  template<typename C>
224  inline
225  bool
226  operator!=(RefProd<C> const& lhs, RefProd<C> const& rhs) {
227  return !(lhs == rhs);
228  }
229 
230  template<typename C>
231  inline
232  bool
233  operator<(RefProd<C> const& lhs, RefProd<C> const& rhs) {
234  return(lhs.refCore() < rhs.refCore());
235  }
236 
237  template<typename C>
238  inline
239  void swap(RefProd<C> const& lhs, RefProd<C> const& rhs) {
240  lhs.swap(rhs);
241  }
242 }
243 
245 
246 namespace edm {
247  namespace reftobase {
248 
249  template<typename T>
251  static std::auto_ptr<BaseVectorHolder<T> > makeVectorHolder() {
252  Exception::throwThis(errors::InvalidReference, "attempting to make a BaseVectorHolder<T> from a RefProd<C>.\n");
253  return std::auto_ptr<BaseVectorHolder<T> >();
254  }
255  static std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() {
256  Exception::throwThis(errors::InvalidReference, "attempting to make a RefVectorHolderBase from a RefProd<C>.\n");
257  return std::auto_ptr<RefVectorHolderBase>();
258  }
259  };
260 
261  template<typename C, typename T>
264  };
265 
267  static std::auto_ptr<RefVectorHolderBase> makeVectorHolder() {
268  Exception::throwThis(errors::InvalidReference, "attempting to make a BaseVectorHolder<T> from a RefProd<C>.\n");
269  return std::auto_ptr<RefVectorHolderBase>();
270  }
271  static std::auto_ptr<RefVectorHolderBase> makeVectorBaseHolder() {
272  Exception::throwThis(errors::InvalidReference, "attempting to make a RefVectorHolderBase from a RefProd<C>.\n");
273  return std::auto_ptr<RefVectorHolderBase>();
274  }
275  };
276 
277  template<typename C>
280  };
281 
282  }
283 }
284 
285 #endif
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
static std::auto_ptr< BaseVectorHolder< T > > makeVectorHolder()
Definition: RefProd.h:251
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
bool operator!() const
Checks for null.
Definition: RefProd.h:137
RefProd()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefProd.h:56
RefProd(OrphanHandle< C > const &handle)
General purpose constructor from orphan handle.
Definition: RefProd.h:65
T const * product() const
Definition: TestHandle.h:60
bool isNull() const
Checks for null.
Definition: RefProd.h:131
C product_type
Definition: RefProd.h:52
bool hasProductCache() const
Checks if product is in memory.
Definition: RefProd.h:149
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_)
void checkTypeAtCompileTime(C const *)
Definition: RefProd.h:166
bool isNonnull() const
Definition: RefCore.h:43
product_type const * operator->() const
Member dereference operator.
Definition: RefProd.h:205
~RefProd()
Destructor.
Definition: RefProd.h:106
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
bool hasCache() const
Checks if product is in memory.
Definition: RefProd.h:146
RefProd(ProductID const &productID, EDProductGetter const *prodGetter)
Definition: RefProd.h:101
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefProd.h:143
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
static std::auto_ptr< RefVectorHolderBase > makeVectorHolder()
Definition: RefProd.h:267
void const * productPtr() const
Definition: RefCore.h:32
bool isAvailable() const
Definition: RefCore.cc:112
tuple handle
Definition: patZpeak.py:22
void swap(RefProd< C > &)
Definition: RefProd.h:212
bool isTransient() const
Checks if this RefProd is transient (i.e. not persistable).
Definition: RefProd.h:156
static std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder()
Definition: RefProd.h:271
bool isAvailable() const
Definition: RefProd.h:153
static std::auto_ptr< RefVectorHolderBase > makeVectorBaseHolder()
Definition: RefProd.h:255
RefCore product_
Definition: RefProd.h:168
RefCore const & refCore() const
Definition: RefProd.h:126
edm::RefProd< Container > RefProd
product_type const & operator*() const
Dereference operator.
Definition: RefProd.h:198
T const * product() const
Definition: OrphanHandle.h:57
string const
Definition: compareJSON.py:14
T const * product() const
Definition: Handle.h:74
EDProductGetter const * productGetter() const
Definition: RefCore.h:53
ProductID id() const
Definition: RefCore.h:29
#define private
Definition: FWFileEntry.h:18
RefProd(TestHandle< C > const &handle)
General purpose constructor from test handle.
Definition: RefProd.h:85
RefProd(C const *iProduct)
Constructor for ref to object that is not in an event.
Definition: RefProd.h:75
bool isTransient() const
Definition: RefCore.h:69
product_type const * product() const
Definition: RefProd.h:122
bool isNonnull() const
Checks for non-null.
Definition: RefProd.h:134
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:140
RefProd(Handle< C > const &handle)
General purpose constructor from handle.
Definition: RefProd.h:59
long double T
edm::RefVector< Container > RefVector
def template
Definition: svgfig.py:520
C value_type
Definition: RefProd.h:53