| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gaudi::Utils::StopSignalHandler Class Reference

Service that stop the processing if a signal is received. More...

Inheritance diagram for Gaudi::Utils::StopSignalHandler:
[legend]
Collaboration diagram for Gaudi::Utils::StopSignalHandler:
[legend]

## Public Member Functions
| StopSignalHandler (const std::string &name, ISvcLocator *svcLoc)
StatusCode | initialize () override
StatusCode | finalize () override
void | handle (const Incident &) override
Public Member Functions inherited from extends< Service, IIncidentListener >
void * | i_cast (const InterfaceID &tid) const override
| Implementation of IInterface::i_cast. More...
StatusCode | queryInterface (const InterfaceID &ti, void **pp) override
| Implementation of IInterface::queryInterface. More...
std::vector< std::string > | getInterfaceNames () const override
| Implementation of IInterface::getInterfaceNames. More...
| ~extends () override=default
| Virtual destructor. More...
Public Member Functions inherited from Service
const std::string & | name () const override
| Retrieve name of the service. More...
StatusCode | configure () override
StatusCode | initialize () override
StatusCode | start () override
StatusCode | stop () override
StatusCode | finalize () override
StatusCode | terminate () override
Gaudi::StateMachine::State | FSMState () const override
Gaudi::StateMachine::State | targetFSMState () const override
StatusCode | reinitialize () override
StatusCode | restart () override
StatusCode | sysInitialize () override
| Initialize Service. More...
StatusCode | sysStart () override
| Initialize Service. More...
StatusCode | sysStop () override
| Initialize Service. More...
StatusCode | sysFinalize () override
| Finalize Service. More...
StatusCode | sysReinitialize () override
| Re-initialize the Service. More...
StatusCode | sysRestart () override
| Re-initialize the Service. More...
StatusCode | setProperty (const Property &p) override
StatusCode | setProperty (const std::string &s) override
StatusCode | setProperty (const std::string &n, const std::string &v) override
StatusCode | getProperty (Property *p) const override
const Property & | getProperty (const std::string &name) const override
StatusCode | getProperty (const std::string &n, std::string &v) const override
const std::vector< Property * > & | getProperties () const override
bool | hasProperty (const std::string &name) const override
template<class TYPE >
StatusCode | setProperty (const std::string &name, const TYPE &value)
| set the property form the value More...
| Service (std::string name, ISvcLocator *svcloc)
| Standard Constructor. More...
SmartIF< ISvcLocator > & | serviceLocator () const override
| Retrieve pointer to service locator. More...
StatusCode | setProperties ()
| Method for setting declared properties to the values specified for the job. More...
template<class T >
StatusCode | service (const std::string &name, const T *&psvc, bool createIf=true) const
| Access a service by name, creating it if it doesn't already exist. More...
template<class T >
StatusCode | service (const std::string &name, T *&psvc, bool createIf=true) const
template<typename IFace = IService>
SmartIF< IFace > | service (const std::string &name, bool createIf=true) const
template<class T >
StatusCode | service (const std::string &svcType, const std::string &svcName, T *&psvc) const
| Access a service by name and type, creating it if it doesn't already exist. More...
template<class T >
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const
| Declare the named property. More...
Property * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
| Declare remote named properties. More...
template<class T >
StatusCode | declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
| Declare used Private tool. More...
template<class T >
StatusCode | declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
| Declare used Public tool. More...
SmartIF< IAuditorSvc > & | auditorSvc () const
| The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
Public Member Functions inherited from CommonMessagingBase
virtual | ~CommonMessagingBase ()=default
| Virtual destructor. More...
SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service. More...
MsgStream & | msgStream () const
| Return an uninitialized MsgStream. More...
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts. More...
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS) More...
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL) More...
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING) More...
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO) More...
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG) More...
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE) More...
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO) More...
MSG::Level | msgLevel () const
| get the output level from the embedded MsgStream More...
MSG::Level | outputLevel () const __attribute__((deprecated))
| Backward compatibility function for getting the output level. More...
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream More...
Public Member Functions inherited from extend_interfaces< Interfaces...>
| ~extend_interfaces () override=default
| Virtual destructor. More...

## Private Member Functions
std::pair< int, bool > | i_decodeSignal (const std::string &sig)
| Function to translate the signal name to the signal number. More...

## Private Attributes
std::vector< std::string > | m_usedSignals
| List of signal names or numbers (encoded as strings) to use to schedule a stop. More...
std::map< int, bool > | m_signals
| Map of monitored signal numbers to the flag telling if they have to be propagated or not. More...
bool | m_stopRequested
| Flag to remember if the stop has been requested because of a signal. More...
SmartIF< Gaudi::ISignalMonitor > | m_signalMonitor
| Pointer to the signal monitor service. More...
SmartIF< IIncidentSvc > | m_incidentSvc
| Pointer to the incident service. More...
SmartIF< IProperty > | m_appProperty
| Pointer to the interface to set the return code of the application. More...

