2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 #ifndef ASGTOOLS_SGTEVENT_ICC
6 #define ASGTOOLS_SGTEVENT_ICC
11 #include <CxxUtils/AthUnlikelyMacros.h>
14 #ifdef XAOD_STANDALONE
15 # include "xAODRootAccess/TEvent.h"
16 # include "xAODRootAccess/TStore.h"
17 #endif // XAOD_STANDALONE
21 /// A constant used in the error message printouts
22 static const char* ERROR_SOURCE = "asg::SgTEvent ERROR ";
24 template< typename T >
25 bool SgTEvent::contains( const std::string& name ) const {
27 // Make sure the object is initialised:
28 if( ATH_UNLIKELY ( ! m_pevm ) && initialize().isFailure() ) {
29 std::cout << ERROR_SOURCE << "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 SgTEvent::transientContains( const std::string& name ) const {
46 // Make sure the object is initialised:
47 if( ATH_UNLIKELY ( ! m_pevm ) && initialize().isFailure() ) {
48 std::cout << ERROR_SOURCE << "Couldn't initialise the tool"
53 // Check if the object is in the transient store:
54 if ( m_ptds && m_ptds->template contains< T >( name ) ) {
58 // Check if the object is in the event store:
59 return m_pevm->template transientContains< T >( name );
62 template< typename T >
63 T* SgTEvent::retrieve( const std::string& name ) const {
65 // Make sure the object is initialised:
66 if( ATH_UNLIKELY ( ! m_pevm ) && initialize().isFailure() ) {
67 std::cout << ERROR_SOURCE << "Couldn't initialise the tool"
72 // Pointer used in the retrieval:
75 // Check the transient store first:
76 if( m_ptds && m_ptds->template contains< T >( name ) ) {
77 if( m_ptds->retrieve( pobj, name ).isSuccess() ) {
84 // If it's not there, then check the event store:
85 if( m_pevm->retrieve( pobj, name ).isSuccess() ) {
92 template< typename T >
93 StatusCode SgTEvent::retrieve( T*& pobj, const std::string& name ) {
95 pobj = retrieve< T >( name );
96 if( ATH_LIKELY( pobj ) ) {
97 return StatusCode::SUCCESS;
99 return StatusCode::FAILURE;
103 template< typename T >
104 StatusCode SgTEvent::retrieve( const T*& pobj,
105 const std::string& name ) const {
107 pobj = retrieve< const T >( name );
108 if( ATH_LIKELY( pobj ) ) {
109 return StatusCode::SUCCESS;
111 return StatusCode::FAILURE;
115 template< typename T >
116 StatusCode SgTEvent::record( std::unique_ptr<T> pobj, const std::string& name ) {
118 // Make sure the object is initialised:
119 if( ATH_UNLIKELY ( ! m_pevm ) && initialize().isFailure() ) {
120 std::cout << ERROR_SOURCE << "Couldn't initialise the tool"
122 return StatusCode::FAILURE;
125 // If a transient store is available, try recording it there:
127 if( m_ptds->template record( std::move( pobj ), name ).isSuccess() ) {
128 return StatusCode::SUCCESS;
130 return StatusCode::FAILURE;
134 // If not, then let's try with the event store:
135 if( m_pevm->template record( std::move( pobj ), name ).isSuccess() ) {
136 return StatusCode::SUCCESS;
138 return StatusCode::FAILURE;
142 template< typename T >
143 StatusCode SgTEvent::record( T* pobj, const std::string& name ) {
144 // this is the legacy interface, forwarding it to new one
145 return record( std::unique_ptr<T>(pobj), name );
148 /// Container overwriting is not allowed in standalone mode. The function is
149 /// just here to allow the compilation of code that was mainly written for
150 /// the offline environment. (In case the behaviour of the code is chosen
151 /// according to its runtime configuration.)
153 /// As it's a dummy, function parameters are not described here. They are
154 /// modeled after the <code>StoreGateSvc::overwrite</code> function.
156 template< typename T >
157 StatusCode SgTEvent::overwrite( T* /*obj*/, const std::string& /*name*/,
158 bool /*allowMods*/, bool /*resetOnly*/,
161 std::cout << ERROR_SOURCE << "Can't use overwrite in standalone mode"
163 return StatusCode::FAILURE;
166 template< typename T >
167 void SgTEvent::keys( std::vector< std::string >& vkeys ) const {
169 m_ptds->keys< T >(vkeys);
170 } else if ( m_pevm ) {
171 m_pevm->keys< T >(vkeys);
177 #endif // ASGTOOLS_SGTEVENT_ICC