Go to the documentation of this file.
11 #ifndef GAUDIHIVE_PRECEDENCERULESGRAPH_H
12 #define GAUDIHIVE_PRECEDENCERULESGRAPH_H
18 #include <unordered_map>
22 #include <boost/filesystem.hpp>
23 #include <boost/graph/adjacency_list.hpp>
24 #include <boost/graph/graphml.hpp>
27 #include "../AlgsExecutionStates.h"
28 #include "../EventSlot.h"
52 long long int start = -1 )
62 using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
137 return props.m_modeConcurrent ?
"Concurrent" :
"Sequential";
155 return props.m_modePromptDecision ?
"Early" :
"Late";
165 return props.m_inverted ?
"Inverted" :
"Non-inverted";
204 log <<
MSG::WARNING <<
"Failed to locate EventDataSvc: no way to add DO "
205 <<
"states to the TTT dump " <<
endmsg;
212 log <<
MSG::WARNING <<
"Failed to locate CondSvc: no way to add Condition DO "
213 <<
"states to the TTT dump " <<
endmsg;
217 log <<
MSG::WARNING <<
"Event context is invalid: no way to add DO states"
218 <<
" in the TTT dump" <<
endmsg;
265 <<
"add algorithm start time to the TTT dumps" <<
endmsg;
282 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
304 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add "
305 <<
"algorithm completion time to the TTT dumps" <<
endmsg;
321 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
343 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add "
344 <<
"algorithm's runtimes to the TTT dumps" <<
endmsg;
375 return props.m_isAsynchronous ?
"Asynchronous" :
"CPU-bound";
391 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
404 class PrecedenceRulesGraph;
488 unsigned int algoIndex )
615 template <
typename T>
617 bool operator()(
const T& a,
const T& b )
const {
return a->name() < b->name(); }
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
float m_rank
Algorithm rank of any kind.
void setAsynchronous(bool value)
Set the asynchronous flag.
virtual bool accept(IGraphVisitor &visitor)=0
Visitor entry point.
SmartIF< ICondSvc > m_condSvc
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
SmartIF< ITimelineSvc > m_timelineSvc
std::vector< AlgorithmNode * > m_producers
DecisionHubProps(const std::string &name, uint nodeIndex, concurrency::Concurrent modeConcurrent, concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR, concurrency::AllPass allPass, concurrency::Inverted isInverted)
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
void dumpPrecTrace(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence trace
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
virtual void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const =0
Print a string representing the control flow state.
void accept(IGraphVisitor &visitor) const
An entry point to visit all graph nodes.
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
std::string operator()(const DecisionHubProps &) const
std::string operator()(const DataProps &) const
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
CondDataProps(const DataObjID &id)
std::vector< AlgorithmNode * > m_consumers
void setRank(float rank)
Set Algorithm rank.
std::string operator()(const DataProps &) const
Class representing an event slot.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
const std::string & name() const
Get node name.
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
std::vector< DataNode * > m_outputs
Algorithm outputs (DataNodes)
SmartIF< ITimelineSvc > m_timelineSvc
EndTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const DecisionHubProps &props) const
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
std::string m_algoName
The name of the algorithm.
unsigned int m_algoIndex
The index of the algorithm.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
bool operator()(const T &a, const T &b) const
SmartIF< IHiveWhiteBoard > m_whiteboard
bool m_isAsynchronous
If an algorithm is asynchronous.
std::string operator()(const DecisionHubProps &) const
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps > PRGraph
bool accept(IGraphVisitor &visitor) override
Need to hide the (identical) base method with this one so that visitEnter(ConditionNode&) and visit(C...
void addParentNode(DecisionNode *node)
Add a parent node.
StatusCode initialize()
Initialize graph.
PrecedenceRulesGraph * m_graph
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
const DataObjID & name() const
std::string operator()(const AlgoProps &) const
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
std::string operator()(const AlgoProps &props) const
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
std::string operator()(const AlgoProps &) const
unsigned int getAlgoIndex() const
Get algorithm index.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const DecisionHubProps &props) const
AlgorithmNode(PrecedenceRulesGraph &graph, Gaudi::Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex)
Constructor.
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
DecisionNode * m_headNode
the head node of the control flow graph
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
std::string operator()(const DataProps &) const
GAUDI_API ISvcLocator * svcLocator()
AlgoTraceProps(const std::string &name, int index=-1, int rank=-1, long int runtime=-1, long long int start=-1)
SmartIF< ITimelineSvc > m_timelineSvc
virtual ~ControlFlowNode()=default
Destructor.
bool isValid() const
Allow for check if smart pointer is valid.
MSG::Level setUpMessaging() const
Set up local caches.
void addInputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
std::ostream & operator<<(std::ostream &o, const Catalog &c)
printout operator
virtual ~DataNode()=default
Destructor.
Base class from which all concrete algorithm classes should be derived.
virtual bool visit(DecisionNode &)
const std::string & name() const override
Retrieve name of the service.
DataProps(const DataObjID &id)
std::string operator()(const DecisionHubProps &props) const
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
virtual ~IPrecedenceRulesGraph()=default
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
std::string operator()(const DecisionHubProps &props) const
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
unsigned int m_nodeCounter
Total number of nodes in the graph.
std::string operator()(const AlgoProps &props) const
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
CFDecision(const EventSlot &slot)
std::string operator()(const DataProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const AlgoProps &) const
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
virtual bool accept(IGraphVisitor &visitor)
Entry point for a visitor.
std::string operator()(const DataProps &props) const
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
StatusCode addDecisionHubNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which aggregates decisions of direct daughter nodes.
std::string operator()(const DataProps &) const
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
const std::vector< ControlFlowNode * > & getDaughters() const
Get children nodes.
bool m_inverted
Whether the selection result is negated or not.
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
float getRank() const
Get Algorithm rank.
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
std::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps
std::string operator()(const DecisionHubProps &) const
DataNode(PrecedenceRulesGraph &graph, const DataObjID &path)
Constructor.
Duration(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const DecisionHubProps &props) const
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
virtual bool visitEnter(DecisionNode &) const
std::string operator()(const CondDataProps &props) const
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
void addProducerNode(AlgorithmNode *node)
Add relationship to producer AlgorithmNode.
EntityState(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator, bool conditionsEnabled)
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
std::vector< DataNode * > m_inputs
Algorithm inputs (DataNodes)
bool m_allPass
Whether always passing regardless of daughter results.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
std::string operator()(const DataProps &props) const
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
void registerIODataObjects(const Gaudi::Algorithm *algo)
Register algorithm in the Data Dependency index.
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.
bool m_inverted
Whether the selection result is negated or not.
StartTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
bool m_isAsynchronous
If an algorithm is asynchronous.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName)
Add algorithm node.
void enableAnalysis()
BGL-based facilities.
std::string operator()(const AlgoProps &) const
std::string operator()(const AlgoProps &props) const
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
std::string operator()(const AlgoProps &props) const
std::string operator()(const DecisionHubProps &) const
std::vector< int > controlFlowState
State of the control flow.
std::string operator()(const DecisionHubProps &props) const
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
std::string operator()(const DataProps &) const
std::vector< DecisionNode * > m_parents
Direct parent nodes.
std::string operator()(const DataProps &) const
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
SmartIF< ICondSvc > m_condSvc
std::string operator()(const DecisionHubProps &) const
DecisionNode * getHeadNode() const
Get head node.
PRVertexDesc node(const std::string &) const
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
ConditionNode(PrecedenceRulesGraph &graph, const DataObjID &path, SmartIF< ICondSvc > condSvc)
Constructor.
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
DataObjID m_data_object_path
bool m_allPass
Whether always passing regardless of daughter results.
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
std::string operator()(const DecisionHubProps &props) const
PrecedenceRulesGraph * m_graph
std::string operator()(const DataProps &) const
AlgsExecutionStates algsStates
Vector of algorithms states.
bool isAsynchronous() const
Check if algorithm is asynchronous.
DecisionNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass, Inverted isInverted)
Constructor.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
Gaudi::Algorithm * getAlgorithm() const
get Algorithm representatives
const unsigned int & getNodeIndex() const
Get node index.
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
std::string operator()(const AlgoProps &) const
void addParentNode(DecisionNode *node)
Add a parent node.
AlgoProps(Gaudi::Algorithm *algo, uint nodeIndex, uint algoIndex)
void addEdgeToPrecTrace(const AlgorithmNode *u, const AlgorithmNode *v)
set cause-effect connection between two algorithms in the precedence trace
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.