The Gaudi Framework  v32r2 (46d42edc)
ApplicationMgr.h
Go to the documentation of this file.
1 #ifndef GAUDI_APPLICATIONMGR_H
2 #define GAUDI_APPLICATIONMGR_H
3 
12 #include <GaudiKernel/IProperty.h>
13 #include <GaudiKernel/IStateful.h>
15 #include <GaudiKernel/Kernel.h>
17 #include <GaudiKernel/Service.h>
18 #include <vector>
19 
20 // Forward declarations
21 class ISvcLocator;
22 class ServiceManager;
23 class AlgorithmManager;
24 class DLLClassManager;
25 
26 class IMessageSvc;
27 class IIncidentSvc;
28 class IRunable;
29 class IDataManagerSvc;
30 class IConversionSvc;
31 class IJobOptionsSvc;
32 
46  : public PropertyHolder<CommonMessaging<implements<IAppMgrUI, Gaudi::Interfaces::IQueueingEventProcessor, IService,
47  IStateful, INamedInterface, IProperty>>> {
48 public:
49  // default creator
50  ApplicationMgr( IInterface* = nullptr );
51 
52  // implementation of IInterface::queryInterface
53  StatusCode queryInterface( const InterfaceID& iid, void** pinterface ) override;
54 
55  // implementation of IAppMgrUI::run
56  StatusCode run() override;
57  // implementation of IAppMgrUI::configure
58  StatusCode configure() override;
59  // implementation of IAppMgrUI::terminate
60  StatusCode terminate() override;
61  // implementation of IAppMgrUI::initialize
62  StatusCode initialize() override;
63  // implementation of IAppMgrUI::start
64  StatusCode start() override;
65  // implementation of IAppMgrUI::stop
66  StatusCode stop() override;
67  // implementation of IAppMgrUI::finalize
68  StatusCode finalize() override;
69  // implementation of IAppMgrUI::nextEvent
70  StatusCode nextEvent( int maxevt ) override;
71  // implementation of IAppMgrUI::name
72  const std::string& name() const override;
78  StatusCode executeRun( int evtmax ) override;
80  StatusCode stopRun() override;
81 
82  // implementation of IStateful::state
83  Gaudi::StateMachine::State FSMState() const override;
84  // implementation of IStateful::targetState
86  // implementation of IStateful::reinitialize
87  StatusCode reinitialize() override;
88  // implementation of IStateful::reinitialize
89  StatusCode restart() override;
90  // implementation of IService::sysItinitilaize
92  // implementation of IService::sysStart
93  StatusCode sysStart() override { return StatusCode::SUCCESS; }
94  // implementation of IService::sysStop
95  StatusCode sysStop() override { return StatusCode::SUCCESS; }
96  // implementation of IService::sysFinalize
98  // implementation of IService::sysReinitialize
100  // implementation of IService::sysRestart
102 
104  void push( EventContext&& ctx ) override;
105  bool empty() const override;
106  std::optional<Gaudi::Interfaces::IQueueingEventProcessor::ResultType> pop() override;
108 
110 
120 
121  template <class I>
123  return m_managers[I::interfaceID().id()];
124  }
125 
127  // Cache the casted pointer to ISvcManager
128  if ( !m_svcManager ) { m_svcManager = getManager<IService>(); }
129  return m_svcManager;
130  }
131 
133  // Cache the casted pointer to IAlgManager
134  if ( !m_algManager ) { m_algManager = getManager<IAlgorithm>(); }
135  return m_algManager;
136  }
137 
139  SmartIF<ISvcLocator>& serviceLocator() const override { return m_svcLocator; }
140 
142  void outputLevelUpdate() override;
143 
145  void printAlgsSequences();
146 
147 protected:
148  // implementation of IService::setServiceManager
149  void setServiceManager( ISvcManager* ) override {}
150 
153 
158  StatusCode GoToState( Gaudi::StateMachine::State state, bool ignoreFailures = false );
159 
169 
172 
175 
176  // data members
180 
182  [this]( auto& ) {
183  // Re-initialize everything
184  this->reinitialize().ignore();
185  // Execute a number of events
186  this->executeRun( m_evtMax ).ignore();
187  },
188  "For SI's \"Go\" command via callback"};
190  [this]( auto& ) {
191  finalize().ignore();
192  terminate().ignore();
193  ::exit( 0 );
194  },
195  "For SI's \"Exit\" command via callback"};
197  this, "TopAlg", {}, &ApplicationMgr::evtLoopPropertyHandler, "List of top level algorithms names"};
199  this, "OutStream", {}, &ApplicationMgr::evtLoopPropertyHandler, "List of output stream names"};
200  Gaudi::Property<std::string> m_outStreamType{this, "OutStreamType", "OutputStream",
202  "[[deprecated]] Output stream type"};
203  Gaudi::Property<std::string> m_messageSvcType{this, "MessageSvcType", "MessageSvc", "MessageSvc type"};
204  Gaudi::Property<std::string> m_jobOptionsSvcType{this, "JobOptionsSvcType", "JobOptionsSvc", "JobOptionsSvc type"};
205 
206  std::string m_name = "ApplicationMgr";
209 
210  Gaudi::Property<std::vector<std::string>> m_svcMapping{this, "SvcMapping", {}, "Default mapping of services"};
212  this, "SvcOptMapping", {}, "Default mapping of optional services"};
213 
218 
220  //
221  // The public ApplicationMgr properties
222  //
223 
224  Gaudi::Property<int> m_evtMax{this, "EvtMax", -1, "Number of events to be processed (-1 means all events)"};
225  Gaudi::Property<std::vector<std::string>> m_extSvcNameList{this, "ExtSvc", {}, "List of external services names"};
226  Gaudi::Property<bool> m_extSvcCreates{this, "ExtSvcCreates", true,
227  "LHCb (default) or ATLAS definition of \"ExtSvc\""};
228 
229  Gaudi::Property<std::vector<std::string>> m_dllNameList{this, "Dlls", {}, "List of DDL's names"};
230  Gaudi::Property<std::string> m_jobOptionsType{this, "JobOptionsType", "FILE", "Source type (e.g. dbase, file...)"};
231  Gaudi::Property<std::string> m_jobOptionsPath{this, "JobOptionsPath", {}, "The \"file\" to look for properties"};
233  this, "JobOptionsPostAction", {}, "additional command to run on config"};
235  this, "JobOptionsPreAction", {}, "additional command to run on config"};
236  Gaudi::Property<std::string> m_runableType{this, "Runable", "AppMgrRunable", "Runable type"};
237  Gaudi::Property<std::string> m_eventLoopMgr{this, "EventLoop", "EventLoopMgr", "Processing manager type"};
238  Gaudi::Property<std::string> m_evtsel{this, "EvtSel", {}, "Event selection"};
239  Gaudi::Property<std::string> m_histPersName{this, "HistogramPersistency", "NONE", "Name of the Hist Pers Svc"};
240  Gaudi::Property<int> m_outputLevel{this, "OutputLevel", MSG::INFO, "Message output level"};
241  Gaudi::Property<std::string> m_appName{this, "AppName", "ApplicationMgr", "The name of the application"};
242  Gaudi::Property<std::string> m_appVersion{this, "AppVersion", {}, "The version of the application"};
243  Gaudi::Property<bool> m_actHistory{this, "ActivateHistory", false, "Activate HistorySvc"};
244  Gaudi::Property<bool> m_codeCheck{this, "StatusCodeCheck", false, "Activate StatusCode checking"};
246  this, "PluginDebugLevel", 0,
247  [this]( auto& ) {
248  // Setup debug level for the plugin system
249  MsgStream log( m_messageSvc, this->name() );
250  log << MSG::INFO << "Updating Gaudi::PluginService::SetDebug(level) to level=" << m_pluginDebugLevel << endmsg;
252  },
253  "Debug level for the plugin system"};
254 
256  this, "CreateSvc", {}, "List of extra services to be created"};
257 
259  Gaudi::Property<bool> m_auditTools{this, "AuditTools", false};
260  Gaudi::Property<bool> m_auditSvcs{this, "AuditServices", false};
261  Gaudi::Property<bool> m_auditAlgs{this, "AuditAlgorithms", false};
262 
264  this, "Environment", {}, "Environment variables to set"};
265 
266  Gaudi::Property<bool> m_loopCheck{this, "InitializationLoopCheck", true,
267  [this]( auto& ) { this->svcManager()->setLoopCheckEnabled( m_loopCheck ); },
268  "For ServiceMgr initialization loop checking"};
269 
273  this, "StopOnSignal", false, "Flag to enable/disable the signal handler that schedule a stop of the event loop"};
274 
278  this, "StalledEventMonitoring", false, "Flag to enable/disable the monitoring and reporting of stalled events"};
279 
280  Gaudi::Property<bool> m_propertiesPrint{this, "PropertiesPrint", false,
281  "Flag to activate the printout of properties"};
282 
285  "Return code of the application. Set internally in case of error conditions."};
286 
287  Gaudi::Property<bool> m_printAlgsSequence{this, "PrintAlgsSequence", false,
288  "Print the sequence of algorithms that have been loaded."};
289 
290  // For concurrency
292 
293 private:
295 
297  template <typename SELF, typename PIMPL, typename METHOD, typename... ARGS>
298  static auto i_delegateToEvtProc( SELF* self, PIMPL& member, std::string_view method_name, METHOD&& method,
299  ARGS&&... args ) {
300  if ( LIKELY( self->m_state == Gaudi::StateMachine::RUNNING ) ) {
301  if ( LIKELY( bool( member ) ) ) {
302  return std::invoke( method, *member.get(), std::forward<ARGS>( args )... );
303  } else {
305  s << method_name << ": event processor is not a \""
306  << System::typeinfoName( typeid( decltype( *member.get() ) ) ) << '"';
307  throw GaudiException{s.str(), self->name(), StatusCode::FAILURE};
308  }
309  }
311  s << method_name << ": Invalid state \"" << self->FSMState() << '"';
312  throw GaudiException{s.str(), self->name(), StatusCode::FAILURE};
313  }
314 };
315 #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:24
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:25
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:352
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:298
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition: ISvcManager.h:28
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:85
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:12
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:24
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:29
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:50
Definition of the basic interface.
Definition: IInterface.h:244
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:37
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:32
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:95
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:153
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:18
Helper class to implement the IProperty interface.
string s
Definition: gaudirun.py:318
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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:260
constexpr int Success
Definition: AppReturnCode.h:16
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:192
Gaudi::Property< int > m_pluginDebugLevel
Gaudi::Property< std::string > m_jobOptionsPath
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
bool m_useHiveAlgorithmManager
Gaudi::StateMachine::State targetFSMState() const override
Gaudi::Property< bool > m_loopCheck