7 #include "GaudiKernel/TypeNameString.h"
8 #include "GaudiKernel/IService.h"
9 #include "GaudiKernel/IRunable.h"
10 #include "GaudiKernel/IMessageSvc.h"
11 #include "GaudiKernel/IJobOptionsSvc.h"
13 #include "GaudiKernel/SmartIF.h"
14 #include "GaudiKernel/MsgStream.h"
15 #include "GaudiKernel/PropertyMgr.h"
16 #include "GaudiKernel/ObjectFactory.h"
18 #include "GaudiKernel/GaudiException.h"
19 #include "GaudiKernel/ThreadGaudi.h"
21 #include "GaudiKernel/StatusCode.h"
22 #include "GaudiKernel/Time.h"
23 #include "GaudiKernel/System.h"
25 #include "GaudiKernel/AppReturnCode.h"
27 #include "GaudiCoreSvcVersion.h"
38 static const char* s_eventloop =
"EventLoop";
39 static const char* s_runable =
"Runable";
41 #define ON_DEBUG if (UNLIKELY(m_outputLevel <= MSG::DEBUG))
42 #define ON_VERBOSE if (UNLIKELY(m_outputLevel <= MSG::VERBOSE))
61 m_managers[IService::interfaceID().id()] =
new ServiceManager(
this);
63 m_managers[IAlgorithm::interfaceID().id()] = algMgr;
65 m_svcLocator = svcManager();
72 m_propertyMgr->declareProperty(
"Go", m_SIGo = 0 );
73 m_propertyMgr->declareProperty(
"Exit", m_SIExit = 0 );
74 m_propertyMgr->declareProperty(
"Dlls", m_dllNameList );
75 m_propertyMgr->declareProperty(
"ExtSvc", m_extSvcNameList );
76 m_propertyMgr->declareProperty(
"CreateSvc", m_createSvcNameList );
77 m_propertyMgr->declareProperty(
"ExtSvcCreates", m_extSvcCreates=
true );
79 m_propertyMgr->declareProperty(
"SvcMapping", m_svcMapping );
80 m_propertyMgr->declareProperty(
"SvcOptMapping", m_svcOptMapping );
82 m_propertyMgr->declareProperty(
"TopAlg", m_topAlgNameList );
83 m_propertyMgr->declareProperty(
"OutStream", m_outStreamNameList );
84 m_propertyMgr->declareProperty(
"OutStreamType", m_outStreamType =
"OutputStream" );
85 m_propertyMgr->declareProperty(
"MessageSvcType",m_messageSvcType=
"MessageSvc" );
86 m_propertyMgr->declareProperty(
"JobOptionsSvcType",
87 m_jobOptionsSvcType =
"JobOptionsSvc" );
88 m_propertyMgr->declareProperty( s_runable, m_runableType =
"AppMgrRunable");
89 m_propertyMgr->declareProperty( s_eventloop, m_eventLoopMgr =
"EventLoopMgr");
91 m_propertyMgr->declareProperty(
"HistogramPersistency", m_histPersName=
"NONE");
94 m_propertyMgr->declareProperty(
"JobOptionsType", m_jobOptionsType =
"FILE");
95 m_propertyMgr->declareProperty(
"JobOptionsPath", m_jobOptionsPath =
"");
96 m_propertyMgr->declareProperty(
"EvtMax", m_evtMax = -1);
97 m_propertyMgr->declareProperty(
"EvtSel", m_evtsel );
98 m_propertyMgr->declareProperty(
"OutputLevel", m_outputLevel =
MSG::INFO);
100 m_propertyMgr->declareProperty(
"MultiThreadExtSvc", m_multiThreadSvcNameList);
101 m_propertyMgr->declareProperty(
"NoOfThreads", m_noOfEvtThreads = 0);
102 m_propertyMgr->declareProperty(
"AppName", m_appName =
"ApplicationMgr");
103 m_propertyMgr->declareProperty(
"AppVersion", m_appVersion =
"");
105 m_propertyMgr->declareProperty(
"AuditTools", m_auditTools =
false);
106 m_propertyMgr->declareProperty(
"AuditServices", m_auditSvcs =
false);
107 m_propertyMgr->declareProperty(
"AuditAlgorithms", m_auditAlgs =
false);
109 m_propertyMgr->declareProperty(
"ActivateHistory", m_actHistory =
false);
110 m_propertyMgr->declareProperty(
"StatusCodeCheck", m_codeCheck =
false);
112 m_propertyMgr->declareProperty(
"Environment", m_environment);
115 m_propertyMgr->declareProperty(
"InitializationLoopCheck", m_loopCheck =
true)
117 svcManager()->setLoopCheckEnabled(m_loopCheck);
120 m_propertyMgr->declareProperty
122 m_propertiesPrint =
false,
123 "Flag to activate the printout of properties" );
125 m_propertyMgr->declareProperty(
"PluginDebugLevel", m_pluginDebugLevel = 0 );
127 m_propertyMgr->declareProperty(
"StopOnSignal", m_stopOnSignal =
false,
128 "Flag to enable/disable the signal handler that schedule a stop of the event loop");
130 m_propertyMgr->declareProperty(
"StalledEventMonitoring", m_stalledEventMonitoring =
false,
131 "Flag to enable/disable the monitoring and reporting of stalled events");
134 "Return code of the application. Set internally in case of error conditions.");
136 m_propertyMgr->declareProperty(
"AlgTypeAliases", algMgr->
typeAliases(),
137 "Aliases of algorithm types, to replace an algorithm type for every instance");
147 m_svcMapping.insert(
std::end(m_svcMapping),
148 {
"EvtDataSvc/EventDataSvc",
149 "DetDataSvc/DetectorDataSvc",
150 "HistogramSvc/HistogramDataSvc",
151 "HbookCnv::PersSvc/HbookHistSvc",
152 "RootHistCnv::PersSvc/RootHistSvc",
153 "EvtPersistencySvc/EventPersistencySvc",
154 "DetPersistencySvc/DetectorPersistencySvc",
155 "HistogramPersistencySvc/HistogramPersistencySvc" } );
174 {
return serviceLocator()-> queryInterface ( iid , ppvi ) ; }
176 {
return svcManager() -> queryInterface ( iid , ppvi ) ; }
178 {
return algManager() -> queryInterface ( iid , ppvi ) ; }
180 {
return m_classManager -> queryInterface ( iid , ppvi ) ; }
182 {
return m_propertyMgr -> queryInterface ( iid , ppvi ) ; }
185 *ppvi =
reinterpret_cast<void*
>(m_messageSvc.get());
186 if (m_messageSvc) m_messageSvc->addRef();
213 fatal() <<
"Error creating JobOptionsSvc" <<
endmsg;
217 auto jobOptsIProp = jobsvc.as<
IProperty>();
218 if ( !jobOptsIProp ) {
219 fatal() <<
"Error locating JobOptionsSvc" <<
endmsg;
224 fatal() <<
"Error setting TYPE option in JobOptionsSvc" <<
endmsg;
231 fatal() <<
"Error setting PATH option in JobOptionsSvc" <<
endmsg;
235 else if (
isEnvSet(
"JOBOPTPATH") ) {
240 <<
"Error setting PATH option in JobOptionsSvc from env"
247 "../options/job.opts"));
250 <<
"Error setting PATH option in JobOptionsSvc to default"
255 jobOptsIProp.reset();
259 auto msgSvcIProp = msgsvc.as<
IProperty>();
263 sc = jobsvc->sysInitialize();
265 fatal() <<
"Error initializing JobOptionsSvc" <<
endmsg;
268 sc = msgsvc->sysInitialize();
270 fatal() <<
"Error initializing MessageSvc" <<
endmsg;
277 fatal() <<
"Error retrieving MessageSvc." <<
endmsg;
282 fatal() <<
"Error retrieving JobOptionsSvc." <<
endmsg;
301 <<
"configure: Invalid state \"" <<
m_state <<
"\"" <<
endmsg;
322 log <<
MSG::WARNING <<
"Problems getting my properties from JobOptionsSvc"
334 <<
"=================================================================="
335 <<
"=================================================================="
346 <<
"v" << GAUDICORESVC_MAJOR_VERSION
347 <<
"r" << GAUDICORESVC_MINOR_VERSION
348 #if GAUDICORESVC_PATCH_VERSION
349 <<
"p" << GAUDICORESVC_PATCH_VERSION
360 <<
"=================================================================="
361 <<
"=================================================================="
370 <<
"List of ALL properties of "
374 { log <<
"Property ['Name': Value] = " << *
property <<
endmsg ; }
382 log <<
MSG::FATAL <<
"Error adding StatusCodeSvc for multiple threads" <<
endmsg;
391 const std::string &
name = var.first;
392 const std::string &
value = var.second;
394 const MSG::Level lvl = (!old.empty() && (old !=
"UNKNOWN" ))
398 log << lvl <<
"Setting " << name <<
" = " << value <<
endmsg;
406 log <<
MSG::ERROR <<
"configure: declaring svc type:'" << j <<
"' failed." <<
endmsg;
413 log <<
MSG::ERROR <<
"configure: declaring svc type:'" << j <<
"' failed." <<
endmsg;
430 log <<
MSG::ERROR <<
"Failure during external service association" <<
endmsg;
436 log <<
MSG::ERROR <<
"Failure during multi thread service creation"
452 sc =
addMultiSvc(evtloop_item, ServiceManager::DEFAULT_SVC_PRIORITY*10);
463 <<
"\n Check option ApplicationMgr." << s_runable <<
endmsg;
470 <<
"\n Check option ApplicationMgr." << s_eventloop
471 <<
"\n No events will be processed." <<
endmsg;
495 sc =
addMultiSvc(
"HistorySvc",std::numeric_limits<int>::max());
497 log <<
MSG::FATAL <<
"Error adding HistorySvc for multiple threads"
504 log <<
MSG::INFO <<
"Application Manager Configured successfully" <<
endmsg;
521 std::string svcname(
"Gaudi::Utils::StopSignalHandler");
524 log <<
MSG::INFO <<
"Cannot instantiate " << svcname <<
"signals will be ignored" <<
endmsg;
530 std::string svcname(
"StalledEventMonitor");
533 log <<
MSG::INFO <<
"Cannot instantiate " << svcname <<
"signals will be ignored" <<
endmsg;
543 <<
"initialize: Invalid state \"" <<
m_state <<
"\"" <<
endmsg;
557 log <<
MSG::INFO <<
"Application Manager Initialized successfully" <<
endmsg;
591 log <<
MSG::INFO <<
"Application Manager Started successfully" <<
endmsg;
609 log <<
MSG::FATAL <<
"No event processing manager specified. Check option:"
648 log <<
MSG::INFO <<
"Application Manager Stopped successfully" <<
endmsg;
695 log <<
MSG::INFO <<
"Application Manager Finalized successfully" <<
endmsg;
723 log <<
MSG::INFO <<
"Application Manager Terminated successfully" <<
endmsg;
725 log <<
MSG::INFO <<
"Application Manager Terminated successfully with a user requested ScheduledStop" <<
endmsg;
746 log <<
MSG::ERROR <<
"Could not get the IService interface of the MessageSvc" <<
endmsg;
748 svc->sysFinalize().ignore();
754 log <<
MSG::ERROR <<
"Could not get the IService interface of the JobOptionsSvc" <<
endmsg;
756 svc->sysFinalize().ignore();
842 log <<
MSG::FATAL <<
"Application execution failed. Ending the job."
846 log <<
MSG::FATAL <<
"Application has no runable object. Check option:"
930 throw GaudiException(
"Cannot reinitialize application if not INITIALIZED or RUNNING",
1002 "MinimalEventLoopMgr::createSvcNameListHandler",
1012 auto it = theNames.begin();
1013 auto et = theNames.end();
1016 if( (result =
svcManager()->addService(item, ServiceManager::DEFAULT_SVC_PRIORITY) ).isFailure()) {
1018 log <<
MSG::ERROR <<
"decodeCreateSvcNameList: Cannot create service "
1023 log <<
MSG::DEBUG <<
"decodeCreateSvcNameList: Created service "
1037 "MinimalEventLoopMgr::extSvcNameListHandler",
1050 auto it = theNames.begin();
1051 auto et = theNames.end();
1055 if ( (result =
svcManager()->addService(item, ServiceManager::DEFAULT_SVC_PRIORITY)).isFailure()) {
1057 log <<
MSG::ERROR <<
"decodeExtSvcNameList: Cannot create service "
1062 item.
type()) ).isFailure()) {
1064 log <<
MSG::ERROR <<
"decodeExtSvcNameList: Cannot declare service "
1078 "MinimalEventLoopMgr::multiThreadSvcNameListHandler",
1091 for (
const auto& it : theNames ) {
1093 result =
addMultiSvc(item, ServiceManager::DEFAULT_SVC_PRIORITY);
1098 <<
"decodeMultiThreadSvcNameList: Cannot create service "
1104 <<
"decodeMultiThreadSvcNameList: created service "
1116 const std::string&
type) {
1122 log <<
MSG::ERROR <<
"declareMultiSvcType: Cannot declare service "
1123 << type <<
"/" << name <<
endmsg;
1126 log <<
MSG::VERBOSE <<
"declareMultiSvcType: declared service "
1127 << type <<
"/" << name <<
endmsg;
1134 log <<
MSG::ERROR <<
"declareMultiSvcType: Cannot declare service "
1135 << type <<
"/" << thrName <<
endmsg;
1138 log <<
MSG::VERBOSE <<
"declareMultiSvcType: declared service "
1139 << type <<
"/" << thrName <<
endmsg;
1157 log <<
MSG::ERROR <<
"addMultiSvc: Cannot add service "
1166 const std::string &
type = typeName.
type();
1169 if( result.isFailure() ) {
1170 log <<
MSG::ERROR <<
"addMultiSvc: Cannot add service "
1171 << type <<
"/" << thrName <<
endmsg;
1175 << type <<
"/" << thrName <<
endmsg;
1188 "MinimalEventLoopMgr::dllNameListHandler",
1203 std::vector<std::string> newList;
1204 std::map<std::string,unsigned int> dllInList, duplicateList;
1206 if ( 0 == dllInList[it] ) {
1207 newList.push_back(it);
1208 }
else { ++duplicateList[it]; }
1214 ON_DEBUG if ( !duplicateList.empty() ) {
1215 log <<
MSG::DEBUG <<
"Removed duplicate entries for modules : ";
1216 for (
auto it = duplicateList.begin(); it != duplicateList.end(); ++it ) {
1217 log << it->first <<
"(" << 1+it->second <<
")";
1218 if ( it != --duplicateList.end() ) log <<
", ";
1224 const std::vector<std::string>& theNames = newList;
1229 std::vector<std::string> successNames, failNames;
1230 for (
const auto& it : theNames) {
1235 failNames.push_back(it);
1239 successNames.push_back(it);
1245 if ( !successNames.empty() ) {
1246 log <<
MSG::INFO <<
"Successfully loaded modules : ";
1247 for (
auto it = successNames.begin(); it != successNames.end(); it++) {
1249 if( (it+1) != successNames.end()) log <<
", ";
1258 for (
auto it = failNames.begin(); it != failNames.end(); it++) {
1260 if( (it+1) != failNames.end()) log <<
", ";
1275 <<
"Updating Gaudi::PluginService::SetDebug(level) to level="
The ServiceManager class is in charge of the creation of concrete instances of Services.
void dllNameListHandler(Property &theProp)
Gaudi::StateMachine::State m_targetState
Internal State.
The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms.
StatusCode initialize() override
std::string m_jobOptionsType
Source type (e.g. dbase, file...)
constexpr int FinalizationFailure
Error codes for operation failures.
StringArrayProperty m_createSvcNameList
void createSvcNameListHandler(Property &)
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)=0
Add a service to the "active" list of services of the factory.
Definition of the MsgStream class used to transmit messages.
virtual StatusCode stopRun()=0
Schedule a stop of the current event processing.
StringProperty m_messageSvcType
MessageSvc type.
virtual StatusCode run()=0
Run the class implementation.
Define general base for Gaudi exception.
StatusCode decodeDllNameList()
StatusCode loadModule(const std::string &module, bool fireIncident=true) override
SmartIF< IRunable > m_runable
Reference to the runable object.
MSG::Level level()
Retrieve output level.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
int m_noOfEvtThreads
no of multiThreadSvc copies
bool m_codeCheck
Activate StatusCode checking.
static Time current(void)
Returns the current time.
bool isSuccess() const
Test for a status code of SUCCESS.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
std::string m_appName
The name of the application.
IntegerProperty m_pluginDebugLevel
Debug level for the plugin system.
virtual StatusCode executeEvent(void *par=0)=0
Process single event.
static GAUDI_API void enableChecking()
std::vector< std::string > m_okDlls
names of successfully loaded dlls
std::map< std::string, std::string > m_environment
Environment variables to set.
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm, Service, AlgTool).
#define DECLARE_OBJECT_FACTORY(x)
StringArrayProperty m_dllNameList
List of DDL's names.
StatusCode nextEvent(int maxevt) override
SmartIF< IJobOptionsSvc > m_jobOptionsSvc
Reference to JobOption service.
AlgTypeAliasesMap & typeAliases()
Property manager helper class.
virtual StatusCode declareSvcType(const std::string &svcname, const std::string &svctype)=0
Declare the type of the service to be used when crating a given service name.
bool isFailure() const
Test for a status code of FAILURE.
SmartIF< IEventProcessor > m_processingMgr
Reference to processing manager object.
StatusCode terminate() override
SmartIF< ISvcManager > & svcManager()
virtual StatusCode start()=0
Start (from INITIALIZED to RUNNING).
constexpr int ScheduledStop
GAUDI_API int setEnv(const std::string &name, const std::string &value, int overwrite=1)
Set an environment variables.
int m_outputLevel
Message output level.
StatusCode addMultiSvc(const Gaudi::Utils::TypeNameString &typeName, int prio)
add one or more copies of svc type/name as determined by NoOfThreads
int m_evtMax
Number of events to be processed.
virtual StatusCode nextEvent(int maxevt)=0
Process the next maxevt events.
IntegerProperty m_returnCode
Property to record the error conditions occurring during the running.
void multiThreadSvcNameListHandler(Property &theProp)
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
SimpleProperty< bool > BooleanProperty
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
Helper class to parse a string of format "type/name".
StatusCode executeRun(int evtmax) override
implementation of IEventProcessor::executeRun(int)
virtual StatusCode stop()=0
Stop (from RUNNING to INITIALIZED).
virtual StatusCode reinitialize()=0
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
std::string m_jobOptionsPath
The "file" to look for properties.
BooleanProperty m_extSvcCreates
LHCb or ATLAS defn of "ExtSvc".
auto end(reverse_wrapper< T > &w)
General service interface definition.
VectorName m_svcMapping
Default mapping of services.
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.
virtual SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype)=0
Creates and instance of a service type that has been declared beforehand and assigns it a name...
Definition of the basic interface.
virtual StatusCode setMyProperties(const std::string &client, IProperty *me)=0
Override default properties of the calling client.
virtual StatusCode setProperty(const Property &p)=0
Set the property by property.
bool m_actHistory
Activate HistorySvc.
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
const std::vector< Property * > & getProperties() const override
get all properties
BooleanProperty m_loopCheck
For ServiceMgr initialization loop checking.
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
SimpleProperty< std::string > StringProperty
SimpleProperty< int > IntegerProperty
GAUDI_API std::string getGaudiThreadIDfromID(int iCopy)
helper function to extract Gaudi Thread ID from thread copy number
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
virtual StatusCode initialize()=0
Initialization (from CONFIGURED to INITIALIZED).
const TYPE & value() const
explicit conversion
StringArrayProperty m_multiThreadSvcNameList
List of external services names for which we want a copy per evt thread.
VectorName m_svcOptMapping
Default mapping of services.
StatusCode executeEvent(void *par) override
implementation of IEventProcessor::executeEvent(void*)
The Application Manager class.
std::string m_runableType
Runable type.
StatusCode queryInterface(const InterfaceID &iid, void **pinterface) override
StatusCode decodeExtSvcNameList()
SmartIF< PropertyMgr > m_propertyMgr
Reference to Property Manager.
void initLoopCheckHndlr(Property &)
bool m_propertiesPrint
flag to activate the printout of properties
Property base class allowing Property* collections to be "homogeneous".
void SIGoHandler(Property &theProp)
GAUDIPS_API void SetDebug(int debugLevel)
Backward compatibility with Reflex.
SmartIF< DLLClassManager > m_classManager
Reference to the class manager.
StatusCode start() override
StatusCode restart() override
StatusCode configure() override
StringArrayProperty m_extSvcNameList
List of external services names.
StringProperty m_jobOptionsSvcType
JobOptionsSvc type.
virtual StatusCode restart()=0
Initialization (from RUNNING to RUNNING, via INITIALIZED).
StatusCode stopRun() override
implementation of IEventProcessor::stopRun()
const std::string & type() const
StatusCode decodeCreateSvcNameList()
void evtLoopPropertyHandler(Property &theProp)
virtual StatusCode finalize()=0
Finalize (from INITIALIZED to CONFIGURED).
BooleanProperty m_stalledEventMonitoring
Property to enable/disable the monitoring and reporting of stalled events (enabled by default)...
GAUDI_API const std::string & hostName()
Host name.
std::string m_eventLoopMgr
Processing manager type.
void SIExitHandler(Property &theProp)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
StatusCode i_startup()
Internal startup routine.
StatusCode stop() override
virtual void declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
static GAUDI_API void disableChecking()
StatusCode reinitialize() override
Gaudi::StateMachine::State m_state
Internal State.
Gaudi::StateMachine::State FSMState() const override
const std::string & name() const
virtual void setLoopCheckEnabled(bool en=true)=0
Set the value of the initialization loop check flag.
virtual StatusCode executeRun(int maxevt)=0
Process the maxevt events as a Run (beginRun() and endRun() called)
StatusCode run() override
std::string typeName(const std::type_info &typ)
StatusCode decodeMultiThreadSvcNameList()
The IProperty is the basic interface for all components which have properties that can be set or get...
SmartIF< IAlgManager > & algManager()
void extSvcNameListHandler(Property &theProp)
void pluginDebugPropertyHandler(Property &theProp)
BooleanProperty m_stopOnSignal
Property to enable/disable the "stop on signal" service (enabled by default).
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
const std::string & name() const override
std::string m_appVersion
The version of the application.
SmartIF< IMessageSvc > m_messageSvc
Reference to the message service.
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
Gaudi::StateMachine::State targetFSMState() const override
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
StatusCode declareMultiSvcType(const std::string &name, const std::string &type)
declare one or more copies of svc type/name as determined by NoOfThreads