ATLAS Offline Software
AsgServiceConfig.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 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 
13 #include <AsgServices/AsgService.h>
15 
16 #ifndef XAOD_STANDALONE
17 #include <GaudiKernel/Service.h>
18 #endif
19 
20 namespace 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 
171  ANA_CHECK (configureComponentExpert ("", false));
172  service.setTypeAndName (typeAndName());
173  ANA_CHECK (service.retrieve());
174  ANA_CHECK (dynamic_cast<::AthService*>(&*service)->sysInitialize());
175 
176  ANA_MSG_DEBUG ("Created component of type " << type());
177  return StatusCode::SUCCESS;
178  }
179 
180 #endif
181 
182 }
183 
184 #endif
asg::AsgServiceConfig::~AsgServiceConfig
virtual ~AsgServiceConfig()=default
Virtual destructor, to make PyROOT happy.
asg::AsgComponentConfig
an object that stores the configuration for an AsgComponent and is able to create one from it
Definition: AsgComponentConfig.h:34
asg::AsgServiceConfig::makeService
::StatusCode makeService(ServiceHandle< T > &service) const
AsgService.h
AsgComponentConfig.h
asg
Definition: DataHandleTestTool.h:28
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:324
asg::AsgService
Base class for the dual-use service implementation classes.
Definition: AsgService.h:43
asg::AsgService::initialize
virtual StatusCode initialize()
set up/tear down functions
Definition: AsgService.cxx:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthService
Definition: AthService.h:32
asg::AsgComponentConfig::type
const std::string & type() const noexcept
the type of the component
Definition: AsgComponentConfig.cxx:74
ServiceHandle.h
asg::AsgServiceConfig
an object that can create a AsgService
Definition: AsgServiceConfig.h:25
asg::AsgComponentConfig::configureComponentExpert
StatusCode configureComponentExpert(const std::string &prefix, bool nestedNames) const
add component configuration to configuration service (expert only)
Definition: AsgComponentConfig.cxx:365
asg::AsgComponentConfig::typeAndName
std::string typeAndName() const
get type and name at the same time
Definition: AsgComponentConfig.cxx:106
asg::AsgServiceConfig::makeService
::StatusCode makeService(std::shared_ptr< T > &service) const
make a service with the given configuration
asg::AsgServiceConfig::AsgServiceConfig
AsgServiceConfig()=default
standard constructor
ServiceHandle
Definition: ClusterMakerTool.h:37
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288