ATLAS Offline Software
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 
15 namespace EL
16 {
17  class AnaAlgorithm;
19 }
20 
21 namespace asg
22 {
23  class AsgComponent;
24  class AsgService;
25  class AsgTool;
26 
27 #ifdef XAOD_STANDALONE
28 
30  StatusCode registerComponentFactory (const std::string& type, const std::function<std::unique_ptr<AsgComponent>(const std::string& name)>& factory);
31 
33  const std::function<std::unique_ptr<AsgComponent>(const std::string& name)> *getComponentFactory (const std::string& type);
34 
35 
41  template<typename T> StatusCode registerToolFactory (const std::string& type)
42  {
43  return registerComponentFactory (type, [] (const std::string& name) -> std::unique_ptr<AsgComponent> { return std::make_unique<T> (name); });
44  }
45  template<typename T> StatusCode registerServiceFactory (const std::string& type)
46  {
47  return registerComponentFactory (type, [] (const std::string& name) -> std::unique_ptr<AsgComponent> { return std::make_unique<T> (name, nullptr); });
48  }
49  template<typename T> StatusCode registerAlgorithmFactory (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  }
54 
57  template<typename T> requires std::is_base_of_v<AsgTool,T>
58  StatusCode registerGenericComponentFactory (const std::string& type)
59  {
60  return registerToolFactory<T> (type);
61  }
62  template<typename T> requires std::is_base_of_v<EL::AnaAlgorithm,T> || std::is_base_of_v<EL::AnaReentrantAlgorithm,T>
63  StatusCode registerGenericComponentFactory (const std::string& type)
64  {
65  return registerAlgorithmFactory<T> (type);
66  }
67  template<typename T> requires std::is_base_of_v<AsgService,T>
68  StatusCode registerGenericComponentFactory (const std::string& type)
69  {
70  return registerServiceFactory<T> (type);
71  }
73 
78  template<typename T> class AutoRegisterComponentFactory final
79  {
80  public:
81  AutoRegisterComponentFactory (const std::string& name)
82  {
83  using namespace asg::msgComponentConfig;
84  if (!asg::registerGenericComponentFactory<T>(name).isSuccess())
85  {
86  ANA_MSG_FATAL("Failed to register component factory for " << name);
87  std::terminate();
88  } else
89  {
90  ANA_MSG_DEBUG("Registered component factory for " << name);
91  }
92  }
93  };
94  #define DECLARE_COMPONENT_JOIN(x,y) DECLARE_COMPONENT_JOIN2(x,y)
95  #define DECLARE_COMPONENT_JOIN2(x,y) x ## y
96  #define DECLARE_COMPONENT(TYPE) \
97  namespace { \
98  asg::AutoRegisterComponentFactory<TYPE> DECLARE_COMPONENT_JOIN(autoRegisterComponent,__LINE__) (#TYPE); \
99  }
100 
102  std::vector<std::string> getLoadedComponentFactoryTypes ();
103 
105  void loadComponentFactoryModule (const std::string& moduleName, const std::string& modulePath = "");
106 
108  void loadComponentFactoryMap (const std::string& path);
109 
110 #endif
111 }
112 
113 #endif
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
asg
Definition: DataHandleTestTool.h:28
requires
requires requires()
This specialization is used for classes deriving from DataObject.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:68
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
EL::AnaAlgorithm
the (new) base class for EventLoop algorithms
Definition: AnaAlgorithm.h:73
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AsgComponentFactories.h:16
columnar::final
CM final
Definition: ColumnAccessor.h:106
ANA_MSG_FATAL
#define ANA_MSG_FATAL(xmsg)
Macro printing fatal messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:296
StatusCode.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
EL::AnaReentrantAlgorithm
the base class for EventLoop reentrant algorithms
Definition: AnaReentrantAlgorithm.h:51
MessageCheckAsgTools.h
ANA_MSG_DEBUG
#define ANA_MSG_DEBUG(xmsg)
Macro printing debug messages.
Definition: Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:288