12 #include "cetlib_except/demangle.h" 30 addService(
string const&
name, vector<ParameterSet>& service_set)
33 tmp.
put(
"service_type", name);
34 ParameterSetRegistry::put(tmp);
35 service_set.emplace_back(
move(tmp));
39 addService(
string const& name,
41 vector<ParameterSet>& service_set)
45 service_set.emplace_back(
move(tmp));
48 addService(name, service_set);
55 ServicesManager::~ServicesManager()
62 while (!actualCreationOrder_.empty()) {
63 actualCreationOrder_.pop();
67 std::vector<std::string>
72 std::vector<std::string> producing_services;
73 for (
auto& pr : services_) {
74 auto& serviceEntry = pr.second;
77 if (serviceEntry.is_interface())
82 auto const& pset = serviceEntry.getParameterSet();
84 if (!pset.get_if_present(
"service_type", moduleLabel)) {
89 auto const before = productsToProduce.size();
91 pset.id(), moduleLabel, moduleLabel, ModuleThreadingType::shared, pc};
92 serviceEntry.registerProducts(productsToProduce, signals,
md);
93 if (productsToProduce.size() != before) {
97 producing_services.push_back(moduleLabel);
100 return producing_services;
108 vector<ParameterSet> psets;
111 addService(
"FileCatalogMetadata", servicesPSet, psets);
112 servicesPSet.erase(
"FileCatalogMetadata");
114 addService(
"DatabaseConnection", servicesPSet, psets);
115 servicesPSet.erase(
"DatabaseConnection");
117 for (
auto const&
key : servicesPSet.get_pset_names()) {
118 addService(
key, servicesPSet, psets);
121 using SHBCREATOR_t = std::unique_ptr<detail::ServiceHelperBase> (*)();
122 for (
auto const&
ps : psets) {
123 auto const service_name =
ps.get<
string>(
"service_type");
124 auto const service_provider =
125 ps.get<
string>(
"service_provider", service_name);
127 unique_ptr<detail::ServiceHelperBase> service_helper{
129 "create_service_helper")()};
130 if (service_helper->is_interface()) {
132 <<
"Service " << service_name <<
" (of type " 133 << service_helper->get_typeid().className()
134 <<
")\nhas been registered as an interface in its header using\n" 135 <<
"DECLARE_ART_SERVICE_INTERFACE.\n" 136 <<
"Use DECLARE_ART_SERVICE OR DECLARE_ART_SERVICE_INTERFACE_IMPL\n" 137 <<
"as appropriate. A true service interface should *not* be\n" 138 <<
"compiled into a _service.so plugin library.\n";
140 unique_ptr<detail::ServiceInterfaceHelper> iface_helper;
141 if (service_helper->is_interface_impl()) {
142 iface_helper.reset(dynamic_cast<detail::ServiceInterfaceHelper*>(
144 .getSymbolByLibspec<SHBCREATOR_t>(service_provider,
145 "create_iface_helper")()
147 if (dynamic_cast<detail::ServiceInterfaceImplHelper*>(
148 service_helper.get())
149 ->get_interface_typeid() != iface_helper->get_typeid()) {
151 <<
"Service registration for " << service_provider
152 <<
" is internally inconsistent: " << iface_helper->get_typeid()
153 <<
" (" << iface_helper->get_typeid().className() <<
") != " 155 service_helper.get())
156 ->get_interface_typeid()
159 service_helper.get())
160 ->get_interface_typeid()
163 <<
"Contact the art developers <artists@fnal.gov>.\n";
165 if (service_provider == service_name) {
167 cet::demangle_symbol(iface_helper->get_typeid().name())};
169 auto const colon_pos = iface_name.find_last_of(
":");
170 if (colon_pos != std::string::npos) {
171 iface_name.erase(0, colon_pos + 1);
174 <<
"Illegal use of service interface implementation as service " 175 "name in configuration.\n" 176 <<
"Correct use: services." << iface_name
177 <<
": { service_provider: \"" << service_provider <<
"\" }\n";
183 TypeID service_typeid{service_helper->get_typeid()};
187 TypeID const sType{service_helper->get_typeid()};
194 TypeID const iType{iface_helper->get_typeid()};
207 std::vector<fhicl::ParameterSet>
tmp;
208 for (
auto const& typeID_and_ServiceCacheEntry :
services_) {
209 auto const&
sce = typeID_and_ServiceCacheEntry.second;
210 tmp.push_back(
sce.getParameterSet());
220 auto const&
sce = it->second;
ActivityRegistry & actReg_
std::vector< TypeID > requestedCreationOrder_
std::vector< BranchDescription > ProductDescriptions
static ServiceRegistry & instance() noexcept
T getSymbolByLibspec(std::string const &libspec, std::string const &sym_name) const
detail::SharedResources & resources_
void setManager(ServicesManager *)
void getParameterSets(std::vector< fhicl::ParameterSet > &out) const
static constexpr double ps
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::map< TypeID, detail::ServiceCacheEntry > services_
std::optional< T > get_if_present(std::string const &key) const
void put(std::string const &key)