ATLAS Offline Software
Loading...
Searching...
No Matches
IAthMetaDataSvc.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_IATHMETADATASVC_H
6#define ATHENAKERNEL_IATHMETADATASVC_H
7
13
14#include "GaudiKernel/INamedInterface.h"
17
18#include <string>
19#include <set>
20#include <mutex>
21#include <typeinfo>
22
28class IAthMetaDataSvc : virtual public ::INamedInterface {
29
30public: // Non-static members
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);
62
64 virtual StoreGateSvc* outputDataStore() const = 0;
65
67 virtual const std::string currentRangeID() const = 0;
68
70 virtual void recordHook(const std::type_info&) {}
71
73 virtual void removeHook(const std::type_info&) {}
74
75private: // Data
76 std::mutex m_mutex;
77};
78
79
81inline std::set<std::string>
82IAthMetaDataSvc::getPerStreamKeysFor(const std::string& key ) const {
83 return std::set<std::string>( {key} );
84}
85
91template <typename T, class TKEY>
92T* IAthMetaDataSvc::tryRetrieve (const TKEY& key) const
93{
95 if( container ) {
96 return container->get( currentRangeID() );
97 }
98 return nullptr;
99}
100
101template <typename T, class TKEY>
102const T* IAthMetaDataSvc::tryConstRetrieve (const TKEY& key) const
103{
105 if( container ) {
106 return container->get( currentRangeID() );
107 }
108 return nullptr;
109}
110
111template <typename T, typename TKEY>
112StatusCode IAthMetaDataSvc::record(T* pObject, const TKEY& key)
113{
114 std::lock_guard lock(m_mutex);
116 StatusCode sc = StatusCode::FAILURE;
117 if( !container ) {
118 auto cont_uptr = std::make_unique< MetaCont<T> >();
119 if( cont_uptr->insert( currentRangeID() , pObject) )
120 sc = outputDataStore()->record( std::move(cont_uptr), key );
121 } else {
122 if (container->insert(currentRangeID(), pObject)) sc = StatusCode::SUCCESS;
123 }
124 if (sc.isSuccess()) recordHook(typeid(T));
125 return sc;
126}
127
128
129template <typename T, typename TKEY>
130StatusCode IAthMetaDataSvc::record(std::unique_ptr<T> pUnique, const TKEY& key)
131{
132 if( this->record( pUnique.release(), key ).isSuccess() ) {
133 return StatusCode::SUCCESS;
134 }
135 return StatusCode::FAILURE;
136}
137
138
139template <typename T, class TKEY>
140StatusCode IAthMetaDataSvc::remove(const TKEY& key, bool ignoreIfAbsent)
141{
142 std::lock_guard lock(m_mutex);
143 // change erase to setting nullptr?
145 if (container && container->erase(currentRangeID())) {
146 if (container->entries() == 0u) removeHook(typeid(T));
147 return StatusCode::SUCCESS;
148 }
149 return ignoreIfAbsent? StatusCode::SUCCESS : StatusCode::FAILURE;
150}
151
152template <typename T, typename TKEY>
153bool IAthMetaDataSvc::contains(const TKEY& key) {
154 if (!outputDataStore()->contains< MetaCont<T> >(key))
155 return false;
156 const MetaCont<T>* container =
158 return container && container->valid(currentRangeID());
159}
160
161#endif
static Double_t sc
This class provides the interface for MetaDataSvc.
const T * tryConstRetrieve(const TKEY &key) const
T * tryRetrieve(const TKEY &key) const
Retrieve an object of type T from MetaDataStore Return 0 if not found.
DeclareInterfaceID(IAthMetaDataSvc, 1, 0)
virtual StoreGateSvc * outputDataStore() const =0
The output MetaData Store.
virtual const std::string currentRangeID() const =0
rangeID for the current EventContext - used to index MetaContainers -
bool contains(const TKEY &key)
Check if object is already is already in store.
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,...
virtual StatusCode shmProxy(const std::string &filename)=0
used by AthenaPoolCnvSvc
virtual void removeHook(const std::type_info &)
Hook for implementation to react to removing an object.
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
StatusCode remove(const TKEY &key, bool ignoreIfAbsent=false)
Remove object with this type+key.
virtual void recordHook(const std::type_info &)
Hook for implementation to react to recording an object.
The Athena Transient Store API.
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
T * tryRetrieve() const
Variant of the above which doesn't print a warning message.
const T * tryConstRetrieve() const