The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
Gaudi::TestSuite::QueueingEventLoopMgr Class Reference
Inheritance diagram for Gaudi::TestSuite::QueueingEventLoopMgr:
Collaboration diagram for Gaudi::TestSuite::QueueingEventLoopMgr:

Public Member Functions

StatusCode start () override
StatusCode stop () override
StatusCode executeEvent (EventContext &&ctx) override
void push (EventContext &&ctx) override
bool empty () const override
 Tell if the processor has events in the queues.
std::optional< ResultType > pop () override
 Get the next available result, if any.
Public Member Functions inherited from extends< MinimalEventLoopMgr, Gaudi::Interfaces::IQueueingEventProcessor >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
Public Member Functions inherited from MinimalEventLoopMgr
 MinimalEventLoopMgr (const std::string &nam, ISvcLocator *svcLoc)
 Standard Constructor.
 MinimalEventLoopMgr (const MinimalEventLoopMgr &)=delete
 No copy allowed.
MinimalEventLoopMgr & operator= (const MinimalEventLoopMgr &)=delete
 No copy allowed.
StatusCode initialize () override
 implementation of IService::initialize
StatusCode start () override
 implementation of IService::start
StatusCode stop () override
 implementation of IService::stop
StatusCode finalize () override
 implementation of IService::finalize
StatusCode reinitialize () override
 implementation of IService::reinitialize
StatusCode restart () override
 implementation of IService::restart
EventContext createEventContext () override
 implementation of IEventProcessor::createEventContext()
StatusCode nextEvent (int maxevt) override
 implementation of IEventProcessor::nextEvent
StatusCode executeEvent (EventContext &&ctx) override
 implementation of IEventProcessor::executeEvent(EventContext&&)
StatusCode executeRun (int maxevt) override
 implementation of IEventProcessor::executeRun( )
StatusCode stopRun () override
 implementation of IEventProcessor::stopRun( )
void topAlgHandler (Gaudi::Details::PropertyBase &p)
 Top algorithm List handler.
StatusCode decodeTopAlgs ()
 decodeTopAlgNameList & topAlgNameListHandler
void outStreamHandler (Gaudi::Details::PropertyBase &p)
 Output stream List handler.
StatusCode decodeOutStreams ()
 decodeOutStreamNameList & outStreamNameListHandler
Public Member Functions inherited from extends< Service, IEventProcessor >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
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.
StatusCode sysStart () override
 Initialize Service.
StatusCode sysStop () override
 Initialize Service.
StatusCode sysFinalize () override
 Finalize Service.
StatusCode sysReinitialize () override
 Re-initialize the Service.
