2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5#ifndef ASGTOOLS_SGEVENT_ICC
6#define ASGTOOLS_SGEVENT_ICC
13# include "xAODRootAccess/Event.h"
14# include "xAODRootAccess/TStore.h"
15#endif // XAOD_STANDALONE
19 /// A constant used in the error message printouts
20 static const char* ERROR_SRC = "asg::SgEvent ERROR ";
22 template< typename T >
23 bool SgEvent::contains( const std::string& name ) const {
25 // Make sure the object is initialised:
26 if ( ! m_pevm ) [[unlikely]] {
27 if ( initialize().isFailure() ) {
28 std::cout << ERROR_SRC << "Couldn't initialise the tool"
34 // Check if the object is in the transient store:
35 if ( m_ptds && m_ptds->template contains< T >( name ) ) {
39 // Check if the object is in the event store:
40 return m_pevm->template contains< T >( name );
43 template< typename T >
44 bool SgEvent::transientContains( const std::string& name ) const {
46 // Make sure the object is initialised:
47 if ( ! m_pevm ) [[unlikely]] {
48 if ( initialize().isFailure() ) {
49 std::cout << ERROR_SRC << "Couldn't initialise the tool"
55 // Check if the object is in the transient store:
56 if ( m_ptds && m_ptds->template contains< T >( name ) ) {
60 // Check if the object is in the event store:
61 return m_pevm->template transientContains< T >( name );
64 template< typename T >
65 T* SgEvent::retrieve( const std::string& name ) const {
67 // Make sure the object is initialised:
68 if ( ! m_pevm ) [[unlikely]] {
69 if ( initialize().isFailure() ) {
70 std::cout << ERROR_SRC << "Couldn't initialise the tool"
76 // Pointer used in the retrieval:
79 // Check the transient store first:
80 if( m_ptds && m_ptds->template contains< T >( name ) ) {
81 if( m_ptds->retrieve( pobj, name ).isSuccess() ) {
88 // If it's not there, then check the event store:
89 if( m_pevm->retrieve( pobj, name ).isSuccess() ) {
96 template< typename T >
97 StatusCode SgEvent::retrieve( T*& pobj, const std::string& name ) {
99 pobj = retrieve< T >( name );
100 if( pobj ) [[likely]] {
101 return StatusCode::SUCCESS;
103 return StatusCode::FAILURE;
107 template< typename T >
108 StatusCode SgEvent::retrieve( const T*& pobj,
109 const std::string& name ) const {
111 pobj = retrieve< const T >( name );
112 if ( pobj ) [[likely]] {
113 return StatusCode::SUCCESS;
115 return StatusCode::FAILURE;
119 template< typename T >
120 StatusCode SgEvent::record( std::unique_ptr<T> pobj, const std::string& name ) {
122 // Make sure the object is initialised:
123 if ( ! m_pevm ) [[unlikely]] {
124 if ( initialize().isFailure() ) {
125 std::cout << ERROR_SRC << "Couldn't initialise the tool"
127 return StatusCode::FAILURE;
131 // If a transient store is available, try recording it there:
133 if( m_ptds->record( std::move( pobj ), name ).isSuccess() ) {
134 return StatusCode::SUCCESS;
136 return StatusCode::FAILURE;
140 // If not, then let's try with the event store:
141 if( m_pevm->record( std::move( pobj ), name ).isSuccess() ) {
142 return StatusCode::SUCCESS;
144 return StatusCode::FAILURE;
148 template< typename T >
149 StatusCode SgEvent::record( T* pobj, const std::string& name ) {
150 // this is the legacy interface, forwarding it to new one
151 return record( std::unique_ptr<T>(pobj), name );
154 /// Container overwriting is not allowed in standalone mode. The function is
155 /// just here to allow the compilation of code that was mainly written for
156 /// the offline environment. (In case the behaviour of the code is chosen
157 /// according to its runtime configuration.)
159 /// As it's a dummy, function parameters are not described here. They are
160 /// modeled after the <code>StoreGateSvc::overwrite</code> function.
162 template< typename T >
163 StatusCode SgEvent::overwrite( T* /*obj*/, const std::string& /*name*/,
164 bool /*allowMods*/, bool /*resetOnly*/,
167 std::cout << ERROR_SRC << "Can't use overwrite in standalone mode"
169 return StatusCode::FAILURE;
172 template< typename T >
173 void SgEvent::keys( std::vector< std::string >& vkeys ) const {
175 m_ptds->keys< T >(vkeys);
176 } else if ( m_pevm ) {
177 m_pevm->keys< T >(vkeys);
183#endif // ASGTOOLS_SGEVENT_ICC