6 #include <boost/property_map/transform_value_property_map.hpp> 9 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 10 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 15 const char* stateToString(
const int& stateId ) {
43 const unsigned int& recursionLevel )
const {
50 for (
auto daughter :
m_children ) daughter->printState(
output, slot, recursionLevel + 2 );
58 bool result = visitor.
visit( *
this );
67 const unsigned int& recursionLevel )
const {
78 if ( states[
m_algoIndex] == AlgsExecutionStates::State::CONTROLREADY ) {
85 ConditionNode* castNode = dynamic_cast<ConditionNode*>( dataNode );
87 bool wasProduced =
false;
91 wasProduced = !visitor.
visitEnter( *castNode );
94 wasProduced = visitor.visit( *dataNode );
102 output << indent <<
"missing conditions data: " << dataNode->getPath() <<
std::endl;
104 output << indent <<
"missing data: " << dataNode->getPath() <<
std::endl;
109 if ( finder.holderNames().size() > 1 ) {
110 output << indent <<
"required by tool:";
111 for (
auto const& holderName : finder.holderNames() ) {
112 if ( holderName != this->
getNodeName() ) output <<
" " << holderName;
118 output << indent <<
"can be produced by alg(s): ";
119 for (
auto algoNode : dataNode->getProducers() ) {
120 output <<
"( " << algoNode->getNodeName() <<
" in state: " << states[algoNode->getAlgoIndex()] <<
" ) ";
134 if ( visitor.visit( *dataNode ) ) {
135 output << indent <<
"data is available at whole-event level" <<
std::endl;
140 for (
auto& pair : *subSlotMap ) {
141 if ( pair.second.size() > 0 ) {
142 bool madeLine =
false;
145 for (
int slotIndex : pair.second ) {
147 EventSlot* subSlot = &testSubSlots->
at( slotIndex );
148 visitor.m_slot = subSlot;
149 if ( visitor.visit( *dataNode ) ) {
153 output << indent <<
"data is available in sub-slot(s) ";
156 output << slotIndex <<
", ";
159 if ( madeLine ) {
output <<
"entered from " << pair.first <<
std::endl; }
173 visitor.
visit( *
this );
202 if ( condSvc.isValid() ) {
203 info() <<
"CondSvc found. DF precedence rules will be augmented with 'Conditions'" <<
endmsg;
211 auto& condAlgs = condSvc->condAlgs();
212 for (
const auto algo : condAlgs ) {
216 debug() <<
"Detaching condition algorithm '" << algo->name() <<
"' from the CF realm.." <<
endmsg;
218 parent->m_children.erase(
std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
219 parent->m_children.end() );
227 warning() <<
"Algorithm '" << algo->name() <<
"' is not registered in the graph" <<
endmsg;
250 verbose() <<
" Inputs of " << algoName <<
": ";
254 verbose() <<
" Outputs of " << algoName <<
": ";
269 for (
auto output : outputs ) {
271 if ( !sc.isSuccess() ) {
272 error() <<
"Extra producer (" << algo.first <<
") for DataObject @ " <<
output 273 <<
" has been detected: this is not allowed." <<
endmsg;
277 dataNode->addProducerNode( algo.second.get() );
278 algo.second->addOutputDataNode( dataNode );
296 algo.second->addInputDataNode( dataNode );
300 boost::add_edge(
node( input.fullKey() ),
node( algo.second->getNodeName() ),
m_PRGraph );
310 bool inverted,
bool allPass ) {
316 auto& algoName = algo->
name();
322 algoNode = itA->second.get();
327 algoNode = r.first->second.get();
343 auto parentNode = itP->second.get();
345 parentNode->addDaughterNode( algoNode );
351 ON_VERBOSE verbose() <<
"Attached AlgorithmNode '" << algo->
name() <<
"' to parent DecisionNode '" << parentName
355 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
369 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
375 if ( condSvc->isRegistered( dataPath ) ) {
376 dataNode = std::make_unique<concurrency::ConditionNode>( *
this, dataPath, condSvc );
381 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
400 auto& decisionHubName = decisionHubAlgo->
name();
405 decisionHubNode = itA->second.get();
409 std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, decisionHubName, modeConcurrent,
410 modePromptDecision, modeOR, allPass, isInverted ) );
411 decisionHubNode = r.first->second.get();
415 allPass, isInverted ),
427 auto parentNode = itP->second.get();
428 parentNode->addDaughterNode( decisionHubNode );
434 ON_VERBOSE verbose() <<
"Attached DecisionNode '" << decisionHubName <<
"' to parent DecisionNode '" << parentName
438 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
454 headName, std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, headName, modeConcurrent,
455 modePromptDecision, modeOR, allPass, isInverted ) );
461 allPass, isInverted ),
473 return std::visit( precedence::VertexName(), m_PRGraph[v] ) == name;
493 info() <<
"Starting ranking by data outputs .. " <<
endmsg;
496 pair.second->accept( ranker );
497 ON_DEBUG debug() <<
" ... rank of " << pair.first <<
": " << pair.second->getRank() <<
endmsg;
508 const int& indent )
const {
514 ost <<
node->getNodeName() <<
" [Seq] ";
517 ost << ( ( dn->
m_modeOR ) ?
" [OR] " :
"" );
518 ost << ( ( dn->
m_allPass ) ?
" [PASS] " :
"" );
522 }
else if ( an != 0 ) {
523 ost <<
node->getNodeName() <<
" [Alg] ";
526 ost <<
" [n= " << ar->cardinality() <<
"]";
527 ost << ( ( !ar->isClonable() ) ?
" [unclonable] " :
"" );
536 const char idt[] =
" ";
539 ost <<
"\n" << idt <<
"====================================\n";
540 ost << idt <<
"Data origins and destinations:\n";
541 ost << idt <<
"====================================\n";
545 for (
auto algoNode : pair.second->getProducers() ) ost << idt <<
" " << algoNode->getNodeName() <<
"\n";
547 ost << idt <<
" V\n";
548 ost << idt <<
" o " << pair.first <<
"\n";
549 ost << idt <<
" V\n";
551 for (
auto algoNode : pair.second->getConsumers() ) ost << idt <<
" " << algoNode->getNodeName() <<
"\n";
553 ost << idt <<
"====================================\n";
562 boost::filesystem::ofstream myfile;
563 myfile.open( fileName, std::ios::app );
566 boost::dynamic_properties dp;
568 dp.property(
"Entity",
569 boost::make_transform_value_property_map(
571 return std::visit( [](
const auto& w ) {
return boost::lexical_cast<std::string>( w ); }, v );
575 auto add_prop = [&](
auto name,
auto&& vis ) {
576 dp.property(
name, boost::make_transform_value_property_map(
578 return std::visit( vis, v );
596 boost::write_graphml( myfile,
m_PRGraph, dp );
603 boost::filesystem::ofstream myfile;
604 myfile.open( fileName, std::ios::app );
608 if ( !timelineSvc.
isValid() ) {
609 warning() <<
"Failed to get the TimelineSvc, timing will not be added to " 610 <<
"the task precedence trace dump" <<
endmsg;
613 for (
auto vp = vertices(
m_precTrace ); vp.first != vp.second; ++vp.first ) {
617 int runtime = std::chrono::duration_cast<std::chrono::microseconds>( te.end - te.start ).count();
623 boost::dynamic_properties dp;
626 dp.property(
"Name",
get( &AlgoTraceProps::m_name,
m_precTrace ) );
627 dp.property(
"Rank",
get( &AlgoTraceProps::m_rank,
m_precTrace ) );
628 dp.property(
"Runtime",
get( &AlgoTraceProps::m_runtime,
m_precTrace ) );
645 source = itT->second;
653 source = itS->second;
666 target = itP->second;
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)
Class representing an event slot.
std::vector< DecisionNode * > m_parents
Direct parent nodes.
const std::string & getNodeName() const
Get node name.
unsigned int m_algoIndex
The index of the algorithm.
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
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.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
virtual bool visit(DecisionNode &)
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
bool isValid() const
Allow for check if smart pointer is valid.
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
constexpr static const auto SUCCESS
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
virtual bool getTimelineEvent(TimelineEvent &) const =0
std::vector< int > controlFlowState
State of the control flow.
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
std::vector< EventSlot > allSubSlots
Actual sub-slot instances.
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
bool m_allPass
Whether always passing regardless of daughter results.
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
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
const unsigned int & getAlgoIndex() const
Get algorithm index.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
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.
void dumpPrecTrace(const boost::filesystem::path &)
dump to file the precedence trace
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
Gaudi::tagged_bool< class Inverted_tag > Inverted
DecisionNode * m_headNode
the head node of the control flow graph
This class is used for returning status codes from appropriate routines.
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
const float & getRank() const
Get Algorithm rank.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
void registerIODataObjects(const Gaudi::Algorithm *algo)
Register algorithm in the Data Dependency index.
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
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.
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
Implements the IDataHandleVisitor interface Class used to explore heirarchy of nested IDataHandleHold...
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
const DataObjIDColl & outputDataObjs() const override
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
void acceptDHVisitor(IDataHandleVisitor *) const override
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.
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.
const std::string & name() const override
Retrieve name of the service.
unsigned int m_nodeCounter
Total number of nodes in the graph.
Base class from which all concrete algorithm classes should be derived.
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
constexpr static const auto FAILURE
EventSlot * parentSlot
Pointer to parent slot (null for top level)
void addParentNode(DecisionNode *node)
Add a parent node.
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.
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
const DataObjIDColl & inputDataObjs() const override
std::unordered_map< std::string, std::vector< unsigned int > > subSlotsByNode
Listing of sub-slots by the node (name) they are attached to.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
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.
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
const std::string & name() const override
The identifying name of the algorithm object.
AlgsExecutionStates algsStates
Vector of algorithms states.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.