28#define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
29#define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
31#define DEBMSG ON_DEBUG debug()
32#define VERMSG ON_VERBOSE verbose()
40 std::vector<IService*> activeSvc(
const C& lst ) {
41 std::vector<IService*> v;
42 v.reserve( lst.size() );
43 for (
auto& i : lst ) {
44 if ( i.active ) v.push_back( i.service.get() );
59 for (
auto& svc :
m_listsvc ) svc.service->setServiceManager(
nullptr );
69 const std::string&
name = typeName.name();
70 std::string type = typeName.type();
71 if ( !typeName.haveType() ) {
73 auto it =
m_maptype.find( typeName.name() );
80 auto ip = type.find(
"__" );
81 if ( ip != std::string::npos ) type.erase( ip, type.length() );
85 fatal() <<
"No Service factory for " << type <<
" available." <<
endmsg;
93 if (
name ==
"JobOptionsSvc" ) {
95 fatal() << typeName <<
" does not implement Gaudi::Interfaces::IOptionsSvc" <<
endmsg;
100 auto lck = std::scoped_lock{
m_gLock };
102 service->setServiceManager(
this );
108 auto it =
find( svc );
109 auto lck = std::scoped_lock{
m_gLock };
114 m_listsvc.emplace_back( svc, prio,
true );
120 auto it =
find( typeName.name() );
130 sc = svc->sysInitialize();
134 error() <<
"Unable to initialize service \"" << typeName.name() <<
"\"" <<
endmsg;
135 auto lck = std::scoped_lock{
m_gLock };
144 auto lck = std::scoped_lock{
m_gLock };
159 const std::string&
name = typeName.name();
167 auto lk = std::scoped_lock{ this->
m_gLock };
170 mit =
m_lockMap.emplace( std::piecewise_construct_t{}, std::forward_as_tuple(
name ), std::forward_as_tuple() )
178 auto lk2 = std::scoped_lock{ *imut };
184 error() <<
"Initialization loop detected when creating service \"" <<
name <<
"\"" <<
endmsg;
195 if ( createIf &&
addService( typeName ).isSuccess() ) {
return find(
name )->service; }
204 []( ListSvc::const_reference i ) {
return i.service.get(); } );
211 auto it =
find( svc );
225 m_maptype.insert_or_assign( std::move( svcname ), std::move( svctype ) );
237 for (
auto& it : activeSvc(
m_listsvc ) ) {
238 const std::string&
name = it->name();
239 switch ( it->FSMState() ) {
245 sc = it->sysInitialize();
252 error() <<
"Service " <<
name <<
" not in the correct state to be initialized (" << it->FSMState() <<
")"
268 for (
auto& it : activeSvc(
m_listsvc ) ) {
269 const std::string&
name = it->name();
270 switch ( it->FSMState() ) {
283 error() <<
"Service " <<
name <<
" not in the correct state to be started (" << it->FSMState() <<
")" <<
endmsg;
300 const std::string&
name = svc->name();
301 switch ( svc->FSMState() ) {
314 DEBMSG <<
"Service " <<
name <<
" not in the correct state to be stopped (" << svc->FSMState() <<
")" <<
endmsg;
329 for (
auto& svc : activeSvc(
m_listsvc ) ) {
330 sc = svc->sysReinitialize();
332 error() <<
"Unable to re-initialize Service: " << svc->name() <<
endmsg;
347 for (
auto& svc : activeSvc(
m_listsvc ) ) {
348 sc = svc->sysRestart();
350 error() <<
"Unable to re-start Service: " << svc->name() <<
endmsg;
361 if ( pri_tool != 0 ) {
374 std::vector<IIncidentListener*> postFinList;
377 p_inc->getListeners( postFinList, IncidentType::SvcPostFinalize );
392 const std::string&
name = svc->name();
396 if ( !svc->sysFinalize().isSuccess() ) {
404 if ( !postFinList.empty() ) {
405 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.size() <<
" clients" <<
endmsg;
406 Incident inc(
"ServiceManager", IncidentType::SvcPostFinalize );
407 for (
auto& itr : postFinList ) itr->handle( inc );
412 DEBMSG <<
"Looping over all active services..." <<
endmsg;
415 DEBMSG <<
"---- " << it->service->name() <<
" (refCount = " << it->service->refCount() <<
")" <<
endmsg;
416 if ( it->service->refCount() < 1 ) {
417 warning() <<
"Too low reference count for " << it->service->name() <<
" (should not go below 1 at this point)"
419 it->service->addRef();
432 return ( it !=
m_listsvc.end() ) ? it->priority : 0;
449 <<
"===================== listing all services ===================\n"
450 <<
" prior ref name active\n";
455 log.flags( std::ios_base::right );
456 log << svc.priority <<
" ";
458 log << svc.service->refCount() <<
" ";
460 log.flags( std::ios_base::left );
461 log << svc.service->name() <<
" ";
463 log << svc.active << std::endl;
466 log <<
"=================================================================\n";
473 const auto svc =
dynamic_cast<Service*
>( svcItem.service.get() );
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_OBJECT_FACTORY(x)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MSG::Level resetMessaging()
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us.
Helper class to parse a string of format "type/name".
Definition of the basic interface.
General service interface definition.
Base class for all Incidents (computing events).
Base class for all services.
The ServiceManager class is in charge of the creation of concrete instances of Services.
StatusCode declareSvcType(std::string svcname, std::string svctype) override
implementation of ISvcManager::declareSvcType
const std::list< IService * > & getServices() const override
Return the list of Services.
const std::string & name() const override
Return the name of the manager (implementation of INamedInterface)
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
StatusCode start() override
Start (from INITIALIZED to RUNNING).
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
bool existsService(std::string_view name) const override
implementation of ISvcLocation::existsService
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype) override
implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once c...
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
~ServiceManager() override
virtual destructor
std::map< std::string, std::recursive_mutex > m_lockMap
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
ServiceManager(IInterface *application)
default creator
ListSvc::iterator find(std::string_view name)
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
bool m_loopCheck
Check for service initialization loops.
int getPriority(std::string_view name) const override
manage priorities of services
std::recursive_mutex m_gLock
Mutex to synchronize shared service initialization between threads.
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
StatusCode setPriority(std::string_view name, int pri) override
MapType m_maptype
Map of service name and service type.
Small smart pointer class with automatic reference counting for IInterface.
TYPE * get() const
Get interface pointer.
This class is used for returning status codes from appropriate routines.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
::details::reverse_wrapper< T > reverse(T &&iterable)
Interface for a component that manages application configuration options.
static const InterfaceID & interfaceID()