CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ----------------------------------------------------------------------*/
17 
18 #include <algorithm>
19 #include <typeinfo>
20 
21 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
22 #include <atomic>
23 #endif
24 
25 namespace edm {
27  public:
29 
30  RefCoreWithIndex(ProductID const& theId, void const* prodPtr, EDProductGetter const* prodGetter, bool transient, unsigned int elementIndex);
31 
32  RefCoreWithIndex(RefCore const& iCore, unsigned int);
33 
35 
37 
38 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
42 #endif
43 
44  ProductID id() const {ID_IMPL;}
45 
47  void const* productPtr() const {PRODUCTPTR_IMPL;}
48 
53  void setProductPtr(void const* prodPtr) const {
54  setCacheIsProductPtr(prodPtr);
55  }
56 
61  bool tryToSetProductPtrForFirstTime(void const* prodPtr) const {
63  }
64 
65  unsigned int index() const { return elementIndex_;}
66 
67  // Checks for null
68  bool isNull() const {return !isNonnull(); }
69 
70  // Checks for non-null
71  bool isNonnull() const {ISNONNULL_IMPL;}
72 
73  // Checks for null
74  bool operator!() const {return isNull();}
75 
76  // Checks if collection is in memory or available
77  // in the Event. No type checking is done.
78 
79  bool isAvailable() const {
80  return toRefCore().isAvailable();
81  }
82 
83  //Convert to an equivalent RefCore. Needed for Ref specialization.
84  RefCore const& toRefCore() const {
85  return *reinterpret_cast<const RefCore*>(this);
86  }
87 
88  EDProductGetter const* productGetter() const {
90  }
91 
92  void setProductGetter(EDProductGetter const* prodGetter) const {
93  toRefCore().setProductGetter(prodGetter);
94  }
95 
96  WrapperBase const* getProductPtr(std::type_info const& type, EDProductGetter const* prodGetter) const {
97  return toRefCore().getProductPtr(type,prodGetter);
98  }
99 
100  void productNotFoundException(std::type_info const& type) const {
102  }
103 
104  void wrongTypeException(std::type_info const& expectedType, std::type_info const& actualType) const {
105  toRefCore().wrongTypeException(expectedType,actualType);
106  }
107 
108  void nullPointerForTransientException(std::type_info const& type) const {
110  }
111 
112  void swap(RefCoreWithIndex &);
113 
115 
116  int isTransientInt() const {return isTransient() ? 1 : 0;}
117 
118  void pushBackItem(RefCoreWithIndex const& productToBeInserted, bool checkPointer) {
119  toUnConstRefCore().pushBackItem(productToBeInserted.toRefCore(),checkPointer);
120  }
121 
122  private:
124  return *reinterpret_cast<RefCore*>(this);
125  }
126 
127  void setId(ProductID const& iId) {
128  toUnConstRefCore().setId(iId);
129  }
131  void setCacheIsProductPtr(void const* iItem) const {SETCACHEISPRODUCTPTR_IMPL(iItem);}
133 
134  //NOTE: the order MUST remain the same as a RefCore
135  // since we play tricks to allow a pointer to a RefCoreWithIndex
136  // to be the same as a pointer to a RefCore
137 
138  //The low bit of the address is used to determine if the cachePtr_
139  // is storing the productPtr or the EDProductGetter. The bit is set if
140  // the address refers to the EDProductGetter.
141 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
142  mutable std::atomic<void const*> cachePtr_; // transient
143 #else
144  mutable void const* cachePtr_; // transient
145 #endif
146  //The following is what is stored in a ProductID
147  // the high bit of processIndex is used to store info on
148  // if this is transient.
151  unsigned int elementIndex_;
152 
153  };
154 
155 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
156  inline
157  void
161  other.cachePtr_.store(cachePtr_.exchange(other.cachePtr_.load()));
163  }
164 #endif
165 
167  lhs.swap(rhs);
168  }
169 }
170 
171 #endif
void pushBackItem(RefCore const &productToBeInserted, bool checkPointer)
Definition: RefCore.cc:193
type
Definition: HCALResponse.h:21
void setCacheIsProductPtr(void const *iItem) const
std::atomic< void const * > cachePtr_
#define ID_IMPL
Definition: classes.h:93
WrapperBase const * getProductPtr(std::type_info const &type, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:60
void nullPointerForTransientException(std::type_info const &type) const
unsigned int index() const
#define nullptr
void setProductGetter(EDProductGetter const *prodGetter) const
ProductID id() const
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
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_)
Definition: classes.h:105
RefCoreWithIndex & operator=(RefCoreWithIndex const &)
def load
Definition: svgfig.py:546
bool isAvailable() const
Definition: RefCore.cc:168
RefCoreWithIndex(RefCoreWithIndex &&iOther)
void productNotFoundException(std::type_info const &type) const
Definition: RefCore.cc:140
void wrongTypeException(std::type_info const &expectedType, std::type_info const &actualType) const
void productNotFoundException(std::type_info const &type) const
unsigned short ProcessIndex
Definition: ProductID.h:25
#define ISNONNULL_IMPL
Definition: classes.h:97
#define ISTRANSIENT_IMPL
Definition: classes.h:101
void setId(ProductID const &iId)
Definition: RefCore.cc:184
#define PRODUCTGETTER_IMPL
Definition: classes.h:99
void setProductPtr(void const *prodPtr) const
unsigned short ProductIndex
Definition: ProductID.h:26
void setProductGetter(EDProductGetter const *prodGetter) const
Definition: RefCore.cc:179
#define SETCACHEISPRODUCTGETTER_IMPL(_getter_)
Definition: classes.h:107
bool tryToSetProductPtrForFirstTime(void const *prodPtr) const
void wrongTypeException(std::type_info const &expectedType, std::type_info const &actualType) const
Definition: RefCore.cc:150
void setId(ProductID const &iId)
void const * productPtr() const
void nullPointerForTransientException(std::type_info const &type) const
Definition: RefCore.cc:160
#define SETTRANSIENT_IMPL
Definition: classes.h:103