ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
AthenaKernel
IAthMetaDataSvc.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#ifndef ATHENAKERNEL_IATHMETADATASVC_H
6
#define ATHENAKERNEL_IATHMETADATASVC_H
7
13
14
#include "GaudiKernel/INamedInterface.h"
15
#include "
AthenaKernel/MetaCont.h
"
16
#include "
StoreGate/StoreGateSvc.h
"
17
18
#include <string>
19
#include <set>
20
#include <mutex>
21
#include <typeinfo>
22
28
class
IAthMetaDataSvc
:
virtual
public
::INamedInterface {
29
30
public
:
// Non-static members
31
DeclareInterfaceID
(
IAthMetaDataSvc
, 1, 0);
32
33
35
virtual
StatusCode
shmProxy
(
const
std::string& filename) = 0;
36
38
virtual
std::set<std::string>
getPerStreamKeysFor
(
const
std::string& key )
const
;
39
40
// ======= Methods for handling metadata objects stored in MetaContainers (EventService)
41
template
<
typename
T,
class
TKEY>
42
T*
tryRetrieve
(
const
TKEY& key)
const
;
43
44
template
<
typename
T,
class
TKEY>
45
const
T*
tryConstRetrieve
(
const
TKEY& key)
const
;
46
48
template
<
typename
T,
typename
TKEY>
49
StatusCode
record
(T* p2BRegistered,
const
TKEY& key);
50
52
template
<
typename
T,
typename
TKEY>
53
StatusCode
record
(std::unique_ptr<T> pUnique,
const
TKEY& key);
54
56
template
<
typename
T,
typename
TKEY>
57
StatusCode
remove
(
const
TKEY& key,
bool
ignoreIfAbsent=
false
);
58
60
template
<
typename
T,
typename
TKEY>
61
bool
contains
(
const
TKEY& key)
const
;
62
64
virtual
const
std::string
currentRangeID
()
const
= 0;
65
66
protected
:
68
virtual
void
recordHook
(
const
std::type_info&) {}
69
71
virtual
void
removeHook
(
const
std::type_info&) {}
72
74
virtual
StoreGateSvc
*
outputDataStore
()
const
= 0;
75
76
private
:
// Data
77
std::mutex
m_mutex
;
78
};
79
80
82
inline
std::set<std::string>
83
IAthMetaDataSvc::getPerStreamKeysFor
(
const
std::string& key )
const
{
84
return
std::set<std::string>( {key} );
85
}
86
92
template
<
typename
T,
class
TKEY>
93
T*
IAthMetaDataSvc::tryRetrieve
(
const
TKEY& key)
const
94
{
95
const
MetaCont<T>
* container =
outputDataStore
()->
tryRetrieve
<
MetaCont<T>
>(key);
96
if
( container ) {
97
return
container->get(
currentRangeID
() );
98
}
99
return
nullptr
;
100
}
101
102
template
<
typename
T,
class
TKEY>
103
const
T*
IAthMetaDataSvc::tryConstRetrieve
(
const
TKEY& key)
const
104
{
105
const
MetaCont<T>
* container =
outputDataStore
()->
tryRetrieve
<
MetaCont<T>
>(key);
106
if
( container ) {
107
return
container->get(
currentRangeID
() );
108
}
109
return
nullptr
;
110
}
111
112
template
<
typename
T,
typename
TKEY>
113
StatusCode
IAthMetaDataSvc::record
(T* pObject,
const
TKEY& key)
114
{
115
std::lock_guard
lock
(
m_mutex
);
116
MetaCont<T>
* container =
outputDataStore
()->
tryRetrieve
<
MetaCont<T>
>(key);
117
StatusCode
sc
= StatusCode::FAILURE;
118
if
( !container ) {
119
auto
cont_uptr = std::make_unique< MetaCont<T> >();
120
if
( cont_uptr->insert(
currentRangeID
() , pObject) )
121
sc
=
outputDataStore
()->
record
( std::move(cont_uptr), key );
122
}
else
{
123
if
(container->insert(
currentRangeID
(), pObject))
sc
= StatusCode::SUCCESS;
124
}
125
if
(
sc
.isSuccess())
recordHook
(
typeid
(T));
126
return
sc
;
127
}
128
129
130
template
<
typename
T,
typename
TKEY>
131
StatusCode
IAthMetaDataSvc::record
(std::unique_ptr<T> pUnique,
const
TKEY& key)
132
{
133
if
( this->
record
( pUnique.release(), key ).isSuccess() ) {
134
return
StatusCode::SUCCESS;
135
}
136
return
StatusCode::FAILURE;
137
}
138
139
140
template
<
typename
T,
class
TKEY>
141
StatusCode
IAthMetaDataSvc::remove
(
const
TKEY& key,
bool
ignoreIfAbsent)
142
{
143
std::lock_guard
lock
(
m_mutex
);
144
// change erase to setting nullptr?
145
MetaCont<T>
* container =
outputDataStore
()->
tryRetrieve
<
MetaCont<T>
>(key);
146
if
(container && container->erase(
currentRangeID
())) {
147
if
(container->entries() == 0u)
removeHook
(
typeid
(T));
148
return
StatusCode::SUCCESS;
149
}
150
return
ignoreIfAbsent? StatusCode::SUCCESS : StatusCode::FAILURE;
151
}
152
153
template
<
typename
T,
typename
TKEY>
154
bool
IAthMetaDataSvc::contains
(
const
TKEY& key)
const
{
155
if
(!
outputDataStore
()->
contains
<
MetaCont<T>
>(key))
156
return
false
;
157
const
MetaCont<T>
* container =
158
outputDataStore
()->
tryConstRetrieve
<
MetaCont<T>
>(key);
159
return
container && container->valid(
currentRangeID
());
160
}
161
162
#endif
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
MetaCont.h
StoreGateSvc.h
IAthMetaDataSvc
This class provides the interface for MetaDataSvc.
Definition
IAthMetaDataSvc.h:28
IAthMetaDataSvc::tryConstRetrieve
const T * tryConstRetrieve(const TKEY &key) const
Definition
IAthMetaDataSvc.h:103
IAthMetaDataSvc::tryRetrieve
T * tryRetrieve(const TKEY &key) const
Retrieve an object of type T from MetaDataStore Return 0 if not found.
Definition
IAthMetaDataSvc.h:93
IAthMetaDataSvc::DeclareInterfaceID
DeclareInterfaceID(IAthMetaDataSvc, 1, 0)
IAthMetaDataSvc::outputDataStore
virtual StoreGateSvc * outputDataStore() const =0
The output MetaData Store.
IAthMetaDataSvc::contains
bool contains(const TKEY &key) const
Check if object is already is already in store.
Definition
IAthMetaDataSvc.h:154
IAthMetaDataSvc::currentRangeID
virtual const std::string currentRangeID() const =0
rangeID for the current EventContext - used to index MetaContainers -
IAthMetaDataSvc::m_mutex
std::mutex m_mutex
Definition
IAthMetaDataSvc.h:77
IAthMetaDataSvc::getPerStreamKeysFor
virtual std::set< std::string > getPerStreamKeysFor(const std::string &key) const
Get all per-stream Key variants created for in-file metadata object with original key - if none,...
Definition
IAthMetaDataSvc.h:83
IAthMetaDataSvc::shmProxy
virtual StatusCode shmProxy(const std::string &filename)=0
used by AthenaPoolCnvSvc
IAthMetaDataSvc::removeHook
virtual void removeHook(const std::type_info &)
Hook for implementation to react to removing an object.
Definition
IAthMetaDataSvc.h:71
IAthMetaDataSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
Definition
IAthMetaDataSvc.h:113
IAthMetaDataSvc::remove
StatusCode remove(const TKEY &key, bool ignoreIfAbsent=false)
Remove object with this type+key.
Definition
IAthMetaDataSvc.h:141
IAthMetaDataSvc::recordHook
virtual void recordHook(const std::type_info &)
Hook for implementation to react to recording an object.
Definition
IAthMetaDataSvc.h:68
MetaCont
Definition
MetaCont.h:48
StoreGateSvc
The Athena Transient Store API.
Definition
StoreGateSvc.h:120
StoreGateSvc::record
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
StoreGateSvc::tryRetrieve
T * tryRetrieve() const
Variant of the above which doesn't print a warning message.
StoreGateSvc::tryConstRetrieve
const T * tryConstRetrieve() const
Generated on
for ATLAS Offline Software by
1.17.0