| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ApplicationMgr.cpp
Go to the documentation of this file.
1 // Include files
2 #include "ApplicationMgr.h"
3 #include "ServiceManager.h"
4 #include "AlgorithmManager.h"
5 #include "DLLClassManager.h"
6
7 #include "GaudiKernel/TypeNameString.h"
8 #include "GaudiKernel/IService.h"
9 #include "GaudiKernel/IRunable.h"
10 #include "GaudiKernel/IMessageSvc.h"
11 #include "GaudiKernel/IJobOptionsSvc.h"
12
13 #include "GaudiKernel/SmartIF.h"
14 #include "GaudiKernel/MsgStream.h"
15 #include "GaudiKernel/PropertyMgr.h"
16 #include "GaudiKernel/ObjectFactory.h"
17
18 #include "GaudiKernel/GaudiException.h"
19 #include "GaudiKernel/ThreadGaudi.h"
20
21 #include "GaudiKernel/StatusCode.h"
22 #include "GaudiKernel/Time.h"
23 #include "GaudiKernel/System.h"
24
25 #include "GaudiKernel/AppReturnCode.h"
26
27 #include "GaudiCoreSvcVersion.h"
28
29
30 using System::getEnv;
31 using System::isEnvSet;
32
33 #include <algorithm>
34 #include <cassert>
35 #include <ctime>
36 #include <limits>
37
38 static const char* s_eventloop = "EventLoop";
39 static const char* s_runable = "Runable";
40
41 #define ON_DEBUG if (UNLIKELY(m_outputLevel <= MSG::DEBUG))
42 #define ON_VERBOSE if (UNLIKELY(m_outputLevel <= MSG::VERBOSE))
43
44 DECLARE_OBJECT_FACTORY(ApplicationMgr)
45
46 // Implementation class for the Application Manager. In this way the
47 // ApplicationMgr class is a fully insulated concrete class. Clients
48 // (main programs) will not need to re-compile if there are changes
49 // in the implementation
50
51 //=======================================================================
52 // Constructor
53 //=======================================================================
54 ApplicationMgr::ApplicationMgr(IInterface*): base_class() {
55 // IInterface initialization
56 addRef(); // Initial count set to 1
57
58 // Initialize two basic services: messagesvc & joboptions
59 m_messageSvc = 0;
60 m_jobOptionsSvc = 0;
61
62 // Instantiate component managers
63 m_managers[IService::interfaceID().id()] = new ServiceManager(this);
64 AlgorithmManager *algMgr = new AlgorithmManager(this);
65 m_managers[IAlgorithm::interfaceID().id()] = algMgr;
66
67 m_svcLocator = svcManager();
68
69 // Instantiate internal services
70 // SvcLocator/Factory HAS to be already instantiated
71 m_classManager = new DLLClassManager(this);
72 m_propertyMgr = new PropertyMgr(this);
73
74 m_name = "ApplicationMgr";
75 m_state = Gaudi::StateMachine::OFFLINE;
76 m_targetState = Gaudi::StateMachine::OFFLINE;
77
78 m_propertyMgr->declareProperty("Go", m_SIGo = 0 );
79 m_propertyMgr->declareProperty("Exit", m_SIExit = 0 );
80 m_propertyMgr->declareProperty("Dlls", m_dllNameList );
81 m_propertyMgr->declareProperty("ExtSvc", m_extSvcNameList );
82 m_propertyMgr->declareProperty("CreateSvc", m_createSvcNameList );
83 m_propertyMgr->declareProperty("ExtSvcCreates", m_extSvcCreates=true );
84
85 m_propertyMgr->declareProperty("SvcMapping", m_svcMapping );
86 m_propertyMgr->declareProperty("SvcOptMapping", m_svcOptMapping );
87
88 m_propertyMgr->declareProperty("TopAlg", m_topAlgNameList );
89 m_propertyMgr->declareProperty("OutStream", m_outStreamNameList );
90 m_propertyMgr->declareProperty("OutStreamType", m_outStreamType = "OutputStream" );
91 m_propertyMgr->declareProperty("MessageSvcType",m_messageSvcType= "MessageSvc" );
92 m_propertyMgr->declareProperty("JobOptionsSvcType",
93 m_jobOptionsSvcType = "JobOptionsSvc" );
94 m_propertyMgr->declareProperty( s_runable, m_runableType = "AppMgrRunable");
95 m_propertyMgr->declareProperty( s_eventloop, m_eventLoopMgr = "EventLoopMgr");
96
97 m_propertyMgr->declareProperty("HistogramPersistency", m_histPersName="NONE");
98
99 // Declare Job Options Service properties and set default
100 m_propertyMgr->declareProperty("JobOptionsType", m_jobOptionsType = "FILE");
101 m_propertyMgr->declareProperty("JobOptionsPath", m_jobOptionsPath = "");
102 m_propertyMgr->declareProperty("EvtMax", m_evtMax = -1);
103 m_propertyMgr->declareProperty("EvtSel", m_evtsel );
104 m_propertyMgr->declareProperty("OutputLevel", m_outputLevel = MSG::INFO);
105
106 m_propertyMgr->declareProperty("MultiThreadExtSvc", m_multiThreadSvcNameList);
107 m_propertyMgr->declareProperty("NoOfThreads", m_noOfEvtThreads = 0);
108 m_propertyMgr->declareProperty("AppName", m_appName = "ApplicationMgr");
109 m_propertyMgr->declareProperty("AppVersion", m_appVersion = "");
110
111 m_propertyMgr->declareProperty("AuditTools", m_auditTools = false);
112 m_propertyMgr->declareProperty("AuditServices", m_auditSvcs = false);
113 m_propertyMgr->declareProperty("AuditAlgorithms", m_auditAlgs = false);
114
115 m_propertyMgr->declareProperty("ActivateHistory", m_actHistory = false);
116 m_propertyMgr->declareProperty("StatusCodeCheck", m_codeCheck = false);
117
118 m_propertyMgr->declareProperty("Environment", m_environment);
119
120 // ServiceMgr Initialization loop checking
121 m_propertyMgr->declareProperty("InitializationLoopCheck", m_loopCheck = true)
122 ->declareUpdateHandler(&ApplicationMgr::initLoopCheckHndlr, this);
123 svcManager()->setLoopCheckEnabled(m_loopCheck);
124
125 // Flag to activate the printout of properties
126 m_propertyMgr->declareProperty
127 ( "PropertiesPrint",
128 m_propertiesPrint = false,
129 "Flag to activate the printout of properties" );
130
131 m_propertyMgr->declareProperty("PluginDebugLevel", m_pluginDebugLevel = 0 );
132
133 m_propertyMgr->declareProperty("StopOnSignal", m_stopOnSignal = false,
134 "Flag to enable/disable the signal handler that schedule a stop of the event loop");
135
136 m_propertyMgr->declareProperty("StalledEventMonitoring", m_stalledEventMonitoring = false,
137 "Flag to enable/disable the monitoring and reporting of stalled events");
138
139 m_propertyMgr->declareProperty("ReturnCode", m_returnCode = Gaudi::ReturnCode::Success,
140 "Return code of the application. Set internally in case of error conditions.");
141
142 m_propertyMgr->declareProperty("AlgTypeAliases", algMgr->typeAliases(),
143 "Aliases of algorithm types, to replace an algorithm type for every instance");
144
145 // Add action handlers to the appropriate properties
146 m_SIGo.declareUpdateHandler ( &ApplicationMgr::SIGoHandler , this );
147 m_SIExit.declareUpdateHandler( &ApplicationMgr::SIExitHandler , this );
148 m_topAlgNameList.declareUpdateHandler(&ApplicationMgr::evtLoopPropertyHandler, this);
149 m_outStreamNameList.declareUpdateHandler(&ApplicationMgr::evtLoopPropertyHandler, this);
150 m_outStreamType.declareUpdateHandler(&ApplicationMgr::evtLoopPropertyHandler, this);
151 m_pluginDebugLevel.declareUpdateHandler(&ApplicationMgr::pluginDebugPropertyHandler, this);
152 m_svcMapping.push_back("EvtDataSvc/EventDataSvc");
153 m_svcMapping.push_back("DetDataSvc/DetectorDataSvc");
154 m_svcMapping.push_back("HistogramSvc/HistogramDataSvc");
155 m_svcMapping.push_back("HbookCnv::PersSvc/HbookHistSvc");
156 m_svcMapping.push_back("RootHistCnv::PersSvc/RootHistSvc");
157 m_svcMapping.push_back("EvtPersistencySvc/EventPersistencySvc");
158 m_svcMapping.push_back("DetPersistencySvc/DetectorPersistencySvc");
159 m_svcMapping.push_back("HistogramPersistencySvc/HistogramPersistencySvc");
160 }
161
162 //============================================================================
163 // destructor
164 //============================================================================
165 ApplicationMgr::~ApplicationMgr() {
166 if( m_classManager ) m_classManager->release();
167 if( m_propertyMgr ) m_propertyMgr->release();
168 if( m_messageSvc ) m_messageSvc->release();
169 if( m_jobOptionsSvc ) m_jobOptionsSvc->release();
170 }
171
172 //============================================================================
173 // IInterface implementation: queryInterface::addRef()
174 //============================================================================
175 StatusCode ApplicationMgr::queryInterface
176 ( const InterfaceID& iid ,
177 void** ppvi )
178 {
179 if ( 0 == ppvi ) { return StatusCode::FAILURE ; }
180
181 // try to find own/direct interfaces:
182 StatusCode sc = base_class::queryInterface(iid,ppvi);
183 if (sc.isSuccess()) return sc;
184
185 // find indirect interfaces :
186 if ( ISvcLocator ::interfaceID() . versionMatch ( iid ) )
187 { return serviceLocator()-> queryInterface ( iid , ppvi ) ; }
188 else if ( ISvcManager ::interfaceID() . versionMatch ( iid ) )
189 { return svcManager() -> queryInterface ( iid , ppvi ) ; }
190 else if ( IAlgManager ::interfaceID() . versionMatch ( iid ) )
191 { return algManager() -> queryInterface ( iid , ppvi ) ; }
192 else if ( IClassManager ::interfaceID() . versionMatch ( iid ) )
193 { return m_classManager -> queryInterface ( iid , ppvi ) ; }
194 else if ( IProperty ::interfaceID() . versionMatch ( iid ) )
195 { return m_propertyMgr -> queryInterface ( iid , ppvi ) ; }
196 else if ( IMessageSvc ::interfaceID() . versionMatch ( iid ) )
197 {
198 *ppvi = reinterpret_cast<void*>(m_messageSvc.get());
199 if (m_messageSvc) {
200 m_messageSvc->addRef();
201 }
202 // Note that 0 can be a valid IMessageSvc pointer value (when used for
203 // MsgStream).
204 return StatusCode::SUCCESS;
205 }
206 *ppvi = 0;
207 return StatusCode::FAILURE;
208 }
209
210 //============================================================================
211 // ApplicationMgr::i_startup()
212 //============================================================================
213 StatusCode ApplicationMgr::i_startup() {
214 StatusCode sc;
215
216 // declare factories in current module
217 m_classManager->loadModule("").ignore();
218
219 // Create the Message service
220 SmartIF<IService> msgsvc = svcManager()->createService(Gaudi::Utils::TypeNameString("MessageSvc", m_messageSvcType));
221 if( !msgsvc.isValid() ) {
222 fatal() << "Error creating MessageSvc of type " << m_messageSvcType << endmsg;
223 return sc;
224 }
225 // Create the Job Options service
226 SmartIF<IService> jobsvc = svcManager()->createService(Gaudi::Utils::TypeNameString("JobOptionsSvc", m_jobOptionsSvcType));
227 if( !jobsvc.isValid() ) {
228 fatal() << "Error creating JobOptionsSvc" << endmsg;
229 return sc;
230 }
231
232 SmartIF<IProperty> jobOptsIProp(jobsvc);
233 if ( !jobOptsIProp.isValid() ) {
234 fatal() << "Error locating JobOptionsSvc" << endmsg;
235 return sc;
236 }
237 sc = jobOptsIProp->setProperty( StringProperty("TYPE", m_jobOptionsType) );
238 if( !sc.isSuccess() ) {
239 fatal() << "Error setting TYPE option in JobOptionsSvc" << endmsg;
240 return sc;
241 }
242
243 if ( m_jobOptionsPath != "") { // The command line takes precedence
244 sc = jobOptsIProp->setProperty( StringProperty("PATH", m_jobOptionsPath) );
245 if( !sc.isSuccess() ) {
246 fatal() << "Error setting PATH option in JobOptionsSvc" << endmsg;
247 return sc;
248 }
249 }
250 else if ( isEnvSet("JOBOPTPATH") ) {// Otherwise the Environment JOBOPTPATH
251 sc = jobOptsIProp->setProperty (StringProperty("PATH",
252 getEnv("JOBOPTPATH")));
253 if( !sc.isSuccess() ) {
254 fatal()
255 << "Error setting PATH option in JobOptionsSvc from env"
256 << endmsg;
257 return sc;
258 }
259 }
260 else { // Otherwise the default
261 sc = jobOptsIProp->setProperty (StringProperty("PATH",
262 "../options/job.opts"));
263 if( !sc.isSuccess() ) {
264 fatal()
265 << "Error setting PATH option in JobOptionsSvc to default"
266 << endmsg;
267 return sc;
268 }
269 }
270 jobOptsIProp->release();
271
272 // Sets my default the Output Level of the Message service to be
273 // the same as this
274 SmartIF<IProperty> msgSvcIProp(msgsvc);
275 msgSvcIProp->setProperty( IntegerProperty("OutputLevel", m_outputLevel)).ignore();
276 msgSvcIProp->release();
277
278 sc = jobsvc->sysInitialize();
279 if( !sc.isSuccess() ) {
280 fatal() << "Error initializing JobOptionsSvc" << endmsg;
281 return sc;
282 }
283 sc = msgsvc->sysInitialize();
284 if( !sc.isSuccess() ) {
285 fatal() << "Error initializing MessageSvc" << endmsg;
286 return sc;
287 }
288
289 // Get the useful interface from Message and JobOptions services
290 m_messageSvc = m_svcLocator->service("MessageSvc");
291 if( !m_messageSvc.isValid() ) {
292 fatal() << "Error retrieving MessageSvc." << endmsg;
293 return sc;
294 }
295 m_jobOptionsSvc = m_svcLocator->service("JobOptionsSvc");
296 if( !m_jobOptionsSvc.isValid() ) {
297 fatal() << "Error retrieving JobOptionsSvc." << endmsg;
298 return sc;
299 }
300
301 return sc;
302 }
303
304 //============================================================================
305 // IAppMgrUI implementation: ApplicationMgr::configure()
306 //============================================================================
307 StatusCode ApplicationMgr::configure() {
308 // Check if the state is compatible with the transition
309 MsgStream tlog( m_messageSvc, name() );
310 if( Gaudi::StateMachine::CONFIGURED == m_state ) {
311 tlog << MSG::INFO << "Already Configured" << endmsg;
312 return StatusCode::SUCCESS;
313 }
314 else if( Gaudi::StateMachine::OFFLINE != m_state ) {
315 tlog << MSG::FATAL
316 << "configure: Invalid state \"" << m_state << "\"" << endmsg;
317 return StatusCode::FAILURE;
318 }
319 m_targetState = Gaudi::StateMachine::CONFIGURED;
320
321 // Reset application return code.
322 m_returnCode = Gaudi::ReturnCode::Success;
323
324 StatusCode sc;
325 sc = i_startup();
326 if ( !sc.isSuccess() ) {
327 return sc;
328 }
329
330 MsgStream log( m_messageSvc, name() );
331
332 // Get my own options using the Job options service
333 if (log.level() <= MSG::DEBUG)
334 log << MSG::DEBUG << "Getting my own properties" << endmsg;
335 sc = m_jobOptionsSvc->setMyProperties( name(), m_propertyMgr );
336 if( !sc.isSuccess() ) {
337 log << MSG::WARNING << "Problems getting my properties from JobOptionsSvc"
338 << endmsg;
339 return sc;
340 }
341
342 // Check current outputLevel to eventually inform the MessageSvc
343 if( m_outputLevel != MSG::NIL && !m_appName.empty() ) {
344 assert(m_messageSvc != 0);
345 m_messageSvc->setOutputLevel( name(), m_outputLevel );
346 // Print a welcome message
347 log << MSG::ALWAYS
348 << std::endl
349 << "=================================================================="
350 << "=================================================================="
351 << std::endl
352 << " "
353 << " Welcome to " << m_appName;
354
355 if( "" != m_appVersion ) {
356 log << MSG::ALWAYS << " version " << m_appVersion;
357 }
358 else {
359 log << MSG::ALWAYS
360 << " (GaudiCoreSvc "
361 << "v" << GAUDICORESVC_MAJOR_VERSION
362 << "r" << GAUDICORESVC_MINOR_VERSION
363 #if GAUDICORESVC_PATCH_VERSION
364 << "p" << GAUDICORESVC_PATCH_VERSION
365 #endif
366 << ")";
367 }
368
369 // Add the host name and current time to the message
370 log << MSG::ALWAYS
371 << std::endl
372 << " "
373 << " running on " << System::hostName()
374 << " on " << Gaudi::Time::current().format(true) << std::endl
375 << "=================================================================="
376 << "=================================================================="
377 << endmsg;
378 }
379
380 // print all own properties if the options "PropertiesPrint" is set to true
381 if ( m_propertiesPrint )
382 {
383 typedef std::vector<Property*> Properties;
384 const Properties& properties = m_propertyMgr->getProperties() ;
385 log << MSG::ALWAYS
386 << "List of ALL properties of "
387 << System::typeinfoName ( typeid( *this ) ) << "/" << this->name()
388 << " #properties = " << properties.size() << endmsg ;
389 for ( Properties::const_iterator property = properties.begin() ;
390 properties.end() != property ; ++property )
391 { log << "Property ['Name': Value] = " << ( **property) << endmsg ; }
392 }
393
394 // Check if StatusCode need to be checked
395 if (m_codeCheck) {
396 StatusCode::enableChecking();
397 sc = addMultiSvc("StatusCodeSvc", -9999);
398 if ( sc.isFailure() ) {
399 log << MSG::FATAL << "Error adding StatusCodeSvc for multiple threads" << endmsg;
400 return StatusCode::FAILURE;
401 }
402 } else {
403 StatusCode::disableChecking();
404 }
405
406 // set the requested environment variables
407 std::map<std::string,std::string>::iterator var;
408 for ( var = m_environment.begin(); var != m_environment.end(); ++var ) {
409 const std::string &name = var->first;
410 const std::string &value = var->second;
411 std::string old = System::getEnv(name.c_str());
412 const MSG::Level lvl = (!old.empty() && (old != "UNKNOWN" ))
413 ? MSG::WARNING
414 : MSG::DEBUG;
415 if (UNLIKELY(m_outputLevel <= lvl))
416 log << lvl << "Setting " << name << " = " << value << endmsg;
417 System::setEnv(name,value);
418 }
419
420 //Declare Service Types
421 VectorName::const_iterator j;
422 for(j=m_svcMapping.begin(); j != m_svcMapping.end(); ++j) {
423 Gaudi::Utils::TypeNameString itm(*j);
424 if ( declareMultiSvcType(itm.name(), itm.type()).isFailure() ) {
425 log << MSG::ERROR << "configure: declaring svc type:'" << *j << "' failed." << endmsg;
426 return StatusCode::FAILURE;
427 }
428 }
429 for(j=m_svcOptMapping.begin(); j != m_svcOptMapping.end(); ++j) {
430 Gaudi::Utils::TypeNameString itm(*j);
431 if ( declareMultiSvcType(itm.name(), itm.type()).isFailure() ) {
432 log << MSG::ERROR << "configure: declaring svc type:'" << *j << "' failed." << endmsg;
433 return StatusCode::FAILURE;
434 }
435 }
436
437 //--------------------------------------------------------------------------
438 // Declare other Services and Algorithms by loading DLL's
439 sc = decodeDllNameList( );
440 if ( sc.isFailure( ) ) {
441 log << MSG::ERROR << "Failure loading declared DLL's" << endmsg;
442 return sc;
443 }
444
445 //--------------------------------------------------------------------------
446 // Deal with the services explicitly declared by the user.
447 sc = decodeExtSvcNameList();
448 if ( sc.isFailure( ) ) {
449 log << MSG::ERROR << "Failure during external service association" << endmsg;
450 return sc;
451 }
452
453 sc = decodeMultiThreadSvcNameList( );
454 if ( sc.isFailure( ) ) {
455 log << MSG::ERROR << "Failure during multi thread service creation"
456 << endmsg;
457 return sc;
458 }
459
460 sc = decodeCreateSvcNameList();
461 if ( sc.isFailure( ) ) {
462 log << MSG::ERROR << "Failure during external service creation" << endmsg;
463 return sc;
464 }
465
466
467 //--------------------------------------------------------------------------
468 // Retrieve intrinsic services. If needed configure them.
469 //--------------------------------------------------------------------------
470 Gaudi::Utils::TypeNameString evtloop_item(m_eventLoopMgr);
471 sc = addMultiSvc(evtloop_item, ServiceManager::DEFAULT_SVC_PRIORITY*10);
472 if( !sc.isSuccess() ) {
473 log << MSG::FATAL << "Error adding :" << m_eventLoopMgr << endmsg;
474 return sc;
475 }
476
477 if (m_noOfEvtThreads == 0) {
478 m_runable = m_svcLocator->service(m_runableType);
479 if( !m_runable.isValid() ) {
480 log << MSG::FATAL
481 << "Error retrieving Runable:" << m_runableType
482 << "\n Check option ApplicationMgr." << s_runable << endmsg;
483 return sc;
484 }
485 m_processingMgr = m_svcLocator->service(evtloop_item);
486 if( !m_processingMgr.isValid() ) {
487 log << MSG::FATAL
488 << "Error retrieving Processing manager:" << m_eventLoopMgr
489 << "\n Check option ApplicationMgr." << s_eventloop
490 << "\n No events will be processed." << endmsg;
491 return sc;
492 }
493 }
494
495 // Establish Update Handlers for ExtSvc and DLLs Properties
496 m_extSvcNameList.declareUpdateHandler (&ApplicationMgr::extSvcNameListHandler,
497 this);
498 m_createSvcNameList.declareUpdateHandler (&ApplicationMgr::createSvcNameListHandler,
499 this);
500 m_multiThreadSvcNameList.declareUpdateHandler
501 (&ApplicationMgr::multiThreadSvcNameListHandler, this);
502 m_dllNameList.declareUpdateHandler (&ApplicationMgr::dllNameListHandler,
503 this );
504
505 if (m_actHistory) {
506 // Create HistorySvc with a priority to ensure it's initialized last, finalized first
507 sc = svcManager()->addService("HistorySvc",std::numeric_limits<int>::max());
508 if ( sc.isFailure() ) {
509 log << MSG::FATAL << "Error adding HistorySvc" << endmsg;
510 return StatusCode::FAILURE;
511 }
512
513 if (m_noOfEvtThreads > 0) {
514 sc = addMultiSvc("HistorySvc",std::numeric_limits<int>::max());
515 if ( sc.isFailure() ) {
516 log << MSG::FATAL << "Error adding HistorySvc for multiple threads"
517 << endmsg;
518 return StatusCode::FAILURE;
519 }
520 }
521 }
522
523 log << MSG::INFO << "Application Manager Configured successfully" << endmsg;
524 m_state = m_targetState;
525 return StatusCode::SUCCESS;
526 }
527
528 //============================================================================
529 // IAppMgrUI implementation: ApplicationMgr::initialize()
530 //============================================================================
531 StatusCode ApplicationMgr::initialize() {
532
533 MsgStream log( m_messageSvc, name() );
534 StatusCode sc;
535
536 // I cannot add these services in configure() because they are coming from GaudiUtils
537 // and it messes up genconf when rebuilding it.
538 if (m_stopOnSignal) {
539 // Instantiate the service that schedules a stop when a signal is received
540 std::string svcname("Gaudi::Utils::StopSignalHandler");
541 sc = svcManager()->addService(svcname);
542 if ( sc.isFailure() ) {
543 log << MSG::INFO << "Cannot instantiate " << svcname << "signals will be ignored" << endmsg;
544 }
545 }
546
547 if (m_stalledEventMonitoring) {
548 // Instantiate the service that schedules a stop when a signal is received
549 std::string svcname("StalledEventMonitor");
550 sc = svcManager()->addService(svcname);
551 if ( sc.isFailure() ) {
552 log << MSG::INFO << "Cannot instantiate " << svcname << "signals will be ignored" << endmsg;
553 }
554 }
555
556 if( m_state == Gaudi::StateMachine::INITIALIZED ) {
557 log << MSG::INFO << "Already Initialized!" << endmsg;
558 return StatusCode::SUCCESS;
559 }
560 else if( m_state != Gaudi::StateMachine::CONFIGURED ) {
561 log << MSG::FATAL
562 << "initialize: Invalid state \"" << m_state << "\"" << endmsg;
563 return StatusCode::FAILURE;
564 }
565 m_targetState = Gaudi::StateMachine::INITIALIZED;
566
567 //--------------------------------------------------------------------------
568 // Initialize the list of top Services
569 //--------------------------------------------------------------------------
570 sc = svcManager()->initialize();
571 if( !sc.isSuccess() ) return sc;
572
573 //--------------------------------------------------------------------------
574 // Final steps: Inform user and change internal state
575 //--------------------------------------------------------------------------
576 log << MSG::INFO << "Application Manager Initialized successfully" << endmsg;
577 m_state = m_targetState;
578
579 return sc;
580 }
581
582 //============================================================================
583 // IAppMgrUI implementation: ApplicationMgr::start()
584 //============================================================================
585 StatusCode ApplicationMgr::start() {
586
587 MsgStream log( m_messageSvc, name() );
588 StatusCode sc;
589
590 if( m_state == Gaudi::StateMachine::RUNNING ) {
591 log << MSG::INFO << "Already Initialized!" << endmsg;
592 return StatusCode::SUCCESS;
593 }
594 else if( m_state != Gaudi::StateMachine::INITIALIZED ) {
595 log << MSG::FATAL
596 << "start: Invalid state \"" << m_state << "\"" << endmsg;
597 return StatusCode::FAILURE;
598 }
599 m_targetState = Gaudi::StateMachine::RUNNING;
600
601 //--------------------------------------------------------------------------
602 // Initialize the list of top Services
603 //--------------------------------------------------------------------------
604 sc = svcManager()->start();
605 if( !sc.isSuccess() ) return sc;
606
607 //--------------------------------------------------------------------------
608 // Final steps: Inform user and change internal state
609 //--------------------------------------------------------------------------
610 log << MSG::INFO << "Application Manager Started successfully" << endmsg;
611 m_state = m_targetState;
612
613 return sc;
614 }
615
616 //============================================================================
617 // IAppMgrUI implementation: ApplicationMgr::nextEvent(int)
618 //============================================================================
619 StatusCode ApplicationMgr::nextEvent(int maxevt) {
620 if( m_state != Gaudi::StateMachine::RUNNING ) {
621 MsgStream log( m_messageSvc, name() );
622 log << MSG::FATAL << "nextEvent: Invalid state \"" << m_state << "\""
623 << endmsg;
624 return StatusCode::FAILURE;
625 }
626 if (!m_processingMgr.isValid()) {
627 MsgStream log( m_messageSvc, name() );
628 log << MSG::FATAL << "No event processing manager specified. Check option:"
629 << s_eventloop << endmsg;
630 return StatusCode::FAILURE;
631 }
632 return m_processingMgr->nextEvent(maxevt);
633 }
634
635 //============================================================================
636 // IAppMgrUI implementation: ApplicationMgr::stop()
637 //============================================================================
638 StatusCode ApplicationMgr::stop() {
639
640 MsgStream log( m_messageSvc, name() );
641 StatusCode sc;
642
643 if( m_state == Gaudi::StateMachine::INITIALIZED ) {
644 log << MSG::INFO << "Already Initialized!" << endmsg;
645 return StatusCode::SUCCESS;
646 }
647 else if( m_state != Gaudi::StateMachine::RUNNING ) {
648 log << MSG::FATAL
649 << "stop: Invalid state \"" << m_state << "\"" << endmsg;
650 return StatusCode::FAILURE;
651 }
652 m_targetState = Gaudi::StateMachine::INITIALIZED;
653
654 // Stop independently managed Algorithms
655 sc = algManager()->stop();
656 if( !sc.isSuccess() ) return sc;
657
658 //--------------------------------------------------------------------------
659 // Stop the list of top Services
660 //--------------------------------------------------------------------------
661 sc = svcManager()->stop();
662 if( !sc.isSuccess() ) return sc;
663
664 //--------------------------------------------------------------------------
665 // Final steps: Inform user and change internal state
666 //--------------------------------------------------------------------------
667 log << MSG::INFO << "Application Manager Stopped successfully" << endmsg;
668 m_state = m_targetState;
669
670 return sc;
671 }
672
673 //============================================================================
674 // IAppMgrUI implementation: ApplicationMgr::finalize()
675 //============================================================================
676 StatusCode ApplicationMgr::finalize() {
677 MsgStream log( m_messageSvc, name() );
678 if( m_state == Gaudi::StateMachine::CONFIGURED ) {
679 log << MSG::INFO << "Already Finalized" << endmsg;
680 return StatusCode::SUCCESS;
681 }
682 else if( m_state != Gaudi::StateMachine::INITIALIZED ) {
683 log << MSG::FATAL << "finalize: Invalid state \"" << m_state << "\""
684 << endmsg;
685 return StatusCode::FAILURE;
686 }
687 m_targetState = Gaudi::StateMachine::CONFIGURED;
688
689 // disable message suppression in finalize
690 m_svcLocator->service<IProperty>("MessageSvc")->setProperty(BooleanProperty("enableSuppression", false)).ignore();
691
692 // Finalize independently managed Algorithms
693 StatusCode sc = algManager()->finalize();
694 if (sc.isFailure()) {
695 log << MSG::WARNING << "Failed to finalize an algorithm." << endmsg;
696 m_returnCode = Gaudi::ReturnCode::FinalizationFailure;
697 }
698
699 // Finalize all Services
700 sc = svcManager()->finalize();
701 if (sc.isFailure()) {
702 log << MSG::WARNING << "Failed to finalize a service." << endmsg;
703 m_returnCode = Gaudi::ReturnCode::FinalizationFailure;
704 }
705
706 //svcManager()->removeService( (IService*) m_processingMgr.get() );
707 //svcManager()->removeService( (IService*) m_runable.get() );
708
709 if (m_codeCheck) {
710 StatusCode::disableChecking();
711 }
712
713 if (sc.isSuccess()) {
714 log << MSG::INFO << "Application Manager Finalized successfully" << endmsg;
715 } else {
716 log << MSG::ERROR << "Application Manager failed to finalize" << endmsg;
717 }
718
719 m_state = m_targetState;
720 return sc;
721 }
722
723 //============================================================================
724 // IAppMgrUI implementation: ApplicationMgr::terminate()
725 //============================================================================
726 StatusCode ApplicationMgr::terminate() {
727 MsgStream log( m_messageSvc, name() );
728
729 if( m_state == Gaudi::StateMachine::OFFLINE ) {
730 log << MSG::INFO << "Already Offline" << endmsg;
731 return StatusCode::SUCCESS;
732 }
733 else if( m_state != Gaudi::StateMachine::CONFIGURED ) {
734 log << MSG::FATAL << "terminate: Invalid state \"" << m_state << "\""
735 << endmsg;
736 return StatusCode::FAILURE;
737 }
738 // release all Services
739 m_targetState = Gaudi::StateMachine::OFFLINE;
740
741 if (m_returnCode.value() == Gaudi::ReturnCode::Success) {
742 log << MSG::INFO << "Application Manager Terminated successfully" << endmsg;
743 } else if (m_returnCode.value() == Gaudi::ReturnCode::ScheduledStop ) {
744 log << MSG::INFO << "Application Manager Terminated successfully with a user requested ScheduledStop" << endmsg;
745 } else {
746 log << MSG::ERROR << "Application Manager Terminated with error code " << m_returnCode.value() << endmsg;
747 }
748
749 { // Force a disable the auditing of finalize for MessageSvc
750 SmartIF<IProperty> prop(m_messageSvc);
751 if (prop.isValid()) {
752 prop->setProperty(BooleanProperty("AuditFinalize", false)).ignore();
753 }
754 }
755 { // Force a disable the auditing of finalize for JobOptionsSvc
756 SmartIF<IProperty> prop(m_jobOptionsSvc);
757 if (prop.isValid()) {
758 prop->setProperty(BooleanProperty("AuditFinalize", false)).ignore();
759 }
760 }
761
762 // finalize MessageSvc
763 SmartIF<IService> svc(m_messageSvc);
764 if ( !svc.isValid() ) {
765 log << MSG::ERROR << "Could not get the IService interface of the MessageSvc" << endmsg;
766 } else {
767 svc->sysFinalize().ignore();
768 }
769
770 // finalize JobOptionsSvc
771 svc = m_jobOptionsSvc;
772 if ( !svc.isValid() ) {
773 log << MSG::ERROR << "Could not get the IService interface of the JobOptionsSvc" << endmsg;
774 } else {
775 svc->sysFinalize().ignore();
776 }
777
778 m_state = m_targetState;
779 return StatusCode::SUCCESS;
780 }
781
782 //============================================================================
783 // Reach the required state going through all the needed transitions
784 //============================================================================
785 StatusCode ApplicationMgr::GoToState(Gaudi::StateMachine::State state, bool ignoreFailures) {
786 StatusCode sc = StatusCode(StatusCode::SUCCESS,true);
787
788 switch (state) {
789
790 case Gaudi::StateMachine::OFFLINE:
791 switch (m_state) {
792 case Gaudi::StateMachine::OFFLINE : return StatusCode::SUCCESS; break;
793 case Gaudi::StateMachine::CONFIGURED : return terminate(); break;
794 default: // Gaudi::StateMachine::INITIALIZED or Gaudi::StateMachine::RUNNING
795 sc = GoToState(Gaudi::StateMachine::CONFIGURED);
796 if (sc.isSuccess()) {
797 return terminate();
798 } break;
799 } break;
800
801 case Gaudi::StateMachine::CONFIGURED:
802 switch (m_state) {
803 case Gaudi::StateMachine::CONFIGURED : return StatusCode::SUCCESS; break;
804 case Gaudi::StateMachine::OFFLINE : return configure(); break;
805 case Gaudi::StateMachine::INITIALIZED : return finalize(); break;
806 default: // Gaudi::StateMachine::RUNNING
807 sc = GoToState(Gaudi::StateMachine::INITIALIZED);
808 if (sc.isSuccess()) {
809 return finalize();
810 } break;
811 } break;
812
813 case Gaudi::StateMachine::INITIALIZED:
814 switch (m_state) {
815 case Gaudi::StateMachine::INITIALIZED : return StatusCode::SUCCESS; break;
816 case Gaudi::StateMachine::CONFIGURED : return initialize(); break;
817 case Gaudi::StateMachine::RUNNING : return stop(); break;
818 default: // Gaudi::StateMachine::OFFLINE
819 sc = GoToState(Gaudi::StateMachine::CONFIGURED);
820 if (sc.isSuccess()) {
821 return initialize();
822 } break;
823 } break;
824
825 case Gaudi::StateMachine::RUNNING:
826 switch (m_state) {
827 case Gaudi::StateMachine::RUNNING : return StatusCode::SUCCESS; break;
828 case Gaudi::StateMachine::INITIALIZED : return start(); break;
829 default: // Gaudi::StateMachine::OFFLINE or Gaudi::StateMachine::CONFIGURED
830 sc = GoToState(Gaudi::StateMachine::INITIALIZED);
831 if (sc.isSuccess()) {
832 return start();
833 } break;
834 } break;
835
836 }
837
838 // If I get here, there has been a problem in the recursion
839
840 if (ignoreFailures){
841 // force the new state
842 m_state = state;
843 return StatusCode::SUCCESS;
844 }
845
846 return sc;
847 }
848
849 //============================================================================
850 // IAppMgrUI implementation: ApplicationMgr::run()
851 //============================================================================
852 StatusCode ApplicationMgr::run() {
853 StatusCode sc = StatusCode::SUCCESS;
854
855 sc = GoToState(Gaudi::StateMachine::RUNNING);
856 if ( sc.isSuccess() ) {
857 MsgStream log(m_messageSvc, name());
858 if ( m_runable != 0 ) { // loop over the events
859 sc = m_runable->run();
860 if ( !sc.isSuccess() ) {
861 log << MSG::FATAL << "Application execution failed. Ending the job."
862 << endmsg;
863 }
864 } else {
865 log << MSG::FATAL << "Application has no runable object. Check option:"
866 << s_runable << endmsg;
867 }
868 }
869 if (sc.isSuccess()) { // try to close cleanly
870 sc = GoToState(Gaudi::StateMachine::OFFLINE);
871 }
872 // either the runable failed of the stut-down
873 if (sc.isFailure()) { // try to close anyway (but keep the StatusCode unchanged)
874 GoToState(Gaudi::StateMachine::OFFLINE,true).ignore();
875 }
876 return sc;
877 }
878
879 //============================================================================
880 // IEventProcessor implementation: executeEvent(void* par)
881 //============================================================================
882 StatusCode ApplicationMgr::executeEvent(void* par) {
883 MsgStream log( m_messageSvc, name() );
884 if( m_state == Gaudi::StateMachine::RUNNING ) {
885 if ( m_processingMgr.isValid() ) {
886 return m_processingMgr->executeEvent(par);
887 }
888 }
889 log << MSG::FATAL << "executeEvent: Invalid state \"" << FSMState() << "\""
890 <<endmsg;
891 return StatusCode::FAILURE;
892 }
893
894 //============================================================================
895 // IEventProcessor implementation: executeRun(int)
896 //============================================================================
897 StatusCode ApplicationMgr::executeRun(int evtmax) {
898 MsgStream log( m_messageSvc, name() );
899 if( m_state == Gaudi::StateMachine::RUNNING ) {
900 if ( m_processingMgr.isValid() ) {
901 return m_processingMgr->executeRun(evtmax);
902 }
903 log << MSG::WARNING << "No EventLoop Manager specified " << endmsg;
904 return StatusCode::SUCCESS;
905 }
906 log << MSG::FATAL << "executeRun: Invalid state \"" << FSMState() << "\""
907 << endmsg;
908 return StatusCode::FAILURE;
909 }
910
911 //============================================================================
912 // IEventProcessor implementation: stopRun(int)
913 //============================================================================
914 StatusCode ApplicationMgr::stopRun() {
915 MsgStream log( m_messageSvc, name() );
916 if( m_state == Gaudi::StateMachine::RUNNING ) {
917 if ( m_processingMgr.isValid() ) {
918 return m_processingMgr->stopRun();
919 }
920 log << MSG::WARNING << "No EventLoop Manager specified " << endmsg;
921 return StatusCode::SUCCESS;
922 }
923 log << MSG::FATAL << "stopRun: Invalid state \"" << FSMState() << "\""
924 << endmsg;
925 return StatusCode::FAILURE;
926 }
927 // Implementation of IAppMgrUI::name
928 const std::string& ApplicationMgr::name() const {
929 return m_name;
930 }
931
932 // implementation of IService::state
933 Gaudi::StateMachine::State ApplicationMgr::FSMState( ) const {
934 return m_state;
935 }
936 // implementation of IService::state
937 Gaudi::StateMachine::State ApplicationMgr::targetFSMState( ) const {
938 return m_targetState;
939 }
940
941
942 //============================================================================
943 // implementation of IService::reinitilaize
944 //============================================================================
945 StatusCode ApplicationMgr::reinitialize() {
946 StatusCode retval = StatusCode::SUCCESS;
947 StatusCode sc;
948 if ( m_state < Gaudi::StateMachine::INITIALIZED ) {
949 throw GaudiException("Cannot reinitialize application if not INITIALIZED or RUNNING",
950 "ApplicationMgr::reinitialize", StatusCode::FAILURE);
951 }
952 if ( m_state == Gaudi::StateMachine::RUNNING ) {
953 retval = GoToState(Gaudi::StateMachine::INITIALIZED);
954 }
955 sc = svcManager()->reinitialize();
956 if (sc.isFailure()) retval = sc;
957 sc = algManager()->reinitialize();
958 if (sc.isFailure()) retval = sc;
959 return retval;
960 }
961
962 //============================================================================
963 // implementation of IService::reinitiaize
964 //============================================================================
965 StatusCode ApplicationMgr::restart() {
966 StatusCode retval = StatusCode::SUCCESS;
967 StatusCode sc;
968 if ( m_state != Gaudi::StateMachine::RUNNING ) {
969 throw GaudiException("Cannot restart application if not RUNNING",
970 "ApplicationMgr::restart", StatusCode::FAILURE);
971 }
972 sc = svcManager()->restart();
973 if (sc.isFailure()) retval = sc;
974 sc = algManager()->restart();
975 if (sc.isFailure()) retval = sc;
976 return retval;
977 }
978
979 //============================================================================
980 // SI Go Handler
981 //============================================================================
982 void ApplicationMgr::SIGoHandler( Property& ) {
983
984 MsgStream log (m_messageSvc, name());
985 StatusCode sc;
986
987 // Re-initialize everything
988 sc = reinitialize();
989 // Execute a number of events
990 executeRun(m_evtMax);
991
992 return;
993 }
994
995 //============================================================================
996 // SI Exit Handler
997 //============================================================================
998 void ApplicationMgr::SIExitHandler( Property& ) {
999 StatusCode status;
1000 status = finalize();
1001 status = terminate();
1002 ::exit( 0 );
1003 }
1004
1005 //============================================================================
1006 // Handle properties of the event loop manager (Top alg/Output stream list)
1007 //============================================================================
1008 void ApplicationMgr::evtLoopPropertyHandler( Property& p ) {
1009 if ( m_processingMgr.isValid() ) {
1010 SmartIF<IProperty> props(m_processingMgr);
1011 if ( props.isValid() ) {
1012 props->setProperty( p ).ignore();
1013 }
1014 }
1015 }
1016
1017 //============================================================================
1018 // External Service List handler
1019 //============================================================================
1020 void ApplicationMgr::createSvcNameListHandler( Property& /* theProp */ ) {
1021 if ( !(decodeCreateSvcNameList()).isSuccess() ) {
1022 throw GaudiException("Failed to create ext services",
1023 "MinimalEventLoopMgr::createSvcNameListHandler",
1024 StatusCode::FAILURE);
1025 }
1026 }
1027 //============================================================================
1028 // decodeCreateSvcNameList
1029 //============================================================================
1030 StatusCode ApplicationMgr::decodeCreateSvcNameList() {
1031 StatusCode result = StatusCode::SUCCESS;
1032 const std::vector<std::string>& theNames = m_createSvcNameList.value( );
1033 VectorName::const_iterator it(theNames.begin());
1034 VectorName::const_iterator et(theNames.end());
1035 while(result.isSuccess() && it != et) {
1036 Gaudi::Utils::TypeNameString item(*it++);
1037 if( (result = svcManager()->addService(item, ServiceManager::DEFAULT_SVC_PRIORITY) ).isFailure()) {
1038 MsgStream log( m_messageSvc, m_name );
1039 log << MSG::ERROR << "decodeCreateSvcNameList: Cannot create service "
1040 << item.type() << "/" << item.name() << endmsg;
1041 } else {
1042 ON_DEBUG {
1043 MsgStream log( m_messageSvc, m_name );
1044 log << MSG::DEBUG << "decodeCreateSvcNameList: Created service "
1045 << item.type() << "/" << item.name() << endmsg;
1046 }
1047 }
1048 }
1049 return result;
1050 }
1051
1052 //============================================================================
1053 // External Service List handler
1054 //============================================================================
1055 void ApplicationMgr::extSvcNameListHandler( Property& /* theProp */ ) {
1056 if ( !(decodeExtSvcNameList( )).isSuccess() ) {
1057 throw GaudiException("Failed to declare ext services",
1058 "MinimalEventLoopMgr::extSvcNameListHandler",
1059 StatusCode::FAILURE);
1060 }
1061 }
1062
1063 //============================================================================
1064 // decodeExtSvcNameList
1065 //============================================================================
1066 StatusCode ApplicationMgr::decodeExtSvcNameList( ) {
1067 StatusCode result = StatusCode::SUCCESS;
1068
1069 std::vector<std::string> theNames = m_extSvcNameList.value( );
1070
1071 VectorName::const_iterator it(theNames.begin());
1072 VectorName::const_iterator et(theNames.end());
1073 while(result.isSuccess() && it != et) {
1074 Gaudi::Utils::TypeNameString item(*it++);
1075 if (m_extSvcCreates == true) {
1076 if ( (result = svcManager()->addService(item, ServiceManager::DEFAULT_SVC_PRIORITY)).isFailure()) {
1077 MsgStream log( m_messageSvc, m_name );
1078 log << MSG::ERROR << "decodeExtSvcNameList: Cannot create service "
1079 << item.type() << "/" << item.name() << endmsg;
1080 }
1081 } else {
1082 if( ( result = svcManager()->declareSvcType(item.name(),
1083 item.type()) ).isFailure()) {
1084 MsgStream log( m_messageSvc, m_name );
1085 log << MSG::ERROR << "decodeExtSvcNameList: Cannot declare service "
1086 << item.type() << "/" << item.name() << endmsg;
1087 }
1088 }
1089 }
1090 return result;
1091 }
1092
1093 //============================================================================
1094 // External Service List handler
1095 //============================================================================
1096 void ApplicationMgr::multiThreadSvcNameListHandler( Property& /* theProp */ ) {
1097 if ( !(decodeMultiThreadSvcNameList( )).isSuccess() ) {
1098 throw GaudiException("Failed to create copies of mt services",
1099 "MinimalEventLoopMgr::multiThreadSvcNameListHandler",
1100 StatusCode::FAILURE);
1101 }
1102
1103 }
1104
1105 //============================================================================
1106 // decodeMultiExtSvcNameList
1107 //============================================================================
1108 StatusCode ApplicationMgr::decodeMultiThreadSvcNameList( ) {
1109 StatusCode result = StatusCode::SUCCESS;
1110 const std::vector<std::string>& theNames = m_multiThreadSvcNameList.value( );
1111 for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
1112 for (VectorName::const_iterator it = theNames.begin();
1113 it != theNames.end();
1114 ++it) {
1115 Gaudi::Utils::TypeNameString item(*it);
1116 result = addMultiSvc(item, ServiceManager::DEFAULT_SVC_PRIORITY);
1117 //FIXME SHOULD CLONE?
1118 if( result.isFailure() ) {
1119 MsgStream log( m_messageSvc, m_name );
1120 log << MSG::ERROR
1121 << "decodeMultiThreadSvcNameList: Cannot create service "
1122 << item.type() << "/" << item.name() << endmsg;
1123 } else {
1124 ON_VERBOSE {
1125 MsgStream log( m_messageSvc, m_name );
1126 log << MSG::VERBOSE
1127 << "decodeMultiThreadSvcNameList: created service "
1128 << item.type() << "/" << item.name() << endmsg;
1129 }
1130 }
1131 }
1132 }
1133 return result;
1134 }
1135 //=============================================================================
1136 // declareMultiSvcType
1137 //=============================================================================
1138 StatusCode ApplicationMgr::declareMultiSvcType(const std::string& name,
1139 const std::string& type) {
1140 StatusCode result = StatusCode::SUCCESS;
1141 MsgStream log( m_messageSvc, m_name );
1142 if (0 == m_noOfEvtThreads) {
1143 result = svcManager()->declareSvcType(name, type);
1144 if( result.isFailure() ) {
1145 log << MSG::ERROR << "declareMultiSvcType: Cannot declare service "
1146 << type << "/" << name << endmsg;
1147 } else {
1148 ON_VERBOSE
1149 log << MSG::VERBOSE << "declareMultiSvcType: declared service "
1150 << type << "/" << name << endmsg;
1151 }
1152 } else {
1153 for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
1154 std::string thrName(name + getGaudiThreadIDfromID(iCopy));
1155 result = svcManager()->declareSvcType(thrName, type);
1156 if( result.isFailure() ) {
1157 log << MSG::ERROR << "declareMultiSvcType: Cannot declare service "
1158 << type << "/" << thrName << endmsg;
1159 } else {
1160 ON_VERBOSE
1161 log << MSG::VERBOSE << "declareMultiSvcType: declared service "
1162 << type << "/" << thrName << endmsg;
1163 }
1164 }
1165 }
1166 return result;
1167 }
1168 //=============================================================================
1169 // addMultiSvc
1170 //=============================================================================
1171 StatusCode ApplicationMgr::addMultiSvc(const Gaudi::Utils::TypeNameString &typeName,
1172 int prio) {
1173 using Gaudi::Utils::TypeNameString;
1174 StatusCode result = StatusCode::SUCCESS;
1175 MsgStream log( m_messageSvc, m_name );
1176 if (0 == m_noOfEvtThreads) {
1177 result = svcManager()->addService(typeName, prio);
1178 // result = svcManager()->addService(name, type, prio); // CHECKME???
1179 if( result.isFailure() ) {
1180 log << MSG::ERROR << "addMultiSvc: Cannot add service "
1181 << typeName.type() << "/" << typeName.name() << endmsg;
1182 } else {
1183 ON_VERBOSE
1184 log << MSG::VERBOSE << "addMultiSvc: added service "
1185 << typeName.type() << "/" << typeName.name() << endmsg;
1186 }
1187 } else {
1188 for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
1189 const std::string &type = typeName.type();
1190 std::string thrName(typeName.name() + getGaudiThreadIDfromID(iCopy));
1191 result = svcManager()->addService(TypeNameString(thrName, type), prio);
1192 if( result.isFailure() ) {
1193 log << MSG::ERROR << "addMultiSvc: Cannot add service "
1194 << type << "/" << thrName << endmsg;
1195 } else {
1196 ON_VERBOSE
1197 log << MSG::VERBOSE << "addMultiSvc: added service "
1198 << type << "/" << thrName << endmsg;
1199 }
1200 }
1201 }
1202 return result;
1203 }
1204
1205 //============================================================================
1206 // Dll List handler
1207 //============================================================================
1208 void ApplicationMgr::dllNameListHandler( Property& /* theProp */ ) {
1209 if ( !(decodeDllNameList( )).isSuccess() ) {
1210 throw GaudiException("Failed to load DLLs.",
1211 "MinimalEventLoopMgr::dllNameListHandler",
1212 StatusCode::FAILURE);
1213 }
1214 }
1215
1216 //============================================================================
1217 // decodeDllNameList
1218 //============================================================================
1219 StatusCode ApplicationMgr::decodeDllNameList() {
1220
1221 MsgStream log( m_messageSvc, m_name );
1222 StatusCode result = StatusCode::SUCCESS;
1223
1224 // Clean up multiple entries from DLL list
1225 // -------------------------------------------------------------------------
1226 std::vector<std::string> newList;
1227 std::map<std::string,unsigned int> dllInList, duplicateList;
1228 {for ( std::vector<std::string>::const_iterator it = m_dllNameList.value().begin();
1229 it != m_dllNameList.value().end(); ++it ) {
1230 if ( 0 == dllInList[*it] ) {
1231 newList.push_back(*it); // first instance of this module
1232 } else { ++duplicateList[*it]; } // module listed multiple times
1233 ++dllInList[*it]; // increment count for this module
1234 }}
1235 //m_dllNameList = newList; // update primary list to new, filtered list (do not use the
1236 // property itself otherwise we get called again infinitely)
1237 // List modules that were in there twice..
1238 ON_DEBUG if ( !duplicateList.empty() ) {
1239 log << MSG::DEBUG << "Removed duplicate entries for modules : ";
1240 for ( std::map<std::string,unsigned int>::const_iterator it = duplicateList.begin();
1241 it != duplicateList.end(); ++it ) {
1242 log << it->first << "(" << 1+it->second << ")";
1243 if ( it != --duplicateList.end() ) log << ", ";
1244 }
1245 log << endmsg;
1246 }
1247 // -------------------------------------------------------------------------
1248
1249 const std::vector<std::string>& theNames = newList;
1250
1251 // only load the new dlls or previously failed dlls
1252 ON_DEBUG log << MSG::DEBUG << "Loading declared DLL's" << endmsg;
1253
1254 std::vector<std::string> successNames, failNames;
1255 std::vector<std::string>::const_iterator it;
1256
1257 for (it = theNames.begin(); it != theNames.end(); it++) {
1258 if (std::find (m_okDlls.rbegin(), m_okDlls.rend(), *it) == m_okDlls.rend()){
1259 // found a new module name
1260 StatusCode status = m_classManager->loadModule( (*it) );
1261 if( status.isFailure() ) {
1262 failNames.push_back(*it);
1263 result = StatusCode::FAILURE;
1264 }
1265 else {
1266 successNames.push_back(*it);
1267 }
1268 }
1269 }
1270
1271 // report back to the user and store the names of the succesfully loaded dlls
1272 if ( !successNames.empty() ) {
1273 log << MSG::INFO << "Successfully loaded modules : ";
1274 for (it = successNames.begin(); it != successNames.end(); it++) {
1275 log<< (*it);
1276 if( (it+1) != successNames.end()) log << ", ";
1277 // save name
1278 m_okDlls.push_back( *it );
1279 }
1280 log << endmsg;
1281 }
1282
1283 if ( result == StatusCode::FAILURE ) {
1284 log << MSG::WARNING << "Failed to load modules: ";
1285 for (it = failNames.begin(); it != failNames.end(); it++) {
1286 log<< (*it);
1287 if( (it+1) != failNames.end()) log << ", ";
1288 }
1289 log << endmsg;
1290 }
1291 return result;
1292 }
1293
1294 //============================================================================
1295 // Plugin debug level handler
1296 //============================================================================
1297 void ApplicationMgr::pluginDebugPropertyHandler( Property& )
1298 {
1299 // Setup debug level for the plugin system
1300 MsgStream log (m_messageSvc, name());
1301 log << MSG::INFO
1302 << "Updating Gaudi::PluginService::SetDebug(level) to level="
1303 << (int)m_pluginDebugLevel
1304 << endmsg;
1305 Gaudi::PluginService::SetDebug(m_pluginDebugLevel);
1306 }
1307
1308 //============================================================================
1309 // Init loop check handler
1310 //============================================================================
1311 void ApplicationMgr::initLoopCheckHndlr(Property&) {
1312 svcManager()->setLoopCheckEnabled(m_loopCheck);
1313 }