The Gaudi Framework  master (e68eea06)
Loading...
Searching...
No Matches
ApplicationMgr.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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#pragma once
12
14#include <Gaudi/MonitoringHub.h>
25#include <GaudiKernel/Kernel.h>
27#include <GaudiKernel/Service.h>
28#include <vector>
29
30class ISvcLocator;
31class ServiceManager;
33class DLLClassManager;
34class IMessageSvc;
35class IIncidentSvc;
36class IRunable;
37class IDataManagerSvc;
38class IConversionSvc;
39
53 : public PropertyHolder<CommonMessaging<implements<IAppMgrUI, Gaudi::Interfaces::IQueueingEventProcessor, IService,
54 IStateful, INamedInterface, IProperty>>> {
55public:
56 // default creator
57 ApplicationMgr( IInterface* = nullptr );
58
59 // Allow delegation of interfaces implementations
60 void const* i_cast( const InterfaceID& iid ) const override;
61
62 // implementation of IAppMgrUI::run
63 StatusCode run() override;
64 // implementation of IAppMgrUI::configure
65 StatusCode configure() override;
66 // implementation of IAppMgrUI::terminate
67 StatusCode terminate() override;
68 // implementation of IAppMgrUI::initialize
69 StatusCode initialize() override;
70 // implementation of IAppMgrUI::start
71 StatusCode start() override;
72 // implementation of IAppMgrUI::stop
73 StatusCode stop() override;
74 // implementation of IAppMgrUI::finalize
75 StatusCode finalize() override;
76 // implementation of IAppMgrUI::nextEvent
77 StatusCode nextEvent( int maxevt ) override;
78 // implementation of IAppMgrUI::name
79 const std::string& name() const override;
83 StatusCode executeEvent( EventContext&& ctx ) override;
85 StatusCode executeRun( int evtmax ) override;
87 StatusCode stopRun() override;
88
89 // implementation of IStateful::state
90 Gaudi::StateMachine::State FSMState() const override;
91 // implementation of IStateful::targetState
93 // implementation of IStateful::reinitialize
94 StatusCode reinitialize() override;
95 // implementation of IStateful::reinitialize
96 StatusCode restart() override;
97 // implementation of IService::sysItinitilaize
99 // implementation of IService::sysStart
101 // implementation of IService::sysStop
103 // implementation of IService::sysFinalize
105 // implementation of IService::sysReinitialize
107 // implementation of IService::sysRestart
109
111 void push( EventContext&& ctx ) override;
112 bool empty() const override;
113 std::optional<Gaudi::Interfaces::IQueueingEventProcessor::ResultType> pop() override;
115
117
127
128 template <class I>
130 return m_managers[I::interfaceID().id()];
131 }
132
134 // Cache the casted pointer to ISvcManager
136 return m_svcManager;
137 }
138
140 // Cache the casted pointer to IAlgManager
142 return m_algManager;
143 }
144
147
149 void outputLevelUpdate() override;
150
152
154 void printAlgsSequences();
155
156protected:
157 // implementation of IService::setServiceManager
158 void setServiceManager( ISvcManager* ) override {}
159
162
167 StatusCode GoToState( Gaudi::StateMachine::State state, bool ignoreFailures = false );
168
171 typedef std::map<unsigned long, SmartIF<IComponentManager>> ManagersMap;
178
181
184
185 // data members
189
191 [this]( auto& ) {
192 // Re-initialize everything
193 this->reinitialize().ignore();
194 // Execute a number of events
195 this->executeRun( m_evtMax ).ignore();
196 },
197 "For SI's \"Go\" command via callback" };
199 [this]( auto& ) {
200 finalize().ignore();
201 terminate().ignore();
202 ::exit( 0 );
203 },
204 "For SI's \"Exit\" command via callback" };
206 "TopAlg",
207 {},
209 "List of top level algorithms names",
210 "vector<Algorithm>" };
212 this, "OutStream", {}, &ApplicationMgr::evtLoopPropertyHandler, "List of output stream names" };
213 Gaudi::Property<std::string> m_messageSvcType{ this, "MessageSvcType", "MessageSvc", "MessageSvc type",
214 "Service:IMessageSvc" };
215 Gaudi::Property<std::string> m_jobOptionsSvcType{ this, "JobOptionsSvcType", "JobOptionsSvc", "JobOptionsSvc type",
216 "Service:Gaudi::Interfaces::IOptionsSvc" };
217
218 std::string m_name = "ApplicationMgr";
221
222 Gaudi::Property<std::vector<std::string>> m_svcMapping{ this, "SvcMapping", {}, "Default mapping of services" };
224 this, "SvcOptMapping", {}, "Default mapping of optional services" };
225
229
231
233
234 //
235 // The public ApplicationMgr properties
236 //
237
238 Gaudi::Property<int> m_evtMax{ this, "EvtMax", -1, "Number of events to be processed (-1 means all events)" };
240 this, "ExtSvc", {}, "List of external services names", "vector<Service>" };
241 Gaudi::Property<bool> m_extSvcCreates{ this, "ExtSvcCreates", true,
242 "LHCb (default) or ATLAS definition of \"ExtSvc\"" };
243
244 Gaudi::Property<std::vector<std::string>> m_dllNameList{ this, "Dlls", {}, "List of DDL's names" };
245 Gaudi::Property<std::string> m_jobOptionsType{ this, "JobOptionsType", "FILE", "Source type (e.g. dbase, file...)" };
246 Gaudi::Property<std::string> m_jobOptionsPath{ this, "JobOptionsPath", {}, "The \"file\" to look for properties" };
248 this, "JobOptionsPostAction", {}, "additional command to run on config" };
250 this, "JobOptionsPreAction", {}, "additional command to run on config" };
251 Gaudi::Property<std::string> m_runableType{ this, "Runable", "AppMgrRunable", "Runable type", "Service:IRunable" };
252 Gaudi::Property<std::string> m_eventLoopMgr{ this, "EventLoop", "EventLoopMgr", "Processing manager type",
253 "Service:IEventProcessor" };
254 Gaudi::Property<std::string> m_evtsel{ this, "EvtSel", {}, "Event selection" };
255 Gaudi::Property<std::string> m_histPersName{ this, "HistogramPersistency", "NONE", "Name of the Hist Pers Svc" };
256 Gaudi::Property<int> m_outputLevel{ this, "OutputLevel", MSG::INFO, "Message output level" };
257 Gaudi::Property<std::string> m_appName{ this, "AppName", "ApplicationMgr", "The name of the application" };
258 Gaudi::Property<std::string> m_appVersion{ this, "AppVersion", {}, "The version of the application" };
259 Gaudi::Property<bool> m_actHistory{ this, "ActivateHistory", false, "Activate HistorySvc" };
260 Gaudi::Property<int> m_pluginDebugLevel{ this, "PluginDebugLevel", 0,
261 [this]( auto& ) {
262 // Setup debug level for the plugin system
263 if ( m_pluginDebugLevel.value() ) {
264 MsgStream log( m_messageSvc, this->name() );
265 log << MSG::INFO
266 << "Updating Gaudi::PluginService::SetDebug(level) to level="
267 << m_pluginDebugLevel.value() << endmsg;
268 }
269 Gaudi::PluginService::SetDebug( m_pluginDebugLevel );
270 },
271 "Debug level for the plugin system" };
272
274 this, "CreateSvc", {}, "List of extra services to be created" };
275
277 Gaudi::Property<bool> m_auditTools{ this, "AuditTools", false };
278 Gaudi::Property<bool> m_auditSvcs{ this, "AuditServices", false };
279 Gaudi::Property<bool> m_auditAlgs{ this, "AuditAlgorithms", false };
280
282 this, "Environment", {}, "Environment variables to set" };
283
284 Gaudi::Property<bool> m_loopCheck{ this, "InitializationLoopCheck", true,
285 [this]( auto& ) { this->svcManager()->setLoopCheckEnabled( m_loopCheck ); },
286 "For ServiceMgr initialization loop checking" };
287
291 this, "StopOnSignal", false, "Flag to enable/disable the signal handler that schedule a stop of the event loop" };
292
293 Gaudi::Property<bool> m_propertiesPrint{ this, "PropertiesPrint", false,
294 "Flag to activate the printout of properties" };
295
298 "Return code of the application. Set internally in case of error conditions." };
299
300 Gaudi::Property<bool> m_printAlgsSequence{ this, "PrintAlgsSequence", false,
301 "Print the sequence of algorithms that have been loaded." };
302
303 Gaudi::Property<bool> m_useMessageSvcForROOTMessages{ this, "UseMessageSvcForROOTMessages", true,
304 "Replace ROOT error handler with MessageSvc." };
305
306 // For concurrency
308
309private:
310 std::vector<std::string> m_okDlls;
311
313 template <typename SELF, typename PIMPL, typename METHOD, typename... ARGS>
314 static auto i_delegateToEvtProc( SELF* self, PIMPL& member, std::string_view method_name, METHOD&& method,
315 ARGS&&... args ) {
316 if ( self->m_state == Gaudi::StateMachine::RUNNING ) {
317 if ( bool( member ) ) {
318 return std::invoke( method, *member.get(), std::forward<ARGS>( args )... );
319 } else {
320 std::stringstream s;
321 s << method_name << ": event processor is not a \""
322 << System::typeinfoName( typeid( decltype( *member.get() ) ) ) << '"';
323 throw GaudiException{ s.str(), self->name(), StatusCode::FAILURE };
324 }
325 }
326 std::stringstream s;
327 s << method_name << ": Invalid state \"" << self->FSMState() << '"';
328 throw GaudiException{ s.str(), self->name(), StatusCode::FAILURE };
329 }
330};
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms.
SmartIF< ISvcManager > m_svcManager
Cached pointer to the manager of services.
Gaudi::Property< std::string > m_jobOptionsType
std::string m_name
Name.
SmartIF< IRunable > m_runable
Reference to the runable object.
Gaudi::Property< bool > m_printAlgsSequence
SmartIF< IQueueingEventProcessor > m_queueingProcessor
Reference to a queueing processing manager object.
Gaudi::Property< int > m_returnCode
Property to record the error conditions occurring during the running.
SmartIF< IComponentManager > & getManager()
Gaudi::Property< std::vector< std::string > > m_svcMapping
Gaudi::Property< bool > m_useMessageSvcForROOTMessages
std::optional< Gaudi::Interfaces::IQueueingEventProcessor::ResultType > pop() override
Gaudi::Property< std::vector< std::string > > m_dllNameList
Gaudi::StateMachine::State m_targetState
Internal State.
Gaudi::Property< std::string > m_runableType
Gaudi::Property< bool > m_actHistory
void createSvcNameListHandler(Gaudi::Details::PropertyBase &)
std::vector< std::string > m_okDlls
names of successfully loaded dlls
StatusCode GoToState(Gaudi::StateMachine::State state, bool ignoreFailures=false)
Reach a state from current state (whichever it is) going through the correct transitions.
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< bool > m_propertiesPrint
SmartIF< ISvcLocator > m_svcLocator
Reference to its own service locator (must be instantiated prior to any service!)
StatusCode run() override
ApplicationMgr(IInterface *=nullptr)
StatusCode finalize() override
Gaudi::Property< std::vector< std::string > > m_outStreamNameList
Gaudi::Property< std::vector< std::string > > m_extSvcNameList
StatusCode nextEvent(int maxevt) override
Gaudi::Property< std::string > m_jobOptionsPath
Gaudi::Property< std::vector< std::string > > m_declaredManagers
Property to declare the list of known managers.
SmartIF< DLLClassManager > m_classManager
Reference to the class manager.
StatusCode terminate() override
StatusCode initialize() override
StatusCode stopRun() override
implementation of IEventProcessor::stopRun()
Gaudi::Property< int > m_SIExit
SmartIF< ISvcLocator > & serviceLocator() const override
Needed to locate the message service.
StatusCode sysStop() override
SmartIF< IMessageSvc > m_messageSvc
Reference to the message service.
Gaudi::Property< std::vector< std::string > > m_svcOptMapping
bool m_useHiveAlgorithmManager
SmartIF< IAlgManager > & algManager()
StatusCode executeEvent(EventContext &&ctx) override
implementation of IEventProcessor::executeEvent(void*)
void const * i_cast(const InterfaceID &iid) const override
void evtLoopPropertyHandler(Gaudi::Details::PropertyBase &theProp)
Gaudi::Property< bool > m_auditTools
Defaults for auditors.
Gaudi::Monitoring::Hub m_monitoringHub
SmartIF< IAlgManager > m_algManager
Cached pointer to the manager of algorithms.
Gaudi::Property< std::string > m_evtsel
Gaudi::Property< std::string > m_eventLoopMgr
const std::string & name() const override
Gaudi::Property< int > m_evtMax
StatusCode sysRestart() override
Gaudi::Property< std::string > m_appVersion
StatusCode sysReinitialize() override
StatusCode decodeDllNameList()
Gaudi::Property< std::vector< std::string > > m_topAlgNameList
Gaudi::Property< bool > m_extSvcCreates
Gaudi::Property< std::vector< std::string > > m_createSvcNameList
Gaudi::Property< bool > m_auditSvcs
Gaudi::Property< std::map< std::string, std::string > > m_environment
EventContext createEventContext() override
implementation of IEventProcessor::createEventContext()
Gaudi::Property< std::string > m_jobOptionsPreAction
StatusCode reinitialize() override
Gaudi::Property< bool > m_loopCheck
Gaudi::Property< std::string > m_appName
void extSvcNameListHandler(Gaudi::Details::PropertyBase &theProp)
Gaudi::StateMachine::State targetFSMState() const override
Gaudi::Property< int > m_pluginDebugLevel
StatusCode restart() override
StatusCode stop() override
void printAlgsSequences()
Print the sequence of algorithms that have been loaded.
StatusCode executeRun(int evtmax) override
implementation of IEventProcessor::executeRun(int)
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.
Gaudi::Property< bool > m_stopOnSignal
Property to enable/disable the "stop on signal" service.
Gaudi::StateMachine::State FSMState() const override
StatusCode i_startup()
Internal startup routine.
StatusCode sysFinalize() override
Gaudi::StateMachine::State m_state
Internal State.
Gaudi::Property< std::string > m_histPersName
StatusCode start() override
void outputLevelUpdate() override
Function to call to update the outputLevel of the components (after a change in MessageSvc).
StatusCode decodeExtSvcNameList()
Gaudi::Property< std::string > m_jobOptionsSvcType
Gaudi::Monitoring::Hub & monitoringHub() override
void push(EventContext &&ctx) override
void setServiceManager(ISvcManager *) override
StatusCode decodeCreateSvcNameList()
void dllNameListHandler(Gaudi::Details::PropertyBase &theProp)
Gaudi::Property< bool > m_auditAlgs
Gaudi::Property< int > m_outputLevel
ManagersMap m_managers
Map of known component managers.
bool empty() const override
StatusCode configure() override
StatusCode sysStart() override
StatusCode sysInitialize() override
Gaudi::Property< int > m_SIGo
void pluginDebugPropertyHandler(Gaudi::Details::PropertyBase &theProp)
SmartIF< ISvcManager > & svcManager()
SmartIF< IEventProcessor > m_processingMgr
Reference to processing manager object.
Gaudi::Property< std::string > m_jobOptionsPostAction
Gaudi::Property< std::string > m_messageSvcType
This class represents an entry point to all the event specific data.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
Define general base for Gaudi exception.
The interface implemented by the IncidentSvc service.
Definition of the basic interface.
Definition IInterface.h:225
The IMessage is the interface implemented by the message service.
Definition IMessageSvc.h:34
Runable interface definition.
Definition IRunable.h:27
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
The ISvcManager is the interface implemented by the Service Factory in the Application Manager to sup...
Definition ISvcManager.h:30
virtual void setLoopCheckEnabled(bool en=true)=0
Set the value of the initialization loop check flag.
Interface ID class.
Definition IInterface.h:38
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
The ServiceManager class is in charge of the creation of concrete instances of Services.
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
constexpr int Success
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
@ INFO
Definition IMessageSvc.h:22
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition System.cpp:260
Central entity in a Gaudi application that manages monitoring objects (i.e.