LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
art::detail::ServiceCacheEntry Class Reference

#include "ServiceCacheEntry.h"

Public Member Functions

 ServiceCacheEntry (fhicl::ParameterSet const &pset, std::unique_ptr< detail::ServiceHelperBase > &&helper)
 
 ServiceCacheEntry (fhicl::ParameterSet const &pset, std::unique_ptr< detail::ServiceHelperBase > &&helper, ServiceCacheEntry const &impl)
 
 ServiceCacheEntry (WrapperBase_ptr premade_service, std::unique_ptr< detail::ServiceHelperBase > &&helper)
 
WrapperBase_ptr getService (ActivityRegistry &reg, detail::ServiceStack &creationOrder) const
 
void forceCreation (ActivityRegistry &reg) const
 
fhicl::ParameterSet const & getParameterSet () const
 
template<typename T , typename = std::enable_if_t<detail::ServiceHelper<T>::scope_val != ServiceScope::PER_SCHEDULE>>
T & get (ActivityRegistry &reg, detail::ServiceStack &creationOrder) const
 
template<typename T , typename = std::enable_if_t<detail::ServiceHelper<T>::scope_val == ServiceScope::PER_SCHEDULE>>
T & get (ActivityRegistry &reg, detail::ServiceStack &creationOrder, ScheduleID sID) const
 
void registerProducts (MasterProductRegistry &mpr, ProductDescriptions &productsToProduce, ProducingServiceSignals &signals, ModuleDescription const &md)
 
bool is_impl () const
 
bool is_interface () const
 
ServiceScope serviceScope () const
 

Static Public Member Functions

static void setNSchedules (size_t nSched)
 

Private Member Functions

void makeAndCacheService (ActivityRegistry &reg) const
 
void createService (ActivityRegistry &reg, detail::ServiceStack &creationOrder) const
 
void convertService (WrapperBase_ptr &swb) const
 

Static Private Member Functions

static size_t & nSchedules ()
 

Private Attributes

fhicl::ParameterSet config_ {}
 
std::unique_ptr< detail::ServiceHelperBasehelper_
 
WrapperBase_ptr service_ {}
 
ServiceCacheEntry const *const interface_impl_ {nullptr}
 

Detailed Description

Definition at line 31 of file ServiceCacheEntry.h.

Constructor & Destructor Documentation

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

Definition at line 24 of file ServiceCacheEntry.cc.

References helper_.

27  : config_{pset}, helper_{std::move(helper)}
28 {}
std::unique_ptr< detail::ServiceHelperBase > helper_
art::detail::ServiceCacheEntry::ServiceCacheEntry ( fhicl::ParameterSet const &  pset,
std::unique_ptr< detail::ServiceHelperBase > &&  helper,
ServiceCacheEntry const &  impl 
)

Definition at line 31 of file ServiceCacheEntry.cc.

References helper_, and interface_impl_.

35  : config_{pset}, helper_{std::move(helper)}, interface_impl_{&impl}
36 {}
ServiceCacheEntry const *const interface_impl_
std::unique_ptr< detail::ServiceHelperBase > helper_
art::detail::ServiceCacheEntry::ServiceCacheEntry ( WrapperBase_ptr  premade_service,
std::unique_ptr< detail::ServiceHelperBase > &&  helper 
)

Definition at line 39 of file ServiceCacheEntry.cc.

References service_.

42  : helper_{std::move(helper)}, service_{premade_service}
43 {}
std::unique_ptr< detail::ServiceHelperBase > helper_

Member Function Documentation

void art::detail::ServiceCacheEntry::convertService ( WrapperBase_ptr swb) const
inlineprivate

Definition at line 125 of file ServiceCacheEntry.h.

References art::detail::ServiceInterfaceImplHelper::convert(), is_impl(), and service_.

Referenced by getService().

126 {
127  assert(is_impl() &&
128  "ServiceCacheEntry::convertService called on a service interface!");
129  swb = dynamic_cast<detail::ServiceInterfaceImplHelper&>(*helper_).convert(
130  service_);
131 }
void art::detail::ServiceCacheEntry::createService ( ActivityRegistry reg,
detail::ServiceStack creationOrder 
) const
inlineprivate

Definition at line 112 of file ServiceCacheEntry.h.

References is_impl(), makeAndCacheService(), and service_.

Referenced by getService().

