ATLAS Offline Software
Loading...
Searching...
No Matches
AsgComponentConfig.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5/// @author Nils Krumnack
6
7
8
9//
10// includes
11//
12
13#include <AsgTools/MessageCheckAsgTools.h>
14
15#ifdef XAOD_STANDALONE
16#include <AsgTools/AsgComponent.h>
17#include <AsgTools/TProperty.h>
18#endif
19
20//
21// method implementations
22//
23
24namespace asg
25{
26#ifdef XAOD_STANDALONE
27 // This template specialization for `AsgComponent` contains most of
28 // the actual logic for creating/configuring components, allowing
29 // the templated version of the function to rely on this one.
30 template<> StatusCode AsgComponentConfig ::
31 makeComponentExpert<AsgComponent> (std::unique_ptr<AsgComponent>& component,
32 const std::string& newCommand,
33 bool nestedNames, std::string prefix) const;
34
35
36
37 template<typename T> StatusCode AsgComponentConfig ::
38 makeComponentExpert (std::unique_ptr<T>& component,
39 const std::string& newCommand,
40 bool nestedNames, std::string prefix) const
41 {
42 using namespace msgComponentConfig;
43
44 // for `AsgComponent` we have a non-templated implementation
45 std::unique_ptr<AsgComponent> baseComponent;
46 if (makeComponentExpert (baseComponent, newCommand, nestedNames, std::move (prefix)).isFailure())
47 return StatusCode::FAILURE;
48
49 // note: I delay releasing the baseComponent after I check the
50 // `dynamic_cast` succeeded, this way it is held temporarily by
51 // two smart pointers, but it simplifies the code.
52 component.reset (dynamic_cast<T*>(baseComponent.get()));
53 if (component == nullptr)
54 {
55 ANA_MSG_ERROR ("component " << type() << "/" << name() << " not of required type");
56 return StatusCode::FAILURE;
57 }
58 baseComponent.release();
59
60 return StatusCode::SUCCESS;
61 }
62#endif
63
64
65
66 template<typename T> StatusCode AsgComponentConfig ::
67 setProperty (const std::string& name, const T& value)
68 {
69 using namespace asg::msgProperty;
70 std::string valueString;
71
72#ifdef XAOD_STANDALONE
73 ANA_CHECK (asg::detail::GetCastStringHelper<T>::get (value, valueString));
74#else
75 valueString = Gaudi::Utils::toString (value);
76#endif
77
78 setPropertyFromString (name, std::move (valueString));
79 return StatusCode::SUCCESS;
80 }
81
82
83
84 template<typename T> StatusCode AsgComponentConfig ::
85 setProperty (const std::string& name, const Gaudi::Property<T>& value)
86 {
87 return setProperty (name, value.value());
88 }
89}