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 ) ) {
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; }
150 ROOT::EnableThreadSafety();
153 <<
"ROOT not yet initialized, we cannot enable thread safety "
154 "(EnableROOTThreadSafety==True)"
173 log <<
MSG::FATAL <<
"Error setting OutputLevel option of MessageSvc" <<
endmsg;
180 s_originalRootErrorHandler = SetErrorHandler( ROOTErrorHandlerAdapter );
183 <<
"ROOT not yet initialized, we cannot override the error handler are requested "
184 "(UseMessageSvcForROOTMessages==true)"
197 if ( !jobOptsIProp ) {
203 log <<
MSG::FATAL <<
"Error setting TYPE option in JobOptionsSvc" <<
endmsg;
210 log <<
MSG::FATAL <<
"Error setting JobOptionsPreAction option in JobOptionsSvc" <<
endmsg;
218 log <<
MSG::FATAL <<
"Error setting JobOptionsPostAction option in JobOptionsSvc" <<
endmsg;
226 log <<
MSG::FATAL <<
"Error setting PATH option in JobOptionsSvc" <<
endmsg;
229 }
else if (
isEnvSet(
"JOBOPTPATH" ) ) {
232 log <<
MSG::FATAL <<
"Error setting PATH option in JobOptionsSvc from env" <<
endmsg;
238 log <<
MSG::FATAL <<
"Error setting PATH option in JobOptionsSvc to default" <<
endmsg;
242 jobOptsIProp.reset();
246 auto msgSvcIProp = msgsvc.as<
IProperty>();
250 sc = jobsvc->sysInitialize();
255 sc = msgsvc->sysInitialize();
303 <<
"=================================================================="
304 <<
"==================================================================" << std::endl
313#if GAUDI_PATCH_VERSION
323 <<
"=================================================================="
324 <<
"==================================================================" <<
endmsg;
331 <<
" #properties = " << properties.size() <<
endmsg;
332 for (
const auto&
property : properties ) { log <<
"Property ['Name': Value] = " << *
property <<
endmsg; }
337 const std::string&
name = var.first;
338 const std::string& value = var.second;
349 log <<
MSG::ERROR <<
"configure: declaring svc type:'" << j <<
"' failed." <<
endmsg;
376 log <<
MSG::ERROR <<
"Failure during external service association" <<
endmsg;
401 log <<
MSG::FATAL <<
"Error retrieving Runable: " <<
m_runableType.value() <<
"\n Check option ApplicationMgr."
408 <<
"\n Check option ApplicationMgr." <<
m_eventLoopMgr.name() <<
"\n No events will be processed." <<
endmsg;
428 log <<
MSG::INFO <<
"Application Manager Configured successfully" <<
endmsg;
445 std::string svcname(
"Gaudi::Utils::StopSignalHandler" );
448 log <<
MSG::INFO <<
"Cannot instantiate " << svcname <<
"signals will be ignored" <<
endmsg;
474 log <<
MSG::INFO <<
"Application Manager Initialized successfully" <<
endmsg;
508 log <<
MSG::INFO <<
"Application Manager Started successfully" <<
endmsg;
549 .andThen( [&]() {
return m_svcLocator->service(
"JobOptionsSvc" )->sysStop(); } )
554 log <<
MSG::INFO <<
"Application Manager Stopped successfully" <<
endmsg;
597 log <<
MSG::INFO <<
"Application Manager Finalized successfully" <<
endmsg;
621 log <<
MSG::INFO <<
"Application Manager Terminated successfully" <<
endmsg;
623 log <<
MSG::INFO <<
"Application Manager Terminated successfully with a user requested ScheduledStop" <<
endmsg;
631 opts.set(
"MessageSvc.AuditFinalize",
"false" );
633 opts.set(
"JobOptionsSvc.AuditFinalize",
"false" );
637 if ( s_originalRootErrorHandler ) {
638 SetErrorHandler( s_originalRootErrorHandler );
639 s_originalRootErrorHandler =
nullptr;
642 s_messageSvcInstance =
nullptr;
646 log <<
MSG::ERROR <<
"Could not get the IService interface of the MessageSvc" <<
endmsg;
648 svc->sysFinalize().ignore();
655 log <<
MSG::ERROR <<
"Could not get the IService interface of the JobOptionsSvc" <<
endmsg;
657 svc->sysFinalize().ignore();
739 if ( ignoreFailures ) {
797 std::stringstream ss;
798 ss <<
"createEventContext: Invalid state \"" <<
FSMState() <<
'"';
833 throw GaudiException(
"Cannot reinitialize application if not INITIALIZED or RUNNING",
844 sc =
m_svcLocator->service(
"JobOptionsSvc" )->sysReinitialize();
847 log <<
MSG::INFO <<
"Application Manager Reinitialized successfully" <<
endmsg;
866 sc =
m_svcLocator->service(
"JobOptionsSvc" )->sysRestart();
875 if ( props ) props->setProperty( p ).ignore();
881 throw GaudiException(
"Failed to create ext services",
"MinimalEventLoopMgr::createSvcNameListHandler",
888 auto it = theNames.begin();
889 auto et = theNames.end();
890 while ( result.
isSuccess() && it != et ) {
892 if ( ( result =
svcManager()->addService( item, ServiceManager::DEFAULT_SVC_PRIORITY ) ).isFailure() ) {
894 log <<
MSG::ERROR <<
"decodeCreateSvcNameList: Cannot create service " << item.
type() <<
"/" << item.
name()
908 throw GaudiException(
"Failed to declare ext services",
"MinimalEventLoopMgr::extSvcNameListHandler",
918 auto it = theNames.begin();
919 auto et = theNames.end();
920 while ( result.
isSuccess() && it != et ) {
923 if ( ( result =
svcManager()->addService( item, ServiceManager::DEFAULT_SVC_PRIORITY ) ).isFailure() ) {
925 log <<
MSG::ERROR <<
"decodeExtSvcNameList: Cannot create service " << item.
type() <<
"/" << item.
name()
929 if ( ( result =
svcManager()->declareSvcType( item.
name(), item.
type() ) ).isFailure() ) {
931 log <<
MSG::ERROR <<
"decodeExtSvcNameList: Cannot declare service " << item.
type() <<
"/" << item.
name()
951 std::vector<std::string> newList;
952 std::map<std::string, unsigned int> dllInList, duplicateList;
955 if ( 0 == dllInList[it] ) {
956 newList.push_back( it );
966 ON_DEBUG if ( !duplicateList.empty() ) {
967 log <<
MSG::DEBUG <<
"Removed duplicate entries for modules : ";
968 for (
auto it = duplicateList.begin(); it != duplicateList.end(); ++it ) {
969 log << it->first <<
"(" << 1 + it->second <<
")";
970 if ( it != --duplicateList.end() ) log <<
", ";
975 const std::vector<std::string>& theNames = newList;
980 std::vector<std::string> successNames, failNames;
981 for (
const auto& it : theNames ) {
986 failNames.push_back( it );
989 successNames.push_back( it );
995 if ( !successNames.empty() ) {
996 log <<
MSG::INFO <<
"Successfully loaded modules : ";
997 for (
auto it = successNames.begin(); it != successNames.end(); it++ ) {
999 if ( ( it + 1 ) != successNames.end() ) log <<
", ";
1008 for (
auto it = failNames.begin(); it != failNames.end(); it++ ) {
1010 if ( ( it + 1 ) != failNames.end() ) log <<
", ";
1019 for (
auto& mgrItem :
m_managers ) { mgrItem.second->outputLevelUpdate(); }
1028 for (
int i = 0; i < indent; ++i ) log <<
" ";
1029 log << algname <<
endmsg;
1030 auto prop = algmgr->algorithm<
IProperty>( algname, false );
1034 if ( prop->getProperty( &p ).isSuccess() ) {
1035 for (
auto& subalgname : p.value() ) { printAlgsSequencesHelper( algmgr, subalgname, log, indent + 1 ); }
1045 log <<
MSG::ALWAYS <<
"****************************** Algorithm Sequence ****************************" <<
endmsg;
1047 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
Gaudi::Property< bool > m_enableROOTThreadSafety
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< 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.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
The IMessage is the interface implemented by the message service.
virtual void reportMessage(const Message &msg, int outputLevel)=0
Report a message by sending a Message object to the message service.
virtual int outputLevel() const =0
Retrieve the current output level threshold.
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.
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
void ignore() const
Allow discarding a StatusCode without warning.
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()