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

#include "ServicesManager.h"

Public Types

using ParameterSets = std::vector< fhicl::ParameterSet >
 

Public Member Functions

 ServicesManager (ServicesManager const &)=delete
 
ServicesManageroperator= (ServicesManager const &)=delete
 
 ServicesManager (ParameterSets const &, cet::LibraryManager const &, ActivityRegistry &)
 
 ~ServicesManager ()
 
template<typename T , typename = std::enable_if_t<detail::ServiceHelper<T>::scope_val != ServiceScope::PER_SCHEDULE>>
T & get ()
 
template<typename T , typename = std::enable_if_t<detail::ServiceHelper<T>::scope_val == ServiceScope::PER_SCHEDULE>>
T & get (ScheduleID)
 
template<class T >
bool isAvailable () const
 
template<typename T , typename = std::enable_if_t<detail::ServiceHelper<T>::scope_val != ServiceScope::PER_SCHEDULE>>
void put (std::unique_ptr< T > &&premade_service)
 
template<typename SP , typename = std::enable_if_t< detail::ServiceHelper<typename SP::element_type>::scope_val == ServiceScope::PER_SCHEDULE>>
void put (std::vector< SP > &&premade_services)
 
void forceCreation ()
 
void registerProducts (MasterProductRegistry &mpr, ProductDescriptions &productsToProduce, ProducingServiceSignals &signals, ProcessConfiguration const &pc)
 
void getParameterSets (ParameterSets &out) const
 

Private Types