## Additional Inherited Members
Public Types inherited from extends< Service, IIncidentListener >
using | base_class = extends
| Typedef to this class. More...
using | extend_interfaces_base = extend_interfaces< Interfaces...>
| Typedef to the base of this class. More...
Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > | Factory
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using | base_class = CommonMessaging
Public Types inherited from extend_interfaces< Interfaces...>
using | ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
| take union of the ext_iids of all Interfaces... More...
Protected Member Functions inherited from Service
| ~Service () override
| Standard Destructor. More...
int | outputLevel () const
| get the `Service's` output level More...
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void | updateMsgStreamOutputLevel (int level)
| Update the output level of the cached MsgStream. More...
Protected Attributes inherited from Service
IntegerProperty | m_outputLevel = MSG::NIL
| Service output level. More...
Gaudi::StateMachine::State | m_state = Gaudi::StateMachine::OFFLINE
| Service state. More...
Gaudi::StateMachine::State | m_targetState = Gaudi::StateMachine::OFFLINE
| Service state. More...

## Detailed Description

Service that stop the processing if a signal is received.

The signals to be intercepted have to be declared in the property Signals as a list of strings (signal names or numbers). If '+' is appended to the signal name, then the signal is propagated to the signal handlers already registered when this service is initialized.

Definition at line 340 of file SignalMonitorSvc.cpp.

## Constructor & Destructor Documentation

Gaudi::Utils::StopSignalHandler::StopSignalHandler | ( | const std::string & | name,
|  | ISvcLocator * | svcLoc
| ) |  |
| inline

Definition at line 343 of file SignalMonitorSvc.cpp.

343 : base_class(name, svcLoc) {
344 m_usedSignals.reserve(2);
345 m_usedSignals.push_back("SIGINT");
346 m_usedSignals.push_back("SIGXCPU");
347 m_stopRequested = false;
348 declareProperty("Signals", m_usedSignals,
349 "List of signal names or numbers to use to schedule a stop. "
350 "If the signal is followed by a '+' the signal is propagated the previously "
351 "registered handler (if any).");
352 }
Gaudi::Utils::StopSignalHandler::m_stopRequested
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
Definition: SignalMonitorSvc.cpp:449
extends< Service, IIncidentListener >::base_class
extends base_class
Typedef to this class.
Definition: extends.h:14
Gaudi::Utils::StopSignalHandler::m_usedSignals
std::vector< std::string > m_usedSignals
List of signal names or numbers (encoded as strings) to use to schedule a stop.
Definition: SignalMonitorSvc.cpp:445
std::vector::push_back
T push_back(T...args)
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
std::vector::reserve
T reserve(T...args)

## Member Function Documentation

StatusCode Gaudi::Utils::StopSignalHandler::finalize | ( |  | ) |
| inline override

Definition at line 398 of file SignalMonitorSvc.cpp.

398 {
399 m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
400 m_incidentSvc.reset();
401 // disable the monitoring of the signals
402 std::for_each( std::begin(m_signals), std::end(m_signals),
403 [&](const std::pair<int,bool>& s) {
404 // tell the signal monitor that we are interested in these signals
405 m_signalMonitor->ignoreSignal(s.first);
406 } );
407 m_signalMonitor.reset();
408 return Service::finalize();
409 }
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
Gaudi::Utils::StopSignalHandler::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
Definition: SignalMonitorSvc.cpp:453
std::end
T end(T...args)
Gaudi::Utils::StopSignalHandler::m_signalMonitor
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
Definition: SignalMonitorSvc.cpp:451
Gaudi::Utils::StopSignalHandler::m_signals
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not...
Definition: SignalMonitorSvc.cpp:447
std::pair
std::begin
T begin(T...args)
gaudirun.s
string s
Definition: gaudirun.py:245
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
IIncidentSvc::removeListener
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
std::for_each
T for_each(T...args)

void Gaudi::Utils::StopSignalHandler::handle | ( | const Incident & |  | ) |
| inline override

Definition at line 411 of file SignalMonitorSvc.cpp.

