| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# ApplicationMgr.cpp

Go to the documentation of this file.

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