CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
refcore_implementation.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_refcore_implementation_h
2 #define DataFormats_Common_refcore_implementation_h
3 // -*- C++ -*-
4 //
5 // Package: Common
6 // Class : refcore_implementation
7 //
18 //
19 // Original Author: Chris Jones
20 // Created: Thu Nov 3 09:16:30 CDT 2011
21 //
22 
23 // system include files
24 #ifndef __GCCXML__
25 #include <limits>
26 #include <cstdint>
27 #include <atomic>
28 #endif
29 
30 // user include files
31 
32 // forward declarations
33 namespace edm {
34  namespace refcoreimpl {
35  const unsigned short kTransientBit = 0x8000;
36  const unsigned short kProcessIndexMask = 0x3FFF;
37 #ifndef __GCCXML__
38  const std::uintptr_t kCacheIsProductPtrBit = 0x1;
40 
41  inline bool cacheIsProductPtr( void const* iPtr) {
42  return 0 == (reinterpret_cast<std::uintptr_t>(iPtr) & refcoreimpl::kCacheIsProductPtrBit);
43  }
44 
45  inline void setCacheIsProductGetter( std::atomic<void const*> & ptr, EDProductGetter const* iGetter) {
46  std::uintptr_t tmp = reinterpret_cast<std::uintptr_t>(iGetter);
48  ptr.store(reinterpret_cast<void const*>(tmp));
49  }
50 
51  //Used by ROOT 5 I/O rule
52  inline void setCacheIsProductGetter(void const*& ptr, EDProductGetter const* iGetter) {
53  std::uintptr_t tmp = reinterpret_cast<std::uintptr_t>(iGetter);
55  ptr = reinterpret_cast<void const*>(tmp);
56  }
57 
58 
59  inline void setCacheIsItem(std::atomic<void const*>& iCache, void const* iNewValue) {
60  iCache = iNewValue;
61  }
62 
63  inline bool tryToSetCacheItemForFirstTime(std::atomic<void const*>&iCache, void const* iNewValue) {
64  auto cache = iCache.load();
65  if(not cacheIsProductPtr(cache)) {
66  return iCache.compare_exchange_strong(cache, iNewValue);
67  }
68  return false;
69  }
70 
71  inline void const* productPtr(std::atomic<void const*> const& iCache) {
72  auto tmp = iCache.load();
73  return refcoreimpl::cacheIsProductPtr(tmp)?tmp:static_cast<void const*>(nullptr);
74  }
75 
76  inline EDProductGetter const* productGetter(std::atomic<void const*> const& iCache) {
77  auto tmp = iCache.load();
78  return (!refcoreimpl::cacheIsProductPtr(tmp))? reinterpret_cast<EDProductGetter const*>(reinterpret_cast<std::uintptr_t>(tmp)&refcoreimpl::kCacheIsProductPtrMask):static_cast<EDProductGetter const*>(nullptr);
79  }
80 #else
81  bool cacheIsProductPtr( void const* iPtr) ;
82  void setCacheIsItem(void const*&, void const*);
83  void setCacheIsProductGetter(void const*&, EDProductGetter const*);
84  void const* productPtr(void const*);
85  EDProductGetter const* productGetter(void const*);
86  bool tryToSetCacheItemForFirstTime(void const*& iCache, void const* iNewValue);
87 #endif
88 
89  }
90 }
91 
92 #define ID_IMPL return ProductID(processIndex_ & refcoreimpl::kProcessIndexMask,productIndex_)
93 
94 #define PRODUCTPTR_IMPL return refcoreimpl::productPtr(cachePtr_)
95 
96 #define ISNONNULL_IMPL return isTransient() ? productPtr() != nullptr : id().isValid()
97 
98 #define PRODUCTGETTER_IMPL return refcoreimpl::productGetter(cachePtr_)
99 
100 #define ISTRANSIENT_IMPL return 0!=(processIndex_ & refcoreimpl::kTransientBit)
101 
102 #define SETTRANSIENT_IMPL processIndex_ |=refcoreimpl::kTransientBit
103 
104 #define SETCACHEISPRODUCTPTR_IMPL(_item_) refcoreimpl::setCacheIsItem(cachePtr_,_item_)
105 
106 #define SETCACHEISPRODUCTGETTER_IMPL(_getter_) refcoreimpl::setCacheIsProductGetter(cachePtr_, _getter_)
107 
108 #endif
void const * productPtr(std::atomic< void const * > const &iCache)
void setCacheIsItem(std::atomic< void const * > &iCache, void const *iNewValue)
EDProductGetter const * productGetter(std::atomic< void const * > const &iCache)
bool tryToSetCacheItemForFirstTime(std::atomic< void const * > &iCache, void const *iNewValue)
void setCacheIsProductGetter(std::atomic< void const * > &ptr, EDProductGetter const *iGetter)
const std::uintptr_t kCacheIsProductPtrMask
const unsigned short kProcessIndexMask
bool cacheIsProductPtr(void const *iPtr)
string const
Definition: compareJSON.py:14
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const std::uintptr_t kCacheIsProductPtrBit
const unsigned short kTransientBit