| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
IncidentSvc Class Reference

Default implementation of the IIncidentSvc interface. More...

`#include <IncidentSvc.h>`

Inheritance diagram for IncidentSvc:
[legend]
Collaboration diagram for IncidentSvc:
[legend]

## Classes
struct | Listener

## Public Types
typedef std::list< Listener > | ListenerList
typedef GaudiUtils::HashMap < Gaudi::StringKey, ListenerList * > | ListenerMap
Public Types inherited from extends1< Service, IIncidentSvc >
typedef extends1 | base_class
| Typedef to this class.
typedef extend_interfaces1 < IIncidentSvc > | extend_interfaces_base
| Typedef to the base of this class.
typedef extend_interfaces_base::ext_iids | interfaces
| MPL set of all the implemented interfaces.
Public Types inherited from Service
typedef Gaudi::PluginService::Factory2 < IService *, const std::string &, ISvcLocator * > | Factory
Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging | base_class
Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 | base_class
| Typedef to this class.
typedef extend_interfaces3 < IService, IProperty, IStateful > | extend_interfaces_base
| Typedef to the base of this class.
typedef extend_interfaces_base::ext_iids | interfaces
| MPL set of all the implemented interfaces.
Public Types inherited from extend_interfaces3< I1, I2, I3 >
typedef mpl::fold< typename I1::iid::iids::type, typename mpl::fold< typename I2::iid::iids::type, typename I3::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type | ext_iids
| MPL set of interfaces extended by this one.
Public Types inherited from extend_interfaces1< IIncidentSvc >
typedef IIncidentSvc::iid::iids::type | ext_iids
| MPL set of interfaces extended by this one.

## Public Member Functions
virtual StatusCode | initialize ()
virtual StatusCode | finalize ()
virtual void | addListener (IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)
| Add listener.
virtual void | removeListener (IIncidentListener *lis, const std::string &type="")
| Remove listener.
virtual void | fireIncident (const Incident &incident)
| Fire an Incident.
virtual void | getListeners (std::vector< IIncidentListener * > &lis, const std::string &type="") const
| IncidentSvc (const std::string &name, ISvcLocator *svc)
virtual | ~IncidentSvc ()
Public Member Functions inherited from extends1< Service, IIncidentSvc >
| extends1 (A1 a1, A2 a2, A3 a3)
| Templated constructor with 3 arguments.
| extends1 (A1 a1, A2 a2)
| Templated constructor with 2 arguments.
| extends1 (A1 a1)
| Templated constructor with 1 argument.
| extends1 ()
| Default constructor.
virtual void * | i_cast (const InterfaceID &tid) const
| Implementation of IInterface::i_cast.
virtual StatusCode | queryInterface (const InterfaceID &ti, void **pp)
| Implementation of IInterface::queryInterface.
virtual std::vector< std::string > | getInterfaceNames () const
| Implementation of IInterface::getInterfaceNames.
virtual | ~extends1 ()
| Virtual destructor.
Public Member Functions inherited from Service
virtual unsigned long | release ()
| Release Interface instance.
virtual const std::string & | name () const
| Retrieve name of the service.
virtual StatusCode | configure ()
virtual StatusCode | start ()
virtual StatusCode | stop ()
virtual StatusCode | terminate ()
virtual Gaudi::StateMachine::State | FSMState () const
virtual Gaudi::StateMachine::State | targetFSMState () const
virtual StatusCode | reinitialize ()
virtual StatusCode | restart ()
virtual StatusCode | sysInitialize ()
| Initialize Service.
virtual StatusCode | sysStart ()
| Initialize Service.
virtual StatusCode | sysStop ()
| Initialize Service.
virtual StatusCode | sysFinalize ()
| Finalize Service.
virtual StatusCode | sysReinitialize ()
| Re-initialize the Service.
virtual StatusCode | sysRestart ()
| Re-initialize the Service.
virtual StatusCode | setProperty (const Property &p)
virtual StatusCode | setProperty (const std::string &s)
virtual StatusCode | setProperty (const std::string &n, const std::string &v)
virtual StatusCode | getProperty (Property *p) const
virtual const Property & | getProperty (const std::string &name) const
virtual StatusCode | getProperty (const std::string &n, std::string &v) const
virtual const std::vector < Property * > & | getProperties () const
template<class TYPE >
StatusCode | setProperty (const std::string &name, const TYPE &value)
| set the property form the value
| Service (const std::string &name, ISvcLocator *svcloc)
| Standard Constructor.
SmartIF< ISvcLocator > & | serviceLocator () const
| Retrieve pointer to service locator.
StatusCode | setProperties ()
| Method for setting declared properties to the values specified for the job.
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.
template<class T >
StatusCode | service (const std::string &name, T *&psvc, 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.
template<class T >
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const
| Declare the named property.
Property * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
| Declare remote named properties.
SmartIF< IAuditorSvc > & | auditorSvc () const
| The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
| CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
| Templated constructor with 3 arguments.
| CommonMessaging (const A1 &a1, const A2 &a2)
| Templated constructor with 2 arguments.
| CommonMessaging (const A1 &a1)
| Templated constructor with 1 argument.
| CommonMessaging ()
| Default constructor.
virtual | ~CommonMessaging ()
| Virtual destructor.
SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service.
MsgStream & | msgStream () const
| Return an uninitialized MsgStream.
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts.
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL)
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING)
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO)
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG)
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO)
MSG::Level | msgLevel () const
| get the output level from the embedded MsgStream
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream
Public Member Functions inherited from extend_interfaces1< IIncidentSvc >
virtual | ~extend_interfaces1 ()
| Virtual destructor.
Public Member Functions inherited from IIncidentSvc
| DeclareInterfaceID (IIncidentSvc, 2, 0)
| InterfaceID.
Public Member Functions inherited from IInterface
virtual unsigned long | addRef ()=0
| Increment the reference count of Interface instance.
virtual unsigned long | release ()=0
| Release Interface instance.
virtual unsigned long | refCount () const =0
| Current reference count.
virtual | ~IInterface ()
| Virtual destructor.

## Private Member Functions
void | i_fireIncident (const Incident &incident, const std::string &type)
| Internal function to allow incidents listening to all events.

## Private Attributes
ListenerMap | m_listenerMap
| List of auditor names.
const std::string * | m_currentIncidentType
| Incident being fired.
boost::recursive_mutex | m_listenerMapMutex
| Mutex to synchronize access to m_listenerMap.
ChronoEntity | m_timer
| timer & it's lock
bool | m_timerLock

## Additional Inherited Members
Static Public Member Functions inherited from IInterface
static const InterfaceID & | interfaceID ()
| Return an instance of InterfaceID identifying the interface.
Protected Member Functions inherited from Service
virtual | ~Service ()
| Standard Destructor.
int | outputLevel () const
| get the `Service's` output level
Protected Attributes inherited from Service
IntegerProperty | m_outputLevel
| Service output level.
Gaudi::StateMachine::State | m_state
| Service state.
Gaudi::StateMachine::State | m_targetState
| Service state.

## Detailed Description

Default implementation of the IIncidentSvc interface.

This implementation is thread-safe with the following features:

- Calls to fireIncident(), addListener() and removeListener() are synchronized across threads.
- Calls to IIncidentListener::handle() are serialized, i.e. at any time there is at most one incident handler being executed across all threads.

Definition at line 34 of file IncidentSvc.h.

## Member Typedef Documentation

typedef std::list<Listener> IncidentSvc::ListenerList

Definition at line 52 of file IncidentSvc.h.

typedef GaudiUtils::HashMap<Gaudi::StringKey, ListenerList*> IncidentSvc::ListenerMap

Definition at line 54 of file IncidentSvc.h.

## Constructor & Destructor Documentation

IncidentSvc::IncidentSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc
| ) |  |

Definition at line 50 of file IncidentSvc.cpp.

: base_class(name, svc)
, m_currentIncidentType(0)
, m_timer()
, m_timerLock ( false )
{}

IncidentSvc::~IncidentSvc | ( |  | ) |
| virtual

Definition at line 57 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
for (ListenerMap::iterator i = m_listenerMap.begin();
i != m_listenerMap.end();
++i) {
delete i->second;
}
}

## Member Function Documentation

void IncidentSvc::addListener | ( | IIncidentListener * | lis,
|  | const std::string & | type = `""`,
|  | long | priority = `0`,
|  | bool | rethrow = `false`,
|  | bool | singleShot = `false`
| ) |  |
| virtual

Add listener.

Parameters

  lis | Listener address
  type | Incident type
  priority | Priority in handling incident

Implements IIncidentSvc.

Definition at line 106 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
std::string ltype;
if( type == "" ) ltype = "ALL";
else ltype = type;
// find if the type already exists
ListenerMap::iterator itMap = m_listenerMap.find( ltype );
if( itMap == m_listenerMap.end() ) {
// if not found, create and insert now a list of listeners
ListenerList* newlist = new ListenerList();
std::pair<ListenerMap::iterator, bool> p;
p = m_listenerMap.insert(ListenerMap::value_type(ltype, newlist));
if( p.second ) itMap = p.first;
}
ListenerList* llist = (*itMap).second;
// add Listener in the ListenerList according to the priority
ListenerList::iterator itlist;
for( itlist = llist->begin(); itlist != llist->end(); itlist++ ) {
if( (*itlist).priority < prio ) {
// We insert before the current position
break;
}
}
DEBMSG << "Adding [" << type << "] listener '" << getListenerName(lis)
<< "' with priority " << prio << endmsg;
llist->insert(itlist, Listener(lis, prio, rethrow, singleShot));
}

StatusCode IncidentSvc::finalize | ( |  | ) |
| virtual

Reimplemented from Service.

Definition at line 91 of file IncidentSvc.cpp.

{
DEBMSG << m_timer.outputUserTime( "Incident timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " , System::milliSec )
<< m_timer.outputUserTime ( "Total:%2%[s]" , System::Sec ) << endmsg ;
// Finalize this specific service
StatusCode sc = Service::finalize();
if ( UNLIKELY(sc.isFailure()) ) { return sc; }
return StatusCode::SUCCESS;
}

void IncidentSvc::fireIncident | ( | const Incident & | incident | ) |
| virtual

Fire an Incident.

Parameters

  Incident | being fired

Implements IIncidentSvc.

Definition at line 283 of file IncidentSvc.cpp.

{
Gaudi::Utils::LockedChrono timer ( m_timer , m_timerLock ) ;
// Call specific listeners
i_fireIncident(incident, incident.type());
// Try listeners registered for ALL incidents
if ( incident.type() != "ALL" ){ // avoid double calls if somebody fires the incident "ALL"
i_fireIncident(incident, "ALL");
}
}

void IncidentSvc::getListeners | ( | std::vector< IIncidentListener * > & | lis,
|  | const std::string & | type = `""`
| ) |  | const
| virtual

Implements IIncidentSvc.

Definition at line 299 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
std::string ltype;
if (type == "") { ltype = "ALL"; } else { ltype = type; }
lis.clear();
ListenerMap::const_iterator itr=m_listenerMap.find( ltype );
if (itr == m_listenerMap.end()) return;
ListenerList::const_iterator itlist;
for (itlist = itr->second->begin(); itlist != itr->second->end(); ++itlist) {
lis.push_back(itlist->iListener);
}
}

void IncidentSvc::i_fireIncident | ( | const Incident & | incident,
|  | const std::string & | type
| ) |  |
| private

Internal function to allow incidents listening to all events.

Definition at line 211 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
// Special case: FailInputFile incident must set the application return code
if (incident.type() == IncidentType::FailInputFile
|| incident.type() == IncidentType::CorruptedInputFile) {
SmartIF<IProperty> appmgr(serviceLocator());
if (incident.type() == IncidentType::FailInputFile)
// Set the return code to Gaudi::ReturnCode::FailInput (2)
Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::FailInput).ignore();
else
Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::CorruptedInput).ignore();
}
ListenerMap::iterator itmap = m_listenerMap.find( listenerType );
if ( m_listenerMap.end() == itmap ) return;
// setting this pointer will avoid that a call to removeListener() during
// the loop triggers a segfault
m_currentIncidentType = &(incident.type());
ListenerList* llist = (*itmap).second;
ListenerList::iterator itlist;
bool weHaveToCleanUp = false;
// loop over all registered Listeners
for( itlist = llist->begin(); itlist != llist->end(); itlist++ )
{
VERMSG << "Calling '" << getListenerName((*itlist).iListener)
<< "' for incident [" << incident.type() << "]" << endmsg;
// handle exceptions if they occur
try {
(*itlist).iListener->handle(incident);
}
catch( const GaudiException& exc ) {
error() << "Exception with tag=" << exc.tag() << " is caught"
" handling incident" << m_currentIncidentType << endmsg;
error() << exc << endmsg;
if ( (*itlist).rethrow ) { throw (exc); }
}
catch( const std::exception& exc ) {
error() << "Standard std::exception is caught"
" handling incident" << m_currentIncidentType << endmsg;
error() << exc.what() << endmsg;
if ( (*itlist).rethrow ) { throw (exc); }
}
catch(...) {
error() << "UNKNOWN Exception is caught"
" handling incident" << m_currentIncidentType << endmsg;
if ( (*itlist).rethrow ) { throw; }
}
// check if at least one of the listeners is a one-shot
weHaveToCleanUp |= itlist->singleShot;
}
if (weHaveToCleanUp) {
// remove all the listeners that need to be removed from the list
llist->remove_if( listenerToBeRemoved() );
// if the list is empty, we can remove it
if( llist->size() == 0) {
delete llist;
m_listenerMap.erase(itmap);
}
}
m_currentIncidentType = 0;
}

