ATLAS Offline Software
Loading...
Searching...
No Matches
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
20template<class T>
22
23public:
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
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; }
80private:
81 std::set<size_t> m_mask;
83 bool m_own;
84};
85
86template< class T >
88{
89 return m_mask.count(i);
90}
91
92template< class T >
93std::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
103template< class T >
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
113template< 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
123template< class T >
125 return m_mask.size();
126}
127
128template< class T >
129bool IdentifiableValueContainer<T>::setOrDrop(size_t i, const T &value){
130 bool b = m_cache->setOrDrop(i, value);
131 m_mask.emplace(i);
132 return b;
133}
134
135#endif
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
This class is to provide an event wide MT container for concurrent storing of basic types,...
size_t maxSize() const
Return the maxSize of the collection.
bool present(size_t i) const
Is the value for this has set and also accepted in the mask.
IdentifiableValueContainer & operator=(const IdentifiableValueContainer &)=delete
IdentifiableValueContainer(IdentifiableValueCache< T > *ptr)
External Cache Constructor Pass the external cache to set up a view specific view interface.
const Cache * cache() const
Obtain const access to the cache.
T retrieve(size_t i) const
Retrieve the value of the hash, if accessible according to the mask.
IdentifiableValueContainer(size_t maxSize, T defaultValue)
Self Owning Constructor Pass the maximum hash to size the cache and the defaultValue which will be in...
bool setOrDrop(size_t i, const T &value)
Set the value for the given hash.
IdentifiableValueCache< T > Cache
const std::vector< std::atomic< T > > & wholeEventReadAccess() const
Get read only access to the whole external cache. This could be useful for special situations.
const T & emptyValue() const
Return the empty value that is interpreted as an empty entry.
const std::set< size_t > & getMask() const
bool tryAddFromCache(size_t i)
Returns true if the value is also in the external cache, sets mask to true if it is.
IdentifiableValueContainer(const IdentifiableValueContainer< T > &)=delete
size_t numberSet() const
Return the number of entries set and accessible according to the mask.
std::vector< std::pair< size_t, T > > getAll() const
Make a vector of hashes and values, convenient for iteration and other uses.
int r
Definition globals.cxx:22