Gaudi Framework, version v22r4

Home   Generated: Fri Sep 2 2011

ApplicationMgr.cpp

Go to the documentation of this file.
00001 // Include files
00002 #include "ApplicationMgr.h"
00003 #include "ServiceManager.h"
00004 #include "AlgorithmManager.h"
00005 #include "DLLClassManager.h"
00006 
00007 #include "GaudiKernel/TypeNameString.h"
00008 #include "GaudiKernel/IService.h"
00009 #include "GaudiKernel/IRunable.h"
00010 #include "GaudiKernel/IMessageSvc.h"
00011 #include "GaudiKernel/IJobOptionsSvc.h"
00012 
00013 #include "GaudiKernel/SmartIF.h"
00014 #include "GaudiKernel/MsgStream.h"
00015 #include "GaudiKernel/PropertyMgr.h"
00016 #include "GaudiKernel/ObjectFactory.h"
00017 
00018 #include "GaudiKernel/GaudiException.h"
00019 #include "GaudiKernel/ThreadGaudi.h"
00020 
00021 #include "GaudiKernel/StatusCode.h"
00022 #include "GaudiKernel/Time.h"
00023 #include "GaudiKernel/System.h"
00024 using System::getEnv;
00025 using System::isEnvSet;
00026 
00027 #include <algorithm>
00028 #include <cassert>
00029 #include <ctime>
00030 #include <limits>
00031 
00032 static const char* s_eventloop = "EventLoop";
00033 static const char* s_runable   = "Runable";
00034 
00035 #define ON_DEBUG if (UNLIKELY(m_outputLevel <= MSG::DEBUG))
00036 #define ON_VERBOSE if (UNLIKELY(m_outputLevel <= MSG::VERBOSE))
00037 
00038 DECLARE_OBJECT_FACTORY(ApplicationMgr)
00039 
00040 // Implementation class for the Application Manager. In this way the
00041 // ApplicationMgr class is a fully insulated concrete class. Clients
00042 // (main programs) will not need to re-compile if there are changes
00043 // in the implementation
00044 
00045 //=======================================================================
00046 // Constructor
00047 //=======================================================================
00048 ApplicationMgr::ApplicationMgr(IInterface*): base_class() {
00049   // IInterface initialization
00050   addRef(); // Initial count set to 1
00051 
00052   // Initialize two basic services: messagesvc & joboptions
00053   m_messageSvc        = 0;
00054   m_jobOptionsSvc     = 0;
00055 
00056   // Instantiate component managers
00057   m_managers[IService::interfaceID().id()] = new ServiceManager(this);
00058   m_managers[IAlgorithm::interfaceID().id()] = new AlgorithmManager(this);
00059 
00060   m_svcLocator = svcManager();
00061 
00062   // Instantiate internal services
00063   // SvcLocator/Factory HAS to be already instantiated
00064   m_classManager = new DLLClassManager(this);
00065   m_propertyMgr  = new PropertyMgr(this);
00066 
00067   m_name  = "ApplicationMgr";
00068   m_state = Gaudi::StateMachine::OFFLINE;
00069   m_targetState = Gaudi::StateMachine::OFFLINE;
00070 
00071   m_propertyMgr->declareProperty("Go",            m_SIGo = 0 );
00072   m_propertyMgr->declareProperty("Exit",          m_SIExit = 0 );
00073   m_propertyMgr->declareProperty("Dlls",          m_dllNameList );
00074   m_propertyMgr->declareProperty("ExtSvc",        m_extSvcNameList );
00075   m_propertyMgr->declareProperty("CreateSvc",     m_createSvcNameList );
00076   m_propertyMgr->declareProperty("ExtSvcCreates", m_extSvcCreates=true );
00077 
00078   m_propertyMgr->declareProperty("SvcMapping",    m_svcMapping );
00079   m_propertyMgr->declareProperty("SvcOptMapping", m_svcOptMapping );
00080 
00081   m_propertyMgr->declareProperty("TopAlg",        m_topAlgNameList );
00082   m_propertyMgr->declareProperty("OutStream",     m_outStreamNameList );
00083   m_propertyMgr->declareProperty("OutStreamType", m_outStreamType = "OutputStream" );
00084   m_propertyMgr->declareProperty("MessageSvcType",m_messageSvcType= "MessageSvc" );
00085   m_propertyMgr->declareProperty("JobOptionsSvcType",
00086                                  m_jobOptionsSvcType = "JobOptionsSvc" );
00087   m_propertyMgr->declareProperty( s_runable,      m_runableType   = "AppMgrRunable");
00088   m_propertyMgr->declareProperty( s_eventloop,    m_eventLoopMgr  = "EventLoopMgr");
00089 
00090   m_propertyMgr->declareProperty("HistogramPersistency", m_histPersName="NONE");
00091 
00092   // Declare Job Options Service properties and set default
00093   m_propertyMgr->declareProperty("JobOptionsType", m_jobOptionsType = "FILE");
00094   m_propertyMgr->declareProperty("JobOptionsPath", m_jobOptionsPath = "");
00095   m_propertyMgr->declareProperty("EvtMax",         m_evtMax = -1);
00096   m_propertyMgr->declareProperty("EvtSel",         m_evtsel );
00097   m_propertyMgr->declareProperty("OutputLevel",    m_outputLevel = MSG::INFO);
00098 
00099   m_propertyMgr->declareProperty("MultiThreadExtSvc", m_multiThreadSvcNameList);
00100   m_propertyMgr->declareProperty("NoOfThreads",    m_noOfEvtThreads = 0);
00101   m_propertyMgr->declareProperty("AppName",        m_appName = "ApplicationMgr");
00102   m_propertyMgr->declareProperty("AppVersion",     m_appVersion = "");
00103 
00104   m_propertyMgr->declareProperty("AuditTools",      m_auditTools = false);
00105   m_propertyMgr->declareProperty("AuditServices",   m_auditSvcs = false);
00106   m_propertyMgr->declareProperty("AuditAlgorithms", m_auditAlgs = false);
00107 
00108   m_propertyMgr->declareProperty("ActivateHistory", m_actHistory = false);
00109   m_propertyMgr->declareProperty("StatusCodeCheck", m_codeCheck = false);
00110 
00111   m_propertyMgr->declareProperty("Environment",    m_environment);
00112 
00113   // ServiceMgr Initialization loop checking
00114   m_propertyMgr->declareProperty("InitializationLoopCheck", m_loopCheck = true)
00115     ->declareUpdateHandler(&ApplicationMgr::initLoopCheckHndlr, this);
00116   svcManager()->setLoopCheckEnabled(m_loopCheck);
00117 
00118   // Flag to activate the printout of properties
00119   m_propertyMgr->declareProperty
00120     ( "PropertiesPrint",
00121       m_propertiesPrint = false,
00122       "Flag to activate the printout of properties" );
00123 
00124   m_propertyMgr->declareProperty("ReflexPluginDebugLevel", m_reflexDebugLevel = 0 );
00125 
00126   m_propertyMgr->declareProperty("StopOnSignal", m_stopOnSignal = false,
00127       "Flag to enable/disable the signal handler that schedule a stop of the event loop");
00128 
00129   m_propertyMgr->declareProperty("StalledEventMonitoring", m_stalledEventMonitoring = false,
00130       "Flag to enable/disable the monitoring and reporting of stalled events");
00131 
00132   m_propertyMgr->declareProperty("ReturnCode", m_returnCode = 0,
00133       "Return code of the application. Set internally in case of error conditions.");
00134 
00135   // Add action handlers to the appropriate properties
00136   m_SIGo.declareUpdateHandler  ( &ApplicationMgr::SIGoHandler         , this );
00137   m_SIExit.declareUpdateHandler( &ApplicationMgr::SIExitHandler       , this );
00138   m_topAlgNameList.declareUpdateHandler(&ApplicationMgr::evtLoopPropertyHandler, this);
00139   m_outStreamNameList.declareUpdateHandler(&ApplicationMgr::evtLoopPropertyHandler, this);
00140   m_outStreamType.declareUpdateHandler(&ApplicationMgr::evtLoopPropertyHandler, this);
00141   m_reflexDebugLevel.declareUpdateHandler(&ApplicationMgr::reflexDebugPropertyHandler, this);
00142   m_svcMapping.push_back("EvtDataSvc/EventDataSvc");
00143   m_svcMapping.push_back("DetDataSvc/DetectorDataSvc");
00144   m_svcMapping.push_back("HistogramSvc/HistogramDataSvc");
00145   m_svcMapping.push_back("HbookCnv::PersSvc/HbookHistSvc");
00146   m_svcMapping.push_back("RootHistCnv::PersSvc/RootHistSvc");
00147   m_svcMapping.push_back("EvtPersistencySvc/EventPersistencySvc");
00148   m_svcMapping.push_back("DetPersistencySvc/DetectorPersistencySvc");
00149   m_svcMapping.push_back("HistogramPersistencySvc/HistogramPersistencySvc");
00150 }
00151 
00152 //============================================================================
00153 // destructor
00154 //============================================================================
00155 ApplicationMgr::~ApplicationMgr() {
00156   if( m_classManager ) m_classManager->release();
00157   if( m_propertyMgr ) m_propertyMgr->release();
00158   if( m_messageSvc ) m_messageSvc->release();
00159   if( m_jobOptionsSvc ) m_jobOptionsSvc->release();
00160 }
00161 
00162 //============================================================================
00163 // IInterface implementation: queryInterface::addRef()
00164 //============================================================================
00165 StatusCode ApplicationMgr::queryInterface
00166 ( const InterfaceID& iid  ,
00167   void**             ppvi )
00168 {
00169   if ( 0 == ppvi ) { return StatusCode::FAILURE ; }
00170 
00171   // try to find own/direct interfaces:
00172   StatusCode sc = base_class::queryInterface(iid,ppvi);
00173   if (sc.isSuccess()) return sc;
00174 
00175   // find indirect interfaces :
00176   if      ( ISvcLocator     ::interfaceID() . versionMatch ( iid ) )
00177   { return serviceLocator()-> queryInterface ( iid , ppvi ) ; }
00178   else if ( ISvcManager     ::interfaceID() . versionMatch ( iid ) )
00179   { return svcManager()    -> queryInterface ( iid , ppvi ) ; }
00180   else if ( IAlgManager     ::interfaceID() . versionMatch ( iid ) )
00181   { return algManager()    -> queryInterface ( iid , ppvi ) ; }
00182   else if ( IClassManager   ::interfaceID() . versionMatch ( iid ) )
00183   { return m_classManager  -> queryInterface ( iid , ppvi ) ; }
00184   else if ( IProperty       ::interfaceID() . versionMatch ( iid ) )
00185   { return m_propertyMgr   -> queryInterface ( iid , ppvi ) ; }
00186   else if ( IMessageSvc     ::interfaceID() . versionMatch ( iid ) )
00187   {
00188     *ppvi = reinterpret_cast<void*>(m_messageSvc.get());
00189     if (m_messageSvc) {
00190       m_messageSvc->addRef();
00191     }
00192     // Note that 0 can be a valid IMessageSvc pointer value (when used for
00193     // MsgStream).
00194     return StatusCode::SUCCESS;
00195   }
00196   *ppvi = 0;
00197   return StatusCode::FAILURE;
00198 }
00199 
00200 //============================================================================
00201 // ApplicationMgr::i_startup()
00202 //============================================================================
00203 StatusCode ApplicationMgr::i_startup() {
00204   StatusCode  sc;
00205 
00206   // declare factories in current module
00207   m_classManager->loadModule("").ignore();
00208 
00209   // Create the Message service
00210   SmartIF<IService> msgsvc = svcManager()->createService(Gaudi::Utils::TypeNameString("MessageSvc", m_messageSvcType));
00211   if( !msgsvc.isValid() )  {
00212     fatal() << "Error creating MessageSvc of type " << m_messageSvcType << endmsg;
00213     return sc;
00214   }
00215   // Create the Job Options service
00216   SmartIF<IService> jobsvc = svcManager()->createService(Gaudi::Utils::TypeNameString("JobOptionsSvc", m_jobOptionsSvcType));
00217   if( !jobsvc.isValid() )   {
00218     fatal() << "Error creating JobOptionsSvc" << endmsg;
00219     return sc;
00220   }
00221 
00222   SmartIF<IProperty> jobOptsIProp(jobsvc);
00223   if ( !jobOptsIProp.isValid() )   {
00224     fatal() << "Error locating JobOptionsSvc" << endmsg;
00225     return sc;
00226   }
00227   sc = jobOptsIProp->setProperty( StringProperty("TYPE", m_jobOptionsType) );
00228   if( !sc.isSuccess() )   {
00229     fatal() << "Error setting TYPE option in JobOptionsSvc" << endmsg;
00230     return sc;
00231   }
00232 
00233   if ( m_jobOptionsPath != "") {         // The command line takes precedence
00234     sc = jobOptsIProp->setProperty( StringProperty("PATH", m_jobOptionsPath) );
00235     if( !sc.isSuccess() )   {
00236       fatal() << "Error setting PATH option in JobOptionsSvc" << endmsg;
00237       return sc;
00238     }
00239   }
00240   else if ( isEnvSet("JOBOPTPATH") ) {// Otherwise the Environment JOBOPTPATH
00241     sc = jobOptsIProp->setProperty (StringProperty("PATH",
00242                                                    getEnv("JOBOPTPATH")));
00243     if( !sc.isSuccess() )   {
00244       fatal()
00245            << "Error setting PATH option in JobOptionsSvc from env"
00246            << endmsg;
00247       return sc;
00248     }
00249   }
00250   else {                                   // Otherwise the default
00251     sc = jobOptsIProp->setProperty (StringProperty("PATH",
00252                                                    "../options/job.opts"));
00253     if( !sc.isSuccess() )   {
00254       fatal()
00255            << "Error setting PATH option in JobOptionsSvc to default"
00256            << endmsg;
00257       return sc;
00258     }
00259   }
00260   jobOptsIProp->release();
00261 
00262   // Sets my default the Output Level of the Message service to be
00263   // the same as this
00264   SmartIF<IProperty> msgSvcIProp(msgsvc);
00265   msgSvcIProp->setProperty( IntegerProperty("OutputLevel", m_outputLevel)).ignore();
00266   msgSvcIProp->release();
00267 
00268   sc = jobsvc->sysInitialize();
00269   if( !sc.isSuccess() )   {
00270     fatal() << "Error initializing JobOptionsSvc" << endmsg;
00271     return sc;
00272   }
00273   sc = msgsvc->sysInitialize();
00274   if( !sc.isSuccess() )  {
00275     fatal() << "Error initializing MessageSvc" << endmsg;
00276     return sc;
00277   }
00278 
00279   // Get the useful interface from Message anf JobOptions services
00280   m_messageSvc = m_svcLocator->service("MessageSvc");
00281   if( !m_messageSvc.isValid() )  {
00282     fatal() << "Error retrieving MessageSvc." << endmsg;
00283     return sc;
00284   }
00285   m_jobOptionsSvc = m_svcLocator->service("JobOptionsSvc");
00286   if( !m_jobOptionsSvc.isValid() )  {
00287     fatal() << "Error retrieving JobOptionsSvc." << endmsg;
00288     return sc;
00289   }
00290 
00291   return sc;
00292 }
00293 
00294 //============================================================================
00295 // IAppMgrUI implementation: ApplicationMgr::configure()
00296 //============================================================================
00297 StatusCode ApplicationMgr::configure() {
00298   // Check if the state is compatible with the transition
00299   MsgStream tlog( m_messageSvc, name() );
00300   if( Gaudi::StateMachine::CONFIGURED == m_state ) {
00301     tlog << MSG::INFO << "Already Configured" << endmsg;
00302     return StatusCode::SUCCESS;
00303   }
00304   else if( Gaudi::StateMachine::OFFLINE != m_state ) {
00305     tlog << MSG::FATAL
00306          << "configure: Invalid state \""  << m_state << "\"" << endmsg;
00307     return StatusCode::FAILURE;
00308   }
00309   m_targetState = Gaudi::StateMachine::CONFIGURED;
00310 
00311   StatusCode  sc;
00312   sc = i_startup();
00313   if ( !sc.isSuccess() )    {
00314     return sc;
00315   }
00316 
00317   MsgStream log( m_messageSvc, name() );
00318 
00319   // Get my own options using the Job options service
00320   if (log.level() <= MSG::DEBUG)
00321     log << MSG::DEBUG << "Getting my own properties" << endmsg;
00322   sc = m_jobOptionsSvc->setMyProperties( name(), m_propertyMgr );
00323   if( !sc.isSuccess() ) {
00324     log << MSG::WARNING << "Problems getting my properties from JobOptionsSvc"
00325         << endmsg;
00326     return sc;
00327   }
00328 
00329   // Check current outputLevel to eventually inform the MessageSvc
00330   if( m_outputLevel != MSG::NIL && !m_appName.empty() ) {
00331     assert(m_messageSvc != 0);
00332     m_messageSvc->setOutputLevel( name(), m_outputLevel );
00333     // Print a welcome message
00334     log << MSG::ALWAYS
00335         << std::endl
00336         << "=================================================================="
00337         << "=================================================================="
00338         << std::endl
00339         << "                                "
00340         << "                   Welcome to " << m_appName;
00341 
00342     if( "" != m_appVersion ) {
00343       log << MSG::ALWAYS << " version " << m_appVersion;
00344     }
00345     else {
00346       log << MSG::ALWAYS << " $Revision: 1.77 $";
00347     }
00348 
00349     // Add the host name and current time to the message
00350     log << MSG::ALWAYS
00351         << std::endl
00352         << "                                "
00353         << "          running on " << System::hostName()
00354         << " on " << Gaudi::Time::current().format(true) << std::endl
00355         << "=================================================================="
00356         << "=================================================================="
00357         << endmsg;
00358   }
00359 
00360   // print all own properties if the options "PropertiesPrint" is set to true
00361   if ( m_propertiesPrint )
00362   {
00363     typedef std::vector<Property*> Properties;
00364     const Properties& properties = m_propertyMgr->getProperties() ;
00365     log << MSG::ALWAYS
00366         << "List of ALL properties of "
00367         << System::typeinfoName ( typeid( *this ) ) << "/" << this->name()
00368         << "  #properties = " << properties.size() << endmsg ;
00369     for ( Properties::const_iterator property = properties.begin() ;
00370           properties.end() != property ; ++property )
00371     { log << "Property ['Name': Value] = " << ( **property) << endmsg ; }
00372   }
00373 
00374   // Check if StatusCode need to be checked
00375   if (m_codeCheck) {
00376     StatusCode::enableChecking();
00377     sc = addMultiSvc("StatusCodeSvc", -9999);
00378     if ( sc.isFailure() ) {
00379       log << MSG::FATAL << "Error adding StatusCodeSvc for multiple threads" << endmsg;
00380       return StatusCode::FAILURE;
00381     }
00382   } else {
00383     StatusCode::disableChecking();
00384   }
00385 
00386   // set the requested environment variables
00387   std::map<std::string,std::string>::iterator var;
00388   for ( var = m_environment.begin(); var != m_environment.end(); ++var ) {
00389     const std::string &name  = var->first;
00390     const std::string &value = var->second;
00391     std::string old = System::getEnv(name.c_str());
00392     const MSG::Level lvl = (!old.empty() && (old != "UNKNOWN" ))
00393         ? MSG::WARNING
00394         : MSG::DEBUG;
00395     if (UNLIKELY(m_outputLevel <= lvl))
00396       log << lvl << "Setting " << name << " = " << value << endmsg;
00397     System::setEnv(name,value);
00398   }
00399 
00400   //Declare Service Types
00401   VectorName::const_iterator j;
00402   for(j=m_svcMapping.begin(); j != m_svcMapping.end(); ++j)  {
00403     Gaudi::Utils::TypeNameString itm(*j);
00404     if ( declareMultiSvcType(itm.name(), itm.type()).isFailure() )  {
00405       log << MSG::ERROR << "configure: declaring svc type:'" << *j << "' failed." << endmsg;
00406       return StatusCode::FAILURE;
00407     }
00408   }
00409   for(j=m_svcOptMapping.begin(); j != m_svcOptMapping.end(); ++j)  {
00410     Gaudi::Utils::TypeNameString itm(*j);
00411     if ( declareMultiSvcType(itm.name(), itm.type()).isFailure() )  {
00412       log << MSG::ERROR << "configure: declaring svc type:'" << *j << "' failed." << endmsg;
00413       return StatusCode::FAILURE;
00414     }
00415   }
00416 
00417   //--------------------------------------------------------------------------
00418   // Declare other Services and Algorithms by loading DLL's
00419   sc = decodeDllNameList( );
00420   if ( sc.isFailure( ) ) {
00421     log << MSG::ERROR << "Failure loading declared DLL's" << endmsg;
00422     return sc;
00423   }
00424 
00425   //--------------------------------------------------------------------------
00426   // Deal with the services explicitely declared by the user.
00427   sc = decodeExtSvcNameList();
00428   if ( sc.isFailure( ) ) {
00429     log << MSG::ERROR << "Failure during external service association" << endmsg;
00430     return sc;
00431   }
00432 
00433   sc = decodeMultiThreadSvcNameList( );
00434   if ( sc.isFailure( ) ) {
00435     log << MSG::ERROR << "Failure during multi thread service creation"
00436         << endmsg;
00437     return sc;
00438   }
00439 
00440   sc = decodeCreateSvcNameList();
00441   if ( sc.isFailure( ) ) {
00442     log << MSG::ERROR << "Failure during external service creation" << endmsg;
00443     return sc;
00444   }
00445 
00446 
00447   //--------------------------------------------------------------------------
00448   // Retrieve intrinsic services. If needed configure them.
00449   //--------------------------------------------------------------------------
00450   Gaudi::Utils::TypeNameString evtloop_item(m_eventLoopMgr);
00451   sc = addMultiSvc(evtloop_item, 100);
00452   if( !sc.isSuccess() )  {
00453     log << MSG::FATAL << "Error adding :" << m_eventLoopMgr << endmsg;
00454     return sc;
00455   }
00456 
00457   if (m_noOfEvtThreads == 0) {
00458     m_runable = m_svcLocator->service(m_runableType);
00459     if( !m_runable.isValid() )  {
00460       log << MSG::FATAL
00461           << "Error retrieving Runable:" << m_runableType
00462           << "\n Check option ApplicationMgr." << s_runable << endmsg;
00463       return sc;
00464     }
00465     m_processingMgr = m_svcLocator->service(evtloop_item);
00466     if( !m_processingMgr.isValid() )  {
00467       log << MSG::FATAL
00468           << "Error retrieving Processing manager:" << m_eventLoopMgr
00469           << "\n Check option ApplicationMgr." << s_eventloop
00470           << "\n No events will be processed." << endmsg;
00471       return sc;
00472     }
00473   }
00474 
00475   // Establish Update Handlers for ExtSvc and DLLs Properties
00476   m_extSvcNameList.declareUpdateHandler (&ApplicationMgr::extSvcNameListHandler,
00477                                          this);
00478   m_createSvcNameList.declareUpdateHandler (&ApplicationMgr::createSvcNameListHandler,
00479                                          this);
00480   m_multiThreadSvcNameList.declareUpdateHandler
00481     (&ApplicationMgr::multiThreadSvcNameListHandler, this);
00482   m_dllNameList.declareUpdateHandler (&ApplicationMgr::dllNameListHandler,
00483                                       this );
00484 
00485   if (m_actHistory) {
00486     // Create HistorySvc with a priority to ensure it's initialized last, finalized first
00487     sc = svcManager()->addService("HistorySvc",std::numeric_limits<int>::max());
00488     if ( sc.isFailure() ) {
00489       log << MSG::FATAL << "Error adding HistorySvc" << endmsg;
00490       return StatusCode::FAILURE;
00491     }
00492 
00493     if (m_noOfEvtThreads > 0) {
00494       sc = addMultiSvc("HistorySvc",std::numeric_limits<int>::max());
00495       if ( sc.isFailure() ) {
00496         log << MSG::FATAL << "Error adding HistorySvc for multiple threads"
00497             << endmsg;
00498         return StatusCode::FAILURE;
00499       }
00500     }
00501   }
00502 
00503   log << MSG::INFO << "Application Manager Configured successfully" << endmsg;
00504   m_state = m_targetState;
00505   return StatusCode::SUCCESS;
00506 }
00507 
00508 //============================================================================
00509 // IAppMgrUI implementation: ApplicationMgr::initialize()
00510 //============================================================================
00511 StatusCode ApplicationMgr::initialize() {
00512 
00513   MsgStream log( m_messageSvc, name() );
00514   StatusCode sc;
00515 
00516   // I cannot add these services in configure() because they are coming from GaudiUtils
00517   // and it messes up genconf when rebuilding it.
00518   if (m_stopOnSignal) {
00519     // Instantiate the service that schedules a stop when a signal is received
00520     std::string svcname("Gaudi::Utils::StopSignalHandler");
00521     sc = svcManager()->addService(svcname);
00522     if ( sc.isFailure() ) {
00523       log << MSG::INFO << "Cannot instantiate " << svcname << "signals will be ignored" << endmsg;
00524     }
00525   }
00526 
00527   if (m_stalledEventMonitoring) {
00528     // Instantiate the service that schedules a stop when a signal is received
00529     std::string svcname("StalledEventMonitor");
00530     sc = svcManager()->addService(svcname);
00531     if ( sc.isFailure() ) {
00532       log << MSG::INFO << "Cannot instantiate " << svcname << "signals will be ignored" << endmsg;
00533     }
00534   }
00535 
00536   if( m_state == Gaudi::StateMachine::INITIALIZED ) {
00537     log << MSG::INFO << "Already Initialized!" << endmsg;
00538     return StatusCode::SUCCESS;
00539   }
00540   else if( m_state != Gaudi::StateMachine::CONFIGURED ) {
00541     log << MSG::FATAL
00542          << "initialize: Invalid state \""  << m_state << "\"" << endmsg;
00543     return StatusCode::FAILURE;
00544   }
00545   m_targetState = Gaudi::StateMachine::INITIALIZED;
00546 
00547   //--------------------------------------------------------------------------
00548   // Initialize the list of top Services
00549   //--------------------------------------------------------------------------
00550   sc = svcManager()->initialize();
00551   if( !sc.isSuccess() ) return sc;
00552 
00553   //--------------------------------------------------------------------------
00554   // Final steps: Inform user and change internal state
00555   //--------------------------------------------------------------------------
00556   log << MSG::INFO << "Application Manager Initialized successfully"  << endmsg;
00557   m_state = m_targetState;
00558 
00559   return sc;
00560 }
00561 
00562 //============================================================================
00563 // IAppMgrUI implementation: ApplicationMgr::start()
00564 //============================================================================
00565 StatusCode ApplicationMgr::start() {
00566 
00567   MsgStream log( m_messageSvc, name() );
00568   StatusCode sc;
00569 
00570   if( m_state == Gaudi::StateMachine::RUNNING ) {
00571     log << MSG::INFO << "Already Initialized!" << endmsg;
00572     return StatusCode::SUCCESS;
00573   }
00574   else if( m_state != Gaudi::StateMachine::INITIALIZED ) {
00575     log << MSG::FATAL
00576          << "start: Invalid state \""  << m_state << "\"" << endmsg;
00577     return StatusCode::FAILURE;
00578   }
00579   m_targetState = Gaudi::StateMachine::RUNNING;
00580 
00581   //--------------------------------------------------------------------------
00582   // Initialize the list of top Services
00583   //--------------------------------------------------------------------------
00584   sc = svcManager()->start();
00585   if( !sc.isSuccess() ) return sc;
00586 
00587   //--------------------------------------------------------------------------
00588   // Final steps: Inform user and change internal state
00589   //--------------------------------------------------------------------------
00590   log << MSG::INFO << "Application Manager Started successfully"  << endmsg;
00591   m_state = m_targetState;
00592 
00593   return sc;
00594 }
00595 
00596 //============================================================================
00597 // IAppMgrUI implementation: ApplicationMgr::nextEvent(int)
00598 //============================================================================
00599 StatusCode ApplicationMgr::nextEvent(int maxevt)    {
00600   if( m_state != Gaudi::StateMachine::RUNNING ) {
00601     MsgStream log( m_messageSvc, name() );
00602     log << MSG::FATAL << "nextEvent: Invalid state \"" << m_state << "\""
00603         << endmsg;
00604     return StatusCode::FAILURE;
00605   }
00606   if (!m_processingMgr.isValid())   {
00607     MsgStream log( m_messageSvc, name() );
00608     log << MSG::FATAL << "No event processing manager specified. Check option:"
00609         << s_eventloop << endmsg;
00610     return StatusCode::FAILURE;
00611   }
00612   return m_processingMgr->nextEvent(maxevt);
00613 }
00614 
00615 //============================================================================
00616 // IAppMgrUI implementation: ApplicationMgr::stop()
00617 //============================================================================
00618 StatusCode ApplicationMgr::stop() {
00619 
00620   MsgStream log( m_messageSvc, name() );
00621   StatusCode sc;
00622 
00623   if( m_state == Gaudi::StateMachine::INITIALIZED ) {
00624     log << MSG::INFO << "Already Initialized!" << endmsg;
00625     return StatusCode::SUCCESS;
00626   }
00627   else if( m_state != Gaudi::StateMachine::RUNNING ) {
00628     log << MSG::FATAL
00629          << "stop: Invalid state \""  << m_state << "\"" << endmsg;
00630     return StatusCode::FAILURE;
00631   }
00632   m_targetState = Gaudi::StateMachine::INITIALIZED;
00633 
00634   // Stop independently managed Algorithms
00635   sc = algManager()->stop();
00636   if( !sc.isSuccess() ) return sc;
00637 
00638   //--------------------------------------------------------------------------
00639   // Stop the list of top Services
00640   //--------------------------------------------------------------------------
00641   sc = svcManager()->stop();
00642   if( !sc.isSuccess() ) return sc;
00643 
00644   //--------------------------------------------------------------------------
00645   // Final steps: Inform user and change internal state
00646   //--------------------------------------------------------------------------
00647   log << MSG::INFO << "Application Manager Stopped successfully"  << endmsg;
00648   m_state = m_targetState;
00649 
00650   return sc;
00651 }
00652 
00653 //============================================================================
00654 // IAppMgrUI implementation: ApplicationMgr::finalize()
00655 //============================================================================
00656 StatusCode ApplicationMgr::finalize() {
00657   MsgStream log( m_messageSvc, name() );
00658   if( m_state == Gaudi::StateMachine::CONFIGURED ) {
00659     log << MSG::INFO << "Already Finalized" << endmsg;
00660     return StatusCode::SUCCESS;
00661   }
00662   else if( m_state != Gaudi::StateMachine::INITIALIZED ) {
00663     log << MSG::FATAL << "finalize: Invalid state \"" << m_state << "\""
00664         << endmsg;
00665     return StatusCode::FAILURE;
00666   }
00667   m_targetState = Gaudi::StateMachine::CONFIGURED;
00668 
00669   // disable message suppression in finalize
00670   m_svcLocator->service<IProperty>("MessageSvc")->setProperty(BooleanProperty("enableSuppression", false)).ignore();
00671 
00672   // Finalize independently managed Algorithms
00673   StatusCode sc = algManager()->finalize();
00674 
00675 
00676   // Finalize all Services
00677   sc = svcManager()->finalize();
00678 
00679   //svcManager()->removeService( (IService*) m_processingMgr.get() );
00680   //svcManager()->removeService( (IService*) m_runable.get() );
00681 
00682   if (m_codeCheck) {
00683     StatusCode::disableChecking();
00684   }
00685 
00686   log << MSG::INFO << "Application Manager Finalized successfully" << endmsg;
00687 
00688   m_state = m_targetState;
00689   return sc;
00690 }
00691 
00692 //============================================================================
00693 // IAppMgrUI implementation: ApplicationMgr::terminate()
00694 //============================================================================
00695 StatusCode ApplicationMgr::terminate() {
00696   MsgStream log( m_messageSvc, name() );
00697 
00698   if( m_state == Gaudi::StateMachine::OFFLINE ) {
00699     log << MSG::INFO << "Already Offline" << endmsg;
00700     return StatusCode::SUCCESS;
00701   }
00702   else if( m_state != Gaudi::StateMachine::CONFIGURED ) {
00703     log << MSG::FATAL << "terminate: Invalid state \"" << m_state << "\""
00704         << endmsg;
00705     return StatusCode::FAILURE;
00706   }
00707   // release all Services
00708   m_targetState = Gaudi::StateMachine::OFFLINE;
00709 
00710 
00711   log << MSG::INFO << "Application Manager Terminated successfully" << endmsg;
00712 
00713   { // Force a disable the auditing of finalize for MessageSvc
00714     SmartIF<IProperty> prop(m_messageSvc);
00715     if (prop.isValid()) {
00716       prop->setProperty(BooleanProperty("AuditFinalize", false)).ignore();
00717     }
00718   }
00719   { // Force a disable the auditing of finalize for JobOptionsSvc
00720     SmartIF<IProperty> prop(m_jobOptionsSvc);
00721     if (prop.isValid()) {
00722       prop->setProperty(BooleanProperty("AuditFinalize", false)).ignore();
00723     }
00724   }
00725 
00726   // finalize MessageSvc
00727   SmartIF<IService> svc(m_messageSvc);
00728   if ( !svc.isValid() ) {
00729     log << MSG::ERROR << "Could not get the IService interface of the MessageSvc" << endmsg;
00730   } else {
00731     svc->sysFinalize().ignore();
00732   }
00733 
00734   // finalize JobOptionsSvc
00735   svc = m_jobOptionsSvc;
00736   if ( !svc.isValid() ) {
00737     log << MSG::ERROR << "Could not get the IService interface of the JobOptionsSvc" << endmsg;
00738   } else {
00739     svc->sysFinalize().ignore();
00740   }
00741 
00742   m_state = m_targetState;
00743   return StatusCode::SUCCESS;
00744 }
00745 
00746 //============================================================================
00747 // Reach the required state going through all the needed transitions
00748 //============================================================================
00749 StatusCode ApplicationMgr::GoToState(Gaudi::StateMachine::State state, bool ignoreFailures) {
00750   StatusCode sc = StatusCode(StatusCode::SUCCESS,true);
00751 
00752   switch (state) {
00753 
00754   case Gaudi::StateMachine::OFFLINE:
00755     switch (m_state) {
00756     case Gaudi::StateMachine::OFFLINE    : return StatusCode::SUCCESS; break;
00757     case Gaudi::StateMachine::CONFIGURED : return terminate(); break;
00758     default: // Gaudi::StateMachine::INITIALIZED or Gaudi::StateMachine::RUNNING
00759       sc = GoToState(Gaudi::StateMachine::CONFIGURED);
00760       if (sc.isSuccess()) {
00761         return terminate();
00762       } break;
00763     } break;
00764 
00765   case Gaudi::StateMachine::CONFIGURED:
00766     switch (m_state) {
00767     case Gaudi::StateMachine::CONFIGURED  : return StatusCode::SUCCESS; break;
00768     case Gaudi::StateMachine::OFFLINE     : return configure(); break;
00769     case Gaudi::StateMachine::INITIALIZED : return finalize(); break;
00770     default: // Gaudi::StateMachine::RUNNING
00771       sc = GoToState(Gaudi::StateMachine::INITIALIZED);
00772       if (sc.isSuccess()) {
00773         return finalize();
00774       } break;
00775     } break;
00776 
00777   case Gaudi::StateMachine::INITIALIZED:
00778     switch (m_state) {
00779     case Gaudi::StateMachine::INITIALIZED : return StatusCode::SUCCESS; break;
00780     case Gaudi::StateMachine::CONFIGURED  : return initialize(); break;
00781     case Gaudi::StateMachine::RUNNING     : return stop(); break;
00782     default: // Gaudi::StateMachine::OFFLINE
00783       sc = GoToState(Gaudi::StateMachine::CONFIGURED);
00784       if (sc.isSuccess()) {
00785         return initialize();
00786       } break;
00787     } break;
00788 
00789   case Gaudi::StateMachine::RUNNING:
00790     switch (m_state) {
00791     case Gaudi::StateMachine::RUNNING     : return StatusCode::SUCCESS; break;
00792     case Gaudi::StateMachine::INITIALIZED : return start(); break;
00793     default: // Gaudi::StateMachine::OFFLINE or Gaudi::StateMachine::CONFIGURED
00794       sc = GoToState(Gaudi::StateMachine::INITIALIZED);
00795       if (sc.isSuccess()) {
00796         return start();
00797       } break;
00798     } break;
00799 
00800   }
00801 
00802   // If I get here, there has been a problem in the recursion
00803 
00804   if (ignoreFailures){
00805     // force the new state
00806     m_state = state;
00807     return StatusCode::SUCCESS;
00808   }
00809 
00810   return sc;
00811 }
00812 
00813 //============================================================================
00814 // IAppMgrUI implementation: ApplicationMgr::run()
00815 //============================================================================
00816 StatusCode ApplicationMgr::run() {
00817   StatusCode sc = StatusCode::SUCCESS;
00818 
00819   sc = GoToState(Gaudi::StateMachine::RUNNING);
00820   if ( sc.isSuccess() ) {
00821     MsgStream log(m_messageSvc, name());
00822     if ( m_runable != 0 ) { // loop over the events
00823       sc = m_runable->run();
00824       if ( !sc.isSuccess() ) {
00825         log << MSG::FATAL << "Application execution failed. Ending the job."
00826             << endmsg;
00827       }
00828     } else {
00829       log << MSG::FATAL << "Application has no runable object. Check option:"
00830           << s_runable << endmsg;
00831     }
00832   }
00833   if (sc.isSuccess()) { // try to close cleanly
00834     sc = GoToState(Gaudi::StateMachine::OFFLINE);
00835   }
00836   // either the runable failed of the stut-down
00837   if (sc.isFailure()) { // try to close anyway (but keep the StatusCode unchanged)
00838     GoToState(Gaudi::StateMachine::OFFLINE,true).ignore();
00839   }
00840   return sc;
00841 }
00842 
00843 //============================================================================
00844 // IEventProcessor implementation: executeEvent(void* par)
00845 //============================================================================
00846 StatusCode ApplicationMgr::executeEvent(void* par)    {
00847   MsgStream log( m_messageSvc, name() );
00848   if( m_state == Gaudi::StateMachine::RUNNING ) {
00849     if ( m_processingMgr.isValid() )    {
00850       return m_processingMgr->executeEvent(par);
00851     }
00852   }
00853   log << MSG::FATAL << "executeEvent: Invalid state \"" << FSMState() << "\""
00854       <<endmsg;
00855   return StatusCode::FAILURE;
00856 }
00857 
00858 //============================================================================
00859 // IEventProcessor implementation: executeRun(int)
00860 //============================================================================
00861 StatusCode ApplicationMgr::executeRun(int evtmax)    {
00862   MsgStream log( m_messageSvc, name() );
00863   if( m_state == Gaudi::StateMachine::RUNNING ) {
00864     if ( m_processingMgr.isValid() )    {
00865       return m_processingMgr->executeRun(evtmax);
00866     }
00867     log << MSG::WARNING << "No EventLoop Manager specified " << endmsg;
00868     return StatusCode::SUCCESS;
00869   }
00870   log << MSG::FATAL << "executeRun: Invalid state \"" << FSMState() << "\""
00871       << endmsg;
00872   return StatusCode::FAILURE;
00873 }
00874 
00875 //============================================================================
00876 // IEventProcessor implementation: stopRun(int)
00877 //============================================================================
00878 StatusCode ApplicationMgr::stopRun()    {
00879   MsgStream log( m_messageSvc, name() );
00880   if( m_state == Gaudi::StateMachine::RUNNING ) {
00881     if ( m_processingMgr.isValid() )    {
00882       return m_processingMgr->stopRun();
00883     }
00884     log << MSG::WARNING << "No EventLoop Manager specified " << endmsg;
00885     return StatusCode::SUCCESS;
00886   }
00887   log << MSG::FATAL << "stopRun: Invalid state \"" << FSMState() << "\""
00888       << endmsg;
00889   return StatusCode::FAILURE;
00890 }
00891 // Implementation of IAppMgrUI::name
00892 const std::string& ApplicationMgr::name() const {
00893   return m_name;
00894 }
00895 
00896 // implementation of IService::state
00897 Gaudi::StateMachine::State ApplicationMgr::FSMState( ) const {
00898   return m_state;
00899 }
00900 // implementation of IService::state
00901 Gaudi::StateMachine::State ApplicationMgr::targetFSMState( ) const {
00902   return m_targetState;
00903 }
00904 
00905 
00906 //============================================================================
00907 // implementation of IService::reinitilaize
00908 //============================================================================
00909 StatusCode ApplicationMgr::reinitialize() {
00910   StatusCode retval = StatusCode::SUCCESS;
00911   StatusCode sc;
00912   if ( m_state < Gaudi::StateMachine::INITIALIZED ) {
00913     throw GaudiException("Cannot reinitialize application if not INITIALIZED or RUNNING",
00914                          "ApplicationMgr::reinitialize", StatusCode::FAILURE);
00915   }
00916   if ( m_state == Gaudi::StateMachine::RUNNING ) {
00917     retval = GoToState(Gaudi::StateMachine::INITIALIZED);
00918   }
00919   sc = svcManager()->reinitialize();
00920   if (sc.isFailure()) retval = sc;
00921   sc = algManager()->reinitialize();
00922   if (sc.isFailure()) retval = sc;
00923   return retval;
00924 }
00925 
00926 //============================================================================
00927 // implementation of IService::reinitiaize
00928 //============================================================================
00929 StatusCode ApplicationMgr::restart() {
00930   StatusCode retval = StatusCode::SUCCESS;
00931   StatusCode sc;
00932   if ( m_state != Gaudi::StateMachine::RUNNING ) {
00933     throw GaudiException("Cannot restart application if not RUNNING",
00934                          "ApplicationMgr::restart", StatusCode::FAILURE);
00935   }
00936   sc = svcManager()->restart();
00937   if (sc.isFailure()) retval = sc;
00938   sc = algManager()->restart();
00939   if (sc.isFailure()) retval = sc;
00940   return retval;
00941 }
00942 
00943 //============================================================================
00944 // SI Go Handler
00945 //============================================================================
00946 void ApplicationMgr::SIGoHandler( Property& ) {
00947 
00948   MsgStream log (m_messageSvc, name());
00949   StatusCode sc;
00950 
00951   // Re-initialize everything
00952   sc = reinitialize();
00953   // Execute a number of events
00954   executeRun(m_evtMax);
00955 
00956   return;
00957 }
00958 
00959 //============================================================================
00960 // SI Exit Handler
00961 //============================================================================
00962 void ApplicationMgr::SIExitHandler( Property& ) {
00963   StatusCode status;
00964   status = finalize();
00965   status = terminate();
00966   ::exit( 0 );
00967 }
00968 
00969 //============================================================================
00970 // Handle properties of the event loop manager (Top alg/Output stream list)
00971 //============================================================================
00972 void ApplicationMgr::evtLoopPropertyHandler( Property& p ) {
00973   if ( m_processingMgr.isValid() )    {
00974     SmartIF<IProperty> props(m_processingMgr);
00975     if ( props.isValid() )    {
00976       props->setProperty( p ).ignore();
00977     }
00978   }
00979 }
00980 
00981 //============================================================================
00982 // External Service List handler
00983 //============================================================================
00984 void ApplicationMgr::createSvcNameListHandler( Property& /* theProp */ ) {
00985   if ( !(decodeCreateSvcNameList()).isSuccess() ) {
00986     throw GaudiException("Failed to create ext services",
00987                          "MinimalEventLoopMgr::createSvcNameListHandler",
00988                          StatusCode::FAILURE);
00989   }
00990 }
00991 //============================================================================
00992 //  decodeCreateSvcNameList
00993 //============================================================================
00994 StatusCode ApplicationMgr::decodeCreateSvcNameList() {
00995   StatusCode result = StatusCode::SUCCESS;
00996   const std::vector<std::string>& theNames = m_createSvcNameList.value( );
00997   VectorName::const_iterator it(theNames.begin());
00998   VectorName::const_iterator et(theNames.end());
00999   while(result.isSuccess() && it != et) {
01000     Gaudi::Utils::TypeNameString item(*it++);
01001     if( (result = svcManager()->addService(item, 10) ).isFailure()) {
01002       MsgStream log( m_messageSvc, m_name );
01003       log << MSG::ERROR << "decodeCreateSvcNameList: Cannot create service "
01004           << item.type() << "/" << item.name() << endmsg;
01005     } else {
01006       ON_DEBUG {
01007         MsgStream log( m_messageSvc, m_name );
01008         log << MSG::DEBUG << "decodeCreateSvcNameList: Created service "
01009             << item.type() << "/" << item.name() << endmsg;
01010       }
01011     }
01012   }
01013   return result;
01014 }
01015 
01016 //============================================================================
01017 // External Service List handler
01018 //============================================================================
01019 void ApplicationMgr::extSvcNameListHandler( Property& /* theProp */ ) {
01020   if ( !(decodeExtSvcNameList( )).isSuccess() ) {
01021     throw GaudiException("Failed to declare ext services",
01022                          "MinimalEventLoopMgr::extSvcNameListHandler",
01023                          StatusCode::FAILURE);
01024   }
01025 }
01026 
01027 //============================================================================
01028 //  decodeExtSvcNameList
01029 //============================================================================
01030 StatusCode ApplicationMgr::decodeExtSvcNameList( ) {
01031   StatusCode result = StatusCode::SUCCESS;
01032 
01033   std::vector<std::string> theNames = m_extSvcNameList.value( );
01034 
01035   VectorName::const_iterator it(theNames.begin());
01036   VectorName::const_iterator et(theNames.end());
01037   while(result.isSuccess() && it != et) {
01038     Gaudi::Utils::TypeNameString item(*it++);
01039     if (m_extSvcCreates == true) {
01040       if ( (result = svcManager()->addService(item, 10)).isFailure()) {
01041         MsgStream log( m_messageSvc, m_name );
01042         log << MSG::ERROR << "decodeExtSvcNameList: Cannot create service "
01043             << item.type() << "/" << item.name() << endmsg;
01044       }
01045     } else {
01046       if( ( result = svcManager()->declareSvcType(item.name(),
01047                                                   item.type()) ).isFailure()) {
01048         MsgStream log( m_messageSvc, m_name );
01049         log << MSG::ERROR << "decodeExtSvcNameList: Cannot declare service "
01050             << item.type() << "/" << item.name() << endmsg;
01051       }
01052     }
01053   }
01054   return result;
01055 }
01056 
01057 //============================================================================
01058 // External Service List handler
01059 //============================================================================
01060 void ApplicationMgr::multiThreadSvcNameListHandler( Property& /* theProp */ ) {
01061   if ( !(decodeMultiThreadSvcNameList( )).isSuccess() ) {
01062     throw GaudiException("Failed to create copies of mt services",
01063                          "MinimalEventLoopMgr::multiThreadSvcNameListHandler",
01064                          StatusCode::FAILURE);
01065   }
01066 
01067 }
01068 
01069 //============================================================================
01070 //  decodeMultiExtSvcNameList
01071 //============================================================================
01072 StatusCode ApplicationMgr::decodeMultiThreadSvcNameList( ) {
01073   StatusCode result = StatusCode::SUCCESS;
01074   const std::vector<std::string>& theNames = m_multiThreadSvcNameList.value( );
01075   for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
01076     for (VectorName::const_iterator it = theNames.begin();
01077          it != theNames.end();
01078          ++it) {
01079       Gaudi::Utils::TypeNameString item(*it);
01080       result = addMultiSvc(item, 10);
01081       //FIXME SHOULD CLONE?
01082       if( result.isFailure() ) {
01083         MsgStream log( m_messageSvc, m_name );
01084         log << MSG::ERROR
01085             << "decodeMultiThreadSvcNameList: Cannot create service "
01086             << item.type() << "/" << item.name() << endmsg;
01087       } else {
01088         ON_VERBOSE {
01089           MsgStream log( m_messageSvc, m_name );
01090           log << MSG::VERBOSE
01091               << "decodeMultiThreadSvcNameList: created service "
01092               << item.type() << "/" << item.name() << endmsg;
01093         }
01094       }
01095     }
01096   }
01097   return result;
01098 }
01099 //=============================================================================
01100 //  declareMultiSvcType
01101 //=============================================================================
01102 StatusCode ApplicationMgr::declareMultiSvcType(const std::string& name,
01103                                                const std::string& type) {
01104   StatusCode result = StatusCode::SUCCESS;
01105   MsgStream log( m_messageSvc, m_name );
01106   if (0 == m_noOfEvtThreads) {
01107     result = svcManager()->declareSvcType(name, type);
01108     if( result.isFailure() ) {
01109       log << MSG::ERROR << "declareMultiSvcType: Cannot declare service "
01110           << type << "/" << name << endmsg;
01111     } else {
01112       ON_VERBOSE
01113         log << MSG::VERBOSE << "declareMultiSvcType: declared service "
01114             << type << "/" << name << endmsg;
01115     }
01116   } else {
01117     for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
01118       std::string thrName(name + getGaudiThreadIDfromID(iCopy));
01119       result = svcManager()->declareSvcType(thrName, type);
01120       if( result.isFailure() ) {
01121         log << MSG::ERROR << "declareMultiSvcType: Cannot declare service "
01122             << type << "/" << thrName << endmsg;
01123       } else {
01124         ON_VERBOSE
01125           log << MSG::VERBOSE << "declareMultiSvcType: declared service "
01126               << type << "/" << thrName << endmsg;
01127       }
01128     }
01129   }
01130   return result;
01131 }
01132 //=============================================================================
01133 //  addMultiSvc
01134 //=============================================================================
01135 StatusCode ApplicationMgr::addMultiSvc(const Gaudi::Utils::TypeNameString &typeName,
01136                                        int prio) {
01137   using Gaudi::Utils::TypeNameString;
01138   StatusCode result = StatusCode::SUCCESS;
01139   MsgStream log( m_messageSvc, m_name );
01140   if (0 == m_noOfEvtThreads) {
01141     result = svcManager()->addService(typeName, prio);
01142     // result = svcManager()->addService(name, type, prio); // CHECKME???
01143     if( result.isFailure() ) {
01144       log << MSG::ERROR << "addMultiSvc: Cannot add service "
01145           << typeName.type() << "/" << typeName.name() << endmsg;
01146     } else {
01147       ON_VERBOSE
01148         log << MSG::VERBOSE << "addMultiSvc: added service "
01149             << typeName.type() << "/" << typeName.name() << endmsg;
01150     }
01151   } else {
01152     for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
01153       const std::string &type = typeName.type();
01154       std::string thrName(typeName.name() + getGaudiThreadIDfromID(iCopy));
01155       result = svcManager()->addService(TypeNameString(thrName, type), prio);
01156       if( result.isFailure() ) {
01157         log << MSG::ERROR << "addMultiSvc: Cannot add service "
01158             << type << "/" << thrName << endmsg;
01159       } else {
01160         ON_VERBOSE
01161           log << MSG::VERBOSE << "addMultiSvc: added service "
01162               << type << "/" << thrName << endmsg;
01163       }
01164     }
01165   }
01166   return result;
01167 }
01168 
01169 //============================================================================
01170 // Dll List handler
01171 //============================================================================
01172 void ApplicationMgr::dllNameListHandler( Property& /* theProp */ ) {
01173   if ( !(decodeDllNameList( )).isSuccess() ) {
01174     throw GaudiException("Failed to load DLLs.",
01175                          "MinimalEventLoopMgr::dllNameListHandler",
01176                          StatusCode::FAILURE);
01177   }
01178 }
01179 
01180 //============================================================================
01181 //  decodeDllNameList
01182 //============================================================================
01183 StatusCode ApplicationMgr::decodeDllNameList() {
01184 
01185   MsgStream log( m_messageSvc, m_name );
01186   StatusCode result = StatusCode::SUCCESS;
01187 
01188   // Clean up multiple entries from DLL list
01189   // -------------------------------------------------------------------------
01190   std::vector<std::string> newList;
01191   std::map<std::string,unsigned int> dllInList, duplicateList;
01192   {for ( std::vector<std::string>::const_iterator it = m_dllNameList.value().begin();
01193         it != m_dllNameList.value().end(); ++it ) {
01194     if ( 0 == dllInList[*it] ) {
01195       newList.push_back(*it);        // first instance of this module
01196     } else { ++duplicateList[*it]; } // module listed multiple times
01197     ++dllInList[*it];                // increment count for this module
01198   }}
01199   //m_dllNameList = newList; // update primary list to new, filtered list (do not use the
01200                              // property itself otherwise we get called again infinitely)
01201   // List modules that were in there twice..
01202   ON_DEBUG if ( !duplicateList.empty() ) {
01203     log << MSG::DEBUG << "Removed duplicate entries for modules : ";
01204     for ( std::map<std::string,unsigned int>::const_iterator it = duplicateList.begin();
01205           it != duplicateList.end(); ++it ) {
01206       log << it->first << "(" << 1+it->second << ")";
01207       if ( it != --duplicateList.end() ) log << ", ";
01208     }
01209     log << endmsg;
01210   }
01211   // -------------------------------------------------------------------------
01212 
01213   const std::vector<std::string>& theNames = newList;
01214 
01215   // only load the new dlls or previously failed dlls
01216   ON_DEBUG log << MSG::DEBUG << "Loading declared DLL's" << endmsg;
01217 
01218   std::vector<std::string> successNames, failNames;
01219   std::vector<std::string>::const_iterator it;
01220 
01221   for (it = theNames.begin(); it != theNames.end(); it++) {
01222     if (std::find (m_okDlls.rbegin(), m_okDlls.rend(), *it) == m_okDlls.rend()){
01223       // found a new module name
01224       StatusCode status = m_classManager->loadModule( (*it) );
01225       if( status.isFailure() ) {
01226         failNames.push_back(*it);
01227         result = StatusCode::FAILURE;
01228       }
01229       else {
01230         successNames.push_back(*it);
01231       }
01232     }
01233   }
01234 
01235   // report back to the user and store the names of the succesfully loaded dlls
01236   if ( !successNames.empty() ) {
01237     log << MSG::INFO << "Successfully loaded modules : ";
01238     for (it = successNames.begin(); it != successNames.end(); it++) {
01239       log<< (*it);
01240       if( (it+1) != successNames.end())  log << ", ";
01241       // save name
01242       m_okDlls.push_back( *it );
01243     }
01244     log << endmsg;
01245   }
01246 
01247   if ( result == StatusCode::FAILURE ) {
01248     log << MSG::WARNING << "Failed to load modules: ";
01249     for (it = failNames.begin(); it != failNames.end(); it++) {
01250       log<< (*it);
01251       if( (it+1) != failNames.end())  log << ", ";
01252     }
01253     log << endmsg;
01254   }
01255   return result;
01256 }
01257 
01258 //============================================================================
01259 // Reflex debug level handler
01260 //============================================================================
01261 void ApplicationMgr::reflexDebugPropertyHandler( Property& )
01262 {
01263   // Setup debug level for Reflex plugin system
01264   MsgStream log (m_messageSvc, name());
01265   log << MSG::INFO
01266       << "Updating ROOT::Reflex::PluginService::SetDebug(level) to level="
01267       << (int)m_reflexDebugLevel
01268       << endmsg;
01269   ROOT::Reflex::PluginService::SetDebug(m_reflexDebugLevel);
01270 }
01271 
01272 //============================================================================
01273 // Reflex debug level handler
01274 //============================================================================
01275 void ApplicationMgr::initLoopCheckHndlr(Property&) {
01276   svcManager()->setLoopCheckEnabled(m_loopCheck);
01277 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Fri Sep 2 2011 16:24:51 for Gaudi Framework, version v22r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004