The Gaudi Framework  master (181af51f)
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 void const* i_cast( const InterfaceID& iid ) const override;
60 // implementation of IInterface::queryInterface
61 StatusCode queryInterface( const InterfaceID& iid, void** pinterface ) override;
62
63 // implementation of IAppMgrUI::run
64 StatusCode run() override;
65 // implementation of IAppMgrUI::configure
66 StatusCode configure() override;
67 // implementation of IAppMgrUI::terminate
68 StatusCode terminate() override;
69 // implementation of IAppMgrUI::initialize
70 StatusCode initialize() override;
71 // implementation of IAppMgrUI::start
72 StatusCode start() override;
73 // implementation of IAppMgrUI::stop
74 StatusCode stop() override;
75 // implementation of IAppMgrUI::finalize
76 StatusCode finalize() override;
77 // implementation of IAppMgrUI::nextEvent
78 StatusCode nextEvent( int maxevt ) override;
79 // implementation of IAppMgrUI::name
80 const std::string& name() const override;
84 StatusCode executeEvent( EventContext&& ctx ) override;
86 StatusCode executeRun( int evtmax ) override;
88 StatusCode stopRun() override;
89
90 // implementation of IStateful::state
91 Gaudi::StateMachine::State FSMState() const override;
92 // implementation of IStateful::targetState
94 // implementation of IStateful::reinitialize
95 StatusCode reinitialize() override;
96 // implementation of IStateful::reinitialize
97 StatusCode restart() override;
98 // implementation of IService::sysItinitilaize
100 // implementation of IService::sysStart
102 // implementation of IService::sysStop
104 // implementation of IService::sysFinalize
106 // implementation of IService::sysReinitialize
108 // implementation of IService::sysRestart
110
112 void push( EventContext&& ctx ) override;
113 bool empty() const override;
114 std::optional<Gaudi::Interfaces::IQueueingEventProcessor::ResultType> pop() override;
116
118
128
129 template <class I>
131 return m_managers[I::interfaceID().id()];
132 }
133
135 // Cache the casted pointer to ISvcManager
137 return m_svcManager;
138 }
139
141 // Cache the casted pointer to IAlgManager
143 return m_algManager;
144 }
145
148
150 void outputLevelUpdate() override;
151
153
155 void printAlgsSequences();
156
157protected:
158 // implementation of IService::setServiceManager
159 void setServiceManager( ISvcManager* ) override {}
160
163
168 StatusCode GoToState( Gaudi::StateMachine::State state, bool ignoreFailures = false );
169
172 typedef std::map<unsigned long, SmartIF<IComponentManager>> ManagersMap;
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_messageSvcType{ this, "MessageSvcType", "MessageSvc", "MessageSvc type",
215 "Service:IMessageSvc" };
216 Gaudi::Property<std::string> m_jobOptionsSvcType{ this, "JobOptionsSvcType", "JobOptionsSvc", "JobOptionsSvc type",
217 "Service:Gaudi::Interfaces::IOptionsSvc" };
218
219 std::string m_name = "ApplicationMgr";
222
223 Gaudi::Property<std::vector<std::string>> m_svcMapping{ this, "SvcMapping", {}, "Default mapping of services" };
225 this, "SvcOptMapping", {}, "Default mapping of optional services" };
226
230
232
234
235 //
236 // The public ApplicationMgr properties
237 //
238
239 Gaudi::Property<int> m_evtMax{ this, "EvtMax", -1, "Number of events to be processed (-1 means all events)" };
241 this, "ExtSvc", {}, "List of external services names", "vector<Service>" };
242 Gaudi::Property<bool> m_extSvcCreates{ this, "ExtSvcCreates", true,
243 "LHCb (default) or ATLAS definition of \"ExtSvc\"" };
244
245 Gaudi::Property<std::vector<std::string>> m_dllNameList{ this, "Dlls", {}, "List of DDL's names" };
246 Gaudi::Property<std::string> m_jobOptionsType{ this, "JobOptionsType", "FILE", "Source type (e.g. dbase, file...)" };
247 Gaudi::Property<std::string> m_jobOptionsPath{ this, "JobOptionsPath", {}, "The \"file\" to look for properties" };
249 this, "JobOptionsPostAction", {}, "additional command to run on config" };
251 this, "JobOptionsPreAction", {}, "additional command to run on config" };
252 Gaudi::Property<std::string> m_runableType{ this, "Runable", "AppMgrRunable", "Runable type", "Service:IRunable" };
253 Gaudi::Property<std::string> m_eventLoopMgr{ this, "EventLoop", "EventLoopMgr", "Processing manager type",
254 "Service:IEventProcessor" };
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<int> m_pluginDebugLevel{ this, "PluginDebugLevel", 0,
262 [this]( auto& ) {
263 // Setup debug level for the plugin system
264 if ( m_pluginDebugLevel.value() ) {
265 MsgStream log( m_messageSvc, this->name() );
266 log << MSG::INFO
267 << "Updating Gaudi::PluginService::SetDebug(level) to level="
268 << m_pluginDebugLevel.value() << endmsg;
269 }
270 Gaudi::PluginService::SetDebug( m_pluginDebugLevel );
271 },
272 "Debug level for the plugin system" };
273
275 this, "CreateSvc", {}, "List of extra services to be created" };
276
278 Gaudi::Property<bool> m_auditTools{ this, "AuditTools", false };
279 Gaudi::Property<bool> m_auditSvcs{ this, "AuditServices", false };
280 Gaudi::Property<bool> m_auditAlgs{ this, "AuditAlgorithms", false };
281
283 this, "Environment", {}, "Environment variables to set" };
284
285 Gaudi::Property<bool> m_loopCheck{ this, "InitializationLoopCheck", true,
286 [this]( auto& ) { this->svcManager()->setLoopCheckEnabled( m_loopCheck ); },
287 "For ServiceMgr initialization loop checking" };
288
292 this, "StopOnSignal", false, "Flag to enable/disable the signal handler that schedule a stop of the event loop" };
293
294 Gaudi::Property<bool> m_propertiesPrint{ this, "PropertiesPrint", false,
295 "Flag to activate the printout of properties" };
296
299 "Return code of the application. Set internally in case of error conditions." };
300
301 Gaudi::Property<bool> m_printAlgsSequence{ this, "PrintAlgsSequence", false,
302 "Print the sequence of algorithms that have been loaded." };
303
304 Gaudi::Property<bool> m_useMessageSvcForROOTMessages{ this, "UseMessageSvcForROOTMessages", true,
305 "Replace ROOT error handler with MessageSvc." };
306
307 // For concurrency
309
310private:
311 std::vector<std::string> m_okDlls;
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 ( self->m_state == Gaudi::StateMachine::RUNNING ) {
318 if ( bool( member ) ) {
319 return std::invoke( method, *member.get(), std::forward<ARGS>( args )... );
320 } else {
321 std::stringstream s;
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 }
327 std::stringstream s;
328 s << method_name << ": Invalid state \"" << self->FSMState() << '"';
329 throw GaudiException{ s.str(), self->name(), StatusCode::FAILURE };
330 }
331};
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
StatusCode queryInterface(const InterfaceID &iid, void **pinterface) 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.