ATLAS Offline Software
TStore.h
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 //
3 // Copyright (C) 2002-2023 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 <vector>
13 
14 // ROOT include(s):
15 #include <Rtypes.h>
16 
17 // EDM include(s):
19 #include "CxxUtils/sgkey_t.h"
20 
21 // Local include(s):
23 
24 namespace xAOD {
25 
26  // Forward declaration(s):
27  class THolder;
28  class TEvent;
29 
44  class TStore {
45 
47  friend class TEvent;
48 
49  public:
51  TStore();
53  TStore( const TStore& ) = delete;
55  virtual ~TStore();
56 
58  TStore& operator=( const TStore& ) = delete;
59 
61  void setActive();
62 
65 
67  template< typename T >
68  ::Bool_t contains( const std::string& key ) const;
69 
71  template< typename T >
72  ::Bool_t isConst( const std::string& key ) const;
73 
75  template< typename T >
76  StatusCode retrieve( const T*& obj, const std::string& key ) const;
78  template< typename T >
79  StatusCode retrieve( T*& obj, const std::string& key ) const;
80 
82  template< typename T >
83  StatusCode record( T* obj, const std::string& key );
85  template< typename T >
86  StatusCode record( std::unique_ptr< T > obj, const std::string& key );
87 
89  template< typename T >
90  StatusCode record( const T* obj, const std::string& key );
92  template< typename T >
93  StatusCode record( std::unique_ptr< const T > obj, const std::string& key );
94 
96  template< typename T >
97  void keys( std::vector< std::string >& vkeys ) const;
98 
100  const THolder* holder( const std::string& key ) const;
101 
103  StatusCode remove( const std::string& key );
105  StatusCode remove( void* ptr );
106 
108  void clear();
109 
111 
113  void print() const;
114 
115  protected:
117  ::Bool_t contains( const std::string& key,
118  const std::type_info& ti ) const;
120  ::Bool_t isConst( const std::string& key,
121  const std::type_info& ti ) const;
123  void* getObject( const std::string& key, const std::type_info& ti ) const;
125  const void* getConstObject( const std::string& key,
126  const std::type_info& ti ) const;
128  StatusCode record( void* obj, const std::string& key,
129  const std::string& classname,
130  ::Bool_t isOwner, ::Bool_t isConst );
132  StatusCode record( void* obj, const std::string& key,
133  const std::type_info& ti,
134  ::Bool_t isOwner, ::Bool_t isConst );
135 
137  template< class T >
139  const std::type_info& ti,
140  ::Bool_t isOwner, ::Bool_t isConst );
142  StatusCode record( THolder* hldr, const std::string& key );
143 
146 
148  ::Bool_t contains( SG::sgkey_t hash ) const;
150  ::Bool_t contains( const void* ptr ) const;
152  const std::string& getName( SG::sgkey_t hash ) const;
154  const std::string& getName( const void* ptr ) const;
156  void getNames(const std::string& targetClassName,
157  std::vector<std::string>& vkeys ) const;
158 
160 
162  typedef std::map< std::string, THolder* > Objects_t;
165 
170 
171  private:
173  template< typename T >
174  StatusCode record_impl( T* obj, const std::string& key,
175  ::Bool_t isOwner, ::Bool_t isConst );
176 
177  }; // class TStore
178 
179 } // namespace xAOD
180 
181 // Include the template implementation.
182 #include "TStore.icc"
183 
184 #endif // XAODROOTACCESS_TSTORE_H
xAOD::TStore::~TStore
virtual ~TStore()
Destructor.
Definition: TStore.cxx:30
xAOD::TStore::m_keys
HashedKeys_t m_keys
The key map.
Definition: TStore.h:169
xAOD::TStore::holder
const THolder * holder(const std::string &key) const
return holder for key
Definition: TStore.cxx:50
TStore.icc
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
xAOD::THolder
This class takes care of holding EDM objects in memory.
Definition: THolder.h:35
xAOD::TStore::record
StatusCode record(const T *obj, const std::string &key)
Add a const object to the store.
xAOD::TStore::retrieve
StatusCode retrieve(const T *&obj, const std::string &key) const
Retrieve either a constant or non-constant object from the store.
xAOD::TStore::getName
const std::string & getName(SG::sgkey_t hash) const
Get the name corresponding to a hashed key.
Definition: TStore.cxx:366
xAOD::TStore::record
StatusCode record(std::unique_ptr< const T > obj, const std::string &key)
Add a const object to the store, explicitly taking ownership of it.
xAOD::TStore::setActive
void setActive()
Set this as the active transient store in the application.
Definition: TStore.cxx:43
xAOD::TStore::Objects_t
std::map< std::string, THolder * > Objects_t
Type of the internal container storing all the objects.
Definition: TStore.h:162
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
xAOD::TStore::clear
void clear()
Clear the store of all of its contents.
Definition: TStore.cxx:105
xAOD::TStore::record
StatusCode record(std::unique_ptr< T > obj, const std::string &key)
Add an object to the store, explicitly taking ownership of it.
xAOD::TStore::contains
::Bool_t contains(const std::string &key) const
Function checking if an object is available from the store.
xAOD::TStore::TStore
TStore(const TStore &)=delete
Disallow copying the object.
xAOD::TStore::record
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.
xAOD::TStore::isConst
::Bool_t isConst(const std::string &key) const
Function checking if an object with a given type is constant.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
xAOD::TStore::retrieve
StatusCode retrieve(T *&obj, const std::string &key) const
Retrieve a non-constant object from the store.
xAOD::TStore::record_impl
StatusCode record_impl(T *obj, const std::string &key, ::Bool_t isOwner, ::Bool_t isConst)
Internal implementation of the templated record method.
xAOD::TStore::remove
StatusCode remove(const std::string &key)
Remove an object from the store by name.
Definition: TStore.cxx:57
xAOD::TStore::HashedKeys_t
SG::SGKeyMap< std::string > HashedKeys_t
Type of the internal storage for the hashed keys of the object names.
Definition: TStore.h:164
xAOD::TStore::getObject
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:191
StatusCode.h
xAOD::TStore::m_objects
Objects_t m_objects
The object storage.
Definition: TStore.h:167
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
xAOD::TStore::print
void print() const
Print the current contents of the transient store.
Definition: TStore.cxx:124
xAOD::TStore::getConstObject
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:211
sgkey_t.h
Define the type used for hashed StoreGate key+CLID pairs.
xAOD::TStore
A relatively simple transient store for objects created in analysis.
Definition: TStore.h:44
xAOD::TStore::record
StatusCode record(T *obj, const std::string &key)
Add an object to the store.
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
xAOD::TStore::operator=
TStore & operator=(const TStore &)=delete
Disallow copying the object.
ConstDataVector< T >
xAOD::TStore::keys
void keys(std::vector< std::string > &vkeys) const
provide a list of keys associated with a type
SG::SGKeyMap
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
Definition: CxxUtils/CxxUtils/sgkey_t.h:93
xAOD::TStore::getNames
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:409
python.PyAthena.obj
obj
Definition: PyAthena.py:135
xAOD::TStore::TStore
TStore()
Default constructor.
Definition: TStore.cxx:24
xAOD::TEvent
Tool for accessing xAOD files outside of Athena.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:81
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37