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 
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&);
34  using WorkerFromModuleMaker_t = Worker*(std::shared_ptr<ModuleBase>,
35  ModuleDescription const&,
36  WorkerParams const&);
37  using WorkerMaker_t = Worker*(WorkerParams const&, ModuleDescription const&);
40 
41  template <typename T, typename = void>
42  struct config_impl {
43  using type = fhicl::ParameterSet;
44  };
45 
46  template <typename T>
47  struct config_impl<T, std::void_t<typename T::Parameters>> {
48  using type = typename T::Parameters;
49  };
50 
51  template <typename T>
52  using Config = typename config_impl<T>::type;
53 
54  template <typename T, typename Config>
55  T*
56  make_module(Config const& config, ProcessingFrame const& frame)
57  {
60  return new T{config};
61  } else {
62  return new T{config, frame};
63  }
64  }
65 }
66 
67 #define DEFINE_ART_MODULE(klass) \
68  extern "C" { \
69  CET_PROVIDE_FILE_PATH() \
70  FHICL_PROVIDE_ALLOWED_CONFIGURATION(klass) \
71  art::ModuleBase* \
72  make_module(fhicl::ParameterSet const& pset, \
73  art::ProcessingFrame const& frame) \
74  { \
75  /* Reference below to avoid copy if Config<klass> is a ParameterSet. */ \
76  art::detail::Config<klass> const& config{pset}; \
77  return art::detail::make_module<klass>(config, frame); \
78  } \
79  art::Worker* \
80  make_worker_from_module(std::shared_ptr<art::ModuleBase> mod, \
81  art::ModuleDescription const& md, \
82  art::WorkerParams const& wp) \
83  { \
84  return new klass::WorkerType( \
85  std::dynamic_pointer_cast<klass::ModuleType>(mod), md, wp); \
86  } \
87  art::ModuleType \
88  moduleType() \
89  { \
90  return art::detail::ModuleTypeDeducer<klass::ModuleType>::value; \
91  } \
92  art::ModuleThreadingType \
93  moduleThreadingType() \
94  { \
95  return art::detail::ModuleThreadingTypeDeducer<klass::ModuleType>::value; \
96  } \
97  }
98 
99 #endif /* art_Framework_Core_ModuleMacros_h */
100 
101 // Local Variables:
102 // mode: c++
103 // End:
ModuleBase *(fhicl::ParameterSet const &, ProcessingFrame const &) ModuleMaker_t
Definition: ModuleMacros.h:33
STL namespace.
Worker *(WorkerParams const &, ModuleDescription const &) WorkerMaker_t
Definition: ModuleMacros.h:37
Definition: config.h:291
static Config * config
Definition: config.cpp:1054
ModuleType( ModuleTypeFunc_t)
Definition: ModuleMacros.h:38
T * make_module(Config const &config, ProcessingFrame const &frame)
Definition: ModuleMacros.h:56
ModuleThreadingType
Definition: ModuleType.h:19
ModuleThreadingType( ModuleThreadingTypeFunc_t)
Definition: ModuleMacros.h:39
Worker *(std::shared_ptr< ModuleBase >, ModuleDescription const &, WorkerParams const &) WorkerFromModuleMaker_t
Definition: ModuleMacros.h:36
ModuleType
Definition: ModuleType.h:11