CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefItemGet.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefItemGet_h
2 #define DataFormats_Common_RefItemGet_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefItemGet: Free function to get pointer to a referenced item.
7 
8 
9 ----------------------------------------------------------------------*/
12 
13 namespace edm {
14 
15  namespace refitem {
16 
17  template <typename C, typename T, typename F, typename K> inline
18  void findRefItem(RefCore const& refCore, C const* container, K const& key) {
19  F finder;
20  T const* item = finder(*container, key);
21  refCore.setProductPtr(item);
22  }
23 
24  template< typename C, typename T, typename F, typename KEY>
25  struct GetRefPtrImpl {
26  static T const* getRefPtr_(RefCore const& product, KEY const& key) {
27  T const* item = static_cast<T const*>(product.productPtr());
28  if(item != nullptr) {
29  return item;
30  }
31  auto prodGetter = product.productGetter();
32  if(nullptr == prodGetter) {
33  item = static_cast<T const*>(product.productPtr());
34  if(item != nullptr) {
35  //Another thread updated the value since we checked
36  return item;
37  }
38  }
39  C const* prod = edm::template getProductWithCoreFromRef<C>(product, prodGetter);
40  /*
41  typename C::const_iterator it = prod->begin();
42  std::advance(it, item.key());
43  T const* p = it.operator->();
44  */
45  F func;
46  item = func(*prod, key);
47  product.setProductPtr(item);
48  return item;
49  }
50  };
51 
52  template< typename C, typename T, typename F>
53  struct GetRefPtrImpl<C, T, F, unsigned int> {
54  static T const* getRefPtr_(RefCore const& product, unsigned int key) {
55  T const* item = static_cast<T const*>(product.productPtr());
56  if(item != nullptr) {
57  return item;
58  }
59  auto getter = product.productGetter();
60  if(getter == nullptr) {
61  auto prod = product.productPtr();
62  if(prod != nullptr) {
63  //another thread updated the value since we last checked.
64  return static_cast<T const*>(prod);
65  }
66  }
67  C const* prod = edm::template tryToGetProductWithCoreFromRef<C>(product, getter);
68  if(prod != nullptr) {
69  F func;
70  item = func(*prod, key);
71  product.setProductPtr(item);
72  return item;
73  }
74  unsigned int thinnedKey = key;
75  prod = edm::template getThinnedProduct<C>(product, thinnedKey, getter);
76  F func;
77  item = func(*prod, thinnedKey);
78  product.setProductPtr(item);
79  return item;
80  }
81  };
82  }
83 
84  template <typename C, typename T, typename F, typename KEY>
85  inline
86  T const* getRefPtr(RefCore const& product, KEY const& iKey) {
88  }
89 
90  namespace refitem {
91  template< typename C, typename KEY>
93  static bool isThinnedAvailable_(RefCore const& product, KEY const& key) {
94  return false;
95  }
96  };
97 
98  template< typename C >
99  struct IsThinnedAvailableImpl<C, unsigned int> {
100  static bool isThinnedAvailable_(RefCore const& ref, unsigned int key) {
101  if(ref.productPtr() != nullptr) {
102  return true;
103  }
104  if (ref.isTransient()) {
105  return false;
106  }
107  auto getter = ref.productGetter();
108  if(getter != nullptr) {
109  return ref.isThinnedAvailable(key,getter);
110  }
111  //another thread may have updated the cache
112  return nullptr != ref.productPtr();
113  }
114  };
115  }
116 
117  template <typename C, typename KEY>
118  inline
119  bool isThinnedAvailable(RefCore const& product, KEY const& iKey) {
121  }
122 }
123 
124 #endif
bool isThinnedAvailable(RefCore const &product, KEY const &iKey)
Definition: RefItemGet.h:119
T const * getRefPtr(RefCore const &product, KEY const &iKey)
Definition: RefItemGet.h:86
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:51
bool isThinnedAvailable(unsigned int thinnedKey, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:129
static bool isThinnedAvailable_(RefCore const &product, KEY const &key)
Definition: RefItemGet.h:93
static T const * getRefPtr_(RefCore const &product, unsigned int key)
Definition: RefItemGet.h:54
void findRefItem(RefCore const &refCore, C const *container, K const &key)
Definition: RefItemGet.h:18
void const * productPtr() const
Definition: RefCore.h:45
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
static T const * getRefPtr_(RefCore const &product, KEY const &key)
Definition: RefItemGet.h:26
string const
Definition: compareJSON.py:14
EDProductGetter const * productGetter() const
Definition: RefCore.h:77
bool isTransient() const
Definition: RefCore.h:99
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
static bool isThinnedAvailable_(RefCore const &ref, unsigned int key)
Definition: RefItemGet.h:100
long double T
def template
Definition: svgfig.py:520