CMS 3D CMS Logo

RefCoreWithIndex.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefCoreWithIndex_h
2 #define DataFormats_Common_RefCoreWithIndex_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefCoreWithIndex: The component of edm::Ref containing the product ID and product getter and the index into the collection.
7  This class is a specialization of RefCore and forwards most of the
8  implementation to RefCore.
9 
10 ----------------------------------------------------------------------*/
15 
16 #include <algorithm>
17 #include <typeinfo>
18 
19 #include <atomic>
20 
21 namespace edm {
22  class EDProductGetter;
23  class WrapperBase;
24 
26  public:
28 
29  RefCoreWithIndex(ProductID const& theId, void const* prodPtr, EDProductGetter const* prodGetter, bool transient, unsigned int elementIndex);
30 
31  RefCoreWithIndex(RefCore const& iCore, unsigned int);
32 
34 
36 
40  cachePtr_.store(iOther.cachePtr_.load(std::memory_order_relaxed), std::memory_order_relaxed);
41  }
42 
44  cachePtr_.store(iOther.cachePtr_.load(std::memory_order_relaxed), std::memory_order_relaxed);
45  processIndex_ = iOther.processIndex_;
46  productIndex_ = iOther.productIndex_;
47  elementIndex_ = iOther.elementIndex_;
48  return *this;
49  }
50 
52 
53  ProductID id() const {ID_IMPL;}
54 
56  void const* productPtr() const {PRODUCTPTR_IMPL;}
57 
62  void setProductPtr(void const* prodPtr) const {
63  setCacheIsProductPtr(prodPtr);
64  }
65 
70  bool tryToSetProductPtrForFirstTime(void const* prodPtr) const {
72  }
73 
74  unsigned int index() const { return elementIndex_;}
75 
76  // Checks for null
77  bool isNull() const {return !isNonnull(); }
78 
79  // Checks for non-null
80  bool isNonnull() const {ISNONNULL_IMPL;}
81 
82  // Checks for null
83  bool operator!() const {return isNull();}
84 
85  // Checks if collection is in memory or available
86  // in the Event. No type checking is done.
87 
88  bool isAvailable() const {
89  return toRefCore().isAvailable();
90  }
91 
92  //Convert to an equivalent RefCore. Needed for Ref specialization.
93  RefCore const& toRefCore() const {
94  return *reinterpret_cast<const RefCore*>(this);
95  }
96 
97  EDProductGetter const* productGetter() const {
99  }
100 
101  void setProductGetter(EDProductGetter const* prodGetter) const {
102  toRefCore().setProductGetter(prodGetter);
103  }
104 
105  WrapperBase const* getProductPtr(std::type_info const& type, EDProductGetter const* prodGetter) const {
106  return toRefCore().getProductPtr(type,prodGetter);
107  }
108 
109  void productNotFoundException(std::type_info const& type) const {
111  }
112 
113  void wrongTypeException(std::type_info const& expectedType, std::type_info const& actualType) const {
114  toRefCore().wrongTypeException(expectedType,actualType);
115  }
116 
117  void nullPointerForTransientException(std::type_info const& type) const {
119  }
120 
121  void swap(RefCoreWithIndex &);
122 
124 
125  int isTransientInt() const {return isTransient() ? 1 : 0;}
126 
127  void pushBackItem(RefCoreWithIndex const& productToBeInserted, bool checkPointer) {
128  toUnConstRefCore().pushBackItem(productToBeInserted.toRefCore(),checkPointer);
129  }
130 
131  private:
133  return *reinterpret_cast<RefCore*>(this);
134  }
135 
136  void setId(ProductID const& iId) {
137  toUnConstRefCore().setId(iId);
138  }
140  void setCacheIsProductPtr(void const* iItem) const {SETCACHEISPRODUCTPTR_IMPL(iItem);}
142 
143  //NOTE: the order MUST remain the same as a RefCore
144  // since we play tricks to allow a pointer to a RefCoreWithIndex
145  // to be the same as a pointer to a RefCore
146 
147  //The low bit of the address is used to determine if the cachePtr_
148  // is storing the productPtr or the EDProductGetter. The bit is set if
149  // the address refers to the EDProductGetter.
150  mutable std::atomic<void const*> cachePtr_; // transient
151  //The following is what is stored in a ProductID
152  // the high bit of processIndex is used to store info on
153  // if this is transient.
156  unsigned int elementIndex_;
157 
158  };
159 
160  inline
161  void
165  other.cachePtr_.store(cachePtr_.exchange(other.cachePtr_.load()));
167  }
168 
170  lhs.swap(rhs);
171  }
172 }
173 
174 #endif
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:194
RefCoreWithIndex & operator=(RefCoreWithIndex &&iOther) noexcept
type
Definition: HCALResponse.h:21
void setCacheIsProductPtr(void const *iItem) const
std::atomic< void const * > cachePtr_
#define ID_IMPL
#define nullptr
WrapperBase const * getProductPtr(std::type_info const &type, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:61
void nullPointerForTransientException(std::type_info const &type) const
unsigned int index() const
void setProductGetter(EDProductGetter const *prodGetter) const
ProductID id() const
bool tryToSetCacheItemForFirstTime(std::atomic< void const * > &iCache, void const *iNewValue)
#define PRODUCTPTR_IMPL
void setCacheIsProductGetter(EDProductGetter const *iGetter) const
EDProductGetter const * productGetter() const
RefCore const & toRefCore() const
WrapperBase const * getProductPtr(std::type_info const &type, EDProductGetter const *prodGetter) const
bool isAvailable() const
void swap(RefCoreWithIndex &)
void pushBackItem(RefCoreWithIndex const &productToBeInserted, bool checkPointer)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
#define SETCACHEISPRODUCTPTR_IMPL(_item_)
RefCoreWithIndex & operator=(RefCoreWithIndex const &)
bool isAvailable() const
Definition: RefCore.cc:169
Definition: value.py:1
void productNotFoundException(std::type_info const &type) const
Definition: RefCore.cc:141
void wrongTypeException(std::type_info const &expectedType, std::type_info const &actualType) const
void productNotFoundException(std::type_info const &type) const
RefCoreWithIndex(RefCoreWithIndex &&iOther) noexcept
unsigned short ProcessIndex
Definition: ProductID.h:25
#define noexcept
#define ISNONNULL_IMPL
#define ISTRANSIENT_IMPL
void setId(ProductID const &iId)
Definition: RefCore.cc:185
HLT enums.
#define PRODUCTGETTER_IMPL
void setProductPtr(void const *prodPtr) const
unsigned short ProductIndex
Definition: ProductID.h:26
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:180
#define SETCACHEISPRODUCTGETTER_IMPL(_getter_)
bool tryToSetProductPtrForFirstTime(void const *prodPtr) const
void wrongTypeException(std::type_info const &expectedType, std::type_info const &actualType) const
Definition: RefCore.cc:151
void setId(ProductID const &iId)
void const * productPtr() const
void nullPointerForTransientException(std::type_info const &type) const
Definition: RefCore.cc:161
#define SETTRANSIENT_IMPL