ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
EventContainers
EventContainers
IdentifiableValueCache.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef EVENTCONTAINERS_IDENTIFIABLEVALUECACHE_H
6
#define EVENTCONTAINERS_IDENTIFIABLEVALUECACHE_H
7
8
#include <atomic>
9
#include <vector>
10
#include <cstdlib>
11
17
18
template
<
class
T>
19
class
IdentifiableValueCache
{
20
21
public
:
22
23
typedef
std::true_type
thread_safe
;
24
26
const
T&
emptyValue
()
const
{
27
return
m_emptyValue
;
28
}
29
30
//Prevent accidental copying
31
IdentifiableValueCache
(
const
IdentifiableValueCache
&) =
delete
;
32
34
IdentifiableValueCache
(
size_t
maxSize
, T emptyValuein)
35
:
m_vec
(
maxSize
),
m_emptyValue
(
std
::move(emptyValuein))
36
{
37
for
(
auto
&
x
:
m_vec
)
x
.store(
emptyValue
(), std::memory_order_relaxed);
38
}
39
41
void
forceReset
();
42
44
size_t
maxSize
()
const
{
return
m_vec
.size(); }
45
46
~IdentifiableValueCache
() =
default
;
47
49
T
retrieve
(
size_t
i){
return
m_vec
.at(i).load(); }
50
52
T
retrieve
(
size_t
i)
const
{
return
i < maxSize() ? static_cast<T>(
m_vec
[i]) :
emptyValue
() ; }
53
55
bool
present
(
size_t
i){
return
m_vec
.at(i).load() !=
emptyValue
(); }
56
58
bool
present
(
size_t
i)
const
{
return
i <
maxSize
() and
m_vec
[i] !=
emptyValue
() ? true :
false
; }
59
61
bool
setOrDrop
(
size_t
i,
const
T &value);
62
64
std::vector<std::pair<size_t, T>>
getAll
()
const
;
65
66
const
std::vector<std::atomic<T>>&
rawReadAccess
()
const
{
return
m_vec
; }
67
68
private
:
69
std::vector<std::atomic<T>>
m_vec
;
70
const
T
m_emptyValue
;
71
};
72
73
template
<
class
T>
74
std::vector<std::pair<size_t, T>>
75
IdentifiableValueCache<T>::getAll
()
const
{
76
std::vector<std::pair<size_t, T>> list;
77
for
(
size_t
i =0; i<
m_vec
.size(); i++){
78
T item =
m_vec
[i].load(std::memory_order_relaxed);
79
if
(item!=
m_emptyValue
) list.emplace_back(i, std::move(item));
80
}
81
return
list;
82
}
83
84
template
<
class
T>
85
void
IdentifiableValueCache<T>::forceReset
(){
86
for
(
auto
&
x
:
m_vec
)
x
.store(
emptyValue
(), std::memory_order_relaxed);
87
}
88
89
template
<
class
T>
90
bool
IdentifiableValueCache<T>::setOrDrop
(
size_t
i,
const
T &value){
91
T val =
emptyValue
();
92
return
m_vec
.at(i).compare_exchange_strong(val, value);
93
}
94
95
#endif
x
#define x
IdentifiableValueCache::thread_safe
std::true_type thread_safe
Definition
IdentifiableValueCache.h:23
IdentifiableValueCache::IdentifiableValueCache
IdentifiableValueCache(const IdentifiableValueCache &)=delete
IdentifiableValueCache::~IdentifiableValueCache
~IdentifiableValueCache()=default
IdentifiableValueCache< IDCInDetBSErrContainer::ErrorCode >::maxSize
size_t maxSize() const
Definition
IdentifiableValueCache.h:44
IdentifiableValueCache::rawReadAccess
const std::vector< std::atomic< T > > & rawReadAccess() const
Definition
IdentifiableValueCache.h:66
IdentifiableValueCache::retrieve
T retrieve(size_t i)
Retrieve the Value stored in that hash.
Definition
IdentifiableValueCache.h:49
IdentifiableValueCache::emptyValue
const T & emptyValue() const
Return the empty value that is interpreted as an empty entry.
Definition
IdentifiableValueCache.h:26
IdentifiableValueCache::IdentifiableValueCache
IdentifiableValueCache(size_t maxSize, T emptyValuein)
Pass the maximum hash to size the cache and the defaultValue which will be interpreted as an empty va...
Definition
IdentifiableValueCache.h:34
IdentifiableValueCache< IDCInDetBSErrContainer::ErrorCode >::m_vec
std::vector< std::atomic< IDCInDetBSErrContainer::ErrorCode > > m_vec
Definition
IdentifiableValueCache.h:69
IdentifiableValueCache::retrieve
T retrieve(size_t i) const
As above, but no cache extension.
Definition
IdentifiableValueCache.h:52
IdentifiableValueCache::present
bool present(size_t i) const
As above, but no cache extension.
Definition
IdentifiableValueCache.h:58
IdentifiableValueCache::getAll
std::vector< std::pair< size_t, T > > getAll() const
Make a vector of hashes and values, convenient for iteration and other uses.
Definition
IdentifiableValueCache.h:75
IdentifiableValueCache< IDCInDetBSErrContainer::ErrorCode >::m_emptyValue
const IDCInDetBSErrContainer::ErrorCode m_emptyValue
Definition
IdentifiableValueCache.h:70
IdentifiableValueCache::present
bool present(size_t i)
Returns true if the value is set to anything but the emptyValue.
Definition
IdentifiableValueCache.h:55
IdentifiableValueCache::forceReset
void forceReset()
Forceable empty the container, DO NOT USE THIS IN MT ENVIRONMENT.
Definition
IdentifiableValueCache.h:85
IdentifiableValueCache::setOrDrop
bool setOrDrop(size_t i, const T &value)
Set the given hash to the value.
Definition
IdentifiableValueCache.h:90
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0