ATLAS Offline Software
Loading...
Searching...
No Matches
SgTEvent.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ASGTOOLS_SGTEVENT_ICC
6#define ASGTOOLS_SGTEVENT_ICC
7
8// System include(s):
9#include <iostream>
10
11#include <CxxUtils/AthUnlikelyMacros.h>
12
13// xAOD include(s):
14#ifdef XAOD_STANDALONE
15# include "xAODRootAccess/TEvent.h"
16# include "xAODRootAccess/TStore.h"
17#endif // XAOD_STANDALONE
18
19namespace asg {
20
21 /// A constant used in the error message printouts
22 static const char* ERROR_SOURCE = "asg::SgTEvent ERROR ";
23
24 template< typename T >
25 bool SgTEvent::contains( const std::string& name ) const {
26
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"
30 << std::endl;
31 return false;
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 SgTEvent::transientContains( const std::string& name ) const {
45
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"
49 << std::endl;
50 return false;
51 }
52
53 // Check if the object is in the transient store:
54 if ( m_ptds && m_ptds->template contains< T >( name ) ) {
55 return true;
56 }
57
58 // Check if the object is in the event store:
59 return m_pevm->template transientContains< T >( name );
60 }
61
62 template< typename T >
63 T* SgTEvent::retrieve( const std::string& name ) const {
64
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"
68 << std::endl;
69 return 0;
70 }
71
72 // Pointer used in the retrieval:
73 T* pobj = 0;
74
75 // Check the transient store first:
76 if( m_ptds && m_ptds->template contains< T >( name ) ) {
77 if( m_ptds->retrieve( pobj, name ).isSuccess() ) {
78 return pobj;
79 } else {
80 return 0;
81 }
82 }
83
84 // If it's not there, then check the event store:
85 if( m_pevm->retrieve( pobj, name ).isSuccess() ) {
86 return pobj;
87 } else {
88 return 0;
89 }
90 }
91
92 template< typename T >
93 StatusCode SgTEvent::retrieve( T*& pobj, const std::string& name ) {
94
95 pobj = retrieve< T >( name );
96 if( ATH_LIKELY( pobj ) ) {
97 return StatusCode::SUCCESS;
98 } else {
99 return StatusCode::FAILURE;
100 }
101 }
102
103 template< typename T >
104 StatusCode SgTEvent::retrieve( const T*& pobj,
105 const std::string& name ) const {
106
107 pobj = retrieve< const T >( name );
108 if( ATH_LIKELY( pobj ) ) {
109 return StatusCode::SUCCESS;
110 } else {
111 return StatusCode::FAILURE;
112 }
113 }
114
115 template< typename T >
116 StatusCode SgTEvent::record( std::unique_ptr<T> pobj, const std::string& name ) {
117
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"
121 << std::endl;
122 return StatusCode::FAILURE;
123 }
124
125 // If a transient store is available, try recording it there:
126 if( m_ptds ) {
127 if( m_ptds->record( std::move( pobj ), name ).isSuccess() ) {
128 return StatusCode::SUCCESS;
129 } else {
130 return StatusCode::FAILURE;
131 }
132 }
133
134 // If not, then let's try with the event store:
135 if( m_pevm->record( std::move( pobj ), name ).isSuccess() ) {
136 return StatusCode::SUCCESS;
137 } else {
138 return StatusCode::FAILURE;
139 }
140 }
141
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 );
146 }
147
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.)
152 ///
153 /// As it's a dummy, function parameters are not described here. They are
154 /// modeled after the <code>StoreGateSvc::overwrite</code> function.
155 ///
156 template< typename T >
157 StatusCode SgTEvent::overwrite( T* /*obj*/, const std::string& /*name*/,
158 bool /*allowMods*/, bool /*resetOnly*/,
159 bool /*noHist*/ ) {
160
161 std::cout << ERROR_SOURCE << "Can't use overwrite in standalone mode"
162 << std::endl;
163 return StatusCode::FAILURE;
164 }
165
166 template< typename T >
167 void SgTEvent::keys( std::vector< std::string >& vkeys ) const {
168 if ( m_ptds ) {
169 m_ptds->keys< T >(vkeys);
170 } else if ( m_pevm ) {
171 m_pevm->keys< T >(vkeys);
172 }
173 }
174
175} // namespace asg
176
177#endif // ASGTOOLS_SGTEVENT_ICC