1 #ifndef GAUDIHIVE_PRECEDENCERULESGRAPH_H 2 #define GAUDIHIVE_PRECEDENCERULESGRAPH_H 8 #include <unordered_map> 11 #include <boost/filesystem.hpp> 12 #include <boost/graph/adjacency_list.hpp> 13 #include <boost/graph/graphml.hpp> 14 #include <boost/variant.hpp> 30 using Concurrent = Gaudi::tagged_bool<class Concurrent_tag>;
32 using ModeOr = Gaudi::tagged_bool<class ModeOr_tag>;
33 using AllPass = Gaudi::tagged_bool<class AllPass_tag>;
34 using Inverted = Gaudi::tagged_bool<class Inverted_tag>;
39 using boost::static_visitor;
45 : m_name( name ), m_index( index ), m_rank( rank ), m_runtime( runtime )
52 int m_eccentricity{-1};
55 using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
62 : m_name( algo->
name() )
63 , m_nodeIndex( nodeIndex )
64 , m_algoIndex( algoIndex )
66 , m_inverted( inverted )
67 , m_allPass( allPass )
68 , m_isIOBound( algo->isIOBound() )
80 bool m_inverted{
false};
82 bool m_allPass{
false};
84 bool m_isIOBound{
false};
92 , m_nodeIndex( nodeIndex )
93 , m_modeConcurrent( modeConcurrent )
94 , m_modePromptDecision( modePromptDecision )
95 , m_inverted( isInverted )
97 , m_allPass( allPass )
110 bool m_inverted{
false};
175 struct AllPass : static_visitor<std::string> {
203 : m_slot( slot ), m_conditionsEnabled( conditionsEnabled )
210 if ( !m_whiteboard.isValid() ) {
211 log <<
MSG::WARNING <<
"Failed to locate EventDataSvc: no way to add DO " 212 <<
"states to the TTT dump " <<
endmsg;
215 if ( m_conditionsEnabled ) {
218 if ( !m_condSvc.isValid() )
219 log <<
MSG::WARNING <<
"Failed to locate CondSvc: no way to add Condition DO " 220 <<
"states to the TTT dump " <<
endmsg;
223 if ( !m_slot.eventContext->valid() )
224 log <<
MSG::WARNING <<
"Event context is invalid: no way to add DO states" 225 <<
" in the TTT dump" <<
endmsg;
241 if ( m_whiteboard.isValid() && m_slot.eventContext->valid() )
242 if ( m_whiteboard->selectStore( m_slot.eventContext->slot() ).isSuccess() )
243 state = m_whiteboard->exists( props.
m_id ) ?
"Produced" :
"Missing";
252 if ( m_condSvc.isValid() && m_slot.eventContext->valid() )
253 state = m_condSvc->isValidID( *( m_slot.eventContext ), props.
m_id ) ?
"Produced" :
"Missing";
262 bool m_conditionsEnabled{
false};
273 if ( !m_timelineSvc.isValid() ) {
275 <<
"add algorithm start time to the TTT dumps" <<
endmsg;
284 if ( m_timelineSvc.isValid() ) {
288 te.slot = m_slot.eventContext->slot();
289 te.event = m_slot.eventContext->evt();
291 m_timelineSvc->getTimelineEvent( te );
293 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
307 struct EndTime : static_visitor<std::string> {
315 if ( !m_timelineSvc.isValid() )
316 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add " 317 <<
"algorithm completion time to the TTT dumps" <<
endmsg;
325 if ( m_timelineSvc.isValid() ) {
329 te.slot = m_slot.eventContext->slot();
330 te.event = m_slot.eventContext->evt();
332 m_timelineSvc->getTimelineEvent( te );
334 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
356 if ( !m_timelineSvc.isValid() )
357 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add " 358 <<
"algorithm's runtimes to the TTT dumps" <<
endmsg;
366 if ( m_timelineSvc.isValid() ) {
370 te.
slot = m_slot.eventContext->slot();
371 te.
event = m_slot.eventContext->evt();
373 m_timelineSvc->getTimelineEvent( te );
374 time =
std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.
end - te.
start ).count() );
404 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
418 class PrecedenceRulesGraph;
433 : m_graph( &graph ), m_nodeIndex( nodeIndex ), m_nodeName( name )
443 const std::vector<int>& node_decisions,
const unsigned int& recursionLevel )
const = 0;
465 , m_modeConcurrent( modeConcurrent )
466 , m_modePromptDecision( modePromptDecision )
468 , m_allPass( allPass )
469 , m_inverted( isInverted )
483 const unsigned int& recursionLevel )
const override;
496 bool m_inverted{
false};
511 bool inverted,
bool allPass )
513 , m_algorithm( algoPtr )
514 , m_algoIndex( algoIndex )
515 , m_algoName( algoPtr->
name() )
516 , m_inverted( inverted )
517 , m_allPass( allPass )
518 , m_isIOBound( algoPtr->isIOBound() ){};
529 void addOutputDataNode(
DataNode* node );
531 void addInputDataNode(
DataNode* node );
538 void setRank(
float& rank ) { m_rank = rank; }
540 const float&
getRank()
const {
return m_rank; }
555 bool isLiar()
const {
return m_inverted; };
559 const unsigned int& recursionLevel )
const override;
607 if (
std::find( m_producers.begin(), m_producers.end(), node ) == m_producers.end() )
608 m_producers.push_back( node );
613 if (
std::find( m_consumers.begin(), m_consumers.end(), node ) == m_consumers.end() )
614 m_consumers.push_back( node );
635 :
DataNode( graph, path ), m_condSvc( condSvc )
679 void registerIODataObjects(
const Algorithm* algo );
693 return m_algoNameToAlgoNodeMap.at( algoName ).get();
712 const unsigned int& recursionLevel )
const 714 m_headNode->printState( output, states, node_decisions, recursionLevel );
748 unsigned int m_nodeCounter = 0;
750 unsigned int m_algoCounter = 0;
759 bool m_enableAnalysis{
false};
764 bool m_conditionsRealmEnabled{
false};
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
std::vector< DataNode * > m_outputs
Algorithm outputs (DataNodes)
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps > PRGraph
std::string operator()(const DecisionHubProps &props) const
Definition of the MsgStream class used to transmit messages.
const unsigned int & getAlgoIndex() const
Get algorithm index.
std::string operator()(const DecisionHubProps &) const
std::vector< DecisionNode * > m_parents
Direct parent nodes.
AlgoTraceProps(const std::string &name, int index, int rank, double runtime)
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
std::string operator()(const AlgoProps &props) const
unsigned int m_algoIndex
The index of the algorithm.
std::string operator()(const AlgoProps &props) const
AlgoProps(Algorithm *algo, uint nodeIndex, uint algoIndex, bool inverted, bool allPass)
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
void setIOBound(bool value)
Set the I/O-boundness flag.
CondDataProps(const DataObjID &id)
std::string operator()(const AlgoProps &props) const
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
std::string m_algoName
The name of the algorithm.
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
bool isOptimist() const
Check if positive control flow decision is enforced.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
virtual bool visit(DecisionNode &)
void setRank(float &rank)
Set Algorithm rank.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
std::string operator()(const CondDataProps &props) const
EntityState(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator, bool conditionsEnabled)
std::string operator()(const AlgoProps &) const
std::string operator()(const DecisionHubProps &props) const
DataProps(const DataObjID &id)
void printState(std::stringstream &output, AlgsExecutionStates &states, const std::vector< int > &node_decisions, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
bool m_isIOBound
If an algorithm is blocking.
SmartIF< ITimelineSvc > m_timelineSvc
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
std::string operator()(const DataProps &) const
bool m_allPass
Whether always passing regardless of daughter results.
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
bool m_inverted
Whether the selection result is negated or not.
bool m_allPass
Whether always passing regardless of daughter results.
std::string operator()(const DataProps &) const
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
std::string operator()(const DecisionHubProps &props) const
bool isIOBound() const
Check if algorithm is I/O-bound.
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
std::string operator()(const DataProps &props) const
SmartIF< ITimelineSvc > m_timelineSvc
virtual bool visitEnter(DecisionNode &) const
Algorithm * getAlgorithm() const
get Algorithm representatives
std::string operator()(const DecisionHubProps &) const
std::string operator()(const DataProps &) const
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
std::string operator()(const AlgoProps &) const
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
std::string operator()(const DataProps &) const
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
SmartIF< ITimelineSvc > m_timelineSvc
Duration(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
const float & getRank() const
Get Algorithm rank.
The AlgsExecutionStates encodes the state machine for the execution of algorithms within a single eve...
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
GAUDI_API ISvcLocator * svcLocator()
PrecedenceRulesGraph * m_graph
Gaudi::tagged_bool< class Inverted_tag > Inverted
std::string operator()(const DataProps &) const
void enableAnalysis()
BGL-based facilities.
const DataObjID & getPath()
std::string operator()(const DecisionHubProps &) const
std::vector< AlgorithmNode * > m_consumers
SmartIF< ICondSvc > m_condSvc
DecisionNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass, Inverted isInverted)
Constructor.
This class is used for returning status codes from appropriate routines.
virtual bool accept(IGraphVisitor &visitor)
Entry point for a visitor.
const std::vector< ControlFlowNode * > & getDaughters() const
Get children nodes.
std::string operator()(const AlgoProps &props) const
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
EndTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const DecisionHubProps &) const
DataNode(PrecedenceRulesGraph &graph, const DataObjID &path)
Constructor.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
std::string operator()(const AlgoProps &props) const
Interface for the Condition Service.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
bool m_allPass
Whether the selection result is relevant or always "pass".
bool m_inverted
Whether the selection result is negated or not.
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
Gaudi::tagged_bool< class Concurrent_tag > Concurrent
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
DataObjID m_data_object_path
std::string operator()(const DecisionHubProps &) const
Base class from which all concrete algorithm classes should be derived.
std::string operator()(const DecisionHubProps &) const
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
std::vector< InputHandle_t< In > > m_inputs
std::string operator()(const AlgoProps &props) const
SmartIF< IHiveWhiteBoard > m_whiteboard
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
std::vector< DataNode * > m_inputs
Algorithm inputs (DataNodes)
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
std::vector< AlgorithmNode * > m_producers
std::string operator()(const DataProps &) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
Class representing the event slot.
Gaudi::tagged_bool< class AllPass_tag > AllPass
std::string operator()(const DecisionHubProps &props) const
bool isLiar() const
Check if control flow logic is always inverted.
DecisionHubProps(const std::string &name, uint nodeIndex, concurrency::Concurrent modeConcurrent, concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR, concurrency::AllPass allPass, concurrency::Inverted isInverted)
PrecedenceRulesGraph * m_graph
AlgorithmNode(PrecedenceRulesGraph &graph, Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex, bool inverted, bool allPass)
Constructor.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
const std::string & getNodeName() const
Get node name.
const unsigned int & getNodeIndex() const
Get node index.
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
std::string operator()(const DecisionHubProps &props) const
std::string fullKey() const
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
bool accept(IGraphVisitor &visitor) override
Need to hide the (identical) base method with this one so that visitEnter(ConditionNode&) and visit(C...
std::string operator()(const DataProps &) const
const std::string & name() const override
Retrieve name of the service.
bool m_isIOBound
If an algorithm is blocking.
StartTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const DecisionHubProps &props) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &props) const
bool m_allPass
Whether the selection result is relevant or always "pass".
void addProducerNode(AlgorithmNode *node)
Add relationship to producer AlgorithmNode.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
std::string operator()(const DataProps &) const
boost::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps
SmartIF< ICondSvc > m_condSvc
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
ConditionNode(PrecedenceRulesGraph &graph, const DataObjID &path, SmartIF< ICondSvc > condSvc)
Constructor.
DecisionNode * getHeadNode() const
Get head node.
std::string operator()(const DataProps &) const
CFDecision(const EventSlot &slot)
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.