ATLAS Offline Software
Loading...
Searching...
No Matches
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"
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) const;
62
64 virtual const std::string currentRangeID() const = 0;
65
66protected:
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
76private: // Data
77 std::mutex m_mutex;
78};
79
80
82inline std::set<std::string>
83IAthMetaDataSvc::getPerStreamKeysFor(const std::string& key ) const {
84 return std::set<std::string>( {key} );
85}
86
92template <typename T, class TKEY>
93T* 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
102template <typename T, class TKEY>
103const 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
112template <typename T, typename TKEY>
113StatusCode 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
130template <typename T, typename TKEY>
131StatusCode 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
140template <typename T, class TKEY>
141StatusCode 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
153template <typename T, typename TKEY>
154bool IAthMetaDataSvc::contains(const TKEY& key) const {
155 if (!outputDataStore()->contains< MetaCont<T> >(key))
156 return false;
157 const MetaCont<T>* container =
159 return container && container->valid(currentRangeID());
160}
161
162#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.
bool contains(const TKEY &key) const
Check if object is already is already in store.
virtual const std::string currentRangeID() const =0
rangeID for the current EventContext - used to index MetaContainers -
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.
virtual bool insert(const SourceID &sid, void *obj) override final
Definition MetaCont.h:117
virtual bool valid(const SourceID &sid) const override final
Definition MetaCont.h:141
T * get(const SourceID &sid) const
Definition MetaCont.h:165
virtual int entries() const override
Definition MetaCont.h:192
virtual size_t erase(const SourceID &sid) override final
Definition MetaCont.h:125
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