LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ToolMacros.h
Go to the documentation of this file.
1 #ifndef art_Utilities_ToolMacros_h
2 #define art_Utilities_ToolMacros_h
3 
5 // ToolMacros
6 //
7 // Defines the macro DEFINE_ART_TOOL(<tool_classname>) to be used in
8 // XXX_tool.cc to declare art tools.
9 //
10 // Note: Libraries that include these symbol definitions cannot be
11 // linked into a main program as other libraries are. This is because
12 // the "one definition" rule would be violated.
13 //
15 
16 #include "cetlib/PluginTypeDeducer.h"
17 #include "cetlib/ProvideFilePathMacro.h"
18 #include "cetlib/compiler_macros.h"
19 #include "fhiclcpp/ParameterSet.h"
21 #include "fhiclcpp/types/Atom.h"
22 
23 #include <memory>
24 #include <string>
25 #include <type_traits>
26 
27 namespace art::detail {
28  struct ToolConfig {
30  };
31 }
32 
33 #define ART_PROVIDE_ALLOWED_CONFIGURATION_FUNCTION_TOOL() \
34  std::unique_ptr<fhicl::ConfigurationTable> allowed_configuration( \
35  std::string const& name) \
36  { \
37  return std::make_unique<fhicl::WrappedTable<art::detail::ToolConfig>>( \
38  fhicl::Name{name}); \
39  }
40 
41 // Produce the injected functions
42 #define DEFINE_ART_CLASS_TOOL(tool) \
43  EXTERN_C_FUNC_DECLARE_START \
44  CET_PROVIDE_FILE_PATH() \
45  FHICL_PROVIDE_ALLOWED_CONFIGURATION(tool) \
46  std::string toolType() \
47  { \
48  return "class"; \
49  } \
50  std::enable_if_t<std::is_class<tool>::value, std::unique_ptr<tool>> \
51  makeTool(fhicl::ParameterSet const& pset) \
52  { \
53  return std::make_unique<tool>(pset); \
54  } \
55  EXTERN_C_FUNC_DECLARE_END
56 
57 #define DEFINE_ART_FUNCTION_TOOL(tool, type) \
58  EXTERN_C_FUNC_DECLARE_START \
59  CET_PROVIDE_FILE_PATH() \
60  ART_PROVIDE_ALLOWED_CONFIGURATION_FUNCTION_TOOL() \
61  std::string toolType() \
62  { \
63  return type; \
64  } \
65  auto toolFunction = tool; \
66  EXTERN_C_FUNC_DECLARE_END
67 
68 #endif /* art_Utilities_ToolMacros_h */
69 
70 // Local Variables:
71 // mode: c++
72 // End: