The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
PrecedenceRulesGraph.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
13// std includes
14#include <algorithm>
15#include <memory>
16#include <sstream>
17#include <unordered_map>
18#include <variant>
19#include <vector>
20
21#include <boost/filesystem.hpp>
22#include <boost/graph/adjacency_list.hpp>
23#include <boost/graph/graphml.hpp>
24
25// fwk includes
27#include "../EventSlot.h"
29#include <Gaudi/Algorithm.h>
37
38namespace concurrency {
44} // namespace concurrency
45
46namespace precedence {
47
48 // Precedence trace utilities ==============================================
51 AlgoTraceProps( const std::string& name, int index = -1, int rank = -1, long int runtime = -1,
52 long long int start = -1 )
53 : m_name( name ), m_index( index ), m_rank( rank ), m_runtime( runtime ), m_start( start ) {}
54 std::string m_name;
55 int m_index{ -1 };
56 int m_rank{ -1 };
57 long int m_runtime{ -1 }; // us
58 long long int m_start{ -1 }; // ns
59 int m_eccentricity{ -1 };
60 };
61
62 using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
63 using AlgoTraceVertex = boost::graph_traits<PrecTrace>::vertex_descriptor;
64
65 // Precedence rules utilities ==============================================
66 struct AlgoProps {
68 AlgoProps( Gaudi::Algorithm* algo, uint nodeIndex, uint algoIndex )
69 : m_name( algo->name() )
70 , m_nodeIndex( nodeIndex )
71 , m_algoIndex( algoIndex )
72 , m_algorithm( algo )
73 , m_isAsynchronous( algo->isAsynchronous() ) {}
74
75 std::string m_name{ "" };
76 int m_nodeIndex{ -1 };
77 int m_algoIndex{ -1 };
78 int m_rank{ -1 };
82 bool m_isAsynchronous{ false };
83 };
84
86 DecisionHubProps( const std::string& name, uint nodeIndex, concurrency::Concurrent modeConcurrent,
87 concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR,
89 : m_name( name )
90 , m_nodeIndex( nodeIndex )
91 , m_modeConcurrent( modeConcurrent )
92 , m_modePromptDecision( modePromptDecision )
93 , m_inverted( isInverted )
94 , m_modeOR( modeOR )
95 , m_allPass( allPass ) {}
96
97 std::string m_name;
99
106 bool m_inverted{ false };
111 };
112
113 struct DataProps {
114 DataProps( const DataObjID& id ) : m_id( id ) {}
115
117 };
118
120 CondDataProps( const DataObjID& id ) : DataProps( id ) {}
121 };
122
123 // Vertex unpacking ========================================================
124
125 struct VertexName {
126 std::string operator()( const AlgoProps& props ) const { return props.m_name; }
127
128 std::string operator()( const DecisionHubProps& props ) const { return props.m_name; }
129
130 std::string operator()( const DataProps& props ) const { return props.m_id.fullKey(); }
131 };
132
133 struct GroupMode {
134 std::string operator()( const AlgoProps& ) const { return ""; }
135
136 std::string operator()( const DecisionHubProps& props ) const {
137 return props.m_modeConcurrent ? "Concurrent" : "Sequential";
138 }
139
140 std::string operator()( const DataProps& ) const { return ""; }
141 };
142
143 struct GroupLogic {
144 std::string operator()( const AlgoProps& ) const { return ""; }
145
146 std::string operator()( const DecisionHubProps& props ) const { return props.m_modeOR ? "OR" : "AND"; }
147
148 std::string operator()( const DataProps& ) const { return ""; }
149 };
150
151 struct GroupExit {
152 std::string operator()( const AlgoProps& ) const { return ""; }
153
154 std::string operator()( const DecisionHubProps& props ) const {
155 return props.m_modePromptDecision ? "Early" : "Late";
156 }
157
158 std::string operator()( const DataProps& ) const { return ""; }
159 };
160
162 std::string operator()( const AlgoProps& ) const { return ""; }
163
164 std::string operator()( const DecisionHubProps& props ) const {
165 return props.m_inverted ? "Inverted" : "Non-inverted";
166 }
167
168 std::string operator()( const DataProps& ) const { return ""; }
169 };
170
171 struct AllPass {
172 std::string operator()( const AlgoProps& ) const { return ""; }
173
174 std::string operator()( const DecisionHubProps& props ) const { return props.m_allPass ? "Optimist" : "Realist"; }
175
176 std::string operator()( const DataProps& ) const { return ""; }
177 };
178
179 struct CFDecision {
180 CFDecision( const EventSlot& slot ) : m_slot( slot ) {}
181
182 std::string operator()( const AlgoProps& props ) const {
183 return std::to_string( m_slot.controlFlowState.at( props.m_nodeIndex ) );
184 }
185
186 std::string operator()( const DecisionHubProps& props ) const {
187 return std::to_string( m_slot.controlFlowState.at( props.m_nodeIndex ) );
188 }
189
190 std::string operator()( const DataProps& ) const { return ""; }
191
193 };
194
195 struct EntityState {
196 EntityState( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator, bool conditionsEnabled )
197 : m_slot( slot )
198 , m_whiteboard( svcLocator->service<IHiveWhiteBoard>( "EventDataSvc", false ) )
199 , m_conditionsEnabled( conditionsEnabled ) {
200 SmartIF<IMessageSvc> msgSvc{ svcLocator };
201 MsgStream log{ msgSvc, "EntityState.Getter" };
202
203 // Figure if we can discover the data object states
204 if ( !m_whiteboard.isValid() ) {
205 log << MSG::WARNING << "Failed to locate EventDataSvc: no way to add DO "
206 << "states to the TTT dump " << endmsg;
207 }
208
209 if ( m_conditionsEnabled ) {
210 // Figure if we can discover Condition data object states
211 m_condSvc = svcLocator->service<ICondSvc>( "CondSvc", false );
212 if ( !m_condSvc.isValid() )
213 log << MSG::WARNING << "Failed to locate CondSvc: no way to add Condition DO "
214 << "states to the TTT dump " << endmsg;
215 }
216
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;
220 }
221
222 // Returns algorithm's FSM state
223 std::string operator()( const AlgoProps& props ) const {
224 std::ostringstream oss;
225 oss << m_slot.algsStates[props.m_algoIndex];
226 return oss.str();
227 }
228
229 std::string operator()( const DecisionHubProps& ) const { return ""; }
230
231 std::string operator()( const DataProps& props ) const {
232 std::string state;
233
234 if ( m_whiteboard.isValid() && m_slot.eventContext->valid() )
235 if ( m_whiteboard->selectStore( m_slot.eventContext->slot() ).isSuccess() )
236 state = m_whiteboard->exists( props.m_id ) ? "Produced" : "Missing";
237
238 return state;
239 }
240
241 std::string operator()( const CondDataProps& props ) const {
242 std::string state;
243
244 if ( m_condSvc.isValid() && m_slot.eventContext->valid() )
245 state = m_condSvc->isValidID( *( m_slot.eventContext ), props.m_id ) ? "Produced" : "Missing";
246
247 return state;
248 }
249
251
254 bool m_conditionsEnabled{ false };
255 };
256
257 struct StartTime {
258 StartTime( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator )
259 : m_slot( slot ), m_timelineSvc( svcLocator->service<ITimelineSvc>( "TimelineSvc", false ) ) {
260 SmartIF<IMessageSvc> msgSvc{ svcLocator };
261 MsgStream log{ msgSvc, "StartTime.Getter" };
262
263 // Figure if we can discover the algorithm timings
264 if ( !m_timelineSvc.isValid() ) {
265 log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to "
266 << "add algorithm start time to the TTT dumps" << endmsg;
267 }
268 }
269
270 std::string operator()( const AlgoProps& props ) const {
271
272 std::string startTime;
273
274 if ( m_timelineSvc.isValid() ) {
275
276 TimelineEvent te{};
277 te.algorithm = props.m_name;
278 te.slot = m_slot.eventContext->slot();
279 te.event = m_slot.eventContext->evt();
280
281 m_timelineSvc->getTimelineEvent( te );
282 startTime = std::to_string(
283 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
284 }
285
286 return startTime;
287 }
288
289 std::string operator()( const DecisionHubProps& ) const { return ""; }
290
291 std::string operator()( const DataProps& ) const { return ""; }
292
295 };
296
297 struct EndTime {
298 EndTime( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator )
299 : m_slot( slot ), m_timelineSvc( svcLocator->service<ITimelineSvc>( "TimelineSvc", false ) ) {
300 SmartIF<IMessageSvc> msgSvc{ svcLocator };
301 MsgStream log{ msgSvc, "EndTime.Getter" };
302
303 // Figure if we can discover the algorithm timings
304 if ( !m_timelineSvc.isValid() )
305 log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to add "
306 << "algorithm completion time to the TTT dumps" << endmsg;
307 }
308
309 std::string operator()( const AlgoProps& props ) const {
310
311 std::string endTime;
312
313 if ( m_timelineSvc.isValid() ) {
314
315 TimelineEvent te{};
316 te.algorithm = props.m_name;
317 te.slot = m_slot.eventContext->slot();
318 te.event = m_slot.eventContext->evt();
319
320 m_timelineSvc->getTimelineEvent( te );
321 endTime =
322 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
323 }
324
325 return endTime;
326 }
327
328 std::string operator()( const DecisionHubProps& ) const { return ""; }
329
330 std::string operator()( const DataProps& ) const { return ""; }
331
334 };
335
336 struct Duration {
337 Duration( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator )
338 : m_slot( slot ), m_timelineSvc( svcLocator->service<ITimelineSvc>( "TimelineSvc", false ) ) {
339 SmartIF<IMessageSvc> msgSvc{ svcLocator };
340 MsgStream log{ msgSvc, "Duration.Getter" };
341
342 // Figure if we can discover the algorithm timings
343 if ( !m_timelineSvc.isValid() )
344 log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to add "
345 << "algorithm's runtimes to the TTT dumps" << endmsg;
346 }
347
348 std::string operator()( const AlgoProps& props ) const {
349
350 std::string time;
351
352 if ( m_timelineSvc.isValid() ) {
353
354 TimelineEvent te;
355 te.algorithm = props.m_name;
356 te.slot = m_slot.eventContext->slot();
357 te.event = m_slot.eventContext->evt();
358
359 m_timelineSvc->getTimelineEvent( te );
360 time = std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end - te.start ).count() );
361 }
362
363 return time;
364 }
365
366 std::string operator()( const DecisionHubProps& ) const { return ""; }
367
368 std::string operator()( const DataProps& ) const { return ""; }
369
372 };
373
374 struct Operations {
375 std::string operator()( const AlgoProps& props ) const {
376 return props.m_isAsynchronous ? "Asynchronous" : "CPU-bound";
377 }
378
379 std::string operator()( const DecisionHubProps& ) const { return ""; }
380
381 std::string operator()( const DataProps& ) const { return ""; }
382 };
383
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"; }
388
389 //=========================================================================
390
391 using VariantVertexProps = std::variant<AlgoProps, DecisionHubProps, DataProps, CondDataProps>;
392 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
393 using PRVertexDesc = boost::graph_traits<PRGraph>::vertex_descriptor;
394
395} // namespace precedence
396
397struct Cause final {
398 enum class source { Root, Task };
399
401 std::string m_sourceName;
402};
403
404namespace concurrency {
405 class PrecedenceRulesGraph;
406
413
414 // ==========================================================================
416 public:
418 ControlFlowNode( PrecedenceRulesGraph& graph, unsigned int nodeIndex, const std::string& name )
419 : m_graph( &graph ), m_nodeIndex( nodeIndex ), m_nodeName( name ) {}
420
421 virtual ~ControlFlowNode() = default;
422
424 virtual bool accept( IGraphVisitor& visitor ) = 0;
426 virtual void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const = 0;
428 const unsigned int& getNodeIndex() const { return m_nodeIndex; }
430 const std::string& name() const { return m_nodeName; }
431
432 public:
434
435 protected:
436 unsigned int m_nodeIndex;
437 std::string m_nodeName;
438 };
439
440 class DecisionNode final : public ControlFlowNode {
441 public:
443 DecisionNode( PrecedenceRulesGraph& graph, unsigned int nodeIndex, const std::string& name,
444 Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass,
445 Inverted isInverted )
446 : ControlFlowNode( graph, nodeIndex, name )
447 , m_modeConcurrent( modeConcurrent )
448 , m_modePromptDecision( modePromptDecision )
449 , m_modeOR( modeOR )
450 , m_allPass( allPass )
451 , m_inverted( isInverted ) {}
452
454 bool accept( IGraphVisitor& visitor ) override;
456 void addParentNode( DecisionNode* node );
458 void addDaughterNode( ControlFlowNode* node );
460 const std::vector<ControlFlowNode*>& getDaughters() const { return m_children; }
462 void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const override;
463
464 public:
475 bool m_inverted{ false };
477 std::vector<ControlFlowNode*> m_children;
479 std::vector<DecisionNode*> m_parents;
480 };
481
482 // ==========================================================================
483 class DataNode;
484
485 class AlgorithmNode final : public ControlFlowNode {
486 public:
488 AlgorithmNode( PrecedenceRulesGraph& graph, Gaudi::Algorithm* algoPtr, unsigned int nodeIndex,
489 unsigned int algoIndex )
490 : ControlFlowNode( graph, nodeIndex, algoPtr->name() )
491 , m_algorithm( algoPtr )
492 , m_algoIndex( algoIndex )
493 , m_algoName( algoPtr->name() )
494 , m_isAsynchronous( algoPtr->isAsynchronous() ) {}
495
497 bool accept( IGraphVisitor& visitor ) override;
498
500 void addParentNode( DecisionNode* node );
502 const std::vector<DecisionNode*>& getParentDecisionHubs() const { return m_parents; }
503
505 void addOutputDataNode( DataNode* node );
507 void addInputDataNode( DataNode* node );
509 const std::vector<DataNode*>& getOutputDataNodes() const { return m_outputs; }
511 const std::vector<DataNode*>& getInputDataNodes() const { return m_inputs; }
512
514 void setRank( float rank ) { m_rank = rank; }
516 float getRank() const { return m_rank; }
517
521 unsigned int getAlgoIndex() const { return m_algoIndex; }
522
524 void setAsynchronous( bool value ) { m_isAsynchronous = value; }
526 bool isAsynchronous() const { return m_isAsynchronous; }
527
529 void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const override;
530
531 public:
533 std::vector<DecisionNode*> m_parents;
534
535 private:
539 unsigned int m_algoIndex;
541 std::string m_algoName;
543 float m_rank = -1;
546
548 std::vector<DataNode*> m_outputs;
550 std::vector<DataNode*> m_inputs;
551 };
552
553 // ==========================================================================
554 class DataNode {
555 public:
557 DataNode( PrecedenceRulesGraph& graph, const DataObjID& path ) : m_graph( &graph ), m_data_object_path( path ) {}
558
560 virtual ~DataNode() = default;
561
562 const DataObjID& name() const { return m_data_object_path; }
563
565 virtual bool accept( IGraphVisitor& visitor ) {
566 return visitor.visitEnter( *this ) ? visitor.visit( *this ) : true;
567 }
568
570 if ( std::find( m_producers.begin(), m_producers.end(), node ) == m_producers.end() )
571 m_producers.push_back( node );
572 }
573
575 if ( std::find( m_consumers.begin(), m_consumers.end(), node ) == m_consumers.end() )
576 m_consumers.push_back( node );
577 }
578
579 const std::vector<AlgorithmNode*>& getProducers() const { return m_producers; }
581 const std::vector<AlgorithmNode*>& getConsumers() const { return m_consumers; }
582
583 public:
585
586 private:
588 std::vector<AlgorithmNode*> m_producers;
589 std::vector<AlgorithmNode*> m_consumers;
590 };
591
592 class ConditionNode final : public DataNode {
593 public:
596 : DataNode( graph, path ), m_condSvc( condSvc ) {}
597
601 bool accept( IGraphVisitor& visitor ) override {
602 return visitor.visitEnter( *this ) ? visitor.visit( *this ) : true;
603 }
604
605 public:
606 // Service for Conditions handling
608 };
609
610 // ==========================================================================
611
613 virtual ~IPrecedenceRulesGraph() = default;
614 };
615
616 template <typename T>
618 bool operator()( const T& a, const T& b ) const { return a->name() < b->name(); }
619 };
620
621 class PrecedenceRulesGraph : public CommonMessaging<IPrecedenceRulesGraph> {
622 public:
624 PrecedenceRulesGraph( const std::string& name, SmartIF<ISvcLocator> svc ) : m_svcLocator( svc ), m_name( name ) {
625 // make sure that CommonMessaging is initialized
627 }
628
631
633 void accept( IGraphVisitor& visitor ) const;
634
636 StatusCode addDataNode( const DataObjID& dataPath );
638 DataNode* getDataNode( const DataObjID& dataPath ) const { return m_dataPathToDataNodeMap.at( dataPath ).get(); }
640 void registerIODataObjects( const Gaudi::Algorithm* algo );
643
645 void addHeadNode( const std::string& headName, concurrency::Concurrent, concurrency::PromptDecision,
650 StatusCode addAlgorithmNode( Gaudi::Algorithm* daughterAlgo, const std::string& parentName );
652 AlgorithmNode* getAlgorithmNode( const std::string& algoName ) const {
653 return m_algoNameToAlgoNodeMap.at( algoName ).get();
654 }
655
656 StatusCode addDecisionHubNode( Gaudi::Algorithm* daughterAlgo, const std::string& parentName,
660 unsigned int getControlFlowNodeCounter() const { return m_nodeCounter; }
661
663 void rankAlgorithms( IGraphVisitor& ranker ) const;
664
666 const std::string& name() const override { return m_name; }
671 void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const;
672
675 PRVertexDesc node( const std::string& ) const;
676
678 std::string dumpDataFlow() const;
680 std::string dumpControlFlow() const;
682 void dumpPrecRules( const boost::filesystem::path&, const EventSlot& slot );
684 void dumpPrecTrace( const boost::filesystem::path&, const EventSlot& slot );
686 void addEdgeToPrecTrace( const AlgorithmNode* u, const AlgorithmNode* v );
688 void dumpControlFlow( std::ostringstream&, ControlFlowNode*, const int& ) const;
689
690 private:
694 std::unordered_map<std::string, std::unique_ptr<AlgorithmNode>> m_algoNameToAlgoNodeMap;
696 std::unordered_map<std::string, std::unique_ptr<DecisionNode>> m_decisionNameToDecisionHubMap;
698 std::unordered_map<DataObjID, std::unique_ptr<DataNode>, DataObjID_Hasher> m_dataPathToDataNodeMap;
700 std::unordered_map<std::string, DataObjIDColl> m_algoNameToAlgoInputsMap;
701 std::unordered_map<std::string, DataObjIDColl> m_algoNameToAlgoOutputsMap;
702
704 unsigned int m_nodeCounter = 0;
706 unsigned int m_algoCounter = 0;
707
710 const std::string m_name;
711
714 std::map<std::string, precedence::AlgoTraceVertex> m_prec_trace_map;
715 bool m_enableAnalysis{ false };
718
721 };
722
723} // namespace concurrency
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.
Definition MsgStream.h:198
friend class CommonMessaging
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:87
Interface for the Condition Service.
Definition ICondSvc.h:38
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.
Definition MsgStream.h:29
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
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.
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.
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.
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
@ WARNING
Definition IMessageSvc.h:22
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
std::string m_sourceName
Class representing an event slot.
Definition EventSlot.h:23
time_point start
time_point end
std::string algorithm
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