Skip to content
Snippets Groups Projects
Commit 84020b9d authored by Charles Leggett's avatar Charles Leggett
Browse files

Isolate EventContext from Algorithm

in order to not have re-entrant Algorithms stomp on each others' EventContexts, we need to isolate the EventContext from the Algorithm, and move it to the AlgoExecutionTask. We can then pass the EventContext explicitly to the tbb::task, instead of carrying it via the Algorithm, which would fail for re-entrant Algs. This also requires a change to the signature of ForwardSchedulerSvc::promoteToExecuted.

We should also make the EventContext* of the Algorithm const, to prevent any modification from inside the Alg.

See merge request !147
parents 0a4087c8 961f56a9
No related branches found
No related tags found
1 merge request!147Isolate EventContext from Algorithm
Pipeline #
......@@ -19,11 +19,10 @@ tbb::task* AlgoExecutionTask::execute() {
}
bool eventfailed=false;
EventContext* eventContext = this_algo->getContext();
// eventContext->m_thread_id = pthread_self();
Gaudi::Hive::setCurrentContext( eventContext );
this_algo->setContext(m_evtCtx);
Gaudi::Hive::setCurrentContext( m_evtCtx );
m_schedSvc->addAlg(this_algo, eventContext, pthread_self());
m_schedSvc->addAlg(this_algo, m_evtCtx, pthread_self());
// Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
const SmartIF<IProperty> appmgr(m_serviceLocator);
......@@ -59,14 +58,15 @@ tbb::task* AlgoExecutionTask::execute() {
// DP it is important to propagate the failure of an event.
// We need to stop execution when this happens so that execute run can
// then receive the FAILURE
eventContext->setFail(eventfailed);
m_evtCtx->setFail(eventfailed);
// Push in the scheduler queue an action to be performed
auto action_promote2Executed = std::bind(&ForwardSchedulerSvc::promoteToExecuted,
m_schedSvc,
m_algoIndex,
eventContext->slot(),
m_algorithm);
m_evtCtx->slot(),
m_algorithm,
m_evtCtx);
m_schedSvc->m_actionsQueue.push(action_promote2Executed);
......
......@@ -5,6 +5,7 @@
#include "GaudiKernel/IAlgorithm.h"
#include "GaudiKernel/SmartIF.h"
#include "GaudiKernel/ISvcLocator.h"
#include "GaudiKernel/EventContext.h"
#include "ForwardSchedulerSvc.h"
......@@ -15,15 +16,18 @@ class AlgoExecutionTask: public tbb::task {
public:
AlgoExecutionTask(IAlgorithm* algorithm,
unsigned int algoIndex,
EventContext* ctx,
ISvcLocator* svcLocator,
ForwardSchedulerSvc* schedSvc):
m_algorithm(algorithm),
m_evtCtx(ctx),
m_algoIndex(algoIndex),
m_schedSvc(schedSvc),
m_serviceLocator(svcLocator){};
virtual tbb::task* execute();
private:
SmartIF<IAlgorithm> m_algorithm;
EventContext* m_evtCtx;
const unsigned int m_algoIndex;
// For the callbacks on task finishing
SmartIF<ForwardSchedulerSvc> m_schedSvc;
......
......@@ -892,10 +892,11 @@ StatusCode ForwardSchedulerSvc::promoteToScheduled(unsigned int iAlgo, int si) {
++m_algosInFlight;
// Avoid to use tbb if the pool size is 1 and run in this thread
if (-100 != m_threadPoolSize) {
tbb::task* t = new( tbb::task::allocate_root() ) AlgoExecutionTask(ialgoPtr, iAlgo, serviceLocator(), this);
tbb::task* t = new( tbb::task::allocate_root() )
AlgoExecutionTask(ialgoPtr, iAlgo, eventContext, serviceLocator(), this);
tbb::task::enqueue( *t);
} else {
AlgoExecutionTask theTask(ialgoPtr, iAlgo, serviceLocator(), this);
AlgoExecutionTask theTask(ialgoPtr, iAlgo, eventContext, serviceLocator(), this);
theTask.execute();
}
......@@ -925,13 +926,15 @@ StatusCode ForwardSchedulerSvc::promoteToScheduled(unsigned int iAlgo, int si) {
/**
* The call to this method is triggered only from within the AlgoExecutionTask.
*/
StatusCode ForwardSchedulerSvc::promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm* algo) {
StatusCode ForwardSchedulerSvc::promoteToExecuted(unsigned int iAlgo, int si,
IAlgorithm* algo,
EventContext* eventContext) {
// Put back the instance
Algorithm* castedAlgo = dynamic_cast<Algorithm*>(algo); // DP: expose context getter in IAlgo?
if (!castedAlgo)
fatal() << "The casting did not succeed!" << endmsg;
EventContext* eventContext = castedAlgo->getContext();
// EventContext* eventContext = castedAlgo->getContext();
// Check if the execution failed
if (eventContext->evtFail())
......
......@@ -173,7 +173,7 @@ private:
StatusCode promoteToControlReady(unsigned int iAlgo, int si);
StatusCode promoteToDataReady(unsigned int iAlgo, int si);
StatusCode promoteToScheduled(unsigned int iAlgo, int si);
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm* algo);
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm* algo, EventContext*);
StatusCode promoteToFinished(unsigned int iAlgo, int si);
/// Check if the scheduling is in a stall
......
......@@ -19,7 +19,7 @@ StatusCode HiveReadAlgorithm::initialize(){
StatusCode HiveReadAlgorithm::execute()
{
EventContext* ctxt = getContext();
const EventContext* ctxt = getContext();
if (ctxt){
info() << "Running now for event " << ctxt->evt() << endmsg;
}
......
......@@ -568,10 +568,10 @@ public:
// For concurrency
/// get the context
EventContext* getContext() const {return m_event_context;}
const EventContext* getContext() const {return m_event_context;}
/// set the context
void setContext(EventContext* context){m_event_context = context;}
void setContext(const EventContext* context){m_event_context = context;}
// From IDataHandleHolder:
......@@ -668,7 +668,7 @@ protected:
bool isFinalized( ) const override{ return Gaudi::StateMachine::CONFIGURED == m_state; }
/// Event specific data for multiple event processing
EventContext* m_event_context;
const EventContext* m_event_context;
/// set instantiation index of Alg
void setIndex(const unsigned int& idx) override;
......
......@@ -17,7 +17,7 @@ namespace Gaudi {
/// algorithms.
GAUDI_API ContextIdType currentContextId();
GAUDI_API ContextIdType currentContextEvt();
GAUDI_API EventContext currentContext();
GAUDI_API const EventContext& currentContext();
/// Used by the framework to change the value of the current context id.
GAUDI_API void setCurrentContextId(ContextIdType newId);
......
......@@ -11,7 +11,7 @@ namespace Gaudi {
ContextIdType currentContextEvt() {
return s_curCtx.evt();
}
EventContext currentContext() {
const EventContext& currentContext() {
return s_curCtx;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment