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