2 #include "GaudiKernel/SvcFactory.h"
3 #include "GaudiKernel/IAlgorithm.h"
4 #include "GaudiKernel/Algorithm.h"
5 #include "GaudiKernel/IProperty.h"
6 #include "GaudiKernel/AppReturnCode.h"
7 #include "GaudiKernel/CommonMessaging.h"
8 #include "GaudiKernel/IDataManagerSvc.h"
10 #include "GaudiKernel/ContextSpecificPtr.h"
31 declareProperty(
"AlgosDependencies", m_algosDependencies);
32 declareProperty(
"UseTopAlgList", m_useTopAlgList =
false);
33 declareProperty(
"ThreadPoolSize", m_threadPoolSize = -1);
34 declareProperty(
"WhiteboardSvc", m_whiteboardSvcName =
"EventDataSvc");
47 warning () <<
"Base class could not be initialized" <<
endmsg;
52 error() <<
"Error retrieving AlgResourcePool" <<
endmsg;
63 fatal() <<
"Error retrieving EventDataSvc interface IHiveWhiteBoard." <<
endmsg;
85 const std::string&
name = algo->name();
97 info() <<
"Algodependecies size is " << algosDependenciesSize <<
endmsg;
105 if (algosDependenciesSize == 0){
108 std::string rootInTESName(dataMgrSvc->
rootName());
109 if (
"" != rootInTESName &&
'/'!=rootInTESName[rootInTESName.size()-1]){
110 rootInTESName = rootInTESName+
"/";
115 if (
nullptr == algoPtr){
116 fatal() <<
"Could not convert IAlgorithm into Algorithm: this will result in a crash." <<
endmsg;
119 #pragma GCC diagnostic push
120 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
121 const std::vector<MinimalDataObjectHandle*>& algoHandles(algoPtr->handles());
122 #pragma GCC diagnostic pop
123 std::vector<std::string> algoDependencies;
124 if (!algoHandles.empty()){
126 info() <<
"Algorithm " << algoPtr->
name() <<
" data dependencies:" <<
endmsg;
129 const std::string& productName = rootInTESName + handlePtr->dataProductName();
130 info() <<
" o READ Handle found for product " << productName <<
endmsg;
131 algoDependencies.emplace_back(productName);
135 info() <<
"Algorithm " << algoPtr->
name() <<
" has no data dependencies." <<
endmsg;
152 warning () <<
"Base class could not be finalized" <<
endmsg;
160 std::vector<EventContext*> eventContexts;
161 eventContexts.push_back(eventContext);
168 for(
auto evt : eventContexts){
173 debug() <<
"Enqueuing event " <<
evt->evt() <<
" @ " <<
evt->slot() <<
endmsg;
175 tbb::task* t =
new( tbb::task::allocate_root() )
177 tbb::task::enqueue( *t);
194 debug() <<
"Popped slot " << eventContext->
slot() <<
"(event "
206 debug() <<
"Try Pop successful slot " << eventContext->
slot()
207 <<
"(event " << eventContext->
evt() <<
")" <<
endmsg;
228 MsgStream log(messageSvc,
"SequentialAlgoExecutionTask");
236 std::vector<int> nodeDecisions(algPool->getExecutionFlowGraph()->getControlFlowNodeCounter(), -1);
246 bool eventFailed =
false;
250 while(!eventFailed && algStates.algsPresent(AlgsExecutionStates::State::CONTROLREADY) ){
257 for(
auto it = algStates.begin(AlgsExecutionStates::State::CONTROLREADY); it != algStates.end(AlgsExecutionStates::State::CONTROLREADY); ++it){
272 if(sc.
isFailure() || ialgoPtr ==
nullptr){
293 log <<
MSG::ERROR <<
".executeEvent(): Exception with tag=" << Exception.
tag()
294 <<
" thrown by " << algName <<
endmsg;
296 }
catch (
const std::exception& Exception ) {
297 log <<
MSG::FATAL <<
".executeEvent(): Standard std::exception thrown by "
301 log <<
MSG::FATAL <<
".executeEvent(): UNKNOWN Exception thrown by "
312 << (eventFailed ?
" failed" :
" succeded") <<
endmsg;
316 state = AlgsExecutionStates::State::EVTACCEPTED;
318 state = AlgsExecutionStates::State::EVTREJECTED;
328 algStates.updateState(algIndex,state);
355 if(!algStates.algsPresent(AlgsExecutionStates::State::CONTROLREADY) && !algStates.allAlgsExecuted()){
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
Definition of the MsgStream class used to transmit messages.
StatusCode initialize() override
virtual StatusCode acquireAlgorithm(const std::string &name, IAlgorithm *&algo, bool blocking=false)=0
Acquire a certain algorithm using its name.
virtual tbb::task * execute()
Define general base for Gaudi exception.
Helper class to set the application return code in case of early exit (e.g.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
void updateEventState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions) const
Update the state of algorithms to controlready, where possible.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode finalize() override
bool isSuccess() const
Test for a status code of SUCCESS.
std::unique_ptr< tbb::task_scheduler_init > m_tbb_sched
SmartIF< ParallelSequentialSchedulerSvc > m_scheduler
EventContext * m_eventContext
tbb::concurrent_bounded_queue< EventContext * > m_finishedEvents
Queue of finished events.
virtual size_t getNumberOfStores()=0
Get the number of 'slots'.
virtual std::list< IAlgorithm * > getFlatAlgList()=0
Get the flat list of algorithms.
The AlgResourcePool is a concrete implementation of the IAlgResourcePool interface.
This class represents an entry point to all the event specific data.
bool isFailure() const
Test for a status code of FAILURE.
GAUDI_API void setCurrentContextId(ContextIdType newId)
Used by the framework to change the value of the current context id.
virtual StatusCode pushNewEvent(EventContext *eventContext)
Make an event available to the scheduler.
void setContext(EventContext *context)
set the context
const std::string & name() const override
The identifying name of the algorithm object.
constexpr int UnhandledException
TYPE * get() const
Get interface pointer.
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
SmartIF< IHiveWhiteBoard > m_whiteboard
A shortcut to the whiteboard.
int m_threadPoolSize
Size of the threadpool initialised by TBB; a value of -1 gives TBB the freedom to choose...
virtual std::list< IAlgorithm * > getTopAlgList()=0
Get top list of algorithms.
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
SmartIF< IAlgResourcePool > m_algPool
void promoteToControlReadyState(AlgsExecutionStates &algo_states, std::vector< int > &node_decisions, const int &slotNum=-1) const
XXX: CF tests.
virtual StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts)
This class is used for returning status codes from appropriate routines.
StatusCode sysExecute() override
The actions to be performed by the algorithm on an event.
void setFail(const bool &b=true)
std::string m_whiteboardSvcName
The whiteboard name.
std::atomic_int m_freeSlots
Atomic to account for asyncronous updates by the scheduler wrt the rest.
virtual const std::string & tag() const
name tag for the exception, or exception type
#define DECLARE_SERVICE_FACTORY(x)
virtual unsigned int freeSlots()
Get free slots number.
virtual concurrency::ExecutionFlowGraph * getExecutionFlowGraph() const
~ParallelSequentialSchedulerSvc()
Destructor.
The IAlgorithm is the interface implemented by the Algorithm base class.
virtual const std::string & rootName() const =0
Get Name of root Event.
virtual bool filterPassed() const =0
Did this algorithm pass or fail its filter criterion for the last event?
Base class from which all concrete algorithm classes should be derived.
bool isValid() const
Allow for check if smart pointer is valid.
Base class used to extend a class implementing other interfaces.
SmartIF< ISvcLocator > m_serviceLocator
virtual StatusCode finalize()
Finalise.
void activate()
Activate MsgStream.
StatusCode initialize(ExecutionFlowGraph *CFGraph, const std::unordered_map< std::string, unsigned int > &algname_index_map)
Initialize the control flow manager It greps the topalg list and the index map for the algo names...
State
Execution states of the algorithms.
virtual StatusCode releaseAlgorithm(const std::string &name, IAlgorithm *&algo)=0
Release a certain algorithm.
std::vector< std::string > m_algname_vect
Vector to bookkeep the information necessary to the index2name conversion.
concurrency::ExecutionFlowManager m_controlFlow
This SchedulerSvc implements the IScheduler interface.
friend class SequentialTask
virtual StatusCode initialize()
Initialise.
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
std::unordered_map< std::string, unsigned int > m_algname_index_map
Map to bookkeep the information necessary to the name2index conversion.
virtual StatusCode tryPopFinishedEvent(EventContext *&eventContext)
Try to fetch an event from the scheduler.
std::vector< std::vector< std::string > > m_algosDependencies
Ugly, will disappear when the deps are declared only within the C++ code of the algos.
virtual StatusCode popFinishedEvent(EventContext *&eventContext)
Blocks until an event is availble.