115 {
116  assert(is_impl() &&
117  "ServiceCacheEntry::createService called on a service interface!");
118  // When we actually create the Service object, we have to
119  // remember the order of creation.
120  makeAndCacheService(reg);
121  creationOrder.push(service_);
122 }
void makeAndCacheService(ActivityRegistry &reg) const
void art::detail::ServiceCacheEntry::forceCreation ( ActivityRegistry reg) const
inline

Definition at line 96 of file ServiceCacheEntry.h.

References is_impl(), makeAndCacheService(), and service_.

97 {
98  assert(is_impl() &&
99  "ServiceCacheEntry::forceCreation called on a service interface!");
100  if (!service_) {
101  makeAndCacheService(reg);
102  }
103 }
void makeAndCacheService(ActivityRegistry &reg) const
template<typename T , typename >
T & art::detail::ServiceCacheEntry::get ( ActivityRegistry reg,
detail::ServiceStack creationOrder 
) const
inline

Definition at line 141 of file ServiceCacheEntry.h.

References getService(), art::PER_SCHEDULE, art::detail::ServiceLGRHelper::retrieve(), and serviceScope().

143 {
145  "Called wrong service get() function: need ScheduleID");
146  WrapperBase_ptr swb = getService(reg, creationOrder);
147  return *reinterpret_cast<T*>(
148  dynamic_cast<detail::ServiceLGRHelper&>(*helper_).retrieve(swb));
149 }
std::shared_ptr< detail::ServiceWrapperBase > WrapperBase_ptr
ServiceScope serviceScope() const
WrapperBase_ptr getService(ActivityRegistry &reg, detail::ServiceStack &creationOrder) const
template<typename T , typename >
T & art::detail::ServiceCacheEntry::get ( ActivityRegistry reg,
detail::ServiceStack creationOrder,
ScheduleID  sID 
) const
inline

Definition at line 153 of file ServiceCacheEntry.h.

References getService(), art::PER_SCHEDULE, art::detail::ServicePSRHelper::retrieve(), and serviceScope().

156 {
158  "Called wrong service get() function!");
159  WrapperBase_ptr swb = getService(reg, creationOrder);
160  return *reinterpret_cast<T*>(
161  dynamic_cast<detail::ServicePSRHelper&>(*helper_).retrieve(swb, sID));
162 }
std::shared_ptr< detail::ServiceWrapperBase > WrapperBase_ptr
ServiceScope serviceScope() const
WrapperBase_ptr getService(ActivityRegistry &reg, detail::ServiceStack &creationOrder) const
fhicl::ParameterSet const & art::detail::ServiceCacheEntry::getParameterSet ( ) const
inline

Definition at line 106 of file ServiceCacheEntry.h.

References config_.

107 {
108  return config_;
109 }
art::detail::WrapperBase_ptr art::detail::ServiceCacheEntry::getService ( ActivityRegistry reg,
detail::ServiceStack creationOrder 
) const

Definition at line 48 of file ServiceCacheEntry.cc.

References convertService(), createService(), interface_impl_, is_interface(), and service_.

Referenced by get().

51 {
52  if (is_interface()) { // Service interface
53  if (!service_) {
54  // No cached instance, we need to make it.
55  if (!interface_impl_->service_) {
56  // The service provider has no cached instance, have it make one.
57  interface_impl_->createService(reg, creationOrder);
58  }
59  // Convert the service provider wrapper to a service interface wrapper,
60  // and use that as our cached instance.
62  }
63  } else { // Concrete service.
64  if (!service_) {
65  // No cached instance, we need to make it.
66  createService(reg, creationOrder);
67  }
68  }
69  return service_;
70 }
void convertService(WrapperBase_ptr &swb) const
void createService(ActivityRegistry &reg, detail::ServiceStack &creationOrder) const
ServiceCacheEntry const *const interface_impl_
bool art::detail::ServiceCacheEntry::is_impl ( ) const
inline

Definition at line 178 of file ServiceCacheEntry.h.

References is_interface().

Referenced by convertService(), createService(), forceCreation(), and makeAndCacheService().

179 {
180  return !is_interface();
181 }
bool art::detail::ServiceCacheEntry::is_interface ( ) const
inline

Definition at line 184 of file ServiceCacheEntry.h.

References helper_.

Referenced by getService(), and is_impl().

185 {
186  return helper_->is_interface();
187 }
std::unique_ptr< detail::ServiceHelperBase > helper_
void art::detail::ServiceCacheEntry::makeAndCacheService ( ActivityRegistry reg) const
private

Definition at line 73 of file ServiceCacheEntry.cc.

