ATLAS Offline Software
Loading...
Searching...
No Matches
AsgServiceConfig.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9#ifndef ASG_SERVICES_ASG_SERVICE_CONFIG_H
10#define ASG_SERVICES_ASG_SERVICE_CONFIG_H
11
15
16#ifndef XAOD_STANDALONE
17#include <GaudiKernel/Service.h>
18#endif
19
20namespace asg
21{
23
25 {
26 //
27 // public interface
28 //
29
35 public:
36 AsgServiceConfig () = default;
37
38
44 public:
45 explicit AsgServiceConfig (const std::string& val_typeAndName);
46
47
53 public:
54 explicit AsgServiceConfig (const AsgComponentConfig& val_config);
55
56
62 public:
63 virtual ~AsgServiceConfig () = default;
64
65
93 public:
94 template<typename T> ::StatusCode
95 makeService (std::shared_ptr<T>& service) const;
96 template<typename T> ::StatusCode
97 makeService (ServiceHandle<T>& service) const;
99
100
101
102 //
103 // private interface
104 //
105 };
106
107
108
109 //
110 // template methods
111 //
112
113#ifdef XAOD_STANDALONE
114
115 template<typename T> ::StatusCode AsgServiceConfig ::
116 makeService (std::shared_ptr<T>& service) const
117 {
118 using namespace msgComponentConfig;
119
120 std::unique_ptr<T> myservice;
121 ANA_CHECK (makeComponentExpert (myservice, "new %1% (\"%2%\", nullptr)", false, ""));
122 AsgService *asgService = dynamic_cast<AsgService*>(myservice.get());
123 ANA_CHECK (asgService->initialize());
124
125 service = std::move (myservice);
126 ANA_CHECK (ServiceStore::put (service));
127
128 ANA_MSG_DEBUG ("Created component of type " << type());
129 return StatusCode::SUCCESS;
130 }
131
132 template<typename T> ::StatusCode AsgServiceConfig ::
133 makeService (ServiceHandle<T>& service) const
134 {
135 using namespace msgComponentConfig;
136
137 std::shared_ptr<T> myservice;
138 ANA_CHECK (makeService (myservice));
139 service = ServiceHandle (myservice, service.parentName());
140 return StatusCode::SUCCESS;
141 }
142
143#else
144
145 template<typename T> ::StatusCode AsgServiceConfig ::
146 makeService (std::shared_ptr<T>& service) const
147 {
148 using namespace msgComponentConfig;
149
150 ServiceHandle<T> serviceHandle (typeAndName(), "AsgServiceConfig");
151 ANA_CHECK (makeService (serviceHandle));
152
153 // This creates an unmanaged shared pointer, i.e. a pointer that
154 // doesn't actually own the pointed to object, it will neither
155 // guarantee to keep the object around until its own destruction,
156 // nor will it ever trigger a destruction of the object on its own
157 // destruction. Since the athena framework will keep the services
158 // around until the end of the job, that ought to be safe if used
159 // as advertised.
160 service = std::shared_ptr<T> (std::shared_ptr<void>(), &*serviceHandle);
161
162 ANA_MSG_DEBUG ("Created component of type " << type());
163 return StatusCode::SUCCESS;
164 }
165
166 template<typename T> ::StatusCode AsgServiceConfig ::
167 makeService (ServiceHandle<T>& service) const
168 {
169 using namespace msgComponentConfig;
170
172 service.setTypeAndName (typeAndName());
173 ANA_CHECK (service.retrieve());
174 if (auto svc = dynamic_cast<::AthService*> (service.get())) {
175 ANA_CHECK (svc->sysInitialize());
176 }
177 else {
178 ANA_MSG_ERROR ("Cannot cast to AthService");
179 return StatusCode::FAILURE;
180 }
181
182 ANA_MSG_DEBUG ("Created component of type " << type());
183 return StatusCode::SUCCESS;
184 }
185
186#endif
187
188}
189
190#endif
#define ANA_MSG_ERROR(xmsg)
Macro printing error messages.
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
an object that stores the configuration for an AsgComponent and is able to create one from it
std::string typeAndName() const
get type and name at the same time
const std::string & type() const noexcept
the type of the component
StatusCode configureComponentExpert(const std::string &prefix, bool nestedNames) const
add component configuration to configuration service (expert only)
AsgComponentConfig()=default
standard constructor
::StatusCode makeService(ServiceHandle< T > &service) const
AsgServiceConfig()=default
standard constructor
::StatusCode makeService(std::shared_ptr< T > &service) const
make a service with the given configuration
virtual ~AsgServiceConfig()=default
Virtual destructor, to make PyROOT happy.
Base class for the dual-use service implementation classes.
Definition AsgService.h:43
virtual StatusCode initialize()
set up/tear down functions