| # Gaudi Framework, version v21r7 |

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