1 #ifndef GAUDIHIVE_PRECEDENCERULESGRAPH_H 2 #define GAUDIHIVE_PRECEDENCERULESGRAPH_H 8 #include <unordered_map> 12 #include <boost/filesystem.hpp> 13 #include <boost/graph/adjacency_list.hpp> 14 #include <boost/graph/graphml.hpp> 17 #include "../AlgsExecutionStates.h" 18 #include "../EventSlot.h" 29 using Concurrent = Gaudi::tagged_bool<class Concurrent_tag>;
31 using ModeOr = Gaudi::tagged_bool<class ModeOr_tag>;
32 using AllPass = Gaudi::tagged_bool<class AllPass_tag>;
33 using Inverted = Gaudi::tagged_bool<class Inverted_tag>;
50 using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
197 log <<
MSG::WARNING <<
"Failed to locate EventDataSvc: no way to add DO " 198 <<
"states to the TTT dump " <<
endmsg;
205 log <<
MSG::WARNING <<
"Failed to locate CondSvc: no way to add Condition DO " 206 <<
"states to the TTT dump " <<
endmsg;
210 log <<
MSG::WARNING <<
"Event context is invalid: no way to add DO states" 211 <<
" in the TTT dump" <<
endmsg;
258 <<
"add algorithm start time to the TTT dumps" <<
endmsg;
275 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
297 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add " 298 <<
"algorithm completion time to the TTT dumps" <<
endmsg;
314 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
336 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add " 337 <<
"algorithm's runtimes to the TTT dumps" <<
endmsg;
382 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
395 class PrecedenceRulesGraph;
479 unsigned int algoIndex,
bool inverted,
bool allPass )
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
std::string operator()(const DecisionHubProps &) const
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.
std::string operator()(const DataProps &) const
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Class representing an event slot.
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.
const std::string & getNodeName() const
Get node name.
unsigned int m_algoIndex
The index of the algorithm.
bool m_inverted
Whether the selection result is negated or not.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
AlgorithmNode(PrecedenceRulesGraph &graph, Gaudi::Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex, bool inverted, bool allPass)
Constructor.
void setIOBound(bool value)
Set the I/O-boundness flag.
CondDataProps(const DataObjID &id)
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
std::string operator()(const DataProps &props) const
std::string m_algoName
The name of the algorithm.
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
virtual bool visit(DecisionNode &)
std::string operator()(const DecisionHubProps &props) const
void setRank(float &rank)
Set Algorithm rank.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
virtual bool visitEnter(DecisionNode &) const
Gaudi::Algorithm * getAlgorithm() const
get Algorithm representatives
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
EntityState(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator, bool conditionsEnabled)
std::string operator()(const CondDataProps &props) const
DataProps(const DataObjID &id)
bool isValid() const
Allow for check if smart pointer is valid.
std::string operator()(const DecisionHubProps &props) const
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
std::string operator()(const DecisionHubProps &) const
virtual bool getTimelineEvent(TimelineEvent &) const =0
bool m_isIOBound
If an algorithm is blocking.
SmartIF< ITimelineSvc > m_timelineSvc
std::vector< int > controlFlowState
State of the control flow.
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
bool m_allPass
Whether always passing regardless of daughter results.
virtual bool accept(IGraphVisitor &visitor)=0
Visitor entry point.
virtual bool exists(const DataObjID &)=0
Check if a data object exists in store.
std::string operator()(const DataProps &) const
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
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 AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
std::string fullKey() const
virtual ~IPrecedenceRulesGraph()=default
bool isOptimist() const
Check if positive control flow decision is enforced.
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
MSG::Level setUpMessaging() const
Set up local caches.
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
SmartIF< ITimelineSvc > m_timelineSvc
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
std::string operator()(const DataProps &) const
const unsigned int & getAlgoIndex() const
Get algorithm index.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
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.
void addInputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
StatusCode initialize()
Initialize graph.
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
SmartIF< ITimelineSvc > m_timelineSvc
void dumpPrecTrace(const boost::filesystem::path &)
dump to file the precedence trace
Duration(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
std::string operator()(const DecisionHubProps &props) const
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given 'slot' for all subsequent calls within the same thread id.
std::string operator()(const AlgoProps &) const
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
bool isIOBound() const
Check if algorithm is I/O-bound.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
GAUDI_API ISvcLocator * svcLocator()
PrecedenceRulesGraph * m_graph
Gaudi::tagged_bool< class Inverted_tag > Inverted
void enableAnalysis()
BGL-based facilities.
const DataObjID & getPath()
DecisionNode * m_headNode
the head node of the control flow graph
std::string operator()(const DataProps &) 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.
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
virtual bool accept(IGraphVisitor &visitor)
Entry point for a visitor.
virtual bool isValidID(const EventContext &ctx, const DataObjID &id) const =0
check to see if a specific condition object ID is valid for this event
std::string operator()(const DecisionHubProps &) const
std::string operator()(const DecisionHubProps &) const
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
EndTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
const float & getRank() const
Get Algorithm rank.
DataNode(PrecedenceRulesGraph &graph, const DataObjID &path)
Constructor.
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
void registerIODataObjects(const Gaudi::Algorithm *algo)
Register algorithm in the Data Dependency index.
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.
std::string operator()(const DataProps &props) const
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
const std::vector< ControlFlowNode * > & getDaughters() const
Get children nodes.
Gaudi::tagged_bool< class Concurrent_tag > Concurrent
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
DataObjID m_data_object_path
PRVertexDesc node(const std::string &) const
void addEdgeToPrecTrace(const AlgorithmNode *u, const AlgorithmNode *v)
set cause-effect connection between two algorithms in the precedence trace
float m_rank
Algorithm rank of any kind.
std::string operator()(const DataProps &) const
virtual ~ControlFlowNode()=default
Destructor.
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
std::string operator()(const DataProps &) const
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.
void accept(IGraphVisitor &visitor) const
An entry point to visit all graph nodes.
SmartIF< IHiveWhiteBoard > m_whiteboard
std::string operator()(const DecisionHubProps &) const
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
std::vector< DataNode * > m_inputs
Algorithm inputs (DataNodes)
void addParentNode(DecisionNode *node)
Add a parent node.
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
AlgoProps(Gaudi::Algorithm *algo, uint nodeIndex, uint algoIndex, bool inverted, bool allPass)
DecisionNode * getHeadNode() const
Get head node.
const std::string & name() const override
Retrieve name of the service.
std::string operator()(const AlgoProps &) const
std::vector< AlgorithmNode * > m_producers
virtual ~DataNode()=default
Destructor.
unsigned int m_nodeCounter
Total number of nodes in the graph.
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
Base class from which all concrete algorithm classes should be derived.
std::string operator()(const AlgoProps &) const
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
Gaudi::tagged_bool< class AllPass_tag > AllPass
EventSlot * parentSlot
Pointer to parent slot (null for top level)
void addParentNode(DecisionNode *node)
Add a parent node.
bool m_inverted
Whether the selection result is negated or not.
DecisionHubProps(const std::string &name, uint nodeIndex, concurrency::Concurrent modeConcurrent, concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR, concurrency::AllPass allPass, concurrency::Inverted isInverted)
std::string operator()(const DecisionHubProps &) const
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
PrecedenceRulesGraph * m_graph
bool isLiar() const
Check if control flow logic is always inverted.
std::string operator()(const DataProps &) const
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
std::string operator()(const DataProps &) const
std::string operator()(const DataProps &) const
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
const unsigned int & getNodeIndex() const
Get node index.
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
bool accept(IGraphVisitor &visitor) override
Need to hide the (identical) base method with this one so that visitEnter(ConditionNode&) and visit(C...
bool m_isIOBound
If an algorithm is blocking.
StartTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
virtual void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const =0
Print a string representing the control flow state.
std::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
bool m_allPass
Whether the selection result is relevant or always "pass".
void addProducerNode(AlgorithmNode *node)
Add relationship to producer AlgorithmNode.
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
AlgsExecutionStates algsStates
Vector of algorithms states.
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
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.
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
CFDecision(const EventSlot &slot)
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.