References art::errors::BadExceptionType, art::detail::bold_fontify(), config_, art::errors::Configuration, e, fhicl::ParameterSet::get(), helper_, is_impl(), art::detail::ServicePSMHelper::make(), art::detail::ServiceLGMHelper::make(), nSchedules(), art::errors::OtherArt, art::PER_SCHEDULE, s, service_, serviceScope(), art::errors::StdException, art::errors::Unknown, and fhicl::detail::validationException::what().

Referenced by createService(), and forceCreation().

74 {
75  assert(
76  is_impl() &&
77  "ServiceCacheEntry::makeAndCacheService called on a service interface!");
78  try {
80  service_ = dynamic_cast<detail::ServicePSMHelper&>(*helper_).make(
81  config_, reg, nSchedules());
82  } else {
83  service_ =
84  dynamic_cast<detail::ServiceLGMHelper&>(*helper_).make(config_, reg);
85  }
86  }
87  catch (fhicl::detail::validationException const& e) {
88  std::ostringstream err_stream;
89  constexpr cet::HorizontalRule rule{100};
90  err_stream << "\n"
91  << rule('=') << "\n\n"
92  << "!! The following service has been misconfigured: !!"
93  << "\n\n"
94  << rule('-') << "\n\nservice_type: "
96  config_.get<std::string>("service_type"))
97  << "\n\n"
98  << e.what() << "\n"
99  << rule('=') << "\n\n";
100  throw art::Exception(art::errors::Configuration) << err_stream.str();
101  }
102  catch (cet::exception& e) {
103  throw Exception(errors::OtherArt, "ServiceCreation", e)
104  << "cet::exception caught during construction of service type "
105  << cet::demangle_symbol(helper_->get_typeid().name()) << ":\n";
106  }
107  catch (std::exception& e) {
108  throw Exception(errors::StdException, "ServiceCreation")
109  << "std::exception caught during construction of service type "
110  << cet::demangle_symbol(helper_->get_typeid().name()) << ": " << e.what();
111  }
112  catch (std::string const& s) {
114  << "String exception during construction of service type "
115  << cet::demangle_symbol(helper_->get_typeid().name()) << ": " << s;
116  }
117  catch (...) {
119  << "String exception during construction of service type "
120  << cet::demangle_symbol(helper_->get_typeid().name()) << ":\n";
121  }
122 }
std::string bold_fontify(std::string const &s)
Definition: bold_fontify.h:9
Float_t s
Definition: plot.C:23
T get(std::string const &key) const
Definition: ParameterSet.h:231
ServiceScope serviceScope() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
char const * what() const noexcept override
std::unique_ptr< detail::ServiceHelperBase > helper_
Float_t e
Definition: plot.C:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
size_t & art::detail::ServiceCacheEntry::nSchedules ( )
inlinestaticprivate

Definition at line 171 of file ServiceCacheEntry.h.

Referenced by makeAndCacheService(), and setNSchedules().

172 {
173  static size_t s_ns{1};
174  return s_ns;
175 }
void art::detail::ServiceCacheEntry::registerProducts ( MasterProductRegistry mpr,
ProductDescriptions productsToProduce,
ProducingServiceSignals signals,
ModuleDescription const &  md 
)

Definition at line 125 of file ServiceCacheEntry.cc.

References service_.

130 {
131  service_->registerProducts(mpr, productsToProduce, signals, md);
132 }
art::ServiceScope art::detail::ServiceCacheEntry::serviceScope ( ) const
inline

Definition at line 134 of file ServiceCacheEntry.h.

References helper_.

Referenced by get(), and makeAndCacheService().

135 {
136  return helper_->scope();
137 }
std::unique_ptr< detail::ServiceHelperBase > helper_
void art::detail::ServiceCacheEntry::setNSchedules ( size_t  nSched)
inlinestatic

Definition at line 165 of file ServiceCacheEntry.h.

References nSchedules().

Referenced by art::ServicesManager::fillCache_().

166 {
167  nSchedules() = nSched;
168 }

Member Data Documentation

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

Definition at line 89 of file ServiceCacheEntry.h.

Referenced by getParameterSet(), and makeAndCacheService().

std::unique_ptr<detail::ServiceHelperBase> art::detail::ServiceCacheEntry::helper_
private
ServiceCacheEntry const* const art::detail::ServiceCacheEntry::interface_impl_ {nullptr}
private

Definition at line 92 of file ServiceCacheEntry.h.

Referenced by getService(), and ServiceCacheEntry().

WrapperBase_ptr art::detail::ServiceCacheEntry::service_ {}
mutableprivate

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