12 #include "GaudiKernel/MsgStream.h"
13 #include "GaudiKernel/ISvcLocator.h"
14 #include "GaudiKernel/SmartIF.h"
15 #include "GaudiKernel/IIncidentListener.h"
16 #include "GaudiKernel/Incident.h"
17 #include "GaudiKernel/GaudiException.h"
18 #include "GaudiKernel/LockedChrono.h"
19 #include "GaudiKernel/AppReturnCode.h"
32 static const std::string s_unknown =
"<unknown>" ;
37 return iNamed ? iNamed->name() : s_unknown ;
42 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
43 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
45 #define DEBMSG ON_DEBUG debug()
46 #define VERMSG ON_VERBOSE verbose()
74 error() <<
"Could not set my properties" <<
endmsg;
95 const std::string&
type ,
96 long prio,
bool rethrow,
bool singleShot)
98 static const std::string all{
"ALL" };
101 const std::string& ltype = ( !type.empty() ? type : all );
111 auto& llist = *itMap->second;
118 DEBMSG <<
"Adding [" << type <<
"] listener '" << getListenerName(lis)
119 <<
"' with priority " << prio <<
endmsg;
120 llist.emplace(
i, lis, prio, rethrow, singleShot);
126 bool scheduleRemoval )
128 auto match = [&](ListenerList::const_reference j )
129 {
return !item || item == j.iListener; };
131 auto&
c = *(i->second);
132 if (!scheduleRemoval) {
134 [&](ListenerList::const_reference j) {
135 if (match(j)) debug() <<
"Removing [" << i->first <<
"] listener '"
136 << getListenerName(j.iListener) <<
"'" <<
endmsg;
149 const std::string& type )
168 constexpr
struct isSingleShot_t {
175 const std::string& listenerType )
187 auto appmgr = serviceLocator()->as<
IProperty>();
202 bool firedSingleShot =
false;
204 auto& listeners = *ilisteners->second;
206 for(
auto& listener : listeners )
209 VERMSG <<
"Calling '" << getListenerName(listener.iListener)
210 <<
"' for incident [" << incident.
type() <<
"]" <<
endmsg;
214 listener.iListener->handle(incident);
217 error() <<
"Exception with tag=" << exc.
tag() <<
" is caught"
220 if ( listener.rethrow ) {
throw exc; }
222 catch(
const std::exception& exc ) {
223 error() <<
"Standard std::exception is caught"
225 error() << exc.what() <<
endmsg;
226 if ( listener.rethrow ) {
throw exc; }
229 error() <<
"UNKNOWN Exception is caught"
231 if ( listener.rethrow ) {
throw; }
234 firedSingleShot |= listener.singleShot;
236 if (firedSingleShot) {
238 listeners.erase( std::remove_if(
std::begin(listeners),
std::end(listeners), isSingleShot ),
254 if ( incident.
type() !=
"ALL" ){
262 const std::string& type)
const
264 static const std::string
ALL {
"ALL" };
267 const std::string& ltype = ( !type.empty() ? type :
ALL );
272 l.reserve(
i->second->size());
274 std::back_inserter(l),
StatusCode initialize() override
ChronoEntity m_timer
timer & it's lock
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & type() const
Access to the incident type.
StatusCode finalize() override
StatusCode finalize() override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
auto begin(reverse_wrapper< T > &w)
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
const std::string FailInputFile
could not open or read from this file
bool isFailure() const
Test for a status code of FAILURE.
IncidentSvc(const std::string &name, ISvcLocator *svc)
constexpr int CorruptedInput
int ALL
message levels --------------------------------------------------------—
The interface implemented by any class wanting to listen to Incidents.
std::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
#define DECLARE_COMPONENT(type)
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
void removeListener(IIncidentListener *l, const std::string &type="") override
iterator find(const key_type &key)
virtual const std::string & tag() const
name tag for the exception, or exception type
StatusCode initialize() override
std::vector< Listener > ListenerList
const std::string * m_currentIncidentType
Incident being fired.
IIncidentListener * iListener
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
std::string outputUserTime() const
print the chrono ;
map_type::iterator iterator
Helper object, useful for measurement of CPU-performance of highly-recursive structures, e.g.
iterator erase(const_iterator pos)
Base class used to extend a class implementing other interfaces.
void i_fireIncident(const Incident &incident, const std::string &type)
Internal function to allow incidents listening to all events.
Base class for all Incidents (computing events).
std::pair< iterator, bool > insert(ValueType &&val)
void fireIncident(const Incident &incident) override
ListenerMap m_listenerMap
List of auditor names.
Default implementation of the IIncidentSvc interface.
The IProperty is the basic interface for all components which have properties that can be set or get...
const std::string CorruptedInputFile
the input file has shown a corruption