ATLAS Offline Software
Loading...
Searching...
No Matches
SgEvent.icc
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 ASGTOOLS_SGEVENT_ICC
6#define ASGTOOLS_SGEVENT_ICC
7
8// System include(s):
9#include <iostream>
10
11// xAOD include(s):
12#ifdef XAOD_STANDALONE
13# include "xAODRootAccess/Event.h"
14# include "xAODRootAccess/TStore.h"
15#endif // XAOD_STANDALONE
16
17namespace asg {
18
19 /// A constant used in the error message printouts
20 static const char* ERROR_SRC = "asg::SgEvent ERROR ";
21
22 template< typename T >
23 bool SgEvent::contains( const std::string& name ) const {
24
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"
29 << std::endl;
30 return false;
31 }
32 }
33
34 // Check if the object is in the transient store:
35 if ( m_ptds && m_ptds->template contains< T >( name ) ) {
36 return true;
37 }
38
39 // Check if the object is in the event store:
40 return m_pevm->template contains< T >( name );
41 }
42
43 template< typename T >
44 bool SgEvent::transientContains( const std::string& name ) const {
45
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"
50 << std::endl;
51 return false;
52 }
53 }
54
55 // Check if the object is in the transient store:
56 if ( m_ptds && m_ptds->template contains< T >( name ) ) {
57 return true;
58 }
59
60 // Check if the object is in the event store:
61 return m_pevm->template transientContains< T >( name );
62 }
63
64 template< typename T >
65 T* SgEvent::retrieve( const std::string& name ) const {
66
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"
71 << std::endl;
72 return 0;
73 }
74 }
75
76 // Pointer used in the retrieval:
77 T* pobj = 0;
78
79 // Check the transient store first:
80 if( m_ptds && m_ptds->template contains< T >( name ) ) {
81 if( m_ptds->retrieve( pobj, name ).isSuccess() ) {
82 return pobj;
83 } else {
84 return 0;
85 }
86 }
87
88 // If it's not there, then check the event store:
89 if( m_pevm->retrieve( pobj, name ).isSuccess() ) {
90 return pobj;
91 } else {
92 return 0;
93 }
94 }
95
96 template< typename T >
97 StatusCode SgEvent::retrieve( T*& pobj, const std::string& name ) {
98
99 pobj = retrieve< T >( name );
100 if( pobj ) [[likely]] {
101 return StatusCode::SUCCESS;
102 } else {
103 return StatusCode::FAILURE;
104 }
105 }
106
107 template< typename T >
108 StatusCode SgEvent::retrieve( const T*& pobj,
109 const std::string& name ) const {
110
111 pobj = retrieve< const T >( name );
112 if ( pobj ) [[likely]] {
113 return StatusCode::SUCCESS;
114 } else {
115 return StatusCode::FAILURE;
116 }
117 }
118
119 template< typename T >
120 StatusCode SgEvent::record( std::unique_ptr<T> pobj, const std::string& name ) {
121
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"
126 << std::endl;
127 return StatusCode::FAILURE;
128 }
129 }
130
131 // If a transient store is available, try recording it there:
132 if( m_ptds ) {
133 if( m_ptds->record( std::move( pobj ), name ).isSuccess() ) {
134 return StatusCode::SUCCESS;
135 } else {
136 return StatusCode::FAILURE;
137 }
138 }
139
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;
143 } else {
144 return StatusCode::FAILURE;
145 }
146 }
147
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 );
152 }
153
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.)
158 ///
159 /// As it's a dummy, function parameters are not described here. They are
160 /// modeled after the <code>StoreGateSvc::overwrite</code> function.
161 ///
162 template< typename T >
163 StatusCode SgEvent::overwrite( T* /*obj*/, const std::string& /*name*/,
164 bool /*allowMods*/, bool /*resetOnly*/,
165 bool /*noHist*/ ) {
166
167 std::cout << ERROR_SRC << "Can't use overwrite in standalone mode"
168 << std::endl;
169 return StatusCode::FAILURE;
170 }
171
172 template< typename T >
173 void SgEvent::keys( std::vector< std::string >& vkeys ) const {
174 if ( m_ptds ) {
175 m_ptds->keys< T >(vkeys);
176 } else if ( m_pevm ) {
177 m_pevm->keys< T >(vkeys);
178 }
179 }
180
181} // namespace asg
182
183#endif // ASGTOOLS_SGEVENT_ICC