Gaudi Framework, version v23r10

Home   Generated: Mon Sep 30 2013
 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  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";
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("ReflexPluginDebugLevel", m_reflexDebugLevel = 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_reflexDebugLevel.declareUpdateHandler(&ApplicationMgr::reflexDebugPropertyHandler, 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 //============================================================================
168  if( m_messageSvc ) m_messageSvc->release();
169  if( m_jobOptionsSvc ) m_jobOptionsSvc->release();
170 }
171 
172 //============================================================================
173 // IInterface implementation: queryInterface::addRef()
174 //============================================================================
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 //============================================================================
214  StatusCode sc;
215 
216  // declare factories in current module
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 //============================================================================
308  // Check if the state is compatible with the transition
309  MsgStream tlog( m_messageSvc, name() );
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  }
320 
321  // Reset application return code.
323 
324  StatusCode sc;
325  sc = i_startup();
326  if ( !sc.isSuccess() ) {
327  return sc;
328  }
329 
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) {
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 {
404  }
405 
406  // set the requested environment variables
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
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 
454  if ( sc.isFailure( ) ) {
455  log << MSG::ERROR << "Failure during multi thread service creation"
456  << endmsg;
457  return sc;
458  }
459 
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, 100);
472  if( !sc.isSuccess() ) {
473  log << MSG::FATAL << "Error adding :" << m_eventLoopMgr << endmsg;
474  return sc;
475  }
476 
477  if (m_noOfEvtThreads == 0) {
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
497  this);
499  this);
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;
525  return StatusCode::SUCCESS;
526 }
527 
528 //============================================================================
529 // IAppMgrUI implementation: ApplicationMgr::initialize()
530 //============================================================================
532 
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 
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 
557  log << MSG::INFO << "Already Initialized!" << endmsg;
558  return StatusCode::SUCCESS;
559  }
561  log << MSG::FATAL
562  << "initialize: Invalid state \"" << m_state << "\"" << endmsg;
563  return StatusCode::FAILURE;
564  }
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;
578 
579  return sc;
580 }
581 
582 //============================================================================
583 // IAppMgrUI implementation: ApplicationMgr::start()
584 //============================================================================
586 
588  StatusCode sc;
589 
591  log << MSG::INFO << "Already Initialized!" << endmsg;
592  return StatusCode::SUCCESS;
593  }
595  log << MSG::FATAL
596  << "start: Invalid state \"" << m_state << "\"" << endmsg;
597  return StatusCode::FAILURE;
598  }
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;
612 
613  return sc;
614 }
615 
616 //============================================================================
617 // IAppMgrUI implementation: ApplicationMgr::nextEvent(int)
618 //============================================================================
622  log << MSG::FATAL << "nextEvent: Invalid state \"" << m_state << "\""
623  << endmsg;
624  return StatusCode::FAILURE;
625  }
626  if (!m_processingMgr.isValid()) {
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 //============================================================================
639 
641  StatusCode sc;
642 
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  }
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;
669 
670  return sc;
671 }
672 
673 //============================================================================
674 // IAppMgrUI implementation: ApplicationMgr::finalize()
675 //============================================================================
679  log << MSG::INFO << "Already Finalized" << endmsg;
680  return StatusCode::SUCCESS;
681  }
683  log << MSG::FATAL << "finalize: Invalid state \"" << m_state << "\""
684  << endmsg;
685  return StatusCode::FAILURE;
686  }
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;
697  }
698 
699  // Finalize all Services
700  sc = svcManager()->finalize();
701  if (sc.isFailure()) {
702  log << MSG::WARNING << "Failed to finalize a service." << endmsg;
704  }
705 
706  //svcManager()->removeService( (IService*) m_processingMgr.get() );
707  //svcManager()->removeService( (IService*) m_runable.get() );
708 
709  if (m_codeCheck) {
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 
720  return sc;
721 }
722 
723 //============================================================================
724 // IAppMgrUI implementation: ApplicationMgr::terminate()
725 //============================================================================
728 
730  log << MSG::INFO << "Already Offline" << endmsg;
731  return StatusCode::SUCCESS;
732  }
734  log << MSG::FATAL << "terminate: Invalid state \"" << m_state << "\""
735  << endmsg;
736  return StatusCode::FAILURE;
737  }
738  // release all Services
740 
742  log << MSG::INFO << "Application Manager Terminated successfully" << endmsg;
743  } else {
744  log << MSG::ERROR << "Application Manager Terminated with error code " << m_returnCode.value() << endmsg;
745  }
746 
747  { // Force a disable the auditing of finalize for MessageSvc
749  if (prop.isValid()) {
750  prop->setProperty(BooleanProperty("AuditFinalize", false)).ignore();
751  }
752  }
753  { // Force a disable the auditing of finalize for JobOptionsSvc
755  if (prop.isValid()) {
756  prop->setProperty(BooleanProperty("AuditFinalize", false)).ignore();
757  }
758  }
759 
760  // finalize MessageSvc
762  if ( !svc.isValid() ) {
763  log << MSG::ERROR << "Could not get the IService interface of the MessageSvc" << endmsg;
764  } else {
765  svc->sysFinalize().ignore();
766  }
767 
768  // finalize JobOptionsSvc
769  svc = m_jobOptionsSvc;
770  if ( !svc.isValid() ) {
771  log << MSG::ERROR << "Could not get the IService interface of the JobOptionsSvc" << endmsg;
772  } else {
773  svc->sysFinalize().ignore();
774  }
775 
777  return StatusCode::SUCCESS;
778 }
779 
780 //============================================================================
781 // Reach the required state going through all the needed transitions
782 //============================================================================
785 
786  switch (state) {
787 
789  switch (m_state) {
791  case Gaudi::StateMachine::CONFIGURED : return terminate(); break;
792  default: // Gaudi::StateMachine::INITIALIZED or Gaudi::StateMachine::RUNNING
794  if (sc.isSuccess()) {
795  return terminate();
796  } break;
797  } break;
798 
800  switch (m_state) {
802  case Gaudi::StateMachine::OFFLINE : return configure(); break;
803  case Gaudi::StateMachine::INITIALIZED : return finalize(); break;
804  default: // Gaudi::StateMachine::RUNNING
806  if (sc.isSuccess()) {
807  return finalize();
808  } break;
809  } break;
810 
812  switch (m_state) {
814  case Gaudi::StateMachine::CONFIGURED : return initialize(); break;
815  case Gaudi::StateMachine::RUNNING : return stop(); break;
816  default: // Gaudi::StateMachine::OFFLINE
818  if (sc.isSuccess()) {
819  return initialize();
820  } break;
821  } break;
822 
824  switch (m_state) {
826  case Gaudi::StateMachine::INITIALIZED : return start(); break;
827  default: // Gaudi::StateMachine::OFFLINE or Gaudi::StateMachine::CONFIGURED
829  if (sc.isSuccess()) {
830  return start();
831  } break;
832  } break;
833 
834  }
835 
836  // If I get here, there has been a problem in the recursion
837 
838  if (ignoreFailures){
839  // force the new state
840  m_state = state;
841  return StatusCode::SUCCESS;
842  }
843 
844  return sc;
845 }
846 
847 //============================================================================
848 // IAppMgrUI implementation: ApplicationMgr::run()
849 //============================================================================
852 
854  if ( sc.isSuccess() ) {
856  if ( m_runable != 0 ) { // loop over the events
857  sc = m_runable->run();
858  if ( !sc.isSuccess() ) {
859  log << MSG::FATAL << "Application execution failed. Ending the job."
860  << endmsg;
861  }
862  } else {
863  log << MSG::FATAL << "Application has no runable object. Check option:"
864  << s_runable << endmsg;
865  }
866  }
867  if (sc.isSuccess()) { // try to close cleanly
869  }
870  // either the runable failed of the stut-down
871  if (sc.isFailure()) { // try to close anyway (but keep the StatusCode unchanged)
873  }
874  return sc;
875 }
876 
877 //============================================================================
878 // IEventProcessor implementation: executeEvent(void* par)
879 //============================================================================
883  if ( m_processingMgr.isValid() ) {
884  return m_processingMgr->executeEvent(par);
885  }
886  }
887  log << MSG::FATAL << "executeEvent: Invalid state \"" << FSMState() << "\""
888  <<endmsg;
889  return StatusCode::FAILURE;
890 }
891 
892 //============================================================================
893 // IEventProcessor implementation: executeRun(int)
894 //============================================================================
898  if ( m_processingMgr.isValid() ) {
899  return m_processingMgr->executeRun(evtmax);
900  }
901  log << MSG::WARNING << "No EventLoop Manager specified " << endmsg;
902  return StatusCode::SUCCESS;
903  }
904  log << MSG::FATAL << "executeRun: Invalid state \"" << FSMState() << "\""
905  << endmsg;
906  return StatusCode::FAILURE;
907 }
908 
909 //============================================================================
910 // IEventProcessor implementation: stopRun(int)
911 //============================================================================
915  if ( m_processingMgr.isValid() ) {
916  return m_processingMgr->stopRun();
917  }
918  log << MSG::WARNING << "No EventLoop Manager specified " << endmsg;
919  return StatusCode::SUCCESS;
920  }
921  log << MSG::FATAL << "stopRun: Invalid state \"" << FSMState() << "\""
922  << endmsg;
923  return StatusCode::FAILURE;
924 }
925 // Implementation of IAppMgrUI::name
927  return m_name;
928 }
929 
930 // implementation of IService::state
932  return m_state;
933 }
934 // implementation of IService::state
936  return m_targetState;
937 }
938 
939 
940 //============================================================================
941 // implementation of IService::reinitilaize
942 //============================================================================
945  StatusCode sc;
947  throw GaudiException("Cannot reinitialize application if not INITIALIZED or RUNNING",
948  "ApplicationMgr::reinitialize", StatusCode::FAILURE);
949  }
952  }
953  sc = svcManager()->reinitialize();
954  if (sc.isFailure()) retval = sc;
955  sc = algManager()->reinitialize();
956  if (sc.isFailure()) retval = sc;
957  return retval;
958 }
959 
960 //============================================================================
961 // implementation of IService::reinitiaize
962 //============================================================================
965  StatusCode sc;
967  throw GaudiException("Cannot restart application if not RUNNING",
968  "ApplicationMgr::restart", StatusCode::FAILURE);
969  }
970  sc = svcManager()->restart();
971  if (sc.isFailure()) retval = sc;
972  sc = algManager()->restart();
973  if (sc.isFailure()) retval = sc;
974  return retval;
975 }
976 
977 //============================================================================
978 // SI Go Handler
979 //============================================================================
981 
983  StatusCode sc;
984 
985  // Re-initialize everything
986  sc = reinitialize();
987  // Execute a number of events
989 
990  return;
991 }
992 
993 //============================================================================
994 // SI Exit Handler
995 //============================================================================
997  StatusCode status;
998  status = finalize();
999  status = terminate();
1000  ::exit( 0 );
1001 }
1002 
1003 //============================================================================
1004 // Handle properties of the event loop manager (Top alg/Output stream list)
1005 //============================================================================
1007  if ( m_processingMgr.isValid() ) {
1009  if ( props.isValid() ) {
1010  props->setProperty( p ).ignore();
1011  }
1012  }
1013 }
1014 
1015 //============================================================================
1016 // External Service List handler
1017 //============================================================================
1019  if ( !(decodeCreateSvcNameList()).isSuccess() ) {
1020  throw GaudiException("Failed to create ext services",
1021  "MinimalEventLoopMgr::createSvcNameListHandler",
1023  }
1024 }
1025 //============================================================================
1026 // decodeCreateSvcNameList
1027 //============================================================================
1030  const std::vector<std::string>& theNames = m_createSvcNameList.value( );
1031  VectorName::const_iterator it(theNames.begin());
1032  VectorName::const_iterator et(theNames.end());
1033  while(result.isSuccess() && it != et) {
1034  Gaudi::Utils::TypeNameString item(*it++);
1035  if( (result = svcManager()->addService(item, 10) ).isFailure()) {
1037  log << MSG::ERROR << "decodeCreateSvcNameList: Cannot create service "
1038  << item.type() << "/" << item.name() << endmsg;
1039  } else {
1040  ON_DEBUG {
1042  log << MSG::DEBUG << "decodeCreateSvcNameList: Created service "
1043  << item.type() << "/" << item.name() << endmsg;
1044  }
1045  }
1046  }
1047  return result;
1048 }
1049 
1050 //============================================================================
1051 // External Service List handler
1052 //============================================================================
1054  if ( !(decodeExtSvcNameList( )).isSuccess() ) {
1055  throw GaudiException("Failed to declare ext services",
1056  "MinimalEventLoopMgr::extSvcNameListHandler",
1058  }
1059 }
1060 
1061 //============================================================================
1062 // decodeExtSvcNameList
1063 //============================================================================
1066 
1068 
1069  VectorName::const_iterator it(theNames.begin());
1070  VectorName::const_iterator et(theNames.end());
1071  while(result.isSuccess() && it != et) {
1072  Gaudi::Utils::TypeNameString item(*it++);
1073  if (m_extSvcCreates == true) {
1074  if ( (result = svcManager()->addService(item, 10)).isFailure()) {
1076  log << MSG::ERROR << "decodeExtSvcNameList: Cannot create service "
1077  << item.type() << "/" << item.name() << endmsg;
1078  }
1079  } else {
1080  if( ( result = svcManager()->declareSvcType(item.name(),
1081  item.type()) ).isFailure()) {
1083  log << MSG::ERROR << "decodeExtSvcNameList: Cannot declare service "
1084  << item.type() << "/" << item.name() << endmsg;
1085  }
1086  }
1087  }
1088  return result;
1089 }
1090 
1091 //============================================================================
1092 // External Service List handler
1093 //============================================================================
1095  if ( !(decodeMultiThreadSvcNameList( )).isSuccess() ) {
1096  throw GaudiException("Failed to create copies of mt services",
1097  "MinimalEventLoopMgr::multiThreadSvcNameListHandler",
1099  }
1100 
1101 }
1102 
1103 //============================================================================
1104 // decodeMultiExtSvcNameList
1105 //============================================================================
1109  for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
1110  for (VectorName::const_iterator it = theNames.begin();
1111  it != theNames.end();
1112  ++it) {
1113  Gaudi::Utils::TypeNameString item(*it);
1114  result = addMultiSvc(item, 10);
1115  //FIXME SHOULD CLONE?
1116  if( result.isFailure() ) {
1118  log << MSG::ERROR
1119  << "decodeMultiThreadSvcNameList: Cannot create service "
1120  << item.type() << "/" << item.name() << endmsg;
1121  } else {
1122  ON_VERBOSE {
1124  log << MSG::VERBOSE
1125  << "decodeMultiThreadSvcNameList: created service "
1126  << item.type() << "/" << item.name() << endmsg;
1127  }
1128  }
1129  }
1130  }
1131  return result;
1132 }
1133 //=============================================================================
1134 // declareMultiSvcType
1135 //=============================================================================
1137  const std::string& type) {
1140  if (0 == m_noOfEvtThreads) {
1141  result = svcManager()->declareSvcType(name, type);
1142  if( result.isFailure() ) {
1143  log << MSG::ERROR << "declareMultiSvcType: Cannot declare service "
1144  << type << "/" << name << endmsg;
1145  } else {
1146  ON_VERBOSE
1147  log << MSG::VERBOSE << "declareMultiSvcType: declared service "
1148  << type << "/" << name << endmsg;
1149  }
1150  } else {
1151  for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
1152  std::string thrName(name + getGaudiThreadIDfromID(iCopy));
1153  result = svcManager()->declareSvcType(thrName, type);
1154  if( result.isFailure() ) {
1155  log << MSG::ERROR << "declareMultiSvcType: Cannot declare service "
1156  << type << "/" << thrName << endmsg;
1157  } else {
1158  ON_VERBOSE
1159  log << MSG::VERBOSE << "declareMultiSvcType: declared service "
1160  << type << "/" << thrName << endmsg;
1161  }
1162  }
1163  }
1164  return result;
1165 }
1166 //=============================================================================
1167 // addMultiSvc
1168 //=============================================================================
1169 StatusCode ApplicationMgr::addMultiSvc(const Gaudi::Utils::TypeNameString &typeName,
1170  int prio) {
1171  using Gaudi::Utils::TypeNameString;
1174  if (0 == m_noOfEvtThreads) {
1175  result = svcManager()->addService(typeName, prio);
1176  // result = svcManager()->addService(name, type, prio); // CHECKME???
1177  if( result.isFailure() ) {
1178  log << MSG::ERROR << "addMultiSvc: Cannot add service "
1179  << typeName.type() << "/" << typeName.name() << endmsg;
1180  } else {
1181  ON_VERBOSE
1182  log << MSG::VERBOSE << "addMultiSvc: added service "
1183  << typeName.type() << "/" << typeName.name() << endmsg;
1184  }
1185  } else {
1186  for(int iCopy=0; iCopy<m_noOfEvtThreads; ++iCopy) {
1187  const std::string &type = typeName.type();
1188  std::string thrName(typeName.name() + getGaudiThreadIDfromID(iCopy));
1189  result = svcManager()->addService(TypeNameString(thrName, type), prio);
1190  if( result.isFailure() ) {
1191  log << MSG::ERROR << "addMultiSvc: Cannot add service "
1192  << type << "/" << thrName << endmsg;
1193  } else {
1194  ON_VERBOSE
1195  log << MSG::VERBOSE << "addMultiSvc: added service "
1196  << type << "/" << thrName << endmsg;
1197  }
1198  }
1199  }
1200  return result;
1201 }
1202 
1203 //============================================================================
1204 // Dll List handler
1205 //============================================================================
1207  if ( !(decodeDllNameList( )).isSuccess() ) {
1208  throw GaudiException("Failed to load DLLs.",
1209  "MinimalEventLoopMgr::dllNameListHandler",
1211  }
1212 }
1213 
1214 //============================================================================
1215 // decodeDllNameList
1216 //============================================================================
1218 
1221 
1222  // Clean up multiple entries from DLL list
1223  // -------------------------------------------------------------------------
1224  std::vector<std::string> newList;
1225  std::map<std::string,unsigned int> dllInList, duplicateList;
1227  it != m_dllNameList.value().end(); ++it ) {
1228  if ( 0 == dllInList[*it] ) {
1229  newList.push_back(*it); // first instance of this module
1230  } else { ++duplicateList[*it]; } // module listed multiple times
1231  ++dllInList[*it]; // increment count for this module
1232  }}
1233  //m_dllNameList = newList; // update primary list to new, filtered list (do not use the
1234  // property itself otherwise we get called again infinitely)
1235  // List modules that were in there twice..
1236  ON_DEBUG if ( !duplicateList.empty() ) {
1237  log << MSG::DEBUG << "Removed duplicate entries for modules : ";
1238  for ( std::map<std::string,unsigned int>::const_iterator it = duplicateList.begin();
1239  it != duplicateList.end(); ++it ) {
1240  log << it->first << "(" << 1+it->second << ")";
1241  if ( it != --duplicateList.end() ) log << ", ";
1242  }
1243  log << endmsg;
1244  }
1245  // -------------------------------------------------------------------------
1246 
1247  const std::vector<std::string>& theNames = newList;
1248 
1249  // only load the new dlls or previously failed dlls
1250  ON_DEBUG log << MSG::DEBUG << "Loading declared DLL's" << endmsg;
1251 
1252  std::vector<std::string> successNames, failNames;
1254 
1255  for (it = theNames.begin(); it != theNames.end(); it++) {
1256  if (std::find (m_okDlls.rbegin(), m_okDlls.rend(), *it) == m_okDlls.rend()){
1257  // found a new module name
1258  StatusCode status = m_classManager->loadModule( (*it) );
1259  if( status.isFailure() ) {
1260  failNames.push_back(*it);
1261  result = StatusCode::FAILURE;
1262  }
1263  else {
1264  successNames.push_back(*it);
1265  }
1266  }
1267  }
1268 
1269  // report back to the user and store the names of the succesfully loaded dlls
1270  if ( !successNames.empty() ) {
1271  log << MSG::INFO << "Successfully loaded modules : ";
1272  for (it = successNames.begin(); it != successNames.end(); it++) {
1273  log<< (*it);
1274  if( (it+1) != successNames.end()) log << ", ";
1275  // save name
1276  m_okDlls.push_back( *it );
1277  }
1278  log << endmsg;
1279  }
1280 
1281  if ( result == StatusCode::FAILURE ) {
1282  log << MSG::WARNING << "Failed to load modules: ";
1283  for (it = failNames.begin(); it != failNames.end(); it++) {
1284  log<< (*it);
1285  if( (it+1) != failNames.end()) log << ", ";
1286  }
1287  log << endmsg;
1288  }
1289  return result;
1290 }
1291 
1292 //============================================================================
1293 // Reflex debug level handler
1294 //============================================================================
1296 {
1297  // Setup debug level for Reflex plugin system
1299  log << MSG::INFO
1300  << "Updating ROOT::Reflex::PluginService::SetDebug(level) to level="
1302  << endmsg;
1303  ROOT::Reflex::PluginService::SetDebug(m_reflexDebugLevel);
1304 }
1305 
1306 //============================================================================
1307 // Reflex debug level handler
1308 //============================================================================
1310  svcManager()->setLoopCheckEnabled(m_loopCheck);
1311 }

Generated at Mon Sep 30 2013 14:51:55 for Gaudi Framework, version v23r10 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004