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