2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
5 #ifndef ASGTOOLS_SGTEVENTMETA_ICC
6 #define ASGTOOLS_SGTEVENTMETA_ICC
12 #ifdef XAOD_STANDALONE
13 # include "xAODRootAccess/TEvent.h"
14 #endif // XAOD_STANDALONE
18 /// A constant used in the error message printouts
19 static const char* META_ERROR_SOURCE = "asg::SgTEventMeta ERROR ";
21 template< typename T >
22 bool SgTEventMeta::contains( const std::string& name ) {
24 // Make sure the object is initialised:
25 if( ( ! m_event ) && initialize().isFailure() ) {
26 std::cout << META_ERROR_SOURCE << "Couldn't initialise the tool"
31 // Decide which function to call:
32 if( m_type == InputStore ) {
33 return m_event->template containsMeta< T >( name );
34 } else if( m_type == OutputStore ) {
35 return m_event->template transientContainsMeta< T >( name );
37 std::cout << META_ERROR_SOURCE << "Unknown store type (" << m_type
38 << ") defined" << std::endl;
43 template< typename T >
44 bool SgTEventMeta::transientContains( const std::string& name ) const {
46 // Make sure the object is initialised:
47 if( ( ! m_event ) && initialize().isFailure() ) {
48 std::cout << META_ERROR_SOURCE << "Couldn't initialise the tool"
54 return m_event->template transientContainsMeta< T >( name );
57 template< typename T >
58 StatusCode SgTEventMeta::retrieve( T*& obj, const std::string& name ) {
60 // Make sure the object is initialised:
61 if( ( ! m_event ) && initialize().isFailure() ) {
62 std::cout << META_ERROR_SOURCE << "Couldn't initialise the tool"
64 return StatusCode::FAILURE;
67 // We can only non-const retrieve from the output store:
68 if( m_type == InputStore ) {
69 std::cout << META_ERROR_SOURCE << "It's not possible to non-const "
70 << "retrieve objects from the input metadata store"
72 return StatusCode::FAILURE;
76 if( ! m_event->retrieveMetaOutput( obj, name ).isSuccess() ) {
77 std::cout << META_ERROR_SOURCE << "Failed to retrieve output metadata "
78 << "object with name " << name << std::endl;
79 return StatusCode::FAILURE;
83 return StatusCode::SUCCESS;
86 template< typename T >
87 StatusCode SgTEventMeta::retrieve( const T*& obj, const std::string& name ) {
89 // Make sure the object is initialised:
90 if( ( ! m_event ) && initialize().isFailure() ) {
91 std::cout << META_ERROR_SOURCE << "Couldn't initialise the tool"
93 return StatusCode::FAILURE;
96 // Decide which function to call:
97 if( m_type == InputStore ) {
99 if( ! m_event->retrieveMetaInput( obj, name ).isSuccess() ) {
100 std::cout << META_ERROR_SOURCE << "Failed to retrieve input "
101 << "metadata object with name " << name << std::endl;
102 return StatusCode::FAILURE;
104 } else if( m_type == OutputStore ) {
106 if( ! m_event->retrieveMetaOutput( obj, name ).isSuccess() ) {
107 std::cout << META_ERROR_SOURCE << "Failed to retrieve output "
108 << "metadata object with name " << name << std::endl;
109 return StatusCode::FAILURE;
112 std::cout << META_ERROR_SOURCE << "Unknown store type (" << m_type
113 << ") defined" << std::endl;
114 return StatusCode::FAILURE;
118 return StatusCode::SUCCESS;
121 template< typename T >
122 StatusCode SgTEventMeta::record( std::unique_ptr<T> obj, const std::string& name ) {
124 // Make sure the object is initialised:
125 if( ( ! m_event ) && initialize().isFailure() ) {
126 std::cout << META_ERROR_SOURCE << "Couldn't initialise the tool"
128 return StatusCode::FAILURE;
131 // We can't record stuff into the input store:
132 if( m_type == InputStore ) {
133 std::cout << META_ERROR_SOURCE << "It's not possible to record "
134 << "objects into the input metadata store" << std::endl;
135 return StatusCode::FAILURE;
139 if( ! m_event->recordMeta( std::move( obj ), name ).isSuccess() ) {
140 std::cout << META_ERROR_SOURCE << "Failed to record output metadata "
141 << "object with name " << name << std::endl;
142 return StatusCode::FAILURE;
146 return StatusCode::SUCCESS;
149 template< typename T >
150 StatusCode SgTEventMeta::record( T* obj, const std::string& name ) {
151 // this is the legacy interface, forwarding it to new one
152 return record( std::unique_ptr<T>(obj), name );
155 template< typename T >
156 void SgTEventMeta::keys( std::vector< std::string >& vkeys ) const {
158 m_event->keys<T>(vkeys, true); // true tells TEvent to scan metadata
163 #endif // ASGTOOLS_SGTEVENTMETA_ICC