411 {
412 if (!m_stopRequested) {
413 const SigMap& sigmap(SigMap::instance());
414 for (const auto& s : m_signals ) {
415 if (!m_signalMonitor->gotSignal(s.first)) continue;
416 warning() << "Received signal '" << sigmap.name(s.first)
417 << "' (" << s.first;
418 const std::string &desc = sigmap.desc(s.first);
419 if ( ! desc.empty() ) warning() << ", " << desc;
420 warning() << ")" << endmsg;
421 m_stopRequested = true;
422 // Report the termination by signal at the end of the application
423 using Gaudi::ReturnCode::SignalOffset;
424 if (Gaudi::setAppReturnCode(m_appProperty, SignalOffset + s.first).isFailure()) {
425 error() << "Could not set return code of the application ("
426 << SignalOffset + s.first << ")"
427 << endmsg;
428 }
429
430 }
431 if (m_stopRequested) {
432 auto ep = serviceLocator()->as<IEventProcessor>();
433 if (ep) {
434 warning() << "Scheduling a stop" << endmsg;
435 ep->stopRun().ignore();
436 }
437 else {
438 warning() << "Cannot stop the processing because the IEventProcessor interface cannot be retrieved." << endmsg;
439 }
440 }
441 }
442 }
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
std::string::empty
T empty(T...args)
Gaudi::Utils::StopSignalHandler::m_stopRequested
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
Definition: SignalMonitorSvc.cpp:449
ep
int maxevt auto ep
Definition: Bootstrap.cpp:285
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:106
Gaudi::Utils::StopSignalHandler::m_signalMonitor
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
Definition: SignalMonitorSvc.cpp:451
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::string
STL class.
Gaudi::Utils::StopSignalHandler::m_signals
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not...
Definition: SignalMonitorSvc.cpp:447
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
Gaudi::Utils::StopSignalHandler::m_appProperty
SmartIF< IProperty > m_appProperty
Pointer to the interface to set the return code of the application.
Definition: SignalMonitorSvc.cpp:455
Gaudi::setAppReturnCode
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
Definition: AppReturnCode.h:50
gaudirun.s
string s
Definition: gaudirun.py:245
IEventProcessor
The IEventProcessor is the interface to process events.
Definition: IEventProcessor.h:16
Gaudi::ReturnCode::SignalOffset
constexpr int SignalOffset
Definition: AppReturnCode.h:34
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

std::pair<int, bool> Gaudi::Utils::StopSignalHandler::i_decodeSignal | ( | const std::string & | sig | ) |
| inline private

Function to translate the signal name to the signal number.

Definition at line 457 of file SignalMonitorSvc.cpp.

457 {
458 debug() << "Decoding signal declaration '" << sig << "'" << endmsg;
459 if ( sig.empty() || sig == "+" ) {
460 debug() << "Empty signal, ignored" << endmsg;
461 return {-1, false}; // silently ignore empty strings
462 }
463 const SigMap& sigmap(SigMap::instance());
464 std::string signal = sig;
465 bool propagate = false;
466 // Check if the signal must be propagated
467 if (signal[signal.size() - 1] == '+') {
468 debug() << "Must be propagated to previously registered signal handlers" << endmsg;
469 propagate = true;
470 signal.erase(signal.size() - 1, 1); // remove the '+' at the end of the string
471 }
472 int signum = -1;
473 // check if the signal is a number
474 if (std::isdigit(signal[0])){
475 std::istringstream ss(signal);
476 ss >> signum;
477 } else {
478 // try to find the signal name in the list of known signals
479 signum = sigmap.signum(signal);
480 }
481 if (signum < 0) {
482 warning() << "Cannot understand signal identifier '" << sig << "', ignored" << endmsg;
483 } else {
484 verbose() << "Matched signal '" << sigmap.name(signum)
485 << "' (" << signum;
486 const std::string &desc = sigmap.desc(signum);
487 if ( ! desc.empty() ) {
488 verbose() << ", " << desc;
489 }
490 verbose() << ")" << endmsg;
491 }
492 return {signum, propagate};
493 }
std::string::empty
T empty(T...args)
std::istringstream
STL class.
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:130
std::string
STL class.
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
std::isdigit
T isdigit(T...args)
std::string::erase
T erase(T...args)
std::signal
T signal(T...args)
std::string::size
T size(T...args)
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

StatusCode Gaudi::Utils::StopSignalHandler::initialize | ( |  | ) |
| inline override

Definition at line 353 of file SignalMonitorSvc.cpp.

