Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
dunecore
dunecore
ArtSupport
ArtServicePointer.h
Go to the documentation of this file.
1
// ArtServicePointer.h
2
3
#ifndef ArtServicePointer_H
4
#define ArtServicePointer_H
5
6
// David Adams
7
// January 2017
8
//
9
// ArtServicePointer provides access to an art service.
10
//
11
// Usage:
12
// MyService* psvc = ArtServicePointer<MyService>()
13
//
14
// Template specializations may be used enable service without
15
// direct use of ServiceHandle, i.e. inside root.
16
17
// This is the function that is specialized and used by clients.
18
template
<
class
T>
19
T
*
ArtServicePointer
();
20
21
#ifdef __CLING__
22
23
#include <iostream>
24
template
<
class
T>
25
T
*
ArtServicePointer
() {
26
std::cout <<
"ArtServicePointer: No specialization found for "
<<
typeid
(
T
).
name
() <<
std::endl
;
27
return
nullptr
;
28
}
29
30
#else
31
32
#include <iostream>
33
#include "
art/Framework/Services/Registry/ServiceHandle.h
"
34
35
// This should not be called directly.
36
template
<
class
T>
37
T
*
GenericArtServicePointer
() {
38
try
{
39
if
( art::ServiceRegistry::isAvailable<T>() ) {
40
return
art::ServiceHandle<T>
().
get
();
41
}
42
/*
43
art::ServiceRegistry& reg = art::ServiceRegistry::instance();
44
if ( ! reg.isAvailable<T>() ) return nullptr;
45
return ®.get<T>();
46
*/
47
}
catch
(
const
art::Exception
& exc) {
48
std::string
msg
= exc.explain_self();
49
if
( msg.find(
"no ServiceRegistry has been set"
) != std::string::npos ) {
50
std::cout <<
"WARNING: ArtServicePointer: ServiceRegistry not found. Instantiate with"
<<
std::endl
;
51
std::cout <<
" ArtServiceHelper::load(\"myfcl.fcl\")"
<<
std::endl
;
52
}
else
{
53
std::cout <<
"WARNING: Art exception: \n"
<<
msg
;
54
}
55
}
catch
(...) {
56
std::cout <<
"ERROR: ArtServicePointer: Unexpected exception."
<<
std::endl
;
57
}
58
return
nullptr
;
59
}
60
61
template
<
class
T>
62
T
*
ArtServicePointer
() {
63
return
GenericArtServicePointer<T>();
64
}
65
66
#endif
67
68
#endif
name
static QCString name
Definition:
declinfo.cpp:673
ArtServicePointer
T * ArtServicePointer()
Definition:
ArtServicePointer.h:62
art::ServiceHandle
Definition:
ServiceHandle.h:37
GenericArtServicePointer
T * GenericArtServicePointer()
Definition:
ArtServicePointer.h:37
msg
void msg(const char *fmt,...)
Definition:
message.cpp:107
string
std::string string
Definition:
nybbler.cc:12
ValidateOpDetSimulation.T
T
Definition:
ValidateOpDetSimulation.py:52
ServiceHandle.h
art::Exception
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition:
Exception.h:66
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
Generated by
1.8.11