using SHBCREATOR_t) = std::unique_ptr< detail::ServiceHelperBase >(*)(
 
using NameIndex = std::map< std::string, detail::ServiceCache::iterator >
 
using TypeIDs = std::vector< TypeID >
 

Private Member Functions

void fillCache_ (ParameterSets const &psets, cet::LibraryManager const &lm)
 
std::pair< detail::ServiceCache::iterator, bool > insertImpl_ (fhicl::ParameterSet const &pset, std::unique_ptr< detail::ServiceHelperBase > &&helper)
 
void insertInterface_ (fhicl::ParameterSet const &pset, std::unique_ptr< detail::ServiceHelperBase > &&helper, detail::ServiceCache::iterator implEntry)
 

Private Attributes

art::ActivityRegistryregistry_
 
detail::ServiceCache factory_ {}
 
NameIndex index_ {}
 
TypeIDs requestedCreationOrder_ {}
 
detail::ServiceStack actualCreationOrder_ {}
 
std::vector< std::string > configErrMsgs_ {}
 

Detailed Description

Definition at line 42 of file ServicesManager.h.

Member Typedef Documentation

using art::ServicesManager::NameIndex = std::map<std::string, detail::ServiceCache::iterator>
private

Definition at line 100 of file ServicesManager.h.

Definition at line 48 of file ServicesManager.h.

using art::ServicesManager::SHBCREATOR_t = std::unique_ptr<detail::ServiceHelperBase> (*)(
private

Definition at line 99 of file ServicesManager.h.

using art::ServicesManager::TypeIDs = std::vector<TypeID>
private

Definition at line 101 of file ServicesManager.h.

Constructor & Destructor Documentation

art::ServicesManager::ServicesManager ( ServicesManager const &  )
delete
art::ServicesManager::ServicesManager ( ParameterSets const &  psets,
cet::LibraryManager const &  lm,
ActivityRegistry reg 
)
explicit

Definition at line 18 of file ServicesManager.cc.

References fillCache_().

21  : registry_{reg}
22 {
23  fillCache_(psets, lm);
24 }
void fillCache_(ParameterSets const &psets, cet::LibraryManager const &lm)
art::ActivityRegistry & registry_
art::ServicesManager::~ServicesManager ( )

Definition at line 26 of file ServicesManager.cc.

References actualCreationOrder_, factory_, and index_.

27 {
28  // Force the Service destructors to execute in the reverse order of
29  // construction. Note that services passed in by a token are not
30  // included in this loop and do not get destroyed until the
31  // ServicesManager object that created them is destroyed which
32  // occurs after the body of this destructor is executed (the correct
33  // order). Services directly passed in by a put and not created in
34  // the constructor may or may not be detroyed in the desired order
35  // because this class does not control their creation (as I'm
36  // writing this comment everything in a standard fw executable is
37  // destroyed in the desired order).
38  index_.clear();
39  factory_.clear();
40  while (!actualCreationOrder_.empty()) {
42  }
43 }
detail::ServiceStack actualCreationOrder_
detail::ServiceCache factory_

Member Function Documentation

void art::ServicesManager::fillCache_ ( ParameterSets const &  psets,
cet::LibraryManager const &  lm 
)
private

Definition at line 99 of file ServicesManager.cc.

References art::errors::Configuration, index_, insertImpl_(), insertInterface_(), art::errors::LogicError, requestedCreationOrder_, and art::detail::ServiceCacheEntry::setNSchedules().

Referenced by ServicesManager().

101 {
102  // Receive from EventProcessor when we go multi-schedule.
104  // Loop over each configured service parameter set.
105  for (auto const& ps : psets) {
106  std::string const service_name{ps.get<std::string>("service_type")};
107  std::string const service_provider{
108  ps.get<std::string>("service_provider", service_name)};
109  // Get the helper from the library.
110  std::unique_ptr<detail::ServiceHelperBase> service_helper{
111  lm.getSymbolByLibspec<SHBCREATOR_t>(service_provider,
112  "create_service_helper")()};
113  if (service_helper->is_interface()) {
115  << "Service " << service_name << " (of type "
116  << service_helper->get_typeid().className()
117  << ")\nhas been registered as an interface in its header using\n"
118  << "DECLARE_ART_SERVICE_INTERFACE.\n"
119  << "Use DECLARE_ART_SERVICE OR DECLARE_ART_SERVICE_INTERFACE_IMPL\n"
120  << "as appropriate. A true service interface should *not* be\n"
121  << "compiled into a _service.so plugin library.\n";
122  }
123  std::unique_ptr<detail::ServiceInterfaceHelper> iface_helper;
124  if (service_helper->is_interface_impl()) { // Expect an interface helper
125  iface_helper.reset(dynamic_cast<detail::ServiceInterfaceHelper*>(
126  lm.getSymbolByLibspec<SHBCREATOR_t>(service_provider,
127  "create_iface_helper")()
128  .release()));
129  if (dynamic_cast<detail::ServiceInterfaceImplHelper*>(
130  service_helper.get())
131  ->get_interface_typeid() != iface_helper->get_typeid()) {
133  << "Service registration for " << service_provider
134  << " is internally inconsistent: " << iface_helper->get_typeid()
135  << " (" << iface_helper->get_typeid().className() << ") != "
136  << dynamic_cast<detail::ServiceInterfaceImplHelper*>(
137  service_helper.get())
138  ->get_interface_typeid()
139  << " ("
140  << dynamic_cast<detail::ServiceInterfaceImplHelper*>(
141  service_helper.get())
142  ->get_interface_typeid()
143  .className()
144  << ").\n"
145  << "Contact the art developers <artists@fnal.gov>.\n";
146  }
147  if (service_provider == service_name) {
148  std::string iface_name{
149  cet::demangle_symbol(iface_helper->get_typeid().name())};
150  // Remove any namespace qualification if necessary
151  auto const colon_pos = iface_name.find_last_of(":");
152  if (colon_pos != std::string::npos) {
153  iface_name.erase(0, colon_pos + 1);
154  }
156  << "Illegal use of service interface implementation as service name "
157  "in configuration.\n"
158  << "Correct use: services." << iface_name
159  << ": { service_provider: \"" << service_provider << "\" }\n";
160  }
161  }
162  // Insert the cache entry for the main service implementation. Note
163  // we save the typeid of the implementation because we're about to
164  // give away the helper.
165  TypeID service_typeid{service_helper->get_typeid()};
166  auto svc = insertImpl_(ps, std::move(service_helper));
167  if (iface_helper) {
168  insertInterface_(ps, std::move(iface_helper), svc.first);
169  }
170  index_[service_name] = svc.first;
171  requestedCreationOrder_.emplace_back(std::move(service_typeid));
172  }
173 } // fillCache()
std::unique_ptr< detail::ServiceHelperBase >(*)( SHBCREATOR_t)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::pair< detail::ServiceCache::iterator, bool > insertImpl_(fhicl::ParameterSet const &pset, std::unique_ptr< detail::ServiceHelperBase > &&helper)
void insertInterface_(fhicl::ParameterSet const &pset, std::unique_ptr< detail::ServiceHelperBase > &&helper, detail::ServiceCache::iterator implEntry)
static void setNSchedules(size_t nSched)
void art::ServicesManager::forceCreation ( )

Definition at line 46 of file ServicesManager.cc.

References factory_, registry_, and requestedCreationOrder_.

47 {
48  for (auto const& val : requestedCreationOrder_) {
49  auto c = factory_.find(val);
50  if (c != factory_.end()) {
51  c->second.forceCreation(registry_);
52  }
53  // JBK - should an exception be thrown if name not found in map?
54  }
55 }
detail::ServiceCache factory_
art::ActivityRegistry & registry_
template<typename T , typename >
T & art::ServicesManager::get ( )

Definition at line 128 of file ServicesManager.h.

References art::errors::ServiceNotFound.

129 {
130  // Find the correct ServiceCacheEntry object.
131  auto it = factory_.find(TypeID{typeid(T)});
132  if (it == factory_.end())
134  << "art::ServicesManager unable to find the service of type '"
135  << cet::demangle_symbol(typeid(T).name()) << "'.\n";
136  return it->second.get<T>(registry_, actualCreationOrder_);
137 } // get<>()
detail::ServiceStack actualCreationOrder_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
detail::ServiceCache factory_
art::ActivityRegistry & registry_
template<typename T , typename >
T & art::ServicesManager::get ( ScheduleID  sID)

Definition at line 141 of file ServicesManager.h.

References art::errors::ServiceNotFound.

142 {
143  // Find the correct ServiceCacheEntry object.
144  auto it = factory_.find(TypeID{typeid(T)});
145  if (it == factory_.end())
147  << "art::ServicesManager unable to find the service of type '"
148  << cet::demangle_symbol(typeid(T).name()) << "'.\n";
149  return it->second.get<T>(registry_, actualCreationOrder_, sID);
150 } // get<>()
detail::ServiceStack actualCreationOrder_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
detail::ServiceCache factory_
art::ActivityRegistry & registry_
void art::ServicesManager::getParameterSets ( ParameterSets out) const

Definition at line 89 of file ServicesManager.cc.

References factory_, and tmp.

90 {
92  for (auto const& cur : factory_) {
93  tmp.push_back(cur.second.getParameterSet());
94  }
95  tmp.swap(out);
96 }
Float_t tmp
Definition: plot.C:37
std::vector< ParameterSet > ParameterSets
detail::ServiceCache factory_
std::pair< art::detail::ServiceCache::iterator, bool > art::ServicesManager::insertImpl_ ( fhicl::ParameterSet const &  pset,
std::unique_ptr< detail::ServiceHelperBase > &&  helper 
)
private

Definition at line 176 of file ServicesManager.cc.

References factory_.

Referenced by fillCache_().

179 {
180  // Need temporary because we can't guarantee the order of evaluation
181  // of the arguments to emplace below.
182  TypeID const sType{helper->get_typeid()};
183  return factory_.emplace(sType,
184  detail::ServiceCacheEntry(pset, std::move(helper)));
185 }
detail::ServiceCache factory_
void art::ServicesManager::insertInterface_ ( fhicl::ParameterSet const &  pset,
std::unique_ptr< detail::ServiceHelperBase > &&  helper,
detail::ServiceCache::iterator  implEntry 
)
private

Definition at line 188 of file ServicesManager.cc.

References factory_.

Referenced by fillCache_().

192 {
193  // Need temporary because we can't guarantee the order of evaluation
194  // of the arguments to emplace below.
195  TypeID const iType{helper->get_typeid()};
196  factory_.emplace(
197  iType,
198  detail::ServiceCacheEntry(pset, std::move(helper), implEntry->second));
199 }
detail::ServiceCache factory_
template<class T >
bool art::ServicesManager::isAvailable ( ) const
inline

Definition at line 69 of file ServicesManager.h.

70  {
71  return factory_.find(TypeID(typeid(T))) != factory_.end();
72  }
detail::ServiceCache factory_
ServicesManager& art::ServicesManager::operator= ( ServicesManager const &  )
delete
template<typename T , typename >
void art::ServicesManager::put ( std::unique_ptr< T > &&  premade_service)

Definition at line 154 of file ServicesManager.h.

References art::errors::LogicError.

155 {
156  std::unique_ptr<detail::ServiceHelperBase> service_helper(
157  new detail::ServiceHelper<T>);
158  TypeID const id{typeid(T)};
160  if (it != factory_.end()) {
161  throw art::Exception(art::errors::LogicError, "Service")
162  << "The system has manually added service of type "
163  << cet::demangle_symbol(id.name())
164  << ", but the service system already has a configured service"
165  << " of that type\n";
166  }
168  new detail::ServiceWrapper<T, detail::ServiceHelper<T>::scope_val>(
169  std::move(premade_service)));
170  actualCreationOrder_.push(swb);
171  factory_.emplace(
172  id, detail::ServiceCacheEntry(std::move(swb), std::move(service_helper)));
173 }
std::shared_ptr< detail::ServiceWrapperBase > WrapperBase_ptr
intermediate_table::const_iterator const_iterator
detail::ServiceStack actualCreationOrder_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
detail::ServiceCache factory_
template<typename SP , typename >
void art::ServicesManager::put ( std::vector< SP > &&  premade_services)

Definition at line 177 of file ServicesManager.h.

References art::errors::LogicError.

178 {
179  using element_type = typename SP::element_type;
180  std::unique_ptr<detail::ServiceHelperBase> service_helper(
181  new detail::ServiceHelper<element_type>);
182  TypeID const id{typeid(element_type)};
184  if (it != factory_.end()) {
185  throw art::Exception(art::errors::LogicError, "Service:")
186  << "The system has manually added service of type "
187  << cet::demangle_symbol(id.name())
188  << ", but the service system already has a configured service"
189  << " of that type\n";
190  }
192  new detail::ServiceWrapper<element_type,
193  detail::ServiceHelper<element_type>::scope_val>(
194  std::move(premade_services)));
195  actualCreationOrder_.push(swb);
196  factory_.emplace(
197  id, detail::ServiceCacheEntry(std::move(swb), std::move(service_helper)));
198 }
std::shared_ptr< detail::ServiceWrapperBase > WrapperBase_ptr
intermediate_table::const_iterator const_iterator
detail::ServiceStack actualCreationOrder_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
detail::ServiceCache factory_
void art::ServicesManager::registerProducts ( MasterProductRegistry mpr,
ProductDescriptions productsToProduce,
ProducingServiceSignals signals,
ProcessConfiguration const &  pc 
)

