Public Member Functions | Private Member Functions | Private Attributes | List of all members
art::detail::ServiceCacheEntry Class Reference

#include <ServiceCacheEntry.h>

Public Member Functions

 ServiceCacheEntry (fhicl::ParameterSet const &pset, std::unique_ptr< ServiceHelperBase > &&helper)
 
 ServiceCacheEntry (fhicl::ParameterSet const &pset, std::unique_ptr< ServiceHelperBase > &&helper, ServiceCacheEntry const &impl)
 
 ServiceCacheEntry (std::shared_ptr< ServiceWrapperBase > premade_service, std::unique_ptr< ServiceHelperBase > &&helper)
 
std::shared_ptr< ServiceWrapperBasegetService (ActivityRegistry &reg, SharedResources &resources, ServiceStack &creationOrder) const
 
void forceCreation (ActivityRegistry &reg, SharedResources &resources) const
 
fhicl::ParameterSet const & getParameterSet () const
 
template<typename T >
T & get (ActivityRegistry &reg, SharedResources &resources, ServiceStack &creationOrder) const
 
void registerProducts (ProductDescriptions &productsToProduce, ProducingServiceSignals &signals, ModuleDescription const &md)
 
bool is_impl () const
 
bool is_interface () const
 
ServiceScope serviceScope () const
 

Private Member Functions

std::shared_ptr< ServiceWrapperBasemakeService (ActivityRegistry &reg, SharedResources &resources) const
 
void createService (ActivityRegistry &reg, SharedResources &resources, ServiceStack &creationOrder) const
 
std::shared_ptr< ServiceWrapperBaseconvertService () const
 

Private Attributes

fhicl::ParameterSet config_ {}
 
std::unique_ptr< ServiceHelperBasehelper_
 
std::shared_ptr< ServiceWrapperBaseservice_ {}
 
cet::exempt_ptr< ServiceCacheEntry const > const interface_impl_ {nullptr}
 

Detailed Description

Definition at line 24 of file ServiceCacheEntry.h.

Constructor & Destructor Documentation

art::detail::ServiceCacheEntry::ServiceCacheEntry ( fhicl::ParameterSet const &  pset,
std::unique_ptr< ServiceHelperBase > &&  helper 
)

Definition at line 22 of file ServiceCacheEntry.cc.

25  : config_{pset}, helper_{move(helper)}
26  {}
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< ServiceHelperBase > helper_
art::detail::ServiceCacheEntry::ServiceCacheEntry ( fhicl::ParameterSet const &  pset,
std::unique_ptr< ServiceHelperBase > &&  helper,
ServiceCacheEntry const &  impl 
)

Definition at line 28 of file ServiceCacheEntry.cc.

32  : config_{pset}
33  , helper_{move(helper)}
35  {}
def move(depos, offset)
Definition: depos.py:107
constexpr exempt_ptr< E > make_exempt_ptr(E *) noexcept
std::unique_ptr< ServiceHelperBase > helper_
cet::exempt_ptr< ServiceCacheEntry const > const interface_impl_
art::detail::ServiceCacheEntry::ServiceCacheEntry ( std::shared_ptr< ServiceWrapperBase premade_service,
std::unique_ptr< ServiceHelperBase > &&  helper 
)

Definition at line 37 of file ServiceCacheEntry.cc.

40  : helper_{move(helper)}, service_{premade_service}
41  {}
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< ServiceHelperBase > helper_
std::shared_ptr< ServiceWrapperBase > service_

Member Function Documentation

std::shared_ptr< ServiceWrapperBase > art::detail::ServiceCacheEntry::convertService ( ) const
private

Definition at line 154 of file ServiceCacheEntry.cc.

155  {
156  assert(is_impl() &&
157  "ServiceCacheEntry::convertService called on a service interface!");
158  return dynamic_cast<ServiceInterfaceImplHelper&>(*helper_).convert(
159  service_);
160  }
std::shared_ptr< ServiceWrapperBase > service_
void art::detail::ServiceCacheEntry::createService ( ActivityRegistry reg,
SharedResources resources,
ServiceStack creationOrder 
) const
private

Definition at line 141 of file ServiceCacheEntry.cc.

144  {
145  assert(is_impl() &&
146  "ServiceCacheEntry::createService called on a service interface!");
147  // When we actually create the Service object, we have to
148  // remember the order of creation.
149  service_ = makeService(reg, resources);
150  creationOrder.push(service_);
151  }
std::shared_ptr< ServiceWrapperBase > makeService(ActivityRegistry &reg, SharedResources &resources) const
std::shared_ptr< ServiceWrapperBase > service_
void art::detail::ServiceCacheEntry::forceCreation ( ActivityRegistry reg,
SharedResources resources 
) const

Definition at line 116 of file ServiceCacheEntry.cc.

118  {
119  assert(is_impl() &&
120  "ServiceCacheEntry::forceCreation called on a service interface!");
121  if (!service_) {
122  service_ = makeService(reg, resources);
123  }
124  }
std::shared_ptr< ServiceWrapperBase > makeService(ActivityRegistry &reg, SharedResources &resources) const
std::shared_ptr< ServiceWrapperBase > service_
template<typename T >
T & art::detail::ServiceCacheEntry::get ( ActivityRegistry reg,
SharedResources resources,
ServiceStack creationOrder 
) const

Definition at line 77 of file ServiceCacheEntry.h.