StatusCode sysRestart () override
 Re-initialize the Service.
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
const std::vector< IAlgTool * > & tools () const
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 PropertyHolder ()=default
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
Gaudi::Details::PropertyBase * declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
Gaudi::Details::PropertyBase * property (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
PropertyHolder & operator= (const PropertyHolder &)=delete
Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
const 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 cached level (originally extracted from the embedded MsgStream)
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream

Private Member Functions

std::tuple< StatusCode, EventContext > processEvent (EventContext &&context)

Private Attributes

tbb::concurrent_bounded_queue< EventContext > m_incoming
tbb::concurrent_bounded_queue< ResultType > m_done
std::atomic< std::size_t > m_inFlight { 0 }
Gaudi::Property< std::size_t > m_queueCapacity
std::thread m_evtLoopThread

Additional Inherited Members

Public Types inherited from extends< MinimalEventLoopMgr, Gaudi::Interfaces::IQueueingEventProcessor >
using base_class
 Typedef to this class.
using extend_interfaces_base
 Typedef to the base of this class.
Public Types inherited from MinimalEventLoopMgr
typedef std::vector< SmartIF< IAlgorithm > > ListAlg
Public Types inherited from extends< Service, IEventProcessor >
using base_class
 Typedef to this class.
using extend_interfaces_base
 Typedef to the base of this class.
Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
Protected Types inherited from MinimalEventLoopMgr
enum  State { OFFLINE , CONFIGURED , FINALIZED , INITIALIZED }
Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 ~Service () override
int outputLevel () const
 get the Service's output level
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const override final
 Set up local caches.
MSG::Level resetMessaging ()
 Reinitialize internal states.
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
Protected Attributes inherited from MinimalEventLoopMgr
Gaudi::Property< std::vector< std::string > > m_topAlgNames
Gaudi::Property< std::vector< std::string > > m_outStreamNames
Gaudi::Property< bool > m_printCFExp
SmartIF< IAppMgrUI > m_appMgrUI
 Reference to the IAppMgrUI interface of the application manager.
SmartIF< IIncidentSvc > m_incidentSvc
 Reference to the incident service.
SmartIF< IAlgExecStateSvc > m_aess
 List of top level algorithms.
ListAlg m_topAlgList
ListAlg m_outStreamList
 List of output streams.
State m_state = OFFLINE
 State of the object.
bool m_scheduledStop = false
 Scheduled stop of event processing.
AbortEventListener m_abortEventListener
 Instance of the incident listener waiting for AbortEvent.
SmartIF< IHiveWhiteBoard > m_WB
 < Event data service (whiteboard)
size_t m_nevt { 0 }
Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
Gaudi::Property< bool > m_autoRetrieveTools
Gaudi::Property< bool > m_checkToolDeps
SmartIF< IAuditorSvc > m_pAuditorSvc
 Auditor Service.

Detailed Description

Definition at line 25 of file QueueingEventLoopMgr.cpp.

Member Function Documentation

◆ empty()

bool Gaudi::TestSuite::QueueingEventLoopMgr::empty ( ) const
inlineoverride

Tell if the processor has events in the queues.

Definition at line 45 of file QueueingEventLoopMgr.cpp.

45 {
46 // because of the way we count "in flight" (+1 while waiting that we get something from the queue)
47 // and the way tbb:concurrent_bounded_queue reports the size while waiting for pop to return (-1)
48 // this is a correct definition of "empty" (nothing pending, nothing being processed and no results
49 // to be popped)
50 return !( m_inFlight + m_done.size() + m_incoming.size() );
51 }
tbb::concurrent_bounded_queue< ResultType > m_done
tbb::concurrent_bounded_queue< EventContext > m_incoming

◆ executeEvent()

StatusCode Gaudi::TestSuite::QueueingEventLoopMgr::executeEvent ( EventContext && ctx)
inlineoverride

Definition at line 34 of file QueueingEventLoopMgr.cpp.

34 {
35 using namespace std::chrono_literals;
36 push( std::move( ctx ) );
37 std::optional<ResultType> result;
38 while ( !( result = pop() ) ) std::this_thread::sleep_for( 1ms );
39 return std::get<0>( std::move( *result ) );
40 }
void push(EventContext &&ctx) override
std::optional< ResultType > pop() override
Get the next available result, if any.

◆ pop()

std::optional< ResultType > Gaudi::TestSuite::QueueingEventLoopMgr::pop ( )
inlineoverride

Get the next available result, if any.

Definition at line 54 of file QueueingEventLoopMgr.cpp.

54 {
55 ResultType out;
56 if ( m_done.try_pop( out ) )
57 return out;
58 else
59 return std::nullopt;
60 }

◆ processEvent()

std::tuple< StatusCode, EventContext > QueueingEventLoopMgr::processEvent ( EventContext && context)
private

Definition at line 128 of file QueueingEventLoopMgr.cpp.

128 {
129 DEBMSG << "processing " << context << endmsg;
130
131 bool eventfailed = false;
132
133 m_aess->reset( context );
135
136 // select the appropriate store
137 if ( m_WB.isValid() ) m_WB->selectStore( context.slot() ).ignore();
138
139 // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
140 const auto appmgr = serviceLocator()->as<IProperty>();
141 // Call the execute() method of all top algorithms
142 for ( auto& ita : m_topAlgList ) {
143 StatusCode sc( StatusCode::FAILURE );
144 try {
145 if ( m_abortEventListener.abortEvent ) {
146 DEBMSG << "AbortEvent incident fired by " << m_abortEventListener.abortEventSource << endmsg;
147 m_abortEventListener.abortEvent = false;
148 sc.ignore();
149 break;
150 }
151 RetCodeGuard rcg( appmgr, Gaudi::ReturnCode::UnhandledException );
152 sc = ita->sysExecute( context );
153 rcg.ignore(); // disarm the guard
154 } catch ( const GaudiException& Exception ) {
155 fatal() << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by " << ita->name() << endmsg;
156 error() << Exception << endmsg;
157 } catch ( const std::exception& Exception ) {
158 fatal() << ".executeEvent(): Standard std::exception thrown by " << ita->name() << endmsg;
159 error() << Exception.what() << endmsg;
160 } catch ( ... ) { fatal() << ".executeEvent(): UNKNOWN Exception thrown by " << ita->name() << endmsg; }
161
162 if ( !sc.isSuccess() ) {
163 warning() << "Execution of algorithm " << ita->name() << " failed" << endmsg;
164 eventfailed = true;
165 }
166 }
167
168 m_aess->updateEventStatus( eventfailed, context );
169
170 // ensure that the abortEvent flag is cleared before the next event
171 if ( m_abortEventListener.abortEvent ) {
172 DEBMSG << "AbortEvent incident fired by " << m_abortEventListener.abortEventSource << endmsg;
173 m_abortEventListener.abortEvent = false;
174 }
175
176 // Call the execute() method of all output streams
177 for ( auto& ito : m_outStreamList ) {
178 AlgExecStateRef state = m_aess->algExecState( ito, context );
179 state.setFilterPassed( true );
180 StatusCode sc = ito->sysExecute( context );
181 if ( !sc.isSuccess() ) {
182 warning() << "Execution of output stream " << ito->name() << " failed" << endmsg;
183 eventfailed = true;
184 }
185 }
186
187 StatusCode outcome = StatusCode::SUCCESS;
188 // Check if there was an error processing current event
189 if ( eventfailed ) {
190 error() << "Error processing event loop." << endmsg;
191 std::ostringstream ost;
192 m_aess->dump( ost, context );
193 DEBMSG << "Dumping AlgExecStateSvc status:\n" << ost.str() << endmsg;
194 outcome = StatusCode::FAILURE;
195 }
196
197 return { std::move( outcome ), std::move( context ) };
198}
#define DEBMSG
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
ContextID_t slot() const
SmartIF< IFace > as()
Definition ISvcLocator.h:64
ListAlg m_outStreamList
List of output streams.
AbortEventListener m_abortEventListener
Instance of the incident listener waiting for AbortEvent.
SmartIF< IAlgExecStateSvc > m_aess
List of top level algorithms.
SmartIF< IHiveWhiteBoard > m_WB
< Event data service (whiteboard)
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
bool isSuccess() const
Definition StatusCode.h:302
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
constexpr int UnhandledException
GAUDI_API void setCurrentContext(const EventContext *ctx)

◆ push()

void Gaudi::TestSuite::QueueingEventLoopMgr::push ( EventContext && ctx)
inlineoverride

Definition at line 42 of file QueueingEventLoopMgr.cpp.

42{ m_incoming.push( std::move( ctx ) ); }

◆ start()

StatusCode QueueingEventLoopMgr::start ( )
override

Definition at line 100 of file QueueingEventLoopMgr.cpp.

100 {
101 auto ok = base_class::start();
102 if ( !ok ) return ok;
103
105
106 m_evtLoopThread = std::thread( [this]() {
107 while ( true ) {
108 EventContext ctx;
109 ++m_inFlight; // yes, this is not accurate.
110 m_incoming.pop( ctx );
111 if ( ctx.valid() ) {
112 // the sleep is not strictly needed, but it should make the output more stable for the test
113 std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) );
114 m_done.push( processEvent( std::move( ctx ) ) );
115 --m_inFlight; // yes, this is not accurate.
116 } else {
117 DEBMSG << "exiting event loop thread" << endmsg;
118 m_done.emplace( StatusCode::SUCCESS, std::move( ctx ) );
119 --m_inFlight; // yes, this is not accurate.
120 break;
121 }
122 }
123 } );
124
125 return ok;
126}
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Gaudi::Property< std::size_t > m_queueCapacity
std::tuple< StatusCode, EventContext > processEvent(EventContext &&context)