Definition at line 58 of file ServicesManager.cc.

References factory_, art::ModuleDescription::id(), and art::PER_SCHEDULE.

62 {
63  for (auto& pr : factory_) {
64  auto& serviceEntry = pr.second;
65 
66  // Per-schedule services cannot register products
67  if (serviceEntry.serviceScope() == ServiceScope::PER_SCHEDULE)
68  continue;
69 
70  // Service interfaces cannot be used for product insertion.
71  if (serviceEntry.is_interface())
72  continue;
73 
74  // The value of service_type becomes the "module name/label" for
75  // the ModuleDescription object.
76  auto const& pset = serviceEntry.getParameterSet();
77  std::string moduleLabel{};
78  if (!pset.get_if_present("service_type", moduleLabel)) {
79  // System services do not insert products.
80  continue;
81  }
82 
83  ModuleDescription const md{pset.id(), moduleLabel, moduleLabel, pc};
84  serviceEntry.registerProducts(mpr, productsToProduce, signals, md);
85  }
86 }
detail::ServiceCache factory_

Member Data Documentation

detail::ServiceStack art::ServicesManager::actualCreationOrder_ {}
private

Definition at line 119 of file ServicesManager.h.

Referenced by ~ServicesManager().

std::vector<std::string> art::ServicesManager::configErrMsgs_ {}
private

Definition at line 120 of file ServicesManager.h.

detail::ServiceCache art::ServicesManager::factory_ {}
private
NameIndex art::ServicesManager::index_ {}
private

Definition at line 116 of file ServicesManager.h.

Referenced by fillCache_(), and ~ServicesManager().

art::ActivityRegistry& art::ServicesManager::registry_
private

Definition at line 114 of file ServicesManager.h.

Referenced by forceCreation().

TypeIDs art::ServicesManager::requestedCreationOrder_ {}
private

Definition at line 118 of file ServicesManager.h.

Referenced by fillCache_(), and forceCreation().


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