11 #include "cetlib/LibraryManager.h" 12 #include "cetlib_except/demangle.h" 15 #include "range/v3/view.hpp" 30 addService(
string const& name, vector<ParameterSet>& service_set)
33 tmp.
put(
"service_type", name);
34 ParameterSetRegistry::put(tmp);
35 service_set.emplace_back(std::move(tmp));
39 addService(
string const& name,
41 vector<ParameterSet>& service_set)
44 service_set.emplace_back(std::move(*service));
47 addService(name, service_set);
54 ServicesManager::~ServicesManager()
61 while (!actualCreationOrder_.empty()) {
62 actualCreationOrder_.pop();
66 std::vector<std::string>
71 std::vector<std::string> producing_services;
74 if (serviceEntry.is_interface())
79 auto const& pset = serviceEntry.getParameterSet();
80 std::string moduleLabel{};
81 if (!pset.get_if_present(
"service_type", moduleLabel)) {
86 auto const before = productsToProduce.size();
88 pset.id(), moduleLabel, moduleLabel, ModuleThreadingType::shared, pc};
89 serviceEntry.registerProducts(productsToProduce, signals, md);
90 if (productsToProduce.size() != before) {
94 producing_services.push_back(moduleLabel);
97 return producing_services;
105 vector<ParameterSet> psets;
108 addService(
"FileCatalogMetadata", servicesPSet, psets);
109 servicesPSet.erase(
"FileCatalogMetadata");
111 addService(
"DatabaseConnection", servicesPSet, psets);
112 servicesPSet.erase(
"DatabaseConnection");
114 for (
auto const& key : servicesPSet.get_pset_names()) {
115 addService(key, servicesPSet, psets);
118 using SHBCREATOR_t = std::unique_ptr<detail::ServiceHelperBase> (*)();
119 for (
auto const& ps : psets) {
120 auto const service_name = ps.get<
string>(
"service_type");
121 auto const service_provider =
122 ps.get<
string>(
"service_provider", service_name);
124 unique_ptr<detail::ServiceHelperBase> service_helper{
125 lm_.getSymbolByLibspec<SHBCREATOR_t>(service_provider,
126 "create_service_helper")()};
127 if (service_helper->is_interface()) {
129 <<
"Service " << service_name <<
" (of type " 130 << service_helper->get_typeid().className()
131 <<
")\nhas been registered as an interface in its header using\n" 132 <<
"DECLARE_ART_SERVICE_INTERFACE.\n" 133 <<
"Use DECLARE_ART_SERVICE OR DECLARE_ART_SERVICE_INTERFACE_IMPL\n" 134 <<
"as appropriate. A true service interface should *not* be\n" 135 <<
"compiled into a _service.so plugin library.\n";
137 unique_ptr<detail::ServiceInterfaceHelper> iface_helper;
138 if (service_helper->is_interface_impl()) {
139 iface_helper.reset(dynamic_cast<detail::ServiceInterfaceHelper*>(
141 .getSymbolByLibspec<SHBCREATOR_t>(service_provider,
142 "create_iface_helper")()
144 if (dynamic_cast<detail::ServiceInterfaceImplHelper*>(
145 service_helper.get())
146 ->get_interface_typeid() != iface_helper->get_typeid()) {
148 <<
"Service registration for " << service_provider
149 <<
" is internally inconsistent: " << iface_helper->get_typeid()
150 <<
" (" << iface_helper->get_typeid().className() <<
") != " 152 service_helper.get())
153 ->get_interface_typeid()
156 service_helper.get())
157 ->get_interface_typeid()
160 <<
"Contact the art developers <artists@fnal.gov>.\n";
162 if (service_provider == service_name) {
164 cet::demangle_symbol(iface_helper->get_typeid().name())};
166 auto const colon_pos = iface_name.find_last_of(
":");
167 if (colon_pos != std::string::npos) {
168 iface_name.erase(0, colon_pos + 1);
171 <<
"Illegal use of service interface implementation as service " 172 "name in configuration.\n" 173 <<
"Correct use: services." << iface_name
174 <<
": { service_provider: \"" << service_provider <<
"\" }\n";
180 TypeID service_typeid{service_helper->get_typeid()};
184 TypeID const sType{service_helper->get_typeid()};
191 TypeID const iType{iface_helper->get_typeid()};
194 ps, std::move(iface_helper), svc.first->second));
207 views::transform([](
auto const&
sce) {
return sce.getParameterSet(); }) |
216 auto const&
sce = it->second;
ActivityRegistry & actReg_
std::vector< TypeID > requestedCreationOrder_
std::vector< BranchDescription > ProductDescriptions
static ServiceRegistry & instance() noexcept
detail::SharedResources & resources_
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
void setManager(ServicesManager *)
void getParameterSets(std::vector< fhicl::ParameterSet > &out) const
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)