ATLAS Offline Software
Loading...
Searching...
No Matches
TStore.h
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2//
3// Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4//
5#ifndef XAODROOTACCESS_TSTORE_H
6#define XAODROOTACCESS_TSTORE_H
7
8// System include(s):
9#include <string>
10#include <map>
11#include <memory>
12#include <unordered_map>
13#include <vector>
14
15// ROOT include(s):
16#include <Rtypes.h>
17
18// EDM include(s):
20#include "SGCore/sgkey_t.h"
21
22// Local include(s):
24
25namespace xAOD {
26
27 // Forward declaration(s):
28 class THolder;
29 class TEvent;
30 class Event;
31
46 class TStore {
47
49 friend class TEvent;
50 friend class Event;
51
52 public:
54 TStore();
56 TStore( const TStore& ) = delete;
58 virtual ~TStore();
59
61 TStore& operator=( const TStore& ) = delete;
62
64 void setActive();
65
68
70 template< typename T >
71 ::Bool_t contains( const std::string& key ) const;
72
74 template< typename T >
75 ::Bool_t isConst( const std::string& key ) const;
76
78 template< typename T >
79 StatusCode retrieve( const T*& obj, const std::string& key ) const;
81 template< typename T >
82 StatusCode retrieve( T*& obj, const std::string& key ) const;
83
85 template< typename T >
86 StatusCode record( T* obj, const std::string& key );
88 template< typename T >
89 StatusCode record( std::unique_ptr< T > obj, const std::string& key );
90
92 template< typename T >
93 StatusCode record( const T* obj, const std::string& key );
95 template< typename T >
96 StatusCode record( std::unique_ptr< const T > obj, const std::string& key );
97
99 template< typename T >
100 void keys( std::vector< std::string >& vkeys ) const;
101
103 const THolder* holder( const std::string& key ) const;
104
106 StatusCode remove( const std::string& key );
108 StatusCode remove( void* ptr );
109
111 void clear();
112
114
116 void print() const;
117
118 protected:
120 ::Bool_t contains( const std::string& key,
121 const std::type_info& ti ) const;
123 ::Bool_t isConst( const std::string& key,
124 const std::type_info& ti ) const;
126 void* getObject( const std::string& key, const std::type_info& ti ) const;
128 const void* getConstObject( const std::string& key,
129 const std::type_info& ti ) const;
131 StatusCode record( void* obj, const std::string& key,
132 const std::string& classname,
133 ::Bool_t isOwner, ::Bool_t isConst );
135 StatusCode record( void* obj, const std::string& key,
136 const std::type_info& ti,
137 ::Bool_t isOwner, ::Bool_t isConst );
138
140 template< class T >
141 StatusCode record( ConstDataVector< T >* obj, const std::string& key,
142 const std::type_info& ti,
143 ::Bool_t isOwner, ::Bool_t isConst );
145 StatusCode record( THolder* hldr, const std::string& key );
146
149
151 ::Bool_t contains( SG::sgkey_t hash ) const;
153 ::Bool_t contains( const void* ptr ) const;
155 const std::string& getName( SG::sgkey_t hash ) const;
157 const std::string& getName( const void* ptr ) const;
159 void getNames(const std::string& targetClassName,
160 std::vector<std::string>& vkeys ) const;
161
163
165 typedef std::unordered_map< std::string, THolder* > Objects_t;
168
174 std::unordered_map< const void*, const std::string* > m_names;
175
176 private:
178 template< typename T >
179 StatusCode record_impl( T* obj, const std::string& key,
180 ::Bool_t isOwner, ::Bool_t isConst );
181
182 }; // class TStore
183
184} // namespace xAOD
185
186// Include the template implementation.
187#include "TStore.icc"
188
189#endif // XAODROOTACCESS_TSTORE_H
DataVector adapter that acts like it holds const pointers.
Base class for the event (xAOD::TEvent and xAOD::REvent) classes.
Definition Event.h:61
Tool for accessing xAOD files outside of Athena.
This class takes care of holding EDM objects in memory.
Definition THolder.h:35
void keys(std::vector< std::string > &vkeys) const
provide a list of keys associated with a type
StatusCode record(std::unique_ptr< const T > obj, const std::string &key)
Add a const object to the store, explicitly taking ownership of it.
StatusCode remove(const std::string &key)
Remove an object from the store by name.
Definition TStore.cxx:57
StatusCode record_impl(T *obj, const std::string &key, ::Bool_t isOwner, ::Bool_t isConst)
Internal implementation of the templated record method.
SG::SGKeyMap< std::string > HashedKeys_t
Type of the internal storage for the hashed keys of the object names.
Definition TStore.h:167
void setActive()
Set this as the active transient store in the application.
Definition TStore.cxx:43
void print() const
Print the current contents of the transient store.
Definition TStore.cxx:115
friend class Event
Definition TStore.h:50
std::unordered_map< std::string, THolder * > Objects_t
Type of the internal container storing all the objects.
Definition TStore.h:165
StatusCode retrieve(const T *&obj, const std::string &key) const
Retrieve either a constant or non-constant object from the store.
const void * getConstObject(const std::string &key, const std::type_info &ti) const
Function retrieving a const object in a non-template way.
Definition TStore.cxx:202
void clear()
Clear the store of all of its contents.
Definition TStore.cxx:95
virtual ~TStore()
Destructor.
Definition TStore.cxx:30
StatusCode record(T *obj, const std::string &key)
Add an object to the store.
void getNames(const std::string &targetClassName, std::vector< std::string > &vkeys) const
Function determining the list keys associated with a type name.
Definition TStore.cxx:371
const std::string & getName(SG::sgkey_t hash) const
Get the name corresponding to a hashed key.
Definition TStore.cxx:337
friend class TEvent
Make TEvent a friend of this class.
Definition TStore.h:49
StatusCode record(std::unique_ptr< T > obj, const std::string &key)
Add an object to the store, explicitly taking ownership of it.
HashedKeys_t m_keys
The key map.
Definition TStore.h:172
void * getObject(const std::string &key, const std::type_info &ti) const
Function retrieving a non-const object in a non-template way.
Definition TStore.cxx:182
TStore & operator=(const TStore &)=delete
Disallow copying the object.
std::unordered_map< const void *, const std::string * > m_names
Key of each managed object, by object pointer (points into m_objects).
Definition TStore.h:174
const THolder * holder(const std::string &key) const
return holder for key
Definition TStore.cxx:50
TStore(const TStore &)=delete
Disallow copying the object.
StatusCode retrieve(T *&obj, const std::string &key) const
Retrieve a non-constant object from the store.
::Bool_t contains(const std::string &key) const
Function checking if an object is available from the store.
Objects_t m_objects
The object storage.
Definition TStore.h:170
StatusCode record(const T *obj, const std::string &key)
Add a const object to the store.
TStore()
Default constructor.
Definition TStore.cxx:24
StatusCode record(ConstDataVector< T > *obj, const std::string &key, const std::type_info &ti, ::Bool_t isOwner, ::Bool_t isConst)
Function doing the first step of recording a ConstDataVector object.
::Bool_t isConst(const std::string &key) const
Function checking if an object with a given type is constant.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
Definition sgkey_t.h:93
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.