ATLAS Offline Software
IdentifiableValueContainer.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVENTCONTAINERS_IDENTIFIABLEVALUECONTAINER_H
6 #define EVENTCONTAINERS_IDENTIFIABLEVALUECONTAINER_H
7 
10 #include <set>
11 
13 
14 
15 /*
16 * This class is the view specific container that can link to the IdentifiableValueCache
17 * It allows you to link to an external cache and keep a mask to track the items in your specific view
18 */
19 
20 template<class T>
22 
23 public:
24  typedef T value_type;
26 
27  //Prevent accidental copying
30 
32 
35  IdentifiableValueContainer(size_t maxSize, T defaultValue) : m_own(true)
36  {
37  m_cache = new IdentifiableValueCache<T>(maxSize, std::move(defaultValue));
38  }
39 
43  m_cache(ptr), m_own(false)
44  {}
45 
46 
48  const T& emptyValue() const { return m_cache->emptyValue(); }
49 
50 
52  bool present(size_t i) const;
53 
55  bool setOrDrop(size_t i, const T &value);
56 
58  size_t maxSize() const { return m_cache->maxSize(); }
59 
62  size_t numberSet() const;
63 
65  bool tryAddFromCache(size_t i);
66 
68  T retrieve(size_t i) const;
69 
71  std::vector<std::pair<size_t, T>> getAll() const;
72 
74  const std::vector<std::atomic<T>>& wholeEventReadAccess() const { return m_cache->rawReadAccess(); }
75 
77  const Cache* cache() const { return m_cache; }
78 
79  const std::set<size_t>& getMask() const { return m_mask; }
80 private:
81  std::set<size_t> m_mask;
83  bool m_own;
84 };
85 
86 template< class T >
88 {
89  return m_mask.count(i);
90 }
91 
92 template< class T >
93 std::vector<std::pair<size_t, T>> IdentifiableValueContainer<T>::getAll() const{
94  std::vector<std::pair<size_t, T>> list;
95  list.reserve(m_mask.size());
96  const auto& raw = m_cache->rawReadAccess();
97  for(size_t i : m_mask){
98  list.emplace_back(i, raw[i].load(std::memory_order_relaxed));
99  }
100  return list;
101 }
102 
103 template< class T >
105  Cache* cache ATLAS_THREAD_SAFE = m_cache;
106  auto r = cache->retrieve(i);
107  //Should be quicker to establish empty cache than empty mask with a std::set
108  //So the cache is checked first
109  if(r!= cache->emptyValue() && present(i)) return r;
110  else return cache->emptyValue();
111 }
112 
113 template< class T >
115  if(i >= maxSize()) return false;
116  bool b = m_cache->present(i);
117  if(b) m_mask.emplace(i);
118  return b;
119 }
120 
121 
122 
123 template< class T >
125  return m_mask.size();
126 }
127 
128 template< class T >
130  bool b = m_cache->setOrDrop(i, value);
131  m_mask.emplace(i);
132  return b;
133 }
134 
135 #endif
IdentifiableValueContainer::getAll
std::vector< std::pair< size_t, T > > getAll() const
Make a vector of hashes and values, convenient for iteration and other uses.
Definition: IdentifiableValueContainer.h:93
beamspotman.r
def r
Definition: beamspotman.py:676
IdentifiableValueContainer::numberSet
size_t numberSet() const
Return the number of entries set and accessible according to the mask.
Definition: IdentifiableValueContainer.h:124
IdentifiableValueContainer::IdentifiableValueContainer
IdentifiableValueContainer(const IdentifiableValueContainer< T > &)=delete
IdentifiableValueContainer::maxSize
size_t maxSize() const
Return the maxSize of the collection.
Definition: IdentifiableValueContainer.h:58
IdentifiableValueContainer::wholeEventReadAccess
const std::vector< std::atomic< T > > & wholeEventReadAccess() const
Get read only access to the whole external cache. This could be useful for special situations.
Definition: IdentifiableValueContainer.h:74
athena.value
value
Definition: athena.py:124
IdentifiableValueCache::rawReadAccess
const std::vector< std::atomic< T > > & rawReadAccess() const
Definition: IdentifiableValueCache.h:66
IdentifiableValueCache::emptyValue
const T & emptyValue() const
Return the empty value that is interpreted as an empty entry.
Definition: IdentifiableValueCache.h:26
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
IdentifiableValueContainer::cache
const Cache * cache() const
Obtain const access to the cache.
Definition: IdentifiableValueContainer.h:77
IdentifiableValueCache.h
IdentifiableValueContainer::m_own
bool m_own
Definition: IdentifiableValueContainer.h:83
IdentifiableValueContainer::m_mask
std::set< size_t > m_mask
Definition: IdentifiableValueContainer.h:81
IdentifiableValueContainer::m_cache
Cache * m_cache
Definition: IdentifiableValueContainer.h:82
IdentifiableValueContainerBase
Definition: IdentifiableValueContainer.h:12
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdentifiableValueContainer::operator=
IdentifiableValueContainer & operator=(const IdentifiableValueContainer &)=delete
IdentifiableValueContainer::Cache
IdentifiableValueCache< T > Cache
Definition: IdentifiableValueContainer.h:25
IdentifiableValueContainer
Definition: IdentifiableValueContainer.h:21
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
IdentifiableValueContainer::present
bool present(size_t i) const
Is the value for this has set and also accepted in the mask.
Definition: IdentifiableValueContainer.h:87
IdentifiableValueContainer::setOrDrop
bool setOrDrop(size_t i, const T &value)
Set the value for the given hash.
Definition: IdentifiableValueContainer.h:129
IdentifiableValueContainer::IdentifiableValueContainer
IdentifiableValueContainer(size_t maxSize, T defaultValue)
Self Owning Constructor Pass the maximum hash to size the cache and the defaultValue which will be in...
Definition: IdentifiableValueContainer.h:35
IdentifiableValueContainer::value_type
T value_type
Definition: IdentifiableValueContainer.h:24
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
IdentifiableValueContainer::retrieve
T retrieve(size_t i) const
Retrieve the value of the hash, if accessible according to the mask.
Definition: IdentifiableValueContainer.h:104
IdentifiableValueContainer::emptyValue
const T & emptyValue() const
Return the empty value that is interpreted as an empty entry.
Definition: IdentifiableValueContainer.h:48
IdentifiableValueContainer::getMask
const std::set< size_t > & getMask() const
Definition: IdentifiableValueContainer.h:79
IdentifiableValueContainer::IdentifiableValueContainer
IdentifiableValueContainer(IdentifiableValueCache< T > *ptr)
External Cache Constructor Pass the external cache to set up a view specific view interface.
Definition: IdentifiableValueContainer.h:42
IdentifiableValueContainer::~IdentifiableValueContainer
~IdentifiableValueContainer()
Definition: IdentifiableValueContainer.h:31
IdentifiableValueContainer::tryAddFromCache
bool tryAddFromCache(size_t i)
Returns true if the value is also in the external cache, sets mask to true if it is.
Definition: IdentifiableValueContainer.h:114
IdentifiableValueCache::maxSize
size_t maxSize() const
Return the maxSize of the collection.
Definition: IdentifiableValueCache.h:44
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
python.root_pickle.load
def load(f, use_proxy=1, key=None)
Definition: root_pickle.py:476
checker_macros.h
Define macros for attributes used to control the static checker.
IdentifiableValueCache
This class is to provide an event wide MT container for concurrent storing of basic types,...
Definition: IdentifiableValueCache.h:19
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35