Loading [MathJax]/extensions/tex2jax.js
Go to the documentation of this file.
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 );
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;
90 fatal() <<
"Incompatible interface IService version for " <<
type <<
endmsg;
94 if (
name ==
"JobOptionsSvc" ) {
96 fatal() <<
typeName <<
" does not implement Gaudi::Interfaces::IOptionsSvc" <<
endmsg;
101 auto lck = std::scoped_lock{
m_gLock };
103 service->setServiceManager(
this );
109 auto it =
find( svc );
110 auto lck = std::scoped_lock{
m_gLock };
115 m_listsvc.emplace_back( svc, prio,
true );
131 sc = svc->sysInitialize();
135 error() <<
"Unable to initialize service \"" <<
typeName.name() <<
"\"" <<
endmsg;
136 auto lck = std::scoped_lock{
m_gLock };
145 auto lck = std::scoped_lock{
m_gLock };
168 auto lk = std::scoped_lock{ this->
m_gLock };
171 mit =
m_lockMap.emplace( std::piecewise_construct_t{}, std::forward_as_tuple(
name ), std::forward_as_tuple() )
179 auto lk2 = std::scoped_lock{ *imut };
185 error() <<
"Initialization loop detected when creating service \"" <<
name <<
"\"" <<
endmsg;
205 []( ListSvc::const_reference i ) {
return i.service.get(); } );
212 auto it =
find( svc );
226 m_maptype.insert_or_assign( std::move( svcname ), std::move( svctype ) );
238 for (
auto& it : activeSvc(
m_listsvc ) ) {
239 const std::string&
name = it->name();
240 switch ( it->FSMState() ) {
246 sc = it->sysInitialize();
248 error() <<
"Unable to initialize Service: " <<
name <<
endmsg;
253 error() <<
"Service " <<
name <<
" not in the correct state to be initialized (" << it->FSMState() <<
")"
269 for (
auto& it : activeSvc(
m_listsvc ) ) {
270 const std::string&
name = it->name();
271 switch ( it->FSMState() ) {
279 error() <<
"Unable to start Service: " <<
name <<
endmsg;
284 error() <<
"Service " <<
name <<
" not in the correct state to be started (" << it->FSMState() <<
")" <<
endmsg;
301 const std::string&
name = svc->name();
302 switch ( svc->FSMState() ) {
310 error() <<
"Unable to stop Service: " <<
name <<
endmsg;
315 DEBMSG <<
"Service " <<
name <<
" not in the correct state to be stopped (" << svc->FSMState() <<
")" <<
endmsg;
330 for (
auto& svc : activeSvc(
m_listsvc ) ) {
331 sc = svc->sysReinitialize();
333 error() <<
"Unable to re-initialize Service: " << svc->name() <<
endmsg;
348 for (
auto& svc : activeSvc(
m_listsvc ) ) {
349 sc = svc->sysRestart();
351 error() <<
"Unable to re-start Service: " << svc->name() <<
endmsg;
362 if ( pri_tool != 0 ) {
375 std::vector<IIncidentListener*> postFinList;
376 auto p_inc = service<IIncidentSvc>(
"IncidentSvc",
false );
378 p_inc->getListeners( postFinList, IncidentType::SvcPostFinalize );
393 const std::string&
name = svc->name();
397 if ( !svc->sysFinalize().isSuccess() ) {
398 warning() <<
"Finalization of service " <<
name <<
" failed" <<
endmsg;
405 if ( !postFinList.empty() ) {
406 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.size() <<
" clients" <<
endmsg;
407 Incident inc(
"ServiceManager", IncidentType::SvcPostFinalize );
408 for (
auto& itr : postFinList ) itr->handle( inc );
413 DEBMSG <<
"Looping over all active services..." <<
endmsg;
416 DEBMSG <<
"---- " << it->service->name() <<
" (refCount = " << it->service->refCount() <<
")" <<
endmsg;
417 if ( it->service->refCount() < 1 ) {
418 warning() <<
"Too low reference count for " << it->service->name() <<
" (should not go below 1 at this point)"
420 it->service->addRef();
433 return ( it !=
m_listsvc.end() ) ? it->priority : 0;
450 <<
"===================== listing all services ===================\n"
451 <<
" prior ref name active\n";
456 log.flags( std::ios_base::right );
457 log << svc.priority <<
" ";
459 log << svc.service->refCount() <<
" ";
461 log.flags( std::ios_base::left );
462 log << svc.service->name() <<
" ";
464 log << svc.active << std::endl;
467 log <<
"=================================================================\n";
474 const auto svc =
dynamic_cast<Service*
>( svcItem.service.get() );
Gaudi::StateMachine::State targetFSMState() const override
When we are in the middle of a transition, get the state where the transition is leading us.
bool loopCheckEnabled() const override
Get the value of the initialization loop check flag.
MSG::Level resetMessaging()
Reinitialize internal states.
StatusCode start() override
Start (from INITIALIZED to RUNNING).
::details::reverse_wrapper< T > reverse(T &&iterable)
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
~ServiceManager() override
virtual destructor
StatusCode reinitialize() override
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Helper class to parse a string of format "type/name".
StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY) override
implementation of ISvcManager::addService
StatusCode initialize() override
Initialization (from CONFIGURED to INITIALIZED).
StatusCode removeService(IService *svc) override
implementation of ISvcManager::removeService
SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true) override
Returns a smart pointer to a service.
ListSvc m_listsvc
List of service maintained by ServiceManager This contains SmartIF<T> for all services – and because ...
StatusCode declareSvcType(std::string svcname, std::string svctype) override
implementation of ISvcManager::declareSvcType
StatusCode finalize() override
Finalize (from INITIALIZED to CONFIGURED).
SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype) override
implementation of ISvcManager::createService NOTE: as this returns a &, we must guarantee that once c...
bool m_loopCheck
Check for service initialization loops.
ServiceManager(IInterface *application)
default creator
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::map< std::string, std::recursive_mutex > m_lockMap
ListSvc::iterator find(std::string_view name)
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
void setLoopCheckEnabled(bool en) override
Set the value of the initialization loop check flag.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
constexpr static const auto SUCCESS
int getPriority(std::string_view name) const override
manage priorities of services
TYPE * get() const
Get interface pointer.
std::string typeName(const std::type_info &typ)
bool existsService(std::string_view name) const override
implementation of ISvcLocation::existsService
bool isValidInterface(IFace *i)
Templated function that throws an exception if the version if the interface implemented by the object...
StatusCode restart() override
Initialization (from RUNNING to RUNNING, via INITIALIZED).
std::recursive_mutex m_gLock
Mutex to synchronize shared service initialization between threads.
constexpr static const auto FAILURE
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)
StatusCode stop() override
Stop (from RUNNING to INITIALIZED).
#define DECLARE_OBJECT_FACTORY(x)
Interface for a component that manages application configuration options.
MapType m_maptype
Map of service name and service type.
StatusCode setPriority(std::string_view name, int pri) override