ATLAS Offline Software
Loading...
Searching...
No Matches
AsgComponentFactories.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#ifndef ASG_TOOLS__ASG_COMPONENT_FACTORIES_H
8#define ASG_TOOLS__ASG_COMPONENT_FACTORIES_H
9
12#include <functional>
13#include <memory>
14
15namespace EL
16{
17 class AnaAlgorithm;
19 namespace Detail
20 {
21 class Module;
22 }
23}
24
25namespace asg
26{
27 class AsgComponent;
28 class AsgService;
29 class AsgTool;
30
31#ifdef XAOD_STANDALONE
32
34 StatusCode registerComponentFactory (const std::string& type, const std::function<std::unique_ptr<AsgComponent>(const std::string& name)>& factory);
35
37 const std::function<std::unique_ptr<AsgComponent>(const std::string& name)> *getComponentFactory (const std::string& type);
38
39
45 template<typename T> StatusCode registerToolFactory (const std::string& type)
46 {
47 return registerComponentFactory (type, [] (const std::string& name) -> std::unique_ptr<AsgComponent> { return std::make_unique<T> (name); });
48 }
49 template<typename T> StatusCode registerServiceFactory (const std::string& type)
50 {
51 return registerComponentFactory (type, [] (const std::string& name) -> std::unique_ptr<AsgComponent> { return std::make_unique<T> (name, nullptr); });
52 }
53 template<typename T> StatusCode registerAlgorithmFactory (const std::string& type)
54 {
55 return registerComponentFactory (type, [] (const std::string& name) -> std::unique_ptr<AsgComponent> { return std::make_unique<T> (name, nullptr); });
56 }
57 template<typename T> StatusCode registerELModuleFactory (const std::string& type)
58 {
59 return registerComponentFactory (type, [] (const std::string& name) -> std::unique_ptr<AsgComponent> { return std::make_unique<T> (name); });
60 }
62
65 template<typename T> requires std::is_base_of_v<AsgTool,T>
66 StatusCode registerGenericComponentFactory (const std::string& type)
67 {
68 return registerToolFactory<T> (type);
69 }
70 template<typename T> requires std::is_base_of_v<EL::AnaAlgorithm,T> || std::is_base_of_v<EL::AnaReentrantAlgorithm,T>
71 StatusCode registerGenericComponentFactory (const std::string& type)
72 {
73 return registerAlgorithmFactory<T> (type);
74 }
75 template<typename T> requires std::is_base_of_v<AsgService,T>
76 StatusCode registerGenericComponentFactory (const std::string& type)
77 {
78 return registerServiceFactory<T> (type);
79 }
80 template<typename T> requires std::is_base_of_v<EL::Detail::Module,T>
81 StatusCode registerGenericComponentFactory (const std::string& type)
82 {
83 return registerELModuleFactory<T> (type);
84 }
86
91 template<typename T> class AutoRegisterComponentFactory final
92 {
93 public:
94 AutoRegisterComponentFactory (const std::string& name)
95 {
96 using namespace asg::msgComponentConfig;
97 if (!asg::registerGenericComponentFactory<T>(name).isSuccess())
98 {
99 ANA_MSG_FATAL("Failed to register component factory for " << name);
100 std::terminate();
101 } else
102 {
103 ANA_MSG_DEBUG("Registered component factory for " << name);
104 }
105 }
106 };
107 #define DECLARE_COMPONENT_JOIN(x,y) DECLARE_COMPONENT_JOIN2(x,y)
108 #define DECLARE_COMPONENT_JOIN2(x,y) x ## y
109 #define DECLARE_COMPONENT(TYPE) \
110 namespace { \
111 asg::AutoRegisterComponentFactory<TYPE> DECLARE_COMPONENT_JOIN(autoRegisterComponent,__LINE__) (#TYPE); \
112 }
113
115 std::vector<std::string> getLoadedComponentFactoryTypes ();
116
118 void loadComponentFactoryModule (const std::string& moduleName, const std::string& modulePath = "");
119
121 void loadComponentFactoryMap (const std::string& path);
122
123#endif
124}
125
126#endif
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
the (new) base class for EventLoop algorithms
the base class for EventLoop reentrant algorithms
the base class for EventLoop instrumentation module
This module defines the arguments passed from the BATCH driver to the BATCH worker.
::StatusCode StatusCode
StatusCode definition for legacy code.