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 ) {
134 if ( validRanges.empty() )
output << indent <<
"no interval(s) of validity" <<
std::endl;
137 output << indent <<
"can be produced by alg(s): ";
138 for (
auto algoNode : dataNode->getProducers() ) {
139 output <<
"( " << algoNode->name() <<
" in state: " << states[algoNode->getAlgoIndex()] <<
" ) ";
145 if ( !conditionNode ) {
154 if ( visitor.visit( *dataNode ) ) {
155 output << indent <<
"data is available at whole-event level" <<
std::endl;
160 for (
auto& pair : *subSlotMap ) {
161 if ( pair.second.size() > 0 ) {
162 bool madeLine =
false;
165 for (
int slotIndex : pair.second ) {
167 EventSlot* subSlot = &testSubSlots->
at( slotIndex );
168 visitor.m_slot = subSlot;
169 if ( visitor.visit( *dataNode ) ) {
173 output << indent <<
"data is available in sub-slot(s) ";
176 output << slotIndex <<
", ";
179 if ( madeLine ) {
output <<
"entered from " << pair.first <<
std::endl; }
193 visitor.
visit( *
this );
222 if ( condSvc.isValid() ) {
223 info() <<
"CondSvc found. DF precedence rules will be augmented with 'Conditions'" <<
endmsg;
231 auto& condAlgs = condSvc->condAlgs();
232 for (
const auto algo : condAlgs ) {
236 debug() <<
"Detaching condition algorithm '" << algo->name() <<
"' from the CF realm.." <<
endmsg;
239 parent->m_children.end() );
246 warning() <<
"Algorithm '" << algo->name() <<
"' is not registered in the graph" <<
endmsg;
269 verbose() <<
" Inputs of " << algoName <<
": ";
273 verbose() <<
" Outputs of " << algoName <<
": ";
288 for (
auto output : outputs ) {
290 if ( !sc.isSuccess() ) {
291 error() <<
"Extra producer (" << algo.first <<
") for DataObject @ " <<
output 292 <<
" has been detected: this is not allowed." <<
endmsg;
296 dataNode->addProducerNode( algo.second.get() );
297 algo.second->addOutputDataNode( dataNode );
314 algo.second->addInputDataNode( dataNode );
327 bool inverted,
bool allPass ) {
333 auto& algoName = algo->
name();
339 algoNode = itA->second.get();
344 algoNode = r.first->second.get();
360 auto parentNode = itP->second.get();
362 parentNode->addDaughterNode( algoNode );
368 ON_VERBOSE verbose() <<
"Attached AlgorithmNode '" << algo->
name() <<
"' to parent DecisionNode '" << parentName
372 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
386 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
392 if ( condSvc->isRegistered( dataPath ) ) {
393 dataNode = std::make_unique<concurrency::ConditionNode>( *
this, dataPath, condSvc );
398 dataNode = std::make_unique<concurrency::DataNode>( *
this, dataPath );
417 auto& decisionHubName = decisionHubAlgo->
name();
422 decisionHubNode = itA->second.get();
426 std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, decisionHubName, modeConcurrent,
427 modePromptDecision, modeOR, allPass, isInverted ) );
428 decisionHubNode = r.first->second.get();
432 allPass, isInverted ),
444 auto parentNode = itP->second.get();
445 parentNode->addDaughterNode( decisionHubNode );
451 ON_VERBOSE verbose() <<
"Attached DecisionNode '" << decisionHubName <<
"' to parent DecisionNode '" << parentName
455 error() <<
"Parent DecisionNode '" << parentName <<
"' was not found" <<
endmsg;
471 headName, std::make_unique<concurrency::DecisionNode>( *
this,
m_nodeCounter, headName, modeConcurrent,
472 modePromptDecision, modeOR, allPass, isInverted ) );
478 allPass, isInverted ),
490 return std::visit( precedence::VertexName(), m_PRGraph[v] ) == name;
510 info() <<
"Starting ranking by data outputs .. " <<
endmsg;
513 pair.second->accept( ranker );
514 ON_DEBUG debug() <<
" ... rank of " << pair.first <<
": " << pair.second->getRank() <<
endmsg;
525 const int& indent )
const {
531 ost <<
node->name() <<
" [Seq] ";
534 ost << ( ( dn->
m_modeOR ) ?
" [OR] " :
"" );
535 ost << ( ( dn->
m_allPass ) ?
" [PASS] " :
"" );
539 }
else if ( an != 0 ) {
540 ost <<
node->name() <<
" [Alg] ";
543 ost <<
" [n= " << ar->cardinality() <<
"]";
544 ost << ( ( !ar->isClonable() ) ?
" [unclonable] " :
"" );
553 const char idt[] =
" ";
556 ost <<
"\n" << idt <<
"====================================\n";
557 ost << idt <<
"Data origins and destinations:\n";
558 ost << idt <<
"====================================\n";
562 for (
auto algoNode : pair.second->getProducers() ) ost << idt <<
" " << algoNode->name() <<
"\n";
564 ost << idt <<
" V\n";
565 ost << idt <<
" o " << pair.first <<
"\n";
566 ost << idt <<
" V\n";
568 for (
auto algoNode : pair.second->getConsumers() ) ost << idt <<
" " << algoNode->name() <<
"\n";
570 ost << idt <<
"====================================\n";
579 boost::filesystem::ofstream myfile;
580 myfile.open( fileName, std::ios::app );
583 boost::dynamic_properties dp;
585 dp.property(
"Entity",
586 boost::make_transform_value_property_map(
588 return std::visit( [](
const auto& w ) {
return boost::lexical_cast<std::string>( w ); }, v );
592 auto add_prop = [&](
auto name,
auto&& vis ) {
593 dp.property(
name, boost::make_transform_value_property_map(
595 return std::visit( vis, v );
613 boost::write_graphml( myfile,
m_PRGraph, dp );
620 boost::filesystem::ofstream myfile;
621 myfile.open( fileName, std::ios::app );
625 if ( !timelineSvc.
isValid() ) {
626 warning() <<
"Failed to get the TimelineSvc, timing will not be added to " 627 <<
"the task precedence trace dump" <<
endmsg;
630 for (
auto vp = vertices(
m_precTrace ); vp.first != vp.second; ++vp.first ) {
634 int runtime = std::chrono::duration_cast<std::chrono::microseconds>( te.end - te.start ).count();
640 boost::dynamic_properties dp;
643 dp.property(
"Name",
get( &AlgoTraceProps::m_name,
m_precTrace ) );
644 dp.property(
"Rank",
get( &AlgoTraceProps::m_rank,
m_precTrace ) );
645 dp.property(
"Runtime",
get( &AlgoTraceProps::m_runtime,
m_precTrace ) );
662 source = itT->second;
670 source = itS->second;
683 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
const Gaudi::Algorithm & parent
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.