ATLAS Offline Software
AsgTool.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_ASGTOOL_ICC
6 #define ASGTOOLS_ASGTOOL_ICC
7 
8 #ifdef XAOD_STANDALONE
9 
10 // Local include(s):
11 #include "AsgTools/PropertyMgr.h"
12 #include "AsgTools/TProperty.h"
13 
14 namespace asg {
15 
16  template< class T >
17  const T* AsgTool::getProperty( const std::string& name ) const {
18 
19  // Get the property object (if it exists):
20  const Property* prop = m_properties->getProperty( name );
21  if( ! prop ) {
22  ATH_MSG_WARNING( "Property with name \"" << name << "\" not found" );
23  return 0;
24  }
25 
26  // Try to cast it to the required type:
27  const TProperty< T >* tprop =
28  dynamic_cast< const TProperty< T >* >( prop );
29  if( ! tprop ) {
30  ATH_MSG_WARNING( "Property \"" << name << "\" is of type: "
31  << prop->typeName() );
32  return 0;
33  }
34 
35  // Okay, we succeeded:
36  return tprop->pointer();
37  }
38 
39 } // namespace asg
40 
41 #endif // XAOD_STANDALONE
42 
43 #ifndef XAOD_STANDALONE
44 
45 // Gaudi/Athena include(s):
46 #include "Gaudi/Property.h"
47 #include "GaudiKernel/System.h"
48 
49 
50 namespace asg {
51 
52  template< class T >
53  const T* AsgTool::getProperty( const std::string& name ) const {
54 
55  // Check if the property exists.
56  if( ! hasProperty( name ) ) {
57  ATH_MSG_WARNING( "Property with name \"" << name << "\" not found" );
58  return nullptr;
59  }
60 
61  // Get the property object.
62  const auto* prop = property( name );
63  if( prop == nullptr ) {
64  ATH_MSG_FATAL( "Internal coding error detected!" );
65  return nullptr;
66  }
67 
68  // Cast it to the underlying type.
69  const Gaudi::Property<T&>* tprop =
70  dynamic_cast< const Gaudi::Property<T&>* >( prop );
71  if( ! tprop ) {
72  ATH_MSG_WARNING( "Property \"" << name << "\" is of type: "
73  << System::typeinfoName( *( prop->type_info() ) ) );
74  return nullptr;
75  }
76 
77 
78  // Okay, we succeeded:
79  return &( tprop->value() );
80  }
81 
82 } // namespace asg
83 
84 #endif // not XAOD_STANDALONE
85 
86 #endif // not ASGTOOLS_ASGTOOL_ICC