Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
art
art
Framework
Services
Registry
ServiceHandle.h
Go to the documentation of this file.
1
#ifndef art_Framework_Services_Registry_ServiceHandle_h
2
#define art_Framework_Services_Registry_ServiceHandle_h
3
// vim: set sw=2 expandtab :
4
5
// =======================================================================
6
// ServiceHandle
7
//
8
// Smart pointer used to give easy access to Services.
9
//
10
// Note invocation only requires one template argument, but the
11
// constructor will require zero or one arguments depending on the scope
12
// of the service (LEGACY, SHARED).
13
//
14
// Technical notes:
15
//
16
// Since ServiceHelper<T> instantiations correspond to
17
// specializations created by macro calls, only a template argument
18
// 'T' that is non-const qualified will match any specialization.
19
// However, const-only access to a service can be provided via
20
// ServiceHandle<MyService const> as long as the const-ness of the
21
// template argument is stripped (via std::remove_const_t<T>)
22
// before serving as an argument to ServiceHelper.
23
// =======================================================================
24
25
#include "
art/Framework/Services/Registry/ServiceRegistry.h
"
26
#include "
art/Framework/Services/Registry/ServiceScope.h
"
27
#include "
art/Framework/Services/Registry/detail/ServiceHandleAllowed.h
"
28
#include "
art/Framework/Services/Registry/detail/ServiceHelper.h
"
29
30
#include <type_traits>
31
32
namespace
art
{
33
34
template
<
typename
T
,
35
ServiceScope
SCOPE =
36
detail::ServiceHelper<std::remove_const_t<T>>::scope_val>
37
class
ServiceHandle
{
38
public
:
39
static_assert(
40
detail::handle_allowed_v<T>,
41
"\n\nart-error: You cannot create a ServiceHandle for this type.\n"
42
" Please contact artists@fnal.gov for guidance.\n"
);
43
44
ServiceHandle
()
try
:
instance
{
45
&
ServiceRegistry::instance
().
get
<std::remove_const_t<T>>()
46
}
47
{}
48
catch
(
Exception
const
&
x
)
49
{
50
throw
Exception
(
errors::ServiceNotFound
)
51
<<
"Unable to create ServiceHandle.\n"
52
<<
"Perhaps the FHiCL configuration does not specify the necessary "
53
"service?\n"
54
<<
"The class of the service is noted below...\n"
55
<<
x
;
56
}
57
58
T
*
operator->
()
const
{
return
instance
; }
59
60
T
&
operator*
()
const
{
return
*
instance
; }
61
62
T
*
63
get
()
const
64
{
65
return
instance
;
66
}
67
68
private
:
69
T
*
instance
;
70
};
71
72
}
// namespace art
73
74
#endif
/* art_Framework_Services_Registry_ServiceHandle_h */
75
76
// Local Variables:
77
// mode: c++
78
// End:
art::ServiceHandle
Definition:
ServiceHandle.h:37
art::ServiceScope
ServiceScope
Definition:
ServiceScope.h:7
ServiceRegistry.h
ServiceHandleAllowed.h
ValidateOpDetSimulation.T
T
Definition:
ValidateOpDetSimulation.py:52
ServiceScope.h
ServiceHelper.h
art::ServiceRegistry::instance
static ServiceRegistry & instance() noexcept
Definition:
ServiceRegistry.cc:10
art::ServiceHandle::instance
T * instance
Definition:
ServiceHandle.h:69
art::errors::ServiceNotFound
Definition:
Exception.h:53
art::ServiceHandle::ServiceHandle
ServiceHandle()
Definition:
ServiceHandle.h:44
art::ServiceHandle::operator*
T & operator*() const
Definition:
ServiceHandle.h:60
art::Exception
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition:
Exception.h:66
art::ServiceRegistry::get
T & get() const
Definition:
ServiceRegistry.h:46
art
Definition:
BasicOptionsHandler.h:9
train.x
list x
Definition:
train.py:276
art::ServiceHandle::operator->
T * operator->() const
Definition:
ServiceHandle.h:58
Generated by
1.8.11