39#define ON_DEBUG if ( m_outputLevel <= MSG::DEBUG )
40#define ON_VERBOSE if ( m_outputLevel <= MSG::VERBOSE )
46 static IMessageSvc* s_messageSvcInstance{
nullptr };
48 static ErrorHandlerFunc_t s_originalRootErrorHandler{
nullptr };
51 void ROOTErrorHandlerAdapter(
int level, Bool_t abort,
const char* location,
const char* msg ) {
52 if ( s_messageSvcInstance ) {
54 if ( level >= gErrorIgnoreLevel ) {
59 int msgLevel = std::min<int>( level / 1000 + 2,
MSG::FATAL );
60 if ( msgLevel >= s_messageSvcInstance->outputLevel( location ) ) {
61 s_messageSvcInstance->reportMessage(
Message{ location, msgLevel, msg }, msgLevel );
66 if ( s_originalRootErrorHandler ) {
68 s_originalRootErrorHandler( level, abort, location, msg );
71 ROOT::Internal::MinimalErrorHandler( level, abort, location, msg );
102 "Aliases of algorithm types, to replace an algorithm type for every instance" );
108 "DetDataSvc/DetectorDataSvc",
109 "HistogramSvc/HistogramDataSvc",
110 "HbookCnv::PersSvc/HbookHistSvc",
111 "RootHistCnv::PersSvc/RootHistSvc",
112 "EvtPersistencySvc/EventPersistencySvc",
113 "DetPersistencySvc/DetectorPersistencySvc",
114 "HistogramPersistencySvc/HistogramPersistencySvc" };
119 if (
auto output = base_class::i_cast( iid ) ) {
return output; }
141 StatusCode sc = base_class::queryInterface( iid, ppvi );
184 log <<
MSG::FATAL <<
"Error setting OutputLevel option of MessageSvc" <<
endmsg;
191 s_originalRootErrorHandler = SetErrorHandler( ROOTErrorHandlerAdapter );
194 <<
"ROOT not yet initialized, we cannot override the error handler are requested "
195 "(UseMessageSvcForROOTMessages==true)"
208 if ( !jobOptsIProp ) {
214 log <<
MSG::FATAL <<
"Error setting TYPE option in JobOptionsSvc" <<
endmsg;
221 log <<
MSG::FATAL <<
"Error setting JobOptionsPreAction option in JobOptionsSvc" <<
endmsg;
229 log <<
MSG::FATAL <<
"Error setting JobOptionsPostAction option in JobOptionsSvc" <<
endmsg;
237 log <<
MSG::FATAL <<
"Error setting PATH option in JobOptionsSvc" <<
endmsg;
240 }
else if (
isEnvSet(
"JOBOPTPATH" ) ) {
243 log <<
MSG::FATAL <<
"Error setting PATH option in JobOptionsSvc from env" <<
endmsg;
249 log <<
MSG::FATAL <<
"Error setting PATH option in JobOptionsSvc to default" <<
endmsg;
253 jobOptsIProp.reset();
257 auto msgSvcIProp = msgsvc.as<
IProperty>();
261 sc = jobsvc->sysInitialize();
266 sc = msgsvc->sysInitialize();
314 <<
"=================================================================="
315 <<
"==================================================================" << std::endl
324#if GAUDI_PATCH_VERSION
334 <<
"=================================================================="
335 <<
"==================================================================" <<
endmsg;
342 <<
" #properties = " << properties.size() <<
endmsg;
343 for (
const auto&
property : properties ) { log <<
"Property ['Name': Value] = " << *
property <<
endmsg; }
348 const std::string&
name = var.first;
349 const std::string& value = var.second;
360 log <<
MSG::ERROR <<
"configure: declaring svc type:'" << j <<
"' failed." <<
endmsg;
387 log <<
MSG::ERROR <<
"Failure during external service association" <<
endmsg;
412 log <<
MSG::FATAL <<
"Error retrieving Runable: " <<
m_runableType.value() <<
"\n Check option ApplicationMgr."
419 <<
"\n Check option ApplicationMgr." <<
m_eventLoopMgr.name() <<
"\n No events will be processed." <<
endmsg;
439 log <<
MSG::INFO <<
"Application Manager Configured successfully" <<
endmsg;
456 std::string svcname(
"Gaudi::Utils::StopSignalHandler" );
459 log <<
MSG::INFO <<
"Cannot instantiate " << svcname <<
"signals will be ignored" <<
endmsg;
485 log <<
MSG::INFO <<
"Application Manager Initialized successfully" <<
endmsg;
519 log <<
MSG::INFO <<
"Application Manager Started successfully" <<
endmsg;
560 .andThen( [&]() {
return m_svcLocator->service(
"JobOptionsSvc" )->sysStop(); } )
565 log <<
MSG::INFO <<
"Application Manager Stopped successfully" <<
endmsg;
608 log <<
MSG::INFO <<
"Application Manager Finalized successfully" <<
endmsg;
632 log <<
MSG::INFO <<
"Application Manager Terminated successfully" <<
endmsg;
634 log <<
MSG::INFO <<
"Application Manager Terminated successfully with a user requested ScheduledStop" <<
endmsg;
642 opts.set(
"MessageSvc.AuditFinalize",
"false" );
644 opts.set(
"JobOptionsSvc.AuditFinalize",
"false" );
648 if ( s_originalRootErrorHandler ) {
649 SetErrorHandler( s_originalRootErrorHandler );
650 s_originalRootErrorHandler =
nullptr;
653 s_messageSvcInstance =
nullptr;
657 log <<
MSG::ERROR <<
"Could not get the IService interface of the MessageSvc" <<
endmsg;
659 svc->sysFinalize().ignore();
666 log <<
MSG::ERROR <<
"Could not get the IService interface of the JobOptionsSvc" <<
endmsg;
668 svc->sysFinalize().ignore();
750 if ( ignoreFailures ) {
808 std::stringstream ss;
809 ss <<
"createEventContext: Invalid state \"" <<
FSMState() <<
'"';
844 throw GaudiException(
"Cannot reinitialize application if not INITIALIZED or RUNNING",
855 sc =
m_svcLocator->service(
"JobOptionsSvc" )->sysReinitialize();
858 log <<
MSG::INFO <<
"Application Manager Reinitialized successfully" <<
endmsg;
877 sc =
m_svcLocator->service(
"JobOptionsSvc" )->sysRestart();
886 if ( props ) props->setProperty( p ).ignore();
892 throw GaudiException(
"Failed to create ext services",
"MinimalEventLoopMgr::createSvcNameListHandler",
899 auto it = theNames.begin();
900 auto et = theNames.end();
901 while ( result.
isSuccess() && it != et ) {
903 if ( ( result =
svcManager()->addService( item, ServiceManager::DEFAULT_SVC_PRIORITY ) ).isFailure() ) {
905 log <<
MSG::ERROR <<
"decodeCreateSvcNameList: Cannot create service " << item.
type() <<
"/" << item.
name()
919 throw GaudiException(
"Failed to declare ext services",
"MinimalEventLoopMgr::extSvcNameListHandler",
929 auto it = theNames.begin();
930 auto et = theNames.end();
931 while ( result.
isSuccess() && it != et ) {
934 if ( ( result =
svcManager()->addService( item, ServiceManager::DEFAULT_SVC_PRIORITY ) ).isFailure() ) {
936 log <<
MSG::ERROR <<
"decodeExtSvcNameList: Cannot create service " << item.
type() <<
"/" << item.
name()
940 if ( ( result =
svcManager()->declareSvcType( item.
name(), item.
type() ) ).isFailure() ) {
942 log <<
MSG::ERROR <<
"decodeExtSvcNameList: Cannot declare service " << item.
type() <<
"/" << item.
name()
962 std::vector<std::string> newList;
963 std::map<std::string, unsigned int> dllInList, duplicateList;
966 if ( 0 == dllInList[it] ) {
967 newList.push_back( it );
977 ON_DEBUG if ( !duplicateList.empty() ) {
978 log <<
MSG::DEBUG <<
"Removed duplicate entries for modules : ";
979 for (
auto it = duplicateList.begin(); it != duplicateList.end(); ++it ) {
980 log << it->first <<
"(" << 1 + it->second <<
")";
981 if ( it != --duplicateList.end() ) log <<
", ";
986 const std::vector<std::string>& theNames = newList;
991 std::vector<std::string> successNames, failNames;
992 for (
const auto& it : theNames ) {
997 failNames.push_back( it );
1000 successNames.push_back( it );
1006 if ( !successNames.empty() ) {
1007 log <<
MSG::INFO <<
"Successfully loaded modules : ";
1008 for (
auto it = successNames.begin(); it != successNames.end(); it++ ) {
1010 if ( ( it + 1 ) != successNames.end() ) log <<
", ";
1019 for (
auto it = failNames.begin(); it != failNames.end(); it++ ) {
1021 if ( ( it + 1 ) != failNames.end() ) log <<
", ";
1030 for (
auto& mgrItem :
m_managers ) { mgrItem.second->outputLevelUpdate(); }
1039 for (
int i = 0; i < indent; ++i ) log <<
" ";
1040 log << algname <<
endmsg;
1041 auto prop = algmgr->algorithm<
IProperty>( algname, false );
1045 if ( prop->getProperty( &p ).isSuccess() ) {
1046 for (
auto& subalgname : p.value() ) { printAlgsSequencesHelper( algmgr, subalgname, log, indent + 1 ); }
1056 log <<
MSG::ALWAYS <<
"****************************** Algorithm Sequence ****************************" <<
endmsg;
1058 log <<
MSG::ALWAYS <<
"******************************************************************************" <<
endmsg;
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
#define GAUDI_MAJOR_VERSION
#define GAUDI_MINOR_VERSION
#define GAUDI_PATCH_VERSION
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
#define DECLARE_OBJECT_FACTORY(x)
The AlgorithmManager class is in charge of the creation of concrete instances of Algorithms.
AlgTypeAliasesMap & typeAliases()
The Application Manager class.
Gaudi::Property< std::string > m_jobOptionsType
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.
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.
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_extSvcNameList
StatusCode nextEvent(int maxevt) override
Gaudi::Property< std::string > m_jobOptionsPath
SmartIF< DLLClassManager > m_classManager
Reference to the class manager.
StatusCode terminate() override
StatusCode initialize() override
StatusCode stopRun() override
implementation of IEventProcessor::stopRun()
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
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< std::string > m_eventLoopMgr
const std::string & name() const override
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< 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
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.
Gaudi::StateMachine::State m_state
Internal State.
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
void push(EventContext &&ctx) override
StatusCode decodeCreateSvcNameList()
void dllNameListHandler(Gaudi::Details::PropertyBase &theProp)
Gaudi::Property< int > m_outputLevel
ManagersMap m_managers
Map of known component managers.
bool empty() const override
StatusCode configure() override
StatusCode sysStart() override
SmartIF< ISvcManager > & svcManager()
SmartIF< IEventProcessor > m_processingMgr
Reference to processing manager object.
Gaudi::Property< std::string > m_jobOptionsPostAction
Gaudi::Property< std::string > m_messageSvcType
MSG::Level resetMessaging()
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.
std::string format(bool local, std::string spec="%c") const
Format the time using strftime.
static Time current()
Returns the current time.
Helper class to parse a string of format "type/name".
const std::string & type() const
const std::string & name() const
Define general base for Gaudi exception.
Definition of the basic interface.
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
The IMessage is the interface implemented by the message service.
The IProperty is the basic interface for all components which have properties that can be set or get.
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Set the property from a property.
General service interface definition.
virtual StatusCode finalize()=0
Finalize (from INITIALIZED to CONFIGURED).
virtual StatusCode restart()=0
Initialization (from RUNNING to RUNNING, via INITIALIZED).
virtual StatusCode reinitialize()=0
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
virtual StatusCode start()=0
Start (from INITIALIZED to RUNNING).
virtual StatusCode stop()=0
Stop (from RUNNING to INITIALIZED).
virtual StatusCode initialize()=0
Initialization (from CONFIGURED to INITIALIZED).
virtual StatusCode removeService(IService *svc)=0
Remove a service from the "active" list of services of the factory.
virtual void setLoopCheckEnabled(bool en=true)=0
Set the value of the initialization loop check flag.
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.
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)=0
Add a service to the "active" list of services of the factory.
constexpr unsigned long id() const
get the interface identifier
Definition of the MsgStream class used to transmit messages.
Gaudi::Details::PropertyBase * property(std::string_view name) const
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
void bindPropertiesTo(Gaudi::Interfaces::IOptionsSvc &optsSvc)
const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
The ServiceManager class is in charge of the creation of concrete instances of Services.
Small smart pointer class with automatic reference counting for IInterface.
TYPE * get() const
Get interface pointer.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
This class is used for returning status codes from appropriate routines.
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
constexpr int ScheduledStop
constexpr int FinalizationFailure
Error codes for operation failures.
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm,...
GAUDI_API bool isEnvSet(const char *var)
Check if an environment variable is set or not.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
GAUDI_API std::vector< std::string > getEnv()
get all environment variables
GAUDI_API const std::string & hostName()
Host name.
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
GAUDI_API int setEnv(const std::string &name, const std::string &value, int overwrite=1)
Set an environment variables.
virtual std::optional< ResultType > pop()=0
Get the next available result.
virtual bool empty() const =0
Tell if the processor has events in the queues.
virtual void push(EventContext &&ctx)=0
Schedule the processing of an event.
static const InterfaceID & interfaceID()