CMS 3D CMS Logo

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>
18  inline 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  } // namespace refitem
83 
84  template <typename C, typename T, typename F, typename KEY>
85  inline T const* getRefPtr(RefCore const& product, KEY const& iKey) {
87  }
88 
89  namespace refitem {
90  template <typename C, typename KEY>
92  static bool isThinnedAvailable_(RefCore const& product, KEY const& key) { return false; }
93  };
94 
95  template <typename C>
96  struct IsThinnedAvailableImpl<C, unsigned int> {
97  static bool isThinnedAvailable_(RefCore const& ref, unsigned int key) {
98  if (ref.productPtr() != nullptr) {
99  return true;
100  }
101  if (ref.isTransient()) {
102  return false;
103  }
104  auto getter = ref.productGetter();
105  if (getter != nullptr) {
106  return ref.isThinnedAvailable(key, getter);
107  }
108  //another thread may have updated the cache
109  return nullptr != ref.productPtr();
110  }
111  };
112  } // namespace refitem
113 
114  template <typename C, typename KEY>
115  inline bool isThinnedAvailable(RefCore const& product, KEY const& iKey) {
117  }
118 } // namespace edm
119 
120 #endif
edm::RefCore
Definition: RefCore.h:21
edm::refitem::IsThinnedAvailableImpl::isThinnedAvailable_
static bool isThinnedAvailable_(RefCore const &product, KEY const &key)
Definition: RefItemGet.h:92
edm::RefCore::setProductPtr
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:57
edm::getRefPtr
T const * getRefPtr(RefCore const &product, KEY const &iKey)
Definition: RefItemGet.h:85
edm::refitem::IsThinnedAvailableImpl
Definition: RefItemGet.h:91
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::refitem::GetRefPtrImpl
Definition: RefItemGet.h:25
edm::refitem::IsThinnedAvailableImpl< C, unsigned int >::isThinnedAvailable_
static bool isThinnedAvailable_(RefCore const &ref, unsigned int key)
Definition: RefItemGet.h:97
edm::refitem::GetRefPtrImpl< C, T, F, unsigned int >::getRefPtr_
static T const * getRefPtr_(RefCore const &product, unsigned int key)
Definition: RefItemGet.h:54
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::RefCore::productGetter
EDProductGetter const * productGetter() const
Definition: RefCore.h:81
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
edm::RefCore::isTransient
bool isTransient() const
Definition: RefCore.h:103
edm::refitem::GetRefPtrImpl::getRefPtr_
static T const * getRefPtr_(RefCore const &product, KEY const &key)
Definition: RefItemGet.h:26
createfilelist.int
int
Definition: createfilelist.py:10
edm::RefCore::isThinnedAvailable
bool isThinnedAvailable(unsigned int thinnedKey, EDProductGetter const *prodGetter) const
Definition: RefCore.cc:114
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
edm::RefCore::productPtr
void const * productPtr() const
Definition: RefCore.h:51
HLT_2018_cff.finder
finder
Definition: HLT_2018_cff.py:50398
edm::refitem::findRefItem
void findRefItem(RefCore const &refCore, C const *container, K const &key)
Definition: RefItemGet.h:18
gen::C
C
Definition: PomwigHadronizer.cc:76
T
long double T
Definition: Basic3DVectorLD.h:48
RefCore.h
RefCoreGet.h
crabWrapper.key
key
Definition: crabWrapper.py:19
edm::isThinnedAvailable
bool isThinnedAvailable(RefCore const &product, KEY const &iKey)
Definition: RefItemGet.h:115