Gaudi Framework, version v21r8

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

Generated at Wed Mar 17 18:06:41 2010 for Gaudi Framework, version v21r8 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004