#include "GaudiKernel/IService.h" #include "GaudiKernel/ISvcLocator.h" #include "GaudiKernel/MsgStream.h" #include "GaudiKernel/ThreadGaudi.h" #include "GaudiKernel/ServiceLocatorHelper.h" std::string ServiceLocatorHelper::threadName() const { return getGaudiThreadIDfromName(requesterName()); } std::string ServiceLocatorHelper::threadedName(const std::string& name) const { return ( isInThread() ? name + threadName() : name ); } bool ServiceLocatorHelper::isInThread() const { return isGaudiThreaded(requesterName()); } StatusCode ServiceLocatorHelper::locateService(const std::string& name, const InterfaceID& iid, void** ppSvc, bool quiet) const { SmartIF theSvc = service(name, quiet, false); if (!theSvc.isValid()) return StatusCode::FAILURE; StatusCode sc = theSvc->queryInterface(iid, ppSvc); if (!sc.isSuccess()) { *ppSvc = 0; if (!quiet) log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service " << name << endmsg; } return sc; } StatusCode ServiceLocatorHelper::createService(const std::string& name, const InterfaceID& iid, void** ppSvc) const { SmartIF theSvc = service(name, false, true); if (!theSvc.isValid()) return StatusCode::FAILURE; StatusCode sc = theSvc->queryInterface(iid, ppSvc); if (!sc.isSuccess()) { *ppSvc = 0; log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name << endmsg; } return sc; } StatusCode ServiceLocatorHelper::createService(const std::string& type, const std::string& name, const InterfaceID& iid, void** ppSvc) const { return createService(type + "/" + name, iid, ppSvc); } SmartIF ServiceLocatorHelper::service(const std::string &name, const bool quiet, const bool createIf) const { SmartIF theSvc; if (isInThread()) { //first we look for a thread-specific version of the service theSvc = serviceLocator()->service(name + threadName(), createIf); } // if not, try to find the common, single-threaded version of the service if (!theSvc.isValid()){ theSvc = serviceLocator()->service(name, createIf); } if (theSvc.isValid()) { if (!quiet) { log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name <