353 {
354 StatusCode sc = Service::initialize();
355 if (sc.isFailure()) {
356 return sc;
357 }
358 std::string serviceName("Gaudi::Utils::SignalMonitorSvc");
359 m_signalMonitor = serviceLocator()->service(serviceName);
360 if ( ! m_signalMonitor ) {
361 error() << "Cannot retrieve " << serviceName << endmsg;
362 return StatusCode::FAILURE;
363 }
364 serviceName = "IncidentSvc";
365 m_incidentSvc = serviceLocator()->service(serviceName);
366 if ( ! m_incidentSvc ) {
367 error() << "Cannot retrieve " << serviceName << endmsg;
368 return StatusCode::FAILURE;
369 }
370 // Get the IMainAppStatus interface of the ApplicationMgr
371 m_appProperty = serviceLocator();
372 if ( ! m_appProperty ) {
373 warning() << "Cannot retrieve IProperty interface of ApplicationMgr, "
374 "the return code will not be changed" << endmsg;
375 }
376 // Decode the signal names
377 for (const auto& signame : m_usedSignals ) {
378 auto sigid = i_decodeSignal(signame);
379 if (sigid.first >= 0) {
380 m_signals[sigid.first] = sigid.second;
381 }
382 }
383 debug() << "Stopping on the signals:" << endmsg;
384 const SigMap& sigmap(SigMap::instance());
385 for (const auto& s : m_signals ) {
386 debug() << "\t" << sigmap.name(s.first) << ": "
387 << sigmap.desc(s.first) << " (" << s.first << ")";
388 if (s.second) debug() << " propagated";
389 debug() << endmsg;
390 // tell the signal monitor that we are interested in these signals
391 m_signalMonitor->monitorSignal(s.first, s.second);
392 }
393 m_stopRequested = false;
394 debug() << "Register to the IncidentSvc" << endmsg;
395 m_incidentSvc->addListener(this, IncidentType::BeginEvent);
396 return StatusCode::SUCCESS;
397 }
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
Gaudi::Utils::StopSignalHandler::m_stopRequested
bool m_stopRequested
Flag to remember if the stop has been requested because of a signal.
Definition: SignalMonitorSvc.cpp:449
Gaudi::Utils::StopSignalHandler::m_incidentSvc
SmartIF< IIncidentSvc > m_incidentSvc
Pointer to the incident service.
Definition: SignalMonitorSvc.cpp:453
Gaudi::Utils::StopSignalHandler::m_signalMonitor
SmartIF< Gaudi::ISignalMonitor > m_signalMonitor
Pointer to the signal monitor service.
Definition: SignalMonitorSvc.cpp:451
merge_files.sc
int sc
Definition: merge_files.py:167
Gaudi::Utils::StopSignalHandler::m_usedSignals
std::vector< std::string > m_usedSignals
List of signal names or numbers (encoded as strings) to use to schedule a stop.
Definition: SignalMonitorSvc.cpp:445
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
std::string
STL class.
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
Gaudi::Utils::StopSignalHandler::m_signals
std::map< int, bool > m_signals
Map of monitored signal numbers to the flag telling if they have to be propagated or not...
Definition: SignalMonitorSvc.cpp:447
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Gaudi::Utils::StopSignalHandler::m_appProperty
SmartIF< IProperty > m_appProperty
Pointer to the interface to set the return code of the application.
Definition: SignalMonitorSvc.cpp:455
Gaudi::Utils::StopSignalHandler::i_decodeSignal
std::pair< int, bool > i_decodeSignal(const std::string &sig)
Function to translate the signal name to the signal number.
Definition: SignalMonitorSvc.cpp:457
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
IIncidentSvc::addListener
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
gaudirun.s
string s
Definition: gaudirun.py:245
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

## Member Data Documentation

SmartIF<IProperty> Gaudi::Utils::StopSignalHandler::m_appProperty
| private

Pointer to the interface to set the return code of the application.

Definition at line 455 of file SignalMonitorSvc.cpp.

SmartIF<IIncidentSvc> Gaudi::Utils::StopSignalHandler::m_incidentSvc
| private

Pointer to the incident service.

Definition at line 453 of file SignalMonitorSvc.cpp.

SmartIF<Gaudi::ISignalMonitor> Gaudi::Utils::StopSignalHandler::m_signalMonitor
| private

Pointer to the signal monitor service.

Definition at line 451 of file SignalMonitorSvc.cpp.

std::map<int, bool> Gaudi::Utils::StopSignalHandler::m_signals
| private

Map of monitored signal numbers to the flag telling if they have to be propagated or not.

Definition at line 447 of file SignalMonitorSvc.cpp.

bool Gaudi::Utils::StopSignalHandler::m_stopRequested
| private

Flag to remember if the stop has been requested because of a signal.

Definition at line 449 of file SignalMonitorSvc.cpp.

std::vector<std::string> Gaudi::Utils::StopSignalHandler::m_usedSignals
| private

List of signal names or numbers (encoded as strings) to use to schedule a stop.

Definition at line 445 of file SignalMonitorSvc.cpp.

The documentation for this class was generated from the following file:

- GaudiUtils/src/component/SignalMonitorSvc.cpp