The Gaudi Framework  v33r1 (b1225454)
ApplicationMgr.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDI_APPLICATIONMGR_H
12 #define GAUDI_APPLICATIONMGR_H
13 
18 #include <GaudiKernel/IAlgorithm.h>
19 #include <GaudiKernel/IAppMgrUI.h>
22 #include <GaudiKernel/IProperty.h>
23 #include <GaudiKernel/IStateful.h>
25 #include <GaudiKernel/Kernel.h>
27 #include <GaudiKernel/Service.h>
28 #include <vector>
29 
30 // Forward declarations
31 class ISvcLocator;
32 class ServiceManager;
33 class AlgorithmManager;
34 class DLLClassManager;
35 
36 class IMessageSvc;
37 class IIncidentSvc;
38 class IRunable;
39 class IDataManagerSvc;
40 class IConversionSvc;
41 class IJobOptionsSvc;
42 
56  : public PropertyHolder<CommonMessaging<implements<IAppMgrUI, Gaudi::Interfaces::IQueueingEventProcessor, IService,
57  IStateful, INamedInterface, IProperty>>> {
58 public:
59  // default creator
60  ApplicationMgr( IInterface* = nullptr );
61 
62  // implementation of IInterface::queryInterface
63  StatusCode queryInterface( const InterfaceID& iid, void** pinterface ) override;
64 
65  // implementation of IAppMgrUI::run
66  StatusCode run() override;
67  // implementation of IAppMgrUI::configure
68  StatusCode configure() override;
69  // implementation of IAppMgrUI::terminate
70  StatusCode terminate() override;
71  // implementation of IAppMgrUI::initialize
72  StatusCode initialize() override;
73  // implementation of IAppMgrUI::start
74  StatusCode start() override;
75  // implementation of IAppMgrUI::stop
76  StatusCode stop() override;
77  // implementation of IAppMgrUI::finalize
78  StatusCode finalize() override;
79  // implementation of IAppMgrUI::nextEvent
80  StatusCode nextEvent( int maxevt ) override;
81  // implementation of IAppMgrUI::name
82  const std::string& name() const override;
88  StatusCode executeRun( int evtmax ) override;
90  StatusCode stopRun() override;
91 
92  // implementation of IStateful::state
93  Gaudi::StateMachine::State FSMState() const override;
94  // implementation of IStateful::targetState
96  // implementation of IStateful::reinitialize
97  StatusCode reinitialize() override;
98  // implementation of IStateful::reinitialize
99  StatusCode restart() override;
100  // implementation of IService::sysItinitilaize
102  // implementation of IService::sysStart
103  StatusCode sysStart() override { return StatusCode::SUCCESS; }
104  // implementation of IService::sysStop
105  StatusCode sysStop() override { return StatusCode::SUCCESS; }
106  // implementation of IService::sysFinalize
108  // implementation of IService::sysReinitialize
110  // implementation of IService::sysRestart
112 
114  void push( EventContext&& ctx ) override;
115  bool empty() const override;
116  std::optional<Gaudi::Interfaces::IQueueingEventProcessor::ResultType> pop() override;
118 
120 
130 
131  template <class I>
133  return m_managers[I::interfaceID().id()];
134  }
135 
137  // Cache the casted pointer to ISvcManager
138  if ( !m_svcManager ) { m_svcManager = getManager<IService>(); }
139  return m_svcManager;
140  }
141 
143  // Cache the casted pointer to IAlgManager
144  if ( !m_algManager ) { m_algManager = getManager<IAlgorithm>(); }
145  return m_algManager;
146  }
147 
149  SmartIF<ISvcLocator>& serviceLocator() const override { return m_svcLocator; }
150 
152  void outputLevelUpdate() override;
153 
155  void printAlgsSequences();
156 
157 protected:
158  // implementation of IService::setServiceManager
159  void setServiceManager( ISvcManager* ) override {}
160 
163 
168  StatusCode GoToState( Gaudi::StateMachine::State state, bool ignoreFailures = false );
169 
179 
182 
185 
186  // data members
190 
192  [this]( auto& ) {
193  // Re-initialize everything
194  this->reinitialize().ignore();
195  // Execute a number of events
196  this->executeRun( m_evtMax ).ignore();
197  },
198  "For SI's \"Go\" command via callback"};
200  [this]( auto& ) {
201  finalize().ignore();
202  terminate().ignore();
203  ::exit( 0 );
204  },
205  "For SI's \"Exit\" command via callback"};
207  "TopAlg",
208  {},
210  "List of top level algorithms names",
211  "vector<Algorithm>"};
213  this, "OutStream", {}, &ApplicationMgr::evtLoopPropertyHandler, "List of output stream names"};
214  Gaudi::Property<std::string> m_outStreamType{this, "OutStreamType", "OutputStream",
216  "[[deprecated]] Output stream type"};
217  Gaudi::Property<std::string> m_messageSvcType{this, "MessageSvcType", "MessageSvc", "MessageSvc type",
218  "Service:IMessageSvc"};
219  Gaudi::Property<std::string> m_jobOptionsSvcType{this, "JobOptionsSvcType", "JobOptionsSvc", "JobOptionsSvc type",
220  "Service:IJobOptionsSvc"};
221 
222  std::string m_name = "ApplicationMgr";
225 
226  Gaudi::Property<std::vector<std::string>> m_svcMapping{this, "SvcMapping", {}, "Default mapping of services"};
228  this, "SvcOptMapping", {}, "Default mapping of optional services"};
229 
234 
236  //
237  // The public ApplicationMgr properties
238  //
239 
240  Gaudi::Property<int> m_evtMax{this, "EvtMax", -1, "Number of events to be processed (-1 means all events)"};
242  this, "ExtSvc", {}, "List of external services names", "vector<Service>"};
243  Gaudi::Property<bool> m_extSvcCreates{this, "ExtSvcCreates", true,
244  "LHCb (default) or ATLAS definition of \"ExtSvc\""};
245 
246  Gaudi::Property<std::vector<std::string>> m_dllNameList{this, "Dlls", {}, "List of DDL's names"};
247  Gaudi::Property<std::string> m_jobOptionsType{this, "JobOptionsType", "FILE", "Source type (e.g. dbase, file...)"};
248  Gaudi::Property<std::string> m_jobOptionsPath{this, "JobOptionsPath", {}, "The \"file\" to look for properties"};
250  this, "JobOptionsPostAction", {}, "additional command to run on config"};
252  this, "JobOptionsPreAction", {}, "additional command to run on config"};
253  Gaudi::Property<std::string> m_runableType{this, "Runable", "AppMgrRunable", "Runable type"};
254  Gaudi::Property<std::string> m_eventLoopMgr{this, "EventLoop", "EventLoopMgr", "Processing manager type"};
255  Gaudi::Property<std::string> m_evtsel{this, "EvtSel", {}, "Event selection"};
256  Gaudi::Property<std::string> m_histPersName{this, "HistogramPersistency", "NONE", "Name of the Hist Pers Svc"};
257  Gaudi::Property<int> m_outputLevel{this, "OutputLevel", MSG::INFO, "Message output level"};
258  Gaudi::Property<std::string> m_appName{this, "AppName", "ApplicationMgr", "The name of the application"};
259  Gaudi::Property<std::string> m_appVersion{this, "AppVersion", {}, "The version of the application"};
260  Gaudi::Property<bool> m_actHistory{this, "ActivateHistory", false, "Activate HistorySvc"};
261  Gaudi::Property<bool> m_codeCheck{this, "StatusCodeCheck", false, "Activate StatusCode checking"};
263  this, "PluginDebugLevel", 0,
264  [this]( auto& ) {
265  // Setup debug level for the plugin system
266  MsgStream log( m_messageSvc, this->name() );
267  log << MSG::INFO << "Updating Gaudi::PluginService::SetDebug(level) to level=" << m_pluginDebugLevel << endmsg;
269  },
270  "Debug level for the plugin system"};
271 
273  this, "CreateSvc", {}, "List of extra services to be created"};
274 
276  Gaudi::Property<bool> m_auditTools{this, "AuditTools", false};
277  Gaudi::Property<bool> m_auditSvcs{this, "AuditServices", false};
278  Gaudi::Property<bool> m_auditAlgs{this, "AuditAlgorithms", false};
279 
281  this, "Environment", {}, "Environment variables to set"};
282 
283  Gaudi::Property<bool> m_loopCheck{this, "InitializationLoopCheck", true,
284  [this]( auto& ) { this->svcManager()->setLoopCheckEnabled( m_loopCheck ); },
285  "For ServiceMgr initialization loop checking"};
286 
290  this, "StopOnSignal", false, "Flag to enable/disable the signal handler that schedule a stop of the event loop"};
291 
295  this, "StalledEventMonitoring", false, "Flag to enable/disable the monitoring and reporting of stalled events"};
296 
297  Gaudi::Property<bool> m_propertiesPrint{this, "PropertiesPrint", false,
298  "Flag to activate the printout of properties"};
299 
302  "Return code of the application. Set internally in case of error conditions."};
303 
304  Gaudi::Property<bool> m_printAlgsSequence{this, "PrintAlgsSequence", false,
305  "Print the sequence of algorithms that have been loaded."};
306 
307  // For concurrency
309 
310 private:
312 
314  template <typename SELF, typename PIMPL, typename METHOD, typename... ARGS>
315  static auto i_delegateToEvtProc( SELF* self, PIMPL& member, std::string_view method_name, METHOD&& method,
316  ARGS&&... args ) {
317  if ( LIKELY( self->m_state == Gaudi::StateMachine::RUNNING ) ) {
318  if ( LIKELY( bool( member ) ) ) {
319  return std::invoke( method, *member.get(), std::forward<ARGS>( args )... );
320  } else {
322  s << method_name << ": event processor is not a \""
323  << System::typeinfoName( typeid( decltype( *member.get() ) ) ) << '"';
324  throw GaudiException{s.str(), self->name(), StatusCode::FAILURE};
325  }
326  }
328  s << method_name << ": Invalid state \"" << self->FSMState() << '"';
329  throw GaudiException{s.str(), self->name(), StatusCode::FAILURE};
330  }
331 };
332 #endif // GAUDI_APPLICATIONMGR_H
The ServiceManager class is in charge of the creation of concrete instances of Services.
Gaudi::StateMachine::State m_targetState
Internal State.
The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms.
StatusCode initialize() override
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
Gaudi::Property< bool > m_propertiesPrint
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
StatusCode decodeDllNameList()
Gaudi::Property< bool > m_printAlgsSequence
Gaudi::Property< int > m_returnCode
Property to record the error conditions occurring during the running.
Gaudi::Property< bool > m_stopOnSignal
Property to enable/disable the "stop on signal" service.
Gaudi::Property< bool > m_auditSvcs
Gaudi::Property< bool > m_codeCheck
std::map< unsigned long, SmartIF< IComponentManager > > ManagersMap
Typedef for the map of component managers, the key is the "id" field of the basic InterfaceID of the ...
Gaudi::Property< int > m_evtMax
SmartIF< IRunable > m_runable
Reference to the runable object.
Implementation of property with value of concrete type.
Definition: Property.h:370
bool empty() const override
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:308
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition: ISvcManager.h:38
ManagersMap m_managers
Map of known component managers.
StatusCode sysStart() override
Gaudi::Property< std::string > m_outStreamType
Gaudi::Property< std::string > m_jobOptionsType
Gaudi::Property< int > m_SIGo
Gaudi::Property< std::map< std::string, std::string > > m_environment
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
Gaudi::Property< bool > m_auditAlgs
Gaudi::Property< std::string > m_appVersion
std::vector< std::string > m_okDlls
names of successfully loaded dlls
StatusCode sysRestart() override
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
Definition: StateMachine.h:22
void push(EventContext &&ctx) override
StatusCode sysFinalize() override
StatusCode nextEvent(int maxevt) override
SmartIF< IJobOptionsSvc > m_jobOptionsSvc
Reference to JobOption service.
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
void createSvcNameListHandler(Gaudi::Details::PropertyBase &)
STL class.
Gaudi::Property< std::vector< std::string > > m_outStreamNameList
static auto i_delegateToEvtProc(SELF *self, PIMPL &member, std::string_view method_name, METHOD &&method, ARGS &&... args)
Helper to delegate calls to event processor implementation.
SmartIF< IEventProcessor > m_processingMgr
Reference to processing manager object.
StatusCode terminate() override
SmartIF< ISvcManager > & svcManager()
SmartIF< IComponentManager > & getManager()
Gaudi::Property< std::string > m_eventLoopMgr
STL class.
Gaudi::Property< std::string > m_evtsel
StatusCode sysReinitialize() override
void evtLoopPropertyHandler(Gaudi::Details::PropertyBase &theProp)
Interface ID class.
Definition: IInterface.h:39
Gaudi::Property< int > m_outputLevel
Main interface for the JobOptions service.
StatusCode executeRun(int evtmax) override
implementation of IEventProcessor::executeRun(int)
Gaudi::Property< std::vector< std::string > > m_topAlgNameList
void extSvcNameListHandler(Gaudi::Details::PropertyBase &theProp)
std::optional< Gaudi::Interfaces::IQueueingEventProcessor::ResultType > pop() override
SmartIF< ISvcLocator > m_svcLocator
Reference to its own service locator (must be instantiated prior to any service!)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
Definition of the basic interface.
Definition: IInterface.h:254
EventContext createEventContext() override
implementation of IEventProcessor::createEventContext()
Gaudi::Property< std::vector< std::string > > m_extSvcNameList
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:47
void dllNameListHandler(Gaudi::Details::PropertyBase &theProp)
StatusCode executeEvent(EventContext &&ctx) override
implementation of IEventProcessor::executeEvent(void*)
Gaudi::Property< std::string > m_runableType
Gaudi::Property< std::vector< std::string > > m_declaredManagers
Property to declare the list of known managers.
StatusCode sysStop() override
SmartIF< ISvcLocator > & serviceLocator() const override
Needed to locate the message service.
Gaudi::Property< int > m_SIExit
Gaudi::Property< bool > m_stalledEventMonitoring
Property to enable/disable the monitoring and reporting of stalled events.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:42
SmartIF< ISvcManager > m_svcManager
Cached pointer to the manager of services.
StatusCode GoToState(Gaudi::StateMachine::State state, bool ignoreFailures=false)
Reach a state from current state (whichever it is) going through the correct transitions.
StatusCode finalize() override
Gaudi::Property< std::vector< std::string > > m_svcOptMapping
Gaudi::Property< std::string > m_jobOptionsPreAction
Gaudi::Property< std::vector< std::string > > m_svcMapping
Gaudi::Property< std::vector< std::string > > m_dllNameList
#define LIKELY(x)
Definition: Kernel.h:105
The Application Manager class.
Gaudi::Property< bool > m_actHistory
StatusCode queryInterface(const InterfaceID &iid, void **pinterface) override
StatusCode decodeExtSvcNameList()
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:168
Gaudi::Property< bool > m_extSvcCreates
Gaudi::Property< bool > m_auditTools
Defaults for auditors.
SmartIF< DLLClassManager > m_classManager
Reference to the class manager.
Gaudi::Property< std::string > m_jobOptionsSvcType
StatusCode start() override
Gaudi::Property< std::vector< std::string > > m_createSvcNameList
StatusCode restart() override
StatusCode configure() override
ApplicationMgr(IInterface *=nullptr)
void pluginDebugPropertyHandler(Gaudi::Details::PropertyBase &theProp)
StatusCode stopRun() override
implementation of IEventProcessor::stopRun()
StatusCode decodeCreateSvcNameList()
void printAlgsSequences()
Print the sequence of algorithms that have been loaded.
Gaudi::Property< std::string > m_jobOptionsPostAction
Runable interface definition.
Definition: IRunable.h:28
Helper class to implement the IProperty interface.
string s
Definition: gaudirun.py:328
constexpr static const auto FAILURE
Definition: StatusCode.h:101
SmartIF< IAlgManager > m_algManager
Cached pointer to the manager of algorithms.
StatusCode i_startup()
Internal startup routine.
StatusCode stop() override
std::string m_name
Name.
Gaudi::Property< std::string > m_messageSvcType
StatusCode reinitialize() override
Gaudi::StateMachine::State m_state
Internal State.
Gaudi::StateMachine::State FSMState() const override
Gaudi::Property< std::string > m_appName
Gaudi::Property< std::string > m_histPersName
virtual void setLoopCheckEnabled(bool en=true)=0
Set the value of the initialization loop check flag.
int maxevt
Definition: Bootstrap.cpp:270
constexpr int Success
Definition: AppReturnCode.h:26
StatusCode run() override
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
SmartIF< IAlgManager > & algManager()
SmartIF< IQueueingEventProcessor > m_queueingProcessor
Reference to a queueing processing manager object.
const std::string & name() const override
void setServiceManager(ISvcManager *) override
SmartIF< IMessageSvc > m_messageSvc
Reference to the message service.
StatusCode sysInitialize() override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::Property< int > m_pluginDebugLevel
Gaudi::Property< std::string > m_jobOptionsPath
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:33
bool m_useHiveAlgorithmManager
Gaudi::StateMachine::State targetFSMState() const override
Gaudi::Property< bool > m_loopCheck