80  {
81  auto swb = getService(reg, resources, creationOrder);
82  return *reinterpret_cast<T*>(
83  dynamic_cast<ServiceLGRHelper&>(*helper_).retrieve(swb));
84  }
std::shared_ptr< ServiceWrapperBase > getService(ActivityRegistry &reg, SharedResources &resources, ServiceStack &creationOrder) const
fhicl::ParameterSet const & art::detail::ServiceCacheEntry::getParameterSet ( ) const

Definition at line 135 of file ServiceCacheEntry.cc.

136  {
137  return config_;
138  }
std::shared_ptr< ServiceWrapperBase > art::detail::ServiceCacheEntry::getService ( ActivityRegistry reg,
SharedResources resources,
ServiceStack creationOrder 
) const

Definition at line 44 of file ServiceCacheEntry.cc.

47  {
48  if (is_interface()) {
49  if (!service_) {
50  // No cached instance, we need to make it.
51  if (!interface_impl_->service_) {
52  // The service provider has no cached instance, have it make one.
53  interface_impl_->createService(reg, resources, creationOrder);
54  }
55  // Convert the service provider wrapper to a service interface
56  // wrapper, and use that as our cached instance.
57  service_ = interface_impl_->convertService();
58  }
59  return service_;
60  }
61  if (!service_) {
62  // No cached instance, we need to make it.
63  createService(reg, resources, creationOrder);
64  }
65  return service_;
66  }
void createService(ActivityRegistry &reg, SharedResources &resources, ServiceStack &creationOrder) const
cet::exempt_ptr< ServiceCacheEntry const > const interface_impl_
std::shared_ptr< ServiceWrapperBase > service_
bool art::detail::ServiceCacheEntry::is_impl ( ) const

Definition at line 175 of file ServiceCacheEntry.cc.

176  {
177  return !is_interface();
178  }
bool art::detail::ServiceCacheEntry::is_interface ( ) const

Definition at line 169 of file ServiceCacheEntry.cc.

170  {
171  return helper_->is_interface();
172  }
std::unique_ptr< ServiceHelperBase > helper_
std::shared_ptr< ServiceWrapperBase > art::detail::ServiceCacheEntry::makeService ( ActivityRegistry reg,
detail::SharedResources resources 
) const
private

Definition at line 69 of file ServiceCacheEntry.cc.

71  {
72  assert(is_impl() && "ServiceCacheEntry::makeAndCacheService called on a "
73  "service interface!");
74  try {
75  return dynamic_cast<ServiceLGMHelper&>(*helper_).make(
76  config_, reg, resources);
77  }
78  catch (fhicl::detail::validationException const& e) {
79  std::ostringstream err_stream;
80  constexpr cet::HorizontalRule rule{100};
81  err_stream << "\n"
82  << rule('=') << "\n\n"
83  << "!! The following service has been misconfigured: !!"
84  << "\n\n"
85  << rule('-') << "\n\nservice_type: "
86  << cet::bold_fontify(config_.get<std::string>("service_type"))
87  << "\n\n"
88  << e.what() << "\n"
89  << rule('=') << "\n\n";
90  throw art::Exception(art::errors::Configuration) << err_stream.str();
91  }
92  catch (cet::exception& e) {
93  throw Exception(errors::OtherArt, "ServiceCreation", e)
94  << "cet::exception caught during construction of service type "
95  << cet::demangle_symbol(helper_->get_typeid().name()) << '\n';
96  }
97  catch (std::exception& e) {
98  throw Exception(errors::StdException, "ServiceCreation")
99  << "exception caught during construction of service type "
100  << cet::demangle_symbol(helper_->get_typeid().name()) << ": "
101  << e.what();
102  }
103  catch (std::string const& s) {
105  << "String exception during construction of service type "
106  << cet::demangle_symbol(helper_->get_typeid().name()) << ": " << s;
107  }
108  catch (...) {
110  << "String exception during construction of service type "
111  << cet::demangle_symbol(helper_->get_typeid().name()) << '\n';
112  }
113  }
std::string string
Definition: nybbler.cc:12
const double e
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::string bold_fontify(std::string const &s)
Definition: bold_fontify.h:8
std::unique_ptr< ServiceHelperBase > helper_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
char const * what() const noexcept override
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void art::detail::ServiceCacheEntry::registerProducts ( ProductDescriptions productsToProduce,
ProducingServiceSignals signals,
ModuleDescription const &  md 
)

Definition at line 127 of file ServiceCacheEntry.cc.

130  {
131  service_->registerProducts(productsToProduce, signals, md);
132  }
std::shared_ptr< ServiceWrapperBase > service_
ServiceScope art::detail::ServiceCacheEntry::serviceScope ( ) const

Definition at line 163 of file ServiceCacheEntry.cc.

164  {
165  return helper_->scope();
166  }
std::unique_ptr< ServiceHelperBase > helper_

Member Data Documentation

fhicl::ParameterSet art::detail::ServiceCacheEntry::config_ {}
private

Definition at line 69 of file ServiceCacheEntry.h.

std::unique_ptr<ServiceHelperBase> art::detail::ServiceCacheEntry::helper_
private

Definition at line 70 of file ServiceCacheEntry.h.

cet::exempt_ptr<ServiceCacheEntry const> const art::detail::ServiceCacheEntry::interface_impl_ {nullptr}
private

Definition at line 72 of file ServiceCacheEntry.h.

std::shared_ptr<ServiceWrapperBase> art::detail::ServiceCacheEntry::service_ {}
mutableprivate

Definition at line 71 of file ServiceCacheEntry.h.


The documentation for this class was generated from the following files: