Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 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:
Inheritance graph
[legend]
Collaboration diagram for IncidentSvc:
Collaboration graph
[legend]

Classes

struct  Listener
 

Public Types

typedef std::list< ListenerListenerList
 
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 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::stringgetInterfaceNames () 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::stringname () 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 PropertygetProperty (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 >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (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.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () 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::stringm_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 InterfaceIDinterfaceID ()
 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:

Definition at line 37 of file IncidentSvc.h.

Member Typedef Documentation

Definition at line 55 of file IncidentSvc.h.

Definition at line 57 of file IncidentSvc.h.

Constructor & Destructor Documentation

IncidentSvc::IncidentSvc ( const std::string name,
ISvcLocator svc 
)

Definition at line 51 of file IncidentSvc.cpp.

: base_class(name, svc)
, m_timer()
, m_timerLock ( false )
{}
IncidentSvc::~IncidentSvc ( )
virtual

Definition at line 58 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
++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
lisListener address
typeIncident type
priorityPriority in handling incident

Implements IIncidentSvc.

Definition at line 107 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
if( itMap == m_listenerMap.end() ) {
// if not found, create and insert now a list of listeners
ListenerList* newlist = new ListenerList();
if( p.second ) itMap = p.first;
}
ListenerList* llist = (*itMap).second;
// add Listener in the ListenerList according to the priority
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 92 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
if ( UNLIKELY(sc.isFailure()) ) { return sc; }
}
void IncidentSvc::fireIncident ( const Incident incident)
virtual

Fire an Incident.

Parameters
Incidentbeing fired

Implements IIncidentSvc.

Definition at line 284 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 300 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
std::string ltype;
if (type == "") { ltype = "ALL"; } else { ltype = type; }
lis.clear();
if (itr == m_listenerMap.end()) return;
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 212 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)
// Set the return code to Gaudi::ReturnCode::FailInput (2)
else
}
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;
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;
}
}
}
StatusCode IncidentSvc::initialize ( )
virtual

Reimplemented from Service.

Definition at line 71 of file IncidentSvc.cpp.

{
// initialize the Service Base class
if ( sc.isFailure() ) {
return sc;
}
// set my own (IncidentSvc) properties via the jobOptionService
sc = setProperties();
if ( UNLIKELY(sc.isFailure()) )
{
error() << "Could not set my properties" << endmsg;
return sc;
}
}
void IncidentSvc::removeListener ( IIncidentListener lis,
const std::string type = "" 
)
virtual

Remove listener.

Parameters
lisListener address
typeIncident type

Implements IIncidentSvc.

Definition at line 143 of file IncidentSvc.cpp.

{
boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);
if( type == "") {
// remove Listener from all the lists
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 {
if( itmap == m_listenerMap.end() ) {
// if not found the incident type then return
return;
}
else {
ListenerList* llist = (*itmap).second;
bool justScheduleForRemoval = ( 0!= 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;
}
}
}
}

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 97 of file IncidentSvc.h.

ListenerMap IncidentSvc::m_listenerMap
private

List of auditor names.

Definition at line 93 of file IncidentSvc.h.

boost::recursive_mutex IncidentSvc::m_listenerMapMutex
mutableprivate

Mutex to synchronize access to m_listenerMap.

Definition at line 100 of file IncidentSvc.h.

ChronoEntity IncidentSvc::m_timer
mutableprivate

timer & it's lock

Definition at line 103 of file IncidentSvc.h.

bool IncidentSvc::m_timerLock
mutableprivate

Definition at line 104 of file IncidentSvc.h.


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

Generated at Wed Dec 4 2013 14:33:17 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004