17#include <unordered_map>
21#include <boost/filesystem.hpp>
22#include <boost/graph/adjacency_list.hpp>
23#include <boost/graph/graphml.hpp>
51 AlgoTraceProps(
const std::string& name,
int index = -1,
int rank = -1,
long int runtime = -1,
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";
183 return std::to_string(
m_slot.controlFlowState.at( props.m_nodeIndex ) );
187 return std::to_string(
m_slot.controlFlowState.at( props.m_nodeIndex ) );
201 MsgStream log{ msgSvc,
"EntityState.Getter" };
205 log << MSG::WARNING <<
"Failed to locate EventDataSvc: no way to add DO "
206 <<
"states to the TTT dump " << endmsg;
213 log <<
MSG::WARNING <<
"Failed to locate CondSvc: no way to add Condition DO "
214 <<
"states to the TTT dump " <<
endmsg;
217 if ( !
m_slot.eventContext->valid() )
218 log <<
MSG::WARNING <<
"Event context is invalid: no way to add DO states"
219 <<
" in the TTT dump" <<
endmsg;
224 std::ostringstream oss;
225 oss <<
m_slot.algsStates[props.m_algoIndex];
236 state =
m_whiteboard->exists( props.m_id ) ?
"Produced" :
"Missing";
245 state =
m_condSvc->isValidID( *(
m_slot.eventContext ), props.m_id ) ?
"Produced" :
"Missing";
261 MsgStream log{ msgSvc,
"StartTime.Getter" };
265 log << MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to "
266 <<
"add algorithm start time to the TTT dumps" << endmsg;
272 std::string startTime;
278 te.slot =
m_slot.eventContext->slot();
279 te.event =
m_slot.eventContext->evt();
282 startTime = std::to_string(
283 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
301 MsgStream log{ msgSvc,
"EndTime.Getter" };
305 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add "
306 <<
"algorithm completion time to the TTT dumps" <<
endmsg;
317 te.slot =
m_slot.eventContext->slot();
318 te.event =
m_slot.eventContext->evt();
322 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
340 MsgStream log{ msgSvc,
"Duration.Getter" };
344 log <<
MSG::WARNING <<
"Failed to locate the TimelineSvc: no way to add "
345 <<
"algorithm's runtimes to the TTT dumps" <<
endmsg;
360 time = std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.
end - te.
start ).count() );
376 return props.m_isAsynchronous ?
"Asynchronous" :
"CPU-bound";
384 static inline std::ostream&
operator<<( std::ostream& os,
const AlgoProps& ) {
return os <<
"Algorithm"; }
385 static inline std::ostream& operator<<( std::ostream& os,
const DecisionHubProps& ) {
return os <<
"DecisionHub"; }
386 static inline std::ostream& operator<<( std::ostream& os,
const DataProps& ) {
return os <<
"Data"; }
387 static inline std::ostream& operator<<( std::ostream& os,
const CondDataProps& ) {
return os <<
"ConditionData"; }
392 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
405 class PrecedenceRulesGraph;
426 virtual void printState( std::stringstream& output,
EventSlot& slot,
const unsigned int& recursionLevel )
const = 0;
462 void printState( std::stringstream& output,
EventSlot& slot,
const unsigned int& recursionLevel )
const override;
489 unsigned int algoIndex )
529 void printState( std::stringstream& output,
EventSlot& slot,
const unsigned int& recursionLevel )
const override;
616 template <
typename T>
618 bool operator()(
const T& a,
const T& b )
const {
return a->name() < b->name(); }
671 void printState( std::stringstream& output,
EventSlot& slot,
const unsigned int& recursionLevel )
const;
std::ostream & operator<<(std::ostream &s, AlgsExecutionStates::State x)
Streaming of State values.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
friend class CommonMessaging
MSG::Level setUpMessaging() const
Base class from which all concrete algorithm classes should be derived.
Interface for the Condition Service.
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
Definition of the MsgStream class used to transmit messages.
Small smart pointer class with automatic reference counting for IInterface.
This class is used for returning status codes from appropriate routines.
void addParentNode(DecisionNode *node)
Add a parent node.
bool isAsynchronous() const
Check if algorithm is asynchronous.
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
std::vector< DataNode * > m_inputs
Algorithm inputs (DataNodes)
float getRank() const
Get Algorithm rank.
const std::vector< DataNode * > & getInputDataNodes() const
Get all consumer nodes.
const std::vector< DecisionNode * > & getParentDecisionHubs() const
Get all parent decision hubs.
bool m_isAsynchronous
If an algorithm is asynchronous.
std::vector< DataNode * > m_outputs
Algorithm outputs (DataNodes)
Gaudi::Algorithm * getAlgorithm() const
get Algorithm representatives
void addInputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data consumer of this one.
void setRank(float rank)
Set Algorithm rank.
unsigned int getAlgoIndex() const
Get algorithm index.
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
std::string m_algoName
The name of the algorithm.
AlgorithmNode(PrecedenceRulesGraph &graph, Gaudi::Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex)
Constructor.
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
void setAsynchronous(bool value)
Set the asynchronous flag.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
float m_rank
Algorithm rank of any kind.
unsigned int m_algoIndex
The index of the algorithm.
bool accept(IGraphVisitor &visitor) override
Need to hide the (identical) base method with this one so that visitEnter(ConditionNode&) and visit(C...
ConditionNode(PrecedenceRulesGraph &graph, const DataObjID &path, SmartIF< ICondSvc > condSvc)
Constructor.
SmartIF< ICondSvc > m_condSvc
virtual bool accept(IGraphVisitor &visitor)=0
Visitor entry point.
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
const unsigned int & getNodeIndex() const
Get node index.
const std::string & name() const
Get node name.
PrecedenceRulesGraph * m_graph
virtual void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const =0
Print a string representing the control flow state.
virtual ~ControlFlowNode()=default
Destructor.
virtual bool accept(IGraphVisitor &visitor)
Entry point for a visitor.
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.
std::vector< AlgorithmNode * > m_producers
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
const DataObjID & name() const
virtual ~DataNode()=default
Destructor.
void addProducerNode(AlgorithmNode *node)
Add relationship to producer AlgorithmNode.
DataObjID m_data_object_path
PrecedenceRulesGraph * m_graph
DataNode(PrecedenceRulesGraph &graph, const DataObjID &path)
Constructor.
std::vector< AlgorithmNode * > m_consumers
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
const std::vector< ControlFlowNode * > & getDaughters() const
Get children nodes.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
bool m_inverted
Whether the selection result is negated or not.
void addDaughterNode(ControlFlowNode *node)
Add a daughter node.
bool m_allPass
Whether always passing regardless of daughter results.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
bool accept(IGraphVisitor &visitor) override
Visitor entry point.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
DecisionNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass, Inverted isInverted)
Constructor.
void addParentNode(DecisionNode *node)
Add a parent node.
std::vector< DecisionNode * > m_parents
Direct parent nodes.
virtual bool visit(DecisionNode &)
virtual bool visitEnter(DecisionNode &) const
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName)
Add algorithm node.
void addEdgeToPrecTrace(const AlgorithmNode *u, const AlgorithmNode *v)
set cause-effect connection between two algorithms in the precedence trace
void registerIODataObjects(const Gaudi::Algorithm *algo)
Register algorithm in the Data Dependency index.
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
StatusCode initialize()
Initialize graph.
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
DecisionNode * m_headNode
the head node of the control flow graph
DataNode * getDataNode(const DataObjID &dataPath) const
Get DataNode by DataObject path using graph index.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
std::string dumpDataFlow() const
Print out all data origins and destinations, as reflected in the EF graph.
PRVertexDesc node(const std::string &) const
void enableAnalysis()
BGL-based facilities.
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
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 dumpPrecTrace(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence trace
void accept(IGraphVisitor &visitor) const
An entry point to visit all graph nodes.
std::unordered_map< std::string, std::unique_ptr< AlgorithmNode > > m_algoNameToAlgoNodeMap
Index: map of algorithm's name to AlgorithmNode.
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
DecisionNode * getHeadNode() const
Get head node.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
unsigned int m_nodeCounter
Total number of nodes in the graph.
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
const std::string & name() const override
Retrieve name of the service.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
Gaudi::tagged_bool< class AllPass_tag > AllPass
Gaudi::tagged_bool< class Concurrent_tag > Concurrent
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
Gaudi::tagged_bool< class PromptDecision_tag > PromptDecision
Gaudi::tagged_bool< class Inverted_tag > Inverted
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps > PRGraph
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
std::variant< AlgoProps, DecisionHubProps, DataProps, CondDataProps > VariantVertexProps
boost::graph_traits< PrecTrace >::vertex_descriptor AlgoTraceVertex
Class representing an event slot.
bool operator()(const T &a, const T &b) const
virtual ~IPrecedenceRulesGraph()=default
AlgoProps(Gaudi::Algorithm *algo, uint nodeIndex, uint algoIndex)
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
bool m_isAsynchronous
If an algorithm is asynchronous.
AlgoTraceProps(const std::string &name, int index=-1, int rank=-1, long int runtime=-1, long long int start=-1)
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const DecisionHubProps &props) const
CFDecision(const EventSlot &slot)
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
CondDataProps(const DataObjID &id)
DataProps(const DataObjID &id)
DecisionHubProps(const std::string &name, uint nodeIndex, concurrency::Concurrent modeConcurrent, concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR, concurrency::AllPass allPass, concurrency::Inverted isInverted)
bool m_inverted
Whether the selection result is negated or not.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
bool m_allPass
Whether always passing regardless of daughter results.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const DecisionHubProps &) const
SmartIF< ITimelineSvc > m_timelineSvc
std::string operator()(const AlgoProps &props) const
Duration(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const DataProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const AlgoProps &props) const
SmartIF< ITimelineSvc > m_timelineSvc
EndTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const DecisionHubProps &) const
std::string operator()(const CondDataProps &props) const
EntityState(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator, bool conditionsEnabled)
SmartIF< ICondSvc > m_condSvc
SmartIF< IHiveWhiteBoard > m_whiteboard
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &props) const
std::string operator()(const DecisionHubProps &) const
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const DataProps &) const
std::string operator()(const AlgoProps &) const
std::string operator()(const DataProps &) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const DecisionHubProps &) const
SmartIF< ITimelineSvc > m_timelineSvc
std::string operator()(const DecisionHubProps &) const
StartTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const DataProps &props) const
std::string operator()(const AlgoProps &props) const