Gaudi Framework, version v23r5

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

Generated at Wed Nov 28 2012 12:17:11 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004