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