CMS 3D CMS Logo

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 #include <limits>
25 #include <cstdint>
26 #include <atomic>
27 
28 // user include files
29 
30 // forward declarations
31 namespace edm {
32  class EDProductGetter;
33 
34  namespace refcoreimpl {
35  const unsigned short kTransientBit = 0x8000;
36  const unsigned short kProcessIndexMask = 0x3FFF;
37  const std::uintptr_t kCacheIsProductPtrBit = 0x1;
39 
40  inline bool cacheIsProductPtr( void const* iPtr) {
41  return 0 == (reinterpret_cast<std::uintptr_t>(iPtr) & refcoreimpl::kCacheIsProductPtrBit);
42  }
43 
44  inline void setCacheIsProductGetter( std::atomic<void const*> & ptr, EDProductGetter const* iGetter) {
45  std::uintptr_t tmp = reinterpret_cast<std::uintptr_t>(iGetter);
47  ptr.store(reinterpret_cast<void const*>(tmp));
48  }
49 
50  //Used by ROOT 5 I/O rule
51  inline void setCacheIsProductGetter(void const*& ptr, EDProductGetter const* iGetter) {
52  std::uintptr_t tmp = reinterpret_cast<std::uintptr_t>(iGetter);
54  ptr = reinterpret_cast<void const*>(tmp);
55  }
56 
57 
58  inline void setCacheIsItem(std::atomic<void const*>& iCache, void const* iNewValue) {
59  iCache = iNewValue;
60  }
61 
62  inline bool tryToSetCacheItemForFirstTime(std::atomic<void const*>&iCache, void const* iNewValue) {
63  auto cache = iCache.load();
64  if(not cacheIsProductPtr(cache)) {
65  return iCache.compare_exchange_strong(cache, iNewValue);
66  }
67  return false;
68  }
69 
70  inline void const* productPtr(std::atomic<void const*> const& iCache) {
71  auto tmp = iCache.load();
72  return refcoreimpl::cacheIsProductPtr(tmp)?tmp:static_cast<void const*>(nullptr);
73  }
74 
75  inline EDProductGetter const* productGetter(std::atomic<void const*> const& iCache) {
76  auto tmp = iCache.load();
77  return (!refcoreimpl::cacheIsProductPtr(tmp))? reinterpret_cast<EDProductGetter const*>(reinterpret_cast<std::uintptr_t>(tmp)&refcoreimpl::kCacheIsProductPtrMask):static_cast<EDProductGetter const*>(nullptr);
78  }
79 
80  }
81 }
82 
83 #define ID_IMPL return ProductID(processIndex_ & refcoreimpl::kProcessIndexMask,productIndex_)
84 
85 #define PRODUCTPTR_IMPL return refcoreimpl::productPtr(cachePtr_)
86 
87 #define ISNONNULL_IMPL return isTransient() ? productPtr() != nullptr : id().isValid()
88 
89 #define PRODUCTGETTER_IMPL return refcoreimpl::productGetter(cachePtr_)
90 
91 #define ISTRANSIENT_IMPL return 0!=(processIndex_ & refcoreimpl::kTransientBit)
92 
93 #define SETTRANSIENT_IMPL processIndex_ |=refcoreimpl::kTransientBit
94 
95 #define SETCACHEISPRODUCTPTR_IMPL(_item_) refcoreimpl::setCacheIsItem(cachePtr_,_item_)
96 
97 #define SETCACHEISPRODUCTGETTER_IMPL(_getter_) refcoreimpl::setCacheIsProductGetter(cachePtr_, _getter_)
98 
99 #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)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const std::uintptr_t kCacheIsProductPtrBit
HLT enums.
def cache(function)
Definition: utilities.py:3
const unsigned short kTransientBit