ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
AthenaKernel
MetaCont.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef ATHENAKERNEL_METACONT_H
6
#define ATHENAKERNEL_METACONT_H
7
8
#include <sstream>
9
#include <map>
10
#include <vector>
11
#include <typeinfo>
12
#include <mutex>
13
14
#include "
AthenaKernel/CLASS_DEF.h
"
15
#include "
AthenaKernel/BaseInfo.h
"
16
#include "
AthenaKernel/SourceID.h
"
17
#include "
AthenaKernel/DataBucketTraitFwd.h
"
18
#include "
AthenaKernel/MetaContDataBucket.h
"
19
20
namespace
SG
{
21
template
<
class
T>
class
ReadMetaHandle
;
22
}
23
24
class
MetaContBase
{
25
public
:
26
typedef
SG::SourceID
SourceID
;
27
MetaContBase
() {};
28
virtual
~MetaContBase
(){};
29
30
virtual
bool
insert
(
const
SourceID
& sid,
void
* obj) = 0;
31
virtual
size_t
erase
(
const
SourceID
& sid) = 0;
32
33
virtual
int
entries
()
const
{
return
0; }
34
virtual
bool
valid
(
const
SourceID
& sid)
const
= 0;
35
36
virtual
std::vector<SourceID>
sources
()
const
= 0;
37
38
virtual
void
list
(std::ostringstream& stream)
const
= 0;
39
40
virtual
void
*
getAsVoid
(
const
SourceID
& sid)
const
= 0;
41
42
private
:
43
};
44
46
47
template
<
typename
T>
48
class
MetaCont
:
public
MetaContBase
{
49
public
:
50
typedef
T
Payload_t
;
51
friend
SG::ReadMetaHandle<T>
;
52
53
MetaCont
() {};
54
~MetaCont
();
55
56
// Virtual functions
57
virtual
bool
insert
(
const
SourceID
& sid,
void
* obj)
override
final
;
58
virtual
size_t
erase
(
const
SourceID
& sid)
override
final
;
59
60
61
virtual
int
entries
()
const override
;
62
virtual
bool
valid
(
const
SourceID
& sid)
const
override
final
;
63
64
virtual
std::vector<SourceID>
sources
()
const
override final;
65
66
virtual
void
list
(
std
::
ostringstream
& stream)
const
override final;
67
68
// Non-virtual functions
69
bool
insert
(
const
SourceID
& sid, T* t);
70
72
bool
find
(
const
SourceID
& sid, T*& t)
const
;
73
T*
get
(
const
SourceID
& sid)
const
;
74
75
void
*
getAsVoid
(
const
SourceID
& sid)
const
override final {
return
get
(sid); }
76
77
private
:
78
79
mutable
std::mutex
m_mut
;
80
81
typedef
std::map<SourceID,T*>
MetaContSet
;
82
MetaContSet
m_metaSet
;
83
};
84
85
86
namespace
SG
{
87
88
95
template
<
class
T,
class
U>
96
struct
DataBucketTrait
<
MetaCont
<T>, U>
97
{
98
typedef
MetaContDataBucket<U>
type
;
99
static
void
init
() {}
100
};
101
102
}
// namespace SG
103
104
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
105
106
template
<
typename
T>
107
MetaCont<T>::~MetaCont
() {
108
for
(
auto
& t :
m_metaSet
) {
109
delete
t.second;
110
}
111
m_metaSet
.clear();
112
}
113
114
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
115
116
template
<
typename
T>
117
bool
MetaCont<T>::insert
(
const
SourceID
& sid,
void
* obj) {
118
T* t =
static_cast<
T*
>
(obj);
119
return
insert
(sid, t);
120
}
121
122
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
123
124
template
<
typename
T>
125
size_t
MetaCont<T>::erase
(
const
SourceID
& sid) {
126
std::lock_guard<std::mutex>
lock
(
m_mut
);
127
return
m_metaSet
.erase(sid);
128
}
129
130
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
131
132
template
<
typename
T>
133
bool
MetaCont<T>::insert
(
const
SourceID
& sid, T* t) {
134
std::lock_guard<std::mutex>
lock
(
m_mut
);
135
return
m_metaSet
.insert(std::make_pair(sid,t)).second;
136
}
137
138
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
139
140
template
<
typename
T>
141
bool
MetaCont<T>::valid
(
const
SourceID
& sid)
const
{
142
std::lock_guard<std::mutex>
lock
(
m_mut
);
143
return
m_metaSet
.find(sid)!=
m_metaSet
.end();
144
}
145
146
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
147
148
template
<
typename
T>
149
bool
MetaCont<T>::find
(
const
SourceID
& sid, T*& t)
const
{
150
std::lock_guard<std::mutex>
lock
(
m_mut
);
151
152
typename
MetaContSet::const_iterator itr =
m_metaSet
.find(sid);
153
if
(itr !=
m_metaSet
.end()) {
154
t=itr->second;
155
return
true
;
156
}
157
158
return
false
;
159
}
160
161
162
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
163
164
template
<
typename
T>
165
T*
MetaCont<T>::get
(
const
SourceID
& sid)
const
{
166
std::lock_guard<std::mutex>
lock
(
m_mut
);
167
168
typename
MetaContSet::const_iterator itr =
m_metaSet
.find(sid);
169
if
(itr !=
m_metaSet
.end()) {
170
return
itr->second;
171
}
172
173
return
nullptr
;
174
}
175
176
177
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
178
179
template
<
typename
T>
180
void
MetaCont<T>::list
(std::ostringstream& stream)
const
{
181
std::lock_guard<std::mutex>
lock
(
m_mut
);
182
// To Do: perhaps extend this output?
183
stream <<
"MetaCont with size : ["
<<
m_metaSet
.size() <<
"]"
<< std::endl;
184
for
(
const
auto
& mapel :
m_metaSet
) {
185
stream <<
"... Key : "
<< mapel.first << std::endl;
186
}
187
}
188
189
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
190
191
template
<
typename
T>
192
int
MetaCont<T>::entries
()
const
{
193
std::lock_guard<std::mutex>
lock
(
m_mut
);
194
return
m_metaSet
.size();
195
}
196
197
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
198
199
template
<
typename
T>
200
std::vector<MetaContBase::SourceID>
201
MetaCont<T>::sources
()
const
{
202
std::lock_guard<std::mutex>
lock
(
m_mut
);
203
204
std::vector<MetaContBase::SourceID>
r
;
205
for
(
const
auto
& ent :
m_metaSet
) {
206
r
.push_back(ent.first);
207
}
208
209
return
r
;
210
}
211
212
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
213
214
CLASS_DEF
(
MetaContBase
, 34480469 , 1 )
215
216
217
218
// METACONT_DEF(TYPE, CLID);
219
//
220
#define METACONT_DEF(T, CLID) \
221
CLASS_DEF( MetaCont<T>, CLID, 1 ) \
222
SG_BASES( MetaCont<T>, MetaContBase )
223
224
#endif
225
SourceID.h
Type used to identify a metadata source.
BaseInfo.h
Provide an interface for finding inheritance information at run time.
CLASS_DEF.h
macros to associate a CLID to a type
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition
Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:67
DataBucketTraitFwd.h
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
MetaContDataBucket.h
Allow converting MetaCont<T> to T.
MetaContBase
Definition
MetaCont.h:24
MetaContBase::SourceID
SG::SourceID SourceID
Definition
MetaCont.h:26
MetaContBase::~MetaContBase
virtual ~MetaContBase()
Definition
MetaCont.h:28
MetaContBase::list
virtual void list(std::ostringstream &stream) const =0
MetaContBase::getAsVoid
virtual void * getAsVoid(const SourceID &sid) const =0
MetaContBase::insert
virtual bool insert(const SourceID &sid, void *obj)=0
MetaContBase::valid
virtual bool valid(const SourceID &sid) const =0
MetaContBase::MetaContBase
MetaContBase()
Definition
MetaCont.h:27
MetaContBase::erase
virtual size_t erase(const SourceID &sid)=0
MetaContBase::entries
virtual int entries() const
Definition
MetaCont.h:33
MetaContBase::sources
virtual std::vector< SourceID > sources() const =0
MetaCont
Definition
MetaCont.h:48
MetaCont::sources
virtual std::vector< SourceID > sources() const override final
Definition
MetaCont.h:201
MetaCont::insert
virtual bool insert(const SourceID &sid, void *obj) override final
Definition
MetaCont.h:117
MetaCont::valid
virtual bool valid(const SourceID &sid) const override final
Definition
MetaCont.h:141
MetaCont::m_mut
std::mutex m_mut
Definition
MetaCont.h:79
MetaCont< DMTest::S1 >::get
DMTest::S1 * get(const SourceID &sid) const
Definition
MetaCont.h:165
MetaCont::Payload_t
T Payload_t
Definition
MetaCont.h:50
MetaCont::m_metaSet
MetaContSet m_metaSet
Definition
MetaCont.h:82
MetaCont< DMTest::S1 >::find
bool find(const SourceID &sid, DMTest::S1 *&t) const
Definition
MetaCont.h:149
MetaCont::MetaContSet
std::map< SourceID, T * > MetaContSet
Definition
MetaCont.h:81
MetaCont::entries
virtual int entries() const override
Definition
MetaCont.h:192
MetaCont::getAsVoid
void * getAsVoid(const SourceID &sid) const override final
Definition
MetaCont.h:75
MetaCont::~MetaCont
~MetaCont()
Definition
MetaCont.h:107
MetaCont< DMTest::S1 >::list
virtual void list(std::ostringstream &stream) const override final
Definition
MetaCont.h:180
MetaCont::MetaCont
MetaCont()
Definition
MetaCont.h:53
MetaCont::erase
virtual size_t erase(const SourceID &sid) override final
Definition
MetaCont.h:125
SG::MetaContDataBucket
Allow converting MetaCont<T> to T.
Definition
MetaContDataBucket.h:43
SG::ReadMetaHandle
Definition
ReadMetaHandle.h:27
ostringstream
STL class.
r
int r
Definition
globals.cxx:22
const
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
SG::SourceID
std::string SourceID
Definition
AthenaKernel/AthenaKernel/SourceID.h:25
std
STL namespace.
SG::DataBucketTrait< MetaCont< T >, U >::type
MetaContDataBucket< U > type
Definition
MetaCont.h:98
SG::DataBucketTrait< MetaCont< T >, U >::init
static void init()
Definition
MetaCont.h:99
SG::DataBucketTrait
Metafunction to find the proper DataBucket class for T.
Definition
StorableConversions.h:130
Generated on
for ATLAS Offline Software by
1.17.0