LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ModuleMacros.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_ModuleMacros_h
2 #define art_Framework_Core_ModuleMacros_h
3 // vim: set sw=2 expandtab :
4 
5 //
6 // ModuleMacros
7 //
8 // Defines the macro DEFINE_ART_MODULE(<module_classname>) to be used in
9 // XXX_module.cc to declare art modules (analyzers, filters, producers
10 // and outputs).
11 //
12 // Note: Libraries that include these symbol definitions cannot be
13 // linked into a main program as other libraries are. This is because
14 // the "one definition" rule would be violated.
15 //
16 
24 #include "cetlib/ProvideFilePathMacro.h"
25 #include "fhiclcpp/ParameterSet.h"
27 
28 #include <memory>
29 #include <type_traits>
30 
31 namespace art::detail {
32  using ModuleMaker_t = ModuleBase*(fhicl::ParameterSet const&,
33  ProcessingFrame const&);
36 
37  template <typename T, typename = void>
38  struct config_for_impl {
39  using type = fhicl::ParameterSet;
40  };
41 
42  template <typename T>
43  struct config_for_impl<T, std::void_t<typename T::Parameters>> {
44  using type = typename T::Parameters;
45  };
46 
47  template <typename T>
49 
50  template <typename T>
51  T*
52  make_module(fhicl::ParameterSet const& pset, ProcessingFrame const& frame)
53  {
54  // Reference to avoid copy if ConfigFor<T> is a ParameterSet.
55  ConfigFor<T> const& config{pset};
58  return new T{config};
59  } else {
60  return new T{config, frame};
61  }
62  }
63 }
64 
65 #define DEFINE_ART_MODULE(klass) \
66  extern "C" { \
67  CET_PROVIDE_FILE_PATH() \
68  FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass) \
69  art::ModuleBase* \
70  make_module(fhicl::ParameterSet const& pset, \
71  art::ProcessingFrame const& frame) \
72  { \
73  return art::detail::make_module<klass>(pset, frame); \
74  } \
75  art::ModuleType \
76  moduleType() \
77  { \
78  return art::detail::ModuleTypeDeducer<klass::ModuleType>::value; \
79  } \
80  art::ModuleThreadingType \
81  moduleThreadingType() \
82  { \
83  return art::detail::ModuleThreadingTypeDeducer<klass::ModuleType>::value; \
84  } \
85  }
86 
87 #endif /* art_Framework_Core_ModuleMacros_h */
88 
89 // Local Variables:
90 // mode: c++
91 // End:
ModuleBase *(fhicl::ParameterSet const &, ProcessingFrame const &) ModuleMaker_t
Definition: ModuleMacros.h:33
STL namespace.
T * make_module(fhicl::ParameterSet const &pset, ProcessingFrame const &frame)
Definition: ModuleMacros.h:52
typename config_for_impl< T >::type ConfigFor
Definition: ModuleMacros.h:48
ModuleType( ModuleTypeFunc_t)
Definition: ModuleMacros.h:34
ModuleThreadingType
Definition: ModuleType.h:19
ModuleThreadingType( ModuleThreadingTypeFunc_t)
Definition: ModuleMacros.h:35
ModuleType
Definition: ModuleType.h:11