ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Event
EventContainers
EventContainers
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
8
#include "
EventContainers/IdentifiableValueCache.h
"
9
#include "
CxxUtils/checker_macros.h
"
10
#include <set>
11
12
class
IdentifiableValueContainerBase
{};
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>
21
class
IdentifiableValueContainer
:
IdentifiableValueContainerBase
{
22
23
public
:
24
typedef
T
value_type
;
25
typedef
IdentifiableValueCache<T>
Cache
;
26
27
//Prevent accidental copying
28
IdentifiableValueContainer
(
const
IdentifiableValueContainer<T>
&) =
delete
;
29
IdentifiableValueContainer
&
operator=
(
const
IdentifiableValueContainer
&) =
delete
;
30
31
~IdentifiableValueContainer
() {
if
(
m_own
)
delete
m_cache
; }
32
35
IdentifiableValueContainer
(
size_t
maxSize
, T defaultValue) :
m_own
(true)
36
{
37
m_cache
=
new
IdentifiableValueCache<T>
(
maxSize
, std::move(defaultValue));
38
}
39
42
IdentifiableValueContainer
(
IdentifiableValueCache<T>
*ptr) :
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
;
82
Cache
*
m_cache
;
83
bool
m_own
;
84
};
85
86
template
<
class
T >
87
bool
IdentifiableValueContainer<T>::present
(
size_t
i)
const
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 >
104
T
IdentifiableValueContainer<T>::retrieve
(
size_t
i)
const
{
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 >
114
bool
IdentifiableValueContainer<T>::tryAddFromCache
(
size_t
i){
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 >
124
size_t
IdentifiableValueContainer<T>::numberSet
()
const
{
125
return
m_mask
.size();
126
}
127
128
template
<
class
T >
129
bool
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
IdentifiableValueCache.h
checker_macros.h
Define macros for attributes used to control the static checker.
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition
checker_macros.h:211
IdentifiableValueCache
This class is to provide an event wide MT container for concurrent storing of basic types,...
Definition
IdentifiableValueCache.h:19
IdentifiableValueContainerBase
Definition
IdentifiableValueContainer.h:12
IdentifiableValueContainer::~IdentifiableValueContainer
~IdentifiableValueContainer()
Definition
IdentifiableValueContainer.h:31
IdentifiableValueContainer::maxSize
size_t maxSize() const
Return the maxSize of the collection.
Definition
IdentifiableValueContainer.h:58
IdentifiableValueContainer::m_mask
std::set< size_t > m_mask
Definition
IdentifiableValueContainer.h:81
IdentifiableValueContainer::m_own
bool m_own
Definition
IdentifiableValueContainer.h:83
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::operator=
IdentifiableValueContainer & operator=(const IdentifiableValueContainer &)=delete
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::cache
const Cache * cache() const
Obtain const access to the cache.
Definition
IdentifiableValueContainer.h: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::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::setOrDrop
bool setOrDrop(size_t i, const T &value)
Set the value for the given hash.
Definition
IdentifiableValueContainer.h:129
IdentifiableValueContainer::Cache
IdentifiableValueCache< T > Cache
Definition
IdentifiableValueContainer.h:25
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
IdentifiableValueContainer::value_type
T value_type
Definition
IdentifiableValueContainer.h:24
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::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
IdentifiableValueContainer::IdentifiableValueContainer
IdentifiableValueContainer(const IdentifiableValueContainer< T > &)=delete
IdentifiableValueContainer::numberSet
size_t numberSet() const
Return the number of entries set and accessible according to the mask.
Definition
IdentifiableValueContainer.h:124
IdentifiableValueContainer::m_cache
Cache * m_cache
Definition
IdentifiableValueContainer.h:82
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
r
int r
Definition
globals.cxx:22
Generated on
for ATLAS Offline Software by
1.17.0