ServiceMacros.h
Go to the documentation of this file.
1 #ifndef art_Framework_Services_Registry_ServiceMacros_h
2 #define art_Framework_Services_Registry_ServiceMacros_h
3 
4 //
5 // ServiceMacros - define the macros used to declare and define an art
6 // service or an interface to be implemented by an art service.
7 //
8 // Notes:
9 //
10 // * Unlike modules, services require macro invocations in their
11 // headers *and* their compile units.
12 //
13 // * In order to declare your service, you must specify your service
14 // with a scope value of LEGACY, or SHARED as follows:
15 //
16 // * LEGACY services are unaware of multi-threaded operation, and
17 // configuration of such a service precludes multi-threaded
18 // operation. Such services must have a constructor:
19 //
20 // MyService(fhicl::ParameterSet const&,
21 // art::ActivityRegistry&);
22 //
23 // * SHARED services are expected to have the same signature as LEGACY
24 // services, but warrant additionally that it is safe to call their
25 // methods (including callbacks) from multiple threads at the same
26 // time. A global service may register for callbacks for per-
27 // schedule signals (however the same callback must be registered
28 // for all schedules per the ActivityRegistry interface).
29 //
30 // * PER_SCHEDULE services must provide a signature:
31 //
32 // MyService(fhicl::ParameterSet const&,
33 // art::ActivityRegistry&,
34 // art::ScheduleID);
35 //
36 // Note that Per-schedule services may register for global callbacks,
37 // but there will be n unique instances of the service (and
38 // therefore unique callbacks), one for each schedule.
39 ////////////////////////////////////////////////////////////////////////
40 //
41 // User-callable macros:
42 //
43 // DECLARE_ART_SERVICE(svc, scope)
44 // Declare (in the header) an art service of type <svc> with scope
45 // (see above).
46 //
47 // DEFINE_ART_SERVICE(svc)
48 // Define (in MyService_service.cc) the service declared with
49 // DECLARE_ART_SERVICE.
50 //
51 ////////////////////////////////////
52 // DECLARE_ART_SERVICE_INTERFACE(iface, scope)
53 // Declare an interface to be used by services (must be invoked in the
54 // header for the interface, *not* any implementations thereof).
55 //
56 ////////////////////////////////////
57 // DECLARE_ART_SERVICE_INTERFACE_IMPL(svc, iface, scope)
58 // Declare (in the header) an art service of type <svc> implementing
59 // (inheriting from) interface <iface>, with scope <scope>.
60 //
61 // DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
62 // Define an art service of type <svc> implementing (inheriting from)
63 // interface <iface>, with scope <scope>.
64 //
65 // Some services closely integrated with art may call:
66 //
67 // DECLARE_ART_SYSTEM_SERVICE(svc, scope);
68 //
69 // and must be constructed by the art system rather than automatically
70 // as part of the service initialization process. A DEFINE... macro call
71 // is not necessary in this case.
72 //
73 
79 
80 // User service macros, Service must provide a constructor with the
81 // correct signature (see notes above).
82 
83 // Multi-schedule-aware service declarations.
84 
85 // Declare and define a service.
86 #define DECLARE_ART_SERVICE(svc, scope) ART_DETAIL_DECLARE_SERVICE(svc, scope)
87 
88 #define DEFINE_ART_SERVICE(svc) \
89  DEFINE_ART_SH_CREATE(svc) \
90  CET_PROVIDE_FILE_PATH() \
91  FHICL_PROVIDE_ALLOWED_CONFIGURATION(svc)
92 
93 // Declare an interface.
94 #define DECLARE_ART_SERVICE_INTERFACE(svc, scope) \
95  static_assert( \
96  art::detail::handle_allowed_v<svc>, \
97  "\n\nart-error: You cannot create a service interface for type " \
98  "'" ART_DETAIL_STRINGIZED_TYPE(svc) "'.\n" \
99  " There is a base class of " \
100  "this type for which a ServiceHandle " \
101  "cannot\n" \
102  " be constructed. Please " \
103  "contact artists@fnal.gov for " \
104  "guidance.\n"); \
105  ART_DETAIL_DECLARE_SERVICE_INTERFACE(svc, scope)
106 
107 // Declare and define a service implementing an interface.
108 #define DECLARE_ART_SERVICE_INTERFACE_IMPL(svc, iface, scope) \
109  static_assert( \
110  art::detail::handle_allowed_v<svc>, \
111  "\n\nart-error: You cannot create a service implementation for type " \
112  "'" ART_DETAIL_STRINGIZED_TYPE(svc) "'.\n" \
113  " There is a base class of " \
114  "this type for which a ServiceHandle " \
115  "cannot\n" \
116  " be constructed. Please " \
117  "contact artists@fnal.gov for " \
118  "guidance.\n"); \
119  ART_DETAIL_DECLARE_SERVICE_INTERFACE_IMPL(svc, iface, scope)
120 
121 #define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface) \
122  DEFINE_ART_SERVICE(svc) \
123  DEFINE_ART_SIH_CREATE(iface)
124 
125 // System service macros (requires support code in Event Processor)
126 // since they have no maker function.
127 
128 #define DECLARE_ART_SYSTEM_SERVICE(svc, scope) \
129  ART_DETAIL_DECLARE_SYSTEM_SERVICE(svc, scope)
130 
131 //
132 // Note that it makes very little sense to have a system service
133 // implementing an interface since it has to be constructed and
134 // added to the service cache list with no way to define the maker
135 // and converter functions. One could conceivably do a second add
136 // for the interface, but one would have to add interface to
137 // ServicesManager (and ServicesManager::Cache). If we ever need it,
138 // it should be relatively trivial.
139 //
140 
141 #endif /* art_Framework_Services_Registry_ServiceMacros_h */
142 
143 // Local Variables:
144 // mode: c++
145 // End: