CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefCore.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefCore_h
2 #define DataFormats_Common_RefCore_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefCore: The component of edm::Ref containing the product ID and product getter.
7 
8 ----------------------------------------------------------------------*/
13 
14 #include <algorithm>
15 #include <typeinfo>
16 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
17 #include <atomic>
18 #endif
19 
20 namespace edm {
21  class RefCoreWithIndex;
22 
23  class RefCore {
24  //RefCoreWithIndex is a specialization of RefCore done for performance
25  // Since we need to freely convert one to the other the friendship is used
26  friend class RefCoreWithIndex;
27  public:
29 
30  RefCore(ProductID const& theId, void const* prodPtr, EDProductGetter const* prodGetter, bool transient);
31 
32  RefCore( RefCore const&);
33 
34  RefCore& operator=(RefCore const&);
35 
36 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
38  productIndex_(iOther.productIndex_) {}
39  RefCore& operator=(RefCore&&) = default;
40 #endif
41 
42  ProductID id() const {ID_IMPL;}
43 
45  void const* productPtr() const {PRODUCTPTR_IMPL;}
46 
51  void setProductPtr(void const* prodPtr) const {
52  setCacheIsProductPtr(prodPtr);
53  }
54 
59  bool tryToSetProductPtrForFirstTime(void const* prodPtr) const {
61  }
62 
63  // Checks for null
64  bool isNull() const {return !isNonnull(); }
65 
66  // Checks for non-null
67  bool isNonnull() const {ISNONNULL_IMPL;}
68 
69  // Checks for null
70  bool operator!() const {return isNull();}
71 
72  // Checks if collection is in memory or available
73  // in the Event. No type checking is done.
74 
75  bool isAvailable() const;
76 
77  EDProductGetter const* productGetter() const {
79  }
80 
81  void setProductGetter(EDProductGetter const* prodGetter) const;
82 
83  WrapperBase const* getProductPtr(std::type_info const& type, EDProductGetter const* prodGetter) const;
84 
85  WrapperBase const* tryToGetProductPtr(std::type_info const& type, EDProductGetter const* prodGetter) const;
86 
87  WrapperBase const* getThinnedProductPtr(std::type_info const& type, unsigned int& thinnedKey, EDProductGetter const* prodGetter) const;
88 
89  bool isThinnedAvailable(unsigned int thinnedKey, EDProductGetter const* prodGetter) const;
90 
91  void productNotFoundException(std::type_info const& type) const;
92 
93  void wrongTypeException(std::type_info const& expectedType, std::type_info const& actualType) const;
94 
95  void nullPointerForTransientException(std::type_info const& type) const;
96 
97  void swap(RefCore &);
98 
99  bool isTransient() const {ISTRANSIENT_IMPL;}
100 
101  int isTransientInt() const {return isTransient() ? 1 : 0;}
102 
103  void pushBackItem(RefCore const& productToBeInserted, bool checkPointer);
104 
105  void pushBackRefItem(RefCore const& productToBeInserted);
106 
107  private:
108  RefCore(void const* iCache, ProcessIndex iProcessIndex, ProductIndex iProductIndex):
109  cachePtr_(iCache), processIndex_(iProcessIndex), productIndex_(iProductIndex) {}
110  void setId(ProductID const& iId);
112  void setCacheIsProductPtr(const void* iItem) const {SETCACHEISPRODUCTPTR_IMPL(iItem);}
114 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
115  bool cachePtrIsInvalid() const { return 0 == (reinterpret_cast<std::uintptr_t>(cachePtr_.load()) & refcoreimpl::kCacheIsProductPtrMask); }
116 #endif
117 
118  //The low bit of the address is used to determine if the cachePtr_
119  // is storing the productPtr or the EDProductGetter. The bit is set if
120  // the address refers to the EDProductGetter.
121 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
122  mutable std::atomic<void const*> cachePtr_; // transient
123 #else
124  mutable void const* cachePtr_; // transient
125 #endif
126  //The following is what is stored in a ProductID
127  // the high bit of processIndex is used to store info on
128  // if this is transient.
129  //If the type or order of the member data is changes you MUST also update
130  // the custom streamer in RefCoreStreamer.cc and RefCoreWithIndex
133 
134  };
135 
136  inline
137  bool
138  operator==(RefCore const& lhs, RefCore const& rhs) {
139  return lhs.isTransient() == rhs.isTransient() && (lhs.isTransient() ? lhs.productPtr() == rhs.productPtr() : lhs.id() == rhs.id());
140  }
141 
142  inline
143  bool
144  operator!=(RefCore const& lhs, RefCore const& rhs) {
145  return !(lhs == rhs);
146  }
147 
148  inline
149  bool
150  operator<(RefCore const& lhs, RefCore const& rhs) {
151  return lhs.isTransient() ? (rhs.isTransient() ? lhs.productPtr() < rhs.productPtr() : false) : (rhs.isTransient() ? true : lhs.id() < rhs.id());
152  }
153 
154 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
155  inline
156  void
160  other.cachePtr_.store(cachePtr_.exchange(other.cachePtr_.load()));
161  }
162 
163  inline void swap(edm::RefCore & lhs, edm::RefCore & rhs) {
164  lhs.swap(rhs);
165  }
166 #endif
167 }
168 
169 #endif
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:193
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:90
type
Definition: HCALResponse.h:21
RefCore(void const *iCache, ProcessIndex iProcessIndex, ProductIndex iProductIndex)
Definition: RefCore.h:108
void swap(RefCore &)
Definition: RefCore.h:157
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:51
int isTransientInt() const
Definition: RefCore.h:101
#define ID_IMPL
Definition: classes.h:93
bool isThinnedAvailable(unsigned int thinnedKey, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:129
bool tryToSetProductPtrForFirstTime(void const *prodPtr) const
Definition: RefCore.h:59
WrapperBase const * getProductPtr(std::type_info const &type, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:60
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
bool isNonnull() const
Definition: RefCore.h:67
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
bool tryToSetCacheItemForFirstTime(std::atomic< void const * > &iCache, void const *iNewValue)
#define PRODUCTPTR_IMPL
Definition: classes.h:95
WrapperBase const * tryToGetProductPtr(std::type_info const &type, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:96
ProductIndex productIndex_
Definition: RefCore.h:132
bool cachePtrIsInvalid() const
Definition: RefCore.h:115
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
WrapperBase const * getThinnedProductPtr(std::type_info const &type, unsigned int &thinnedKey, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:114
#define SETCACHEISPRODUCTPTR_IMPL(_item_)
Definition: classes.h:105
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
def load
Definition: svgfig.py:546
void const * productPtr() const
Definition: RefCore.h:45
bool isAvailable() const
Definition: RefCore.cc:168
void productNotFoundException(std::type_info const &type) const
Definition: RefCore.cc:140
ProcessIndex processIndex_
Definition: RefCore.h:131
bool isNull() const
Definition: RefCore.h:64
const std::uintptr_t kCacheIsProductPtrMask
RefCore(RefCore &&iOther)
Definition: RefCore.h:37
unsigned short ProcessIndex
Definition: ProductID.h:25
#define ISNONNULL_IMPL
Definition: classes.h:97
RefCore & operator=(RefCore const &)
Definition: RefCore.cc:52
#define ISTRANSIENT_IMPL
Definition: classes.h:101
void setId(ProductID const &iId)
Definition: RefCore.cc:184
void setCacheIsProductPtr(const void *iItem) const
Definition: RefCore.h:112
EDProductGetter const * productGetter() const
Definition: RefCore.h:77
ProductID id() const
Definition: RefCore.h:42
bool operator!() const
Definition: RefCore.h:70
bool isTransient() const
Definition: RefCore.h:99
std::atomic< void const * > cachePtr_
Definition: RefCore.h:122
#define PRODUCTGETTER_IMPL
Definition: classes.h:99
unsigned short ProductIndex
Definition: ProductID.h:26
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:179
void pushBackRefItem(RefCore const &productToBeInserted)
Definition: RefCore.cc:242
void setCacheIsProductGetter(EDProductGetter const *iGetter) const
Definition: RefCore.h:113
#define SETCACHEISPRODUCTGETTER_IMPL(_getter_)
Definition: classes.h:107
void setTransient()
Definition: RefCore.h:111
void wrongTypeException(std::type_info const &expectedType, std::type_info const &actualType) const
Definition: RefCore.cc:150
void nullPointerForTransientException(std::type_info const &type) const
Definition: RefCore.cc:160
#define SETTRANSIENT_IMPL
Definition: classes.h:103