ATLAS Offline Software
TVirtualEvent.icc
Go to the documentation of this file.
1 // Dear emacs, this is -*- c++ -*-
2 //
3 // Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
4 //
5 #ifndef XAODROOTACCESSINTERFACES_TVIRTUALEVENT_ICC
6 #define XAODROOTACCESSINTERFACES_TVIRTUALEVENT_ICC
7 
8 #include "AthContainers/normalizedTypeinfoName.h"
9 
10 // ROOT include(s):
11 #include <TError.h>
12 
13 namespace xAOD {
14 
15  /// This is the function used by all the smart pointers to get access
16  /// to objects in the event.
17  ///
18  /// @param obj The pointer that should be set [output]
19  /// @param key The hashed key of the object to retrieve
20  /// @param silent When set to <code>true</code>, failure is handled silently
21  /// @returns <code>true</code> if the operation was successful,
22  /// <code>false</code> otherwise
23  ///
24  template< typename T >
25  bool TVirtualEvent::retrieve( const T*& obj, sgkey_t key, bool silent ) {
26 
27  // Look among the output objects first:
28  const void* result = getOutputObject( key, typeid( T ) );
29  // Check if it succeeded:
30  if( ! result ) {
31  // Try the input then:
32  result = getInputObject( key, typeid( T ), silent );
33  if( ! result ) {
34  if( ! silent ) {
35  ::Warning( "xAOD::TVirtualEvent::retrieve",
36  "Couldn't retrieve %s/0x%08x",
37  typeid( T ).name(), key );
38  }
39  return false;
40  }
41  }
42 
43  // If we were successful:
44  obj = reinterpret_cast< const T* >( result );
45  return true;
46  }
47 
48  /// This is a convenience function for human users for getting access to
49  /// an existing object, using a string key instead of a hashed identifier.
50  ///
51  /// Internally it just creates a hash from the key, and perform the retrieve
52  /// with that.
53  ///
54  /// @param obj The pointer that should be set [output]
55  /// @param key The key of the object to retrieve
56  /// @returns <code>true</code> if the operation was successful,
57  /// <code>false</code> otherwise
58  ///
59  template< typename T >
60  bool TVirtualEvent::retrieve( const T*& obj, const std::string& key,
61  bool silent ) {
62 
63  return retrieve( obj, getHash( key ), silent );
64  }
65 
66  template< typename T >
67  void TVirtualEvent::keys( std::vector< std::string >& vkeys,
68  bool metadata ) const {
69  getNames( SG::normalizedTypeinfoName( typeid( T ) ), vkeys, metadata);
70  }
71 
72 } // namespace xAOD
73 
74 #endif // XAODROOTACCESSINTERFACES_TVIRTUALEVENT_ICC