Loading [MathJax]/extensions/tex2jax.js
Go to the documentation of this file.
25 static const std::string s_unknown =
"<unknown>";
29 return iNamed ? iNamed->name() : s_unknown;
33 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
34 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
36 #define DEBMSG ON_DEBUG debug()
37 #define VERMSG ON_VERBOSE verbose()
52 static const std::string
all{
"ALL" };
55 const std::string& ltype = ( !
type.empty() ?
type :
all );
66 auto& llist = *itMap->second;
71 [&](
const Listener&
j ) {
return j.priority >= prio; } );
73 DEBMSG <<
"Adding [" <<
type <<
"] listener '" << getListenerName( lis ) <<
"' with priority " << prio <<
endmsg;
78 auto match = [&]( ListenerList::const_reference
j ) {
return !item || item ==
j.iListener; };
80 auto&
c = *( i->second );
81 if ( !scheduleRemoval ) {
84 debug() <<
"Removing [" << i->first <<
"] listener '" << getListenerName(
j.iListener ) <<
"'" <<
endmsg;
89 if ( match( i ) ) i.singleShot =
true;
108 constexpr
struct isSingleShot_t {
109 bool operator()(
const IncidentSvc::Listener&
l )
const {
return l.singleShot; }
121 if ( incident.
type() == IncidentType::FailInputFile || incident.
type() == IncidentType::CorruptedInputFile ) {
135 std::string curIncTyp;
139 curIncTyp =
"UNKNOWN";
142 bool firedSingleShot =
false;
144 auto& listeners = *ilisteners->second;
146 for (
auto& listener : listeners ) {
148 VERMSG <<
"Calling '" << getListenerName( listener.iListener ) <<
"' for incident [" << incident.
type() <<
"]"
153 listener.iListener->handle( incident );
155 error() <<
"Exception with tag=" << exc.
tag()
157 " handling incident "
158 << curIncTyp <<
" in listener " << getListenerName( listener.iListener ) <<
endmsg;
160 if ( listener.rethrow ) {
throw exc; }
161 }
catch (
const std::exception& exc ) {
162 error() <<
"Standard std::exception is caught"
163 " handling incident "
164 << curIncTyp <<
" in listener " << getListenerName( listener.iListener ) <<
endmsg;
165 error() << exc.what() <<
endmsg;
166 if ( listener.rethrow ) {
throw exc; }
168 error() <<
"UNKNOWN Exception is caught"
169 " handling incident "
170 << curIncTyp <<
" in listener " << getListenerName( listener.iListener ) <<
endmsg;
171 if ( listener.rethrow ) {
throw; }
174 firedSingleShot |= listener.singleShot;
176 if ( firedSingleShot ) {
178 listeners.erase( std::remove_if(
std::begin( listeners ),
std::end( listeners ), isSingleShot ),
192 if ( incident.
type() !=
"ALL" ) {
199 DEBMSG <<
"Async incident '" << incident->
type() <<
"' fired on context " <<
ctx <<
endmsg;
207 if ( slotItr->second !=
ctx.evt() ) {
208 slotItr->second =
ctx.evt();
211 debug() <<
"Clearing remaining obsolete incidents from slot " <<
ctx.slot() <<
":";
212 std::unique_ptr<Incident> inc;
213 while ( incItr->second.try_pop( inc ) ) { debug() <<
" " << inc->
type() <<
"(" << inc->
context() <<
")"; }
216 incItr->second.
clear();
218 incItr->second.push( std::move( incident ) );
222 static const std::string
ALL{
"ALL" };
225 const std::string& ltype = ( !
type.empty() ?
type :
ALL );
230 l.reserve( i->second->size() );
232 [](
const Listener&
j ) { return j.iListener; } );
241 std::unique_ptr<Incident> inc;
244 while ( incs->second.try_pop( inc ) ) {
250 p.emplace_back( std::move( inc ), std::vector<Listener>{ i->second->begin(), i->second->end() } );
tbb::concurrent_queue< std::unique_ptr< Incident > > IncQueue_t
iterator find(const key_type &key)
void i_fireIncident(const Incident &incident, const std::string &type)
Internal function to allow incidents listening to all events.
tbb::concurrent_unordered_map< EventContext::ContextID_t, IncQueue_t > m_firedIncidents
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
StatusCode finalize() override
ChronoEntity m_timer
timer & it's lock
Default implementation of the IIncidentSvc interface.
EventContext context() const
Access to the EventContext of the source of the incident.
AttribStringParser::Iterator begin(const AttribStringParser &parser)
void for_each(ContainerOfSynced &c, Fun &&f)
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
std::string outputUserTime() const
print the chrono ;
constexpr int CorruptedInput
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
void clear(STATE_TYPE _i=std::ios_base::failbit)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual const std::string & tag() const
name tag for the exception, or exception type
tbb::concurrent_unordered_map< EventContext::ContextID_t, EventContext::ContextEvt_t > m_slotEvent
Event ID for each slot.
std::vector< std::pair< std::unique_ptr< Incident >, std::vector< Listener > > > IncidentPack
List of incidents and their listeners.
iterator erase(const_iterator pos)
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
SmartIF< IFace > as() const
return a new SmartIF instance to another interface
void fireIncident(const Incident &incident) override
#define DECLARE_COMPONENT(type)
std::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
map_type::iterator iterator
std::pair< iterator, bool > insert(ValueType &&val)
void removeListener(IIncidentListener *l, const std::string &type="") override
const std::string & type() const
Access to the incident type.
IncidentSvc(const std::string &name, ISvcLocator *svc)
const std::string * m_currentIncidentType
Incident being fired.
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
ListenerMap m_listenerMap
List of auditor names.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
StatusCode finalize() override