StatusCode IncidentSvc::initialize | ( |  | ) |
| virtual

Reimplemented from Service.

Definition at line 70 of file IncidentSvc.cpp.

{
// initialize the Service Base class
StatusCode sc = Service::initialize();
if ( sc.isFailure() ) {
return sc;
}
m_currentIncidentType = 0;
// set my own (IncidentSvc) properties via the jobOptionService
sc = setProperties();
if ( UNLIKELY(sc.isFailure()) )
{
error() << "Could not set my properties" << endmsg;
return sc;
}
return StatusCode::SUCCESS;
}

void IncidentSvc::removeListener | ( | IIncidentListener * | lis,
|  | const std::string & | type = `""`
| ) |  |
| virtual

Remove listener.

Parameters

  lis | Listener address
  type | Incident type

Implements IIncidentSvc.

Definition at line 142 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
if( type == "") {
// remove Listener from all the lists
ListenerMap::iterator itmap;
for ( itmap = m_listenerMap.begin(); itmap != m_listenerMap.end();)
{
// since the current entry may be eventually deleted
// we need to keep a memory of the next index before
// calling recursively this method
ListenerMap::iterator itmap_old = itmap;
itmap++;
removeListener( lis, (*itmap_old).first );
}
}
else {
ListenerMap::iterator itmap = m_listenerMap.find( type );
if( itmap == m_listenerMap.end() ) {
// if not found the incident type then return
return;
}
else {
ListenerList* llist = (*itmap).second;
ListenerList::iterator itlist;
bool justScheduleForRemoval = ( 0!= m_currentIncidentType )
&& (type == *m_currentIncidentType);
// loop over all the entries in the Listener list
// to remove all of them than matches
// the listener address. Remember the next index
// before erasing the current one
for( itlist = llist->begin(); itlist != llist->end(); ) {
if( (*itlist).iListener == lis || lis == 0) {
if (justScheduleForRemoval) {
(itlist++)->singleShot = true; // remove it as soon as it is safe
}
else {
DEBMSG << "Removing [" << type << "] listener '"
<< getListenerName(lis) << "'" << endmsg;
itlist = llist->erase(itlist); // remove from the list now
}
}
else {
itlist++;
}
}
if( llist->size() == 0) {
delete llist;
m_listenerMap.erase(itmap);
}
}
}
}

## Member Data Documentation

const std::string* IncidentSvc::m_currentIncidentType
| private

Incident being fired.

It is used to know if we can safely remove a listener or we have to schedule its removal for later.

Definition at line 94 of file IncidentSvc.h.

ListenerMap IncidentSvc::m_listenerMap
| private

List of auditor names.

Definition at line 90 of file IncidentSvc.h.

boost::recursive_mutex IncidentSvc::m_listenerMapMutex
| mutable private

Mutex to synchronize access to m_listenerMap.

Definition at line 97 of file IncidentSvc.h.

ChronoEntity IncidentSvc::m_timer
| mutable private

timer & it's lock

Definition at line 100 of file IncidentSvc.h.

bool IncidentSvc::m_timerLock
| mutable private

Definition at line 101 of file IncidentSvc.h.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiCoreSvc/src/IncidentSvc/IncidentSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiCoreSvc/src/IncidentSvc/IncidentSvc.cpp