◆ stop()

StatusCode QueueingEventLoopMgr::stop ( )
override

Definition at line 200 of file QueueingEventLoopMgr.cpp.

200 {
201 // Send an invalid context to stop the processing thread
202 push( EventContext{} );
203 m_evtLoopThread.join();
204
205 return base_class::stop();
206}

Member Data Documentation

◆ m_done

tbb::concurrent_bounded_queue<ResultType> Gaudi::TestSuite::QueueingEventLoopMgr::m_done
private

Definition at line 64 of file QueueingEventLoopMgr.cpp.

◆ m_evtLoopThread

std::thread Gaudi::TestSuite::QueueingEventLoopMgr::m_evtLoopThread
private

Definition at line 74 of file QueueingEventLoopMgr.cpp.

◆ m_incoming

tbb::concurrent_bounded_queue<EventContext> Gaudi::TestSuite::QueueingEventLoopMgr::m_incoming
private

Definition at line 63 of file QueueingEventLoopMgr.cpp.

◆ m_inFlight

std::atomic<std::size_t> Gaudi::TestSuite::QueueingEventLoopMgr::m_inFlight { 0 }
private

Definition at line 65 of file QueueingEventLoopMgr.cpp.

65{ 0 };

◆ m_queueCapacity

Gaudi::Property<std::size_t> Gaudi::TestSuite::QueueingEventLoopMgr::m_queueCapacity
private
Initial value:
{
this, "Capacity", m_incoming.capacity() + 1,
[this]( Gaudi::Details::PropertyBase& ) { m_incoming.set_capacity( m_queueCapacity - 1 ); } }
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".

Definition at line 68 of file QueueingEventLoopMgr.cpp.

68 {
69 this, "Capacity", m_incoming.capacity() + 1,
70 [this]( Gaudi::Details::PropertyBase& ) { m_incoming.set_capacity( m_queueCapacity - 1 ); } };

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