16 #include <boost/property_map/transform_value_property_map.hpp> 19 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 20 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 25 const char* stateToString(
const int& stateId ) {
53 const unsigned int& recursionLevel )
const {
60 for (
auto daughter :
m_children ) daughter->printState(
output, slot, recursionLevel + 2 );
68 bool result = visitor.
visit( *
this );
77 const unsigned int& recursionLevel )
const {
88 if ( states[
m_algoIndex] == AlgsExecutionStates::State::CONTROLREADY ) {
95 ConditionNode* conditionNode = dynamic_cast<ConditionNode*>( dataNode );
97 bool wasProduced =
false;
98 if ( conditionNode ) {
101 wasProduced = !visitor.
visitEnter( *conditionNode );
104 wasProduced = visitor.visit( *dataNode );
108 if ( !wasProduced ) {
112 output << indent <<
"missing conditions data: " << dataNode->name() <<
std::endl;
119 if ( finder.holderNames().size() > 1 ) {
120 output << indent <<
"required by tool:";
121 for (
auto const& holderName : finder.holderNames() ) {
122 if ( holderName != this->
name() ) output <<
" " << holderName;
127 if ( conditionNode ) {
133 if ( validRanges.empty() )
output << indent <<
"no interval(s) of validity" <<
std::endl;
136 output << indent <<
"can be produced by alg(s): ";
137 for (
auto algoNode : dataNode->getProducers() ) {
138 output <<
"( " << algoNode->name() <<
" in state: " << states[algoNode->getAlgoIndex()] <<
" ) ";
144 if ( !conditionNode ) {
153 if ( visitor.visit( *dataNode ) ) {
154 output << indent <<
"data is available at whole-event level" <<
std::endl;
159 for (
auto& pair : *subSlotMap ) {
160 if ( pair.second.size() > 0 ) {
161 bool madeLine =
false;
164 for (
int slotIndex : pair.second ) {
166 EventSlot* subSlot = &testSubSlots->
at( slotIndex );
167 visitor.m_slot = subSlot;
168 if ( visitor.visit( *dataNode ) ) {
172 output << indent <<
"data is available in sub-slot(s) ";
175 output << slotIndex <<
", ";
178 if ( madeLine ) {
output <<
"entered from " << pair.first <<
std::endl; }
192 visitor.
visit( *
this );
221 if ( condSvc.isValid() ) {
222 info() <<
"CondSvc found. DF precedence rules will be augmented with 'Conditions'" <<
endmsg;
230 auto& condAlgs = condSvc->condAlgs();
231 for (
const auto algo : condAlgs ) {
235 debug() <<
"Detaching condition algorithm '" << algo->name() <<
"' from the CF realm.." <<
endmsg;
237 parent->m_children.erase(
std::remove( parent->m_children.begin(), parent->m_children.end(), algoNode ),
238 parent->m_children.end() );
245 warning() <<
"Algorithm '" << algo->name() <<
"' is not registered in the graph" <<
endmsg;
268 verbose() <<
" Inputs of " << algoName <<
": ";
272 verbose() <<
" Outputs of " << algoName <<
": ";
287 for (
auto output : outputs ) {
289 if ( !sc.isSuccess() ) {
290 error() <<
"Extra producer (" << algo.first <<
") for DataObject @ " <<
output 291 <<
" has been detected: this is not allowed." <<
endmsg;
295 dataNode->addProducerNode( algo.second.get() );
296 algo.second->addOutputDataNode( dataNode );
313 algo.second->addInputDataNode( dataNode );
326 bool inverted,
bool allPass ) {
332 auto& algoName = algo->
name();
338 algoNode = itA->second.get();
343 algoNode = r.first->second.get();
359 auto parentNode = itP->second.get();
361 parentNode->addDaughterNode( algoNode );
367 ON_VERBOSE verbose() <<
"Attached AlgorithmNode '" << algo->
name() <<
"' to parent DecisionNode '" << parentName
371 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
385 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
391 if ( condSvc->isRegistered( dataPath ) ) {
392 dataNode = std::make_unique<concurrency::ConditionNode>( *
this, dataPath, condSvc );
397 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
416 auto& decisionHubName = decisionHubAlgo->
name();
421 decisionHubNode = itA->second.get();
425 std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, decisionHubName, modeConcurrent,
426 modePromptDecision, modeOR, allPass, isInverted ) );
427 decisionHubNode = r.first->second.get();
431 allPass, isInverted ),
443 auto parentNode = itP->second.get();
444 parentNode->addDaughterNode( decisionHubNode );
450 ON_VERBOSE verbose() <<
"Attached DecisionNode '" << decisionHubName <<
"' to parent DecisionNode '" << parentName
454 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
470 headName, std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, headName, modeConcurrent,
471 modePromptDecision, modeOR, allPass, isInverted ) );
477 allPass, isInverted ),
489 return std::visit( precedence::VertexName(), m_PRGraph[v] ) == name;
509 info() <<
"Starting ranking by data outputs .. " <<
endmsg;
512 pair.second->accept( ranker );
513 ON_DEBUG debug() <<
" ... rank of " << pair.first <<
": " << pair.second->getRank() <<
endmsg;
524 const int& indent )
const {
530 ost <<
node->name() <<
" [Seq] ";
533 ost << ( ( dn->
m_modeOR ) ?
" [OR] " :
"" );
534 ost << ( ( dn->
m_allPass ) ?
" [PASS] " :
"" );
538 }
else if ( an != 0 ) {
539 ost <<
node->name() <<
" [Alg] ";
542 ost <<
" [n= " << ar->cardinality() <<
"]";
543 ost << ( ( !ar->isClonable() ) ?
" [unclonable] " :
"" );
552 const char idt[] =
" ";
555 ost <<
"\n" << idt <<
"====================================\n";
556 ost << idt <<
"Data origins and destinations:\n";
557 ost << idt <<
"====================================\n";
561 for (
auto algoNode : pair.second->getProducers() ) ost << idt <<
" " << algoNode->name() <<
"\n";
563 ost << idt <<
" V\n";
564 ost << idt <<
" o " << pair.first <<
"\n";
565 ost << idt <<
" V\n";
567 for (
auto algoNode : pair.second->getConsumers() ) ost << idt <<
" " << algoNode->name() <<
"\n";
569 ost << idt <<
"====================================\n";
578 boost::filesystem::ofstream myfile;
579 myfile.open( fileName, std::ios::app );
582 boost::dynamic_properties dp;
584 dp.property(
"Entity",
585 boost::make_transform_value_property_map(
587 return std::visit( [](
const auto& w ) {
return boost::lexical_cast<std::string>( w ); }, v );
591 auto add_prop = [&](
auto name,
auto&& vis ) {
592 dp.property(
name, boost::make_transform_value_property_map(
594 return std::visit( vis, v );
612 boost::write_graphml( myfile,
m_PRGraph, dp );
619 boost::filesystem::ofstream myfile;
620 myfile.open( fileName, std::ios::app );
624 if ( !timelineSvc.
isValid() ) {
625 warning() <<
"Failed to get the TimelineSvc, timing will not be added to " 626 <<
"the task precedence trace dump" <<
endmsg;
629 for (
auto vp = vertices(
m_precTrace ); vp.first != vp.second; ++vp.first ) {
633 int runtime = std::chrono::duration_cast<std::chrono::microseconds>( te.end - te.start ).count();
639 boost::dynamic_properties dp;
642 dp.property(
"Name",
get( &AlgoTraceProps::m_name,
m_precTrace ) );
643 dp.property(
"Rank",
get( &AlgoTraceProps::m_rank,
m_precTrace ) );
644 dp.property(
"Runtime",
get( &AlgoTraceProps::m_runtime,
m_precTrace ) );
661 source = itT->second;
669 source = itS->second;
682 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.
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.
virtual StatusCode validRanges(std::vector< EventIDRange > &ranges, const DataObjID &id) const =0
retrieve all valid ranges for one Object ID
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
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
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.
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
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.
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
const std::string & name() const
Get node name.
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.
const EventIDBase & eventID() const
SmartIF< ICondSvc > m_condSvc
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.