The Gaudi Framework  master (9f3f8895)
Loading...
Searching...
No Matches
PrecedenceRulesGraph.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2026 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// Local includes
15#include "../EventSlot.h"
17
18// Framework includes
19#include <Gaudi/Algorithm.h>
27
28// STL includes
29#include <algorithm>
30#include <filesystem>
31#include <memory>
32#include <sstream>
33#include <unordered_map>
34#include <variant>
35#include <vector>
36
37// Boost includes
38#include <boost/graph/adjacency_list.hpp>
39#include <boost/graph/graphml.hpp>
40
41namespace concurrency {
47} // namespace concurrency
48
49namespace precedence {
50
51 // Precedence trace utilities ==============================================
54 AlgoTraceProps( const std::string& name, int index = -1, int rank = -1, long int runtime = -1,
55 long long int start = -1 )
56 : m_name( name ), m_index( index ), m_rank( rank ), m_runtime( runtime ), m_start( start ) {}
57 std::string m_name;
58 int m_index{ -1 };
59 int m_rank{ -1 };
60 long int m_runtime{ -1 }; // us
61 long long int m_start{ -1 }; // ns
62 int m_eccentricity{ -1 };
63 };
64
65 using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
66 using AlgoTraceVertex = boost::graph_traits<PrecTrace>::vertex_descriptor;
67
68 // Precedence rules utilities ==============================================
69 struct AlgoProps {
71 AlgoProps( Gaudi::Algorithm* algo, uint nodeIndex, uint algoIndex )
72 : m_name( algo->name() )
73 , m_nodeIndex( nodeIndex )
74 , m_algoIndex( algoIndex )
75 , m_algorithm( algo )
76 , m_isAsynchronous( algo->isAsynchronous() ) {}
77
78 std::string m_name{ "" };
79 int m_nodeIndex{ -1 };
80 int m_algoIndex{ -1 };
81 int m_rank{ -1 };
85 bool m_isAsynchronous{ false };
86 };
87
89 DecisionHubProps( const std::string& name, uint nodeIndex, concurrency::Concurrent modeConcurrent,
90 concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR,
92 : m_name( name )
93 , m_nodeIndex( nodeIndex )
94 , m_modeConcurrent( modeConcurrent )
95 , m_modePromptDecision( modePromptDecision )
96 , m_inverted( isInverted )
97 , m_modeOR( modeOR )
98 , m_allPass( allPass ) {}
99
100 std::string m_name;
102
109 bool m_inverted{ false };
114 };
115
116 struct DataProps {
117 DataProps( const DataObjID& id ) : m_id( id ) {}
118
120 };
121
123 CondDataProps( const DataObjID& id ) : DataProps( id ) {}
124 };
125
126 // Vertex unpacking ========================================================
127
128 struct VertexName {
129 std::string operator()( const AlgoProps& props ) const { return props.m_name; }
130
131 std::string operator()( const DecisionHubProps& props ) const { return props.m_name; }
132
133 std::string operator()( const DataProps& props ) const { return props.m_id.fullKey(); }
134 };
135
136 struct GroupMode {
137 std::string operator()( const AlgoProps& ) const { return ""; }
138
139 std::string operator()( const DecisionHubProps& props ) const {
140 return props.m_modeConcurrent ? "Concurrent" : "Sequential";
141 }
142
143 std::string operator()( const DataProps& ) const { return ""; }
144 };
145
146 struct GroupLogic {
147 std::string operator()( const AlgoProps& ) const { return ""; }
148
149 std::string operator()( const DecisionHubProps& props ) const { return props.m_modeOR ? "OR" : "AND"; }
150
151 std::string operator()( const DataProps& ) const { return ""; }
152 };
153
154 struct GroupExit {
155 std::string operator()( const AlgoProps& ) const { return ""; }
156
157 std::string operator()( const DecisionHubProps& props ) const {
158 return props.m_modePromptDecision ? "Early" : "Late";
159 }
160
161 std::string operator()( const DataProps& ) const { return ""; }
162 };
163
165 std::string operator()( const AlgoProps& ) const { return ""; }
166
167 std::string operator()( const DecisionHubProps& props ) const {
168 return props.m_inverted ? "Inverted" : "Non-inverted";
169 }
170
171 std::string operator()( const DataProps& ) const { return ""; }
172 };
173
174 struct AllPass {
175 std::string operator()( const AlgoProps& ) const { return ""; }
176
177 std::string operator()( const DecisionHubProps& props ) const { return props.m_allPass ? "Optimist" : "Realist"; }
178
179 std::string operator()( const DataProps& ) const { return ""; }
180 };
181
182 struct CFDecision {
183 CFDecision( const EventSlot& slot ) : m_slot( slot ) {}
184
185 std::string operator()( const AlgoProps& props ) const {
186 return std::to_string( m_slot.controlFlowState.at( props.m_nodeIndex ) );
187 }
188
189 std::string operator()( const DecisionHubProps& props ) const {
190 return std::to_string( m_slot.controlFlowState.at( props.m_nodeIndex ) );
191 }
192
193 std::string operator()( const DataProps& ) const { return ""; }
194
196 };
197
198 struct EntityState {
199 EntityState( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator, bool conditionsEnabled )
200 : m_slot( slot )
201 , m_whiteboard( svcLocator->service<IHiveWhiteBoard>( "EventDataSvc", false ) )
202 , m_conditionsEnabled( conditionsEnabled ) {
203 SmartIF<IMessageSvc> msgSvc{ svcLocator };
204 MsgStream log{ msgSvc, "EntityState.Getter" };
205
206 // Figure if we can discover the data object states
207 if ( !m_whiteboard.isValid() ) {
208 log << MSG::WARNING << "Failed to locate EventDataSvc: no way to add DO "
209 << "states to the TTT dump " << endmsg;
210 }
211
212 if ( m_conditionsEnabled ) {
213 // Figure if we can discover Condition data object states
214 m_condSvc = svcLocator->service<ICondSvc>( "CondSvc", false );
215 if ( !m_condSvc.isValid() )
216 log << MSG::WARNING << "Failed to locate CondSvc: no way to add Condition DO "
217 << "states to the TTT dump " << endmsg;
218 }
219
220 if ( !m_slot.eventContext->valid() )
221 log << MSG::WARNING << "Event context is invalid: no way to add DO states"
222 << " in the TTT dump" << endmsg;
223 }
224
225 // Returns algorithm's FSM state
226 std::string operator()( const AlgoProps& props ) const {
227 std::ostringstream oss;
228 oss << m_slot.algsStates[props.m_algoIndex];
229 return oss.str();
230 }
231
232 std::string operator()( const DecisionHubProps& ) const { return ""; }
233
234 std::string operator()( const DataProps& props ) const {
235 std::string state;
236
237 if ( m_whiteboard.isValid() && m_slot.eventContext->valid() )
238 if ( m_whiteboard->selectStore( m_slot.eventContext->slot() ).isSuccess() )
239 state = m_whiteboard->exists( props.m_id ) ? "Produced" : "Missing";
240
241 return state;
242 }
243
244 std::string operator()( const CondDataProps& props ) const {
245 std::string state;
246
247 if ( m_condSvc.isValid() && m_slot.eventContext->valid() )
248 state = m_condSvc->isValidID( *( m_slot.eventContext ), props.m_id ) ? "Produced" : "Missing";
249
250 return state;
251 }
252
254
257 bool m_conditionsEnabled{ false };
258 };
259
260 struct StartTime {
261 StartTime( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator )
262 : m_slot( slot ), m_timelineSvc( svcLocator->service<ITimelineSvc>( "TimelineSvc", false ) ) {
263 SmartIF<IMessageSvc> msgSvc{ svcLocator };
264 MsgStream log{ msgSvc, "StartTime.Getter" };
265
266 // Figure if we can discover the algorithm timings
267 if ( !m_timelineSvc.isValid() ) {
268 log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to "
269 << "add algorithm start time to the TTT dumps" << endmsg;
270 }
271 }
272
273 std::string operator()( const AlgoProps& props ) const {
274
275 std::string startTime;
276
277 if ( m_timelineSvc.isValid() ) {
278
279 TimelineEvent te{};
280 te.algorithm = props.m_name;
281 te.slot = m_slot.eventContext->slot();
282 te.event = m_slot.eventContext->evt();
283
284 m_timelineSvc->getFirstMatching( te );
285 startTime = std::to_string(
286 std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
287 }
288
289 return startTime;
290 }
291
292 std::string operator()( const DecisionHubProps& ) const { return ""; }
293
294 std::string operator()( const DataProps& ) const { return ""; }
295
298 };
299
300 struct EndTime {
301 EndTime( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator )
302 : m_slot( slot ), m_timelineSvc( svcLocator->service<ITimelineSvc>( "TimelineSvc", false ) ) {
303 SmartIF<IMessageSvc> msgSvc{ svcLocator };
304 MsgStream log{ msgSvc, "EndTime.Getter" };
305
306 // Figure if we can discover the algorithm timings
307 if ( !m_timelineSvc.isValid() )
308 log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to add "
309 << "algorithm completion time to the TTT dumps" << endmsg;
310 }
311
312 std::string operator()( const AlgoProps& props ) const {
313
314 std::string endTime;
315
316 if ( m_timelineSvc.isValid() ) {
317
318 TimelineEvent te{};
319 te.algorithm = props.m_name;
320 te.slot = m_slot.eventContext->slot();
321 te.event = m_slot.eventContext->evt();
322
323 m_timelineSvc->getLastMatching( te );
324 endTime =
325 std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
326 }
327
328 return endTime;
329 }
330
331 std::string operator()( const DecisionHubProps& ) const { return ""; }
332
333 std::string operator()( const DataProps& ) const { return ""; }
334
337 };
338
339 struct Duration {
340 Duration( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator )
341 : m_slot( slot ), m_timelineSvc( svcLocator->service<ITimelineSvc>( "TimelineSvc", false ) ) {
342 SmartIF<IMessageSvc> msgSvc{ svcLocator };
343 MsgStream log{ msgSvc, "Duration.Getter" };
344
345 // Figure if we can discover the algorithm timings
346 if ( !m_timelineSvc.isValid() )
347 log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to add "
348 << "algorithm's runtimes to the TTT dumps" << endmsg;
349 }
350
351 std::string operator()( const AlgoProps& props ) const {
352
353 std::string time;
354
355 if ( m_timelineSvc.isValid() ) {
356
357 TimelineEvent te;
358 te.algorithm = props.m_name;
359 te.slot = m_slot.eventContext->slot();
360 te.event = m_slot.eventContext->evt();
361
362 // Calculate duration that is the difference between stop and and start for given algorithm. Asynchronous
363 // algorithms will have multiple TimelineEvents, so the start should be taken from the first and the end from
364 // the last.
365 m_timelineSvc->getFirstMatching( te );
366 auto start = te.start;
367 m_timelineSvc->getLastMatching( te );
368 auto end = te.end;
369 time = std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( end - start ).count() );
370 }
371
372 return time;
373 }
374
375 std::string operator()( const DecisionHubProps& ) const { return ""; }
376
377 std::string operator()( const DataProps& ) const { return ""; }
378
381 };
382
383 struct Operations {
384 std::string operator()( const AlgoProps& props ) const {
385 return props.m_isAsynchronous ? "Asynchronous" : "CPU-bound";
386 }
387
388 std::string operator()( const DecisionHubProps& ) const { return ""; }
389
390 std::string operator()( const DataProps& ) const { return ""; }
391 };
392
393 static inline std::ostream& operator<<( std::ostream& os, const AlgoProps& ) { return os << "Algorithm"; }
394 static inline std::ostream& operator<<( std::ostream& os, const DecisionHubProps& ) { return os << "DecisionHub"; }
395 static inline std::ostream& operator<<( std::ostream& os, const DataProps& ) { return os << "Data"; }
396 static inline std::ostream& operator<<( std::ostream& os, const CondDataProps& ) { return os << "ConditionData"; }
397
398 //=========================================================================
399
400 using VariantVertexProps = std::variant<AlgoProps, DecisionHubProps, DataProps, CondDataProps>;
401 using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
402 using PRVertexDesc = boost::graph_traits<PRGraph>::vertex_descriptor;
403
404} // namespace precedence
405
406struct Cause final {
407 enum class source { Root, Task };
408
410 std::string m_sourceName;
411};
412
413namespace concurrency {
414 class PrecedenceRulesGraph;
415
422
423 // ==========================================================================
425 public:
427 ControlFlowNode( PrecedenceRulesGraph& graph, unsigned int nodeIndex, const std::string& name )
428 : m_graph( &graph ), m_nodeIndex( nodeIndex ), m_nodeName( name ) {}
429
430 virtual ~ControlFlowNode() = default;
431
433 virtual bool accept( IGraphVisitor& visitor ) = 0;
435 virtual void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const = 0;
437 const unsigned int& getNodeIndex() const { return m_nodeIndex; }
439 const std::string& name() const { return m_nodeName; }
440
441 public:
443
444 protected:
445 unsigned int m_nodeIndex;
446 std::string m_nodeName;
447 };
448
449 class DecisionNode final : public ControlFlowNode {
450 public:
452 DecisionNode( PrecedenceRulesGraph& graph, unsigned int nodeIndex, const std::string& name,
453 Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass,
454 Inverted isInverted )
455 : ControlFlowNode( graph, nodeIndex, name )
456 , m_modeConcurrent( modeConcurrent )
457 , m_modePromptDecision( modePromptDecision )
458 , m_modeOR( modeOR )
459 , m_allPass( allPass )
460 , m_inverted( isInverted ) {}
461
463 bool accept( IGraphVisitor& visitor ) override;
465 void addParentNode( DecisionNode* node );
467 void addDaughterNode( ControlFlowNode* node );
469 const std::vector<ControlFlowNode*>& getDaughters() const { return m_children; }
471 void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const override;
472
473 public:
484 bool m_inverted{ false };
486 std::vector<ControlFlowNode*> m_children;
488 std::vector<DecisionNode*> m_parents;
489 };
490
491 // ==========================================================================
492 class DataNode;
493
494 class AlgorithmNode final : public ControlFlowNode {
495 public:
497 AlgorithmNode( PrecedenceRulesGraph& graph, Gaudi::Algorithm* algoPtr, unsigned int nodeIndex,
498 unsigned int algoIndex )
499 : ControlFlowNode( graph, nodeIndex, algoPtr->name() )
500 , m_algorithm( algoPtr )
501 , m_algoIndex( algoIndex )
502 , m_algoName( algoPtr->name() )
503 , m_isAsynchronous( algoPtr->isAsynchronous() ) {}
504
506 bool accept( IGraphVisitor& visitor ) override;
507
509 void addParentNode( DecisionNode* node );
511 const std::vector<DecisionNode*>& getParentDecisionHubs() const { return m_parents; }
512
514 void addOutputDataNode( DataNode* node );
516 void addInputDataNode( DataNode* node );
518 const std::vector<DataNode*>& getOutputDataNodes() const { return m_outputs; }
520 const std::vector<DataNode*>& getInputDataNodes() const { return m_inputs; }
521
523 void setRank( float rank ) { m_rank = rank; }
525 float getRank() const { return m_rank; }
526
530 unsigned int getAlgoIndex() const { return m_algoIndex; }
531
533 void setAsynchronous( bool value ) { m_isAsynchronous = value; }
535 bool isAsynchronous() const { return m_isAsynchronous; }
536
538 void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const override;
539
540 public:
542 std::vector<DecisionNode*> m_parents;
543
544 private:
548 unsigned int m_algoIndex;
550 std::string m_algoName;
552 float m_rank = -1;
555
557 std::vector<DataNode*> m_outputs;
559 std::vector<DataNode*> m_inputs;
560 };
561
562 // ==========================================================================
563 class DataNode {
564 public:
566 DataNode( PrecedenceRulesGraph& graph, const DataObjID& path ) : m_graph( &graph ), m_data_object_path( path ) {}
567
569 virtual ~DataNode() = default;
570
571 const DataObjID& name() const { return m_data_object_path; }
572
574 virtual bool accept( IGraphVisitor& visitor ) {
575 return visitor.visitEnter( *this ) ? visitor.visit( *this ) : true;
576 }
577
579 if ( std::find( m_producers.begin(), m_producers.end(), node ) == m_producers.end() )
580 m_producers.push_back( node );
581 }
582
584 if ( std::find( m_consumers.begin(), m_consumers.end(), node ) == m_consumers.end() )
585 m_consumers.push_back( node );
586 }
587
588 const std::vector<AlgorithmNode*>& getProducers() const { return m_producers; }
590 const std::vector<AlgorithmNode*>& getConsumers() const { return m_consumers; }
591
592 public:
594
595 private:
597 std::vector<AlgorithmNode*> m_producers;
598 std::vector<AlgorithmNode*> m_consumers;
599 };
600
601 class ConditionNode final : public DataNode {
602 public:
605 : DataNode( graph, path ), m_condSvc( condSvc ) {}
606
610 bool accept( IGraphVisitor& visitor ) override {
611 return visitor.visitEnter( *this ) ? visitor.visit( *this ) : true;
612 }
613
614 public:
615 // Service for Conditions handling
617 };
618
619 // ==========================================================================
620
622 virtual ~IPrecedenceRulesGraph() = default;
623 };
624
625 template <typename T>
627 bool operator()( const T& a, const T& b ) const { return a->name() < b->name(); }
628 };
629
630 class PrecedenceRulesGraph : public CommonMessaging<IPrecedenceRulesGraph> {
631 public:
633 PrecedenceRulesGraph( const std::string& name, SmartIF<ISvcLocator> svc ) : m_svcLocator( svc ), m_name( name ) {
634 // make sure that CommonMessaging is initialized
636 }
637
640
642 void accept( IGraphVisitor& visitor ) const;
643
645 StatusCode addDataNode( const DataObjID& dataPath );
647 DataNode* getDataNode( const DataObjID& dataPath ) const { return m_dataPathToDataNodeMap.at( dataPath ).get(); }
649 void registerIODataObjects( const Gaudi::Algorithm* algo );
652
654 void addHeadNode( const std::string& headName, concurrency::Concurrent, concurrency::PromptDecision,
659 StatusCode addAlgorithmNode( Gaudi::Algorithm* daughterAlgo, const std::string& parentName );
661 AlgorithmNode* getAlgorithmNode( const std::string& algoName ) const {
662 return m_algoNameToAlgoNodeMap.at( algoName ).get();
663 }
664
665 StatusCode addDecisionHubNode( Gaudi::Algorithm* daughterAlgo, const std::string& parentName,
669 unsigned int getControlFlowNodeCounter() const { return m_nodeCounter; }
670
672 void rankAlgorithms( IGraphVisitor& ranker ) const;
673
675 const std::string& name() const override { return m_name; }
680 void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const;
681
684 PRVertexDesc node( const std::string& ) const;
685
687 std::string dumpDataFlow() const;
689 std::string dumpControlFlow() const;
691 void dumpPrecRules( const std::filesystem::path&, const EventSlot& slot );
693 void dumpPrecTrace( const std::filesystem::path&, const EventSlot& slot );
695 void addEdgeToPrecTrace( const AlgorithmNode* u, const AlgorithmNode* v );
697 void dumpControlFlow( std::ostringstream&, ControlFlowNode*, const int& ) const;
698
699 private:
703 std::unordered_map<std::string, std::unique_ptr<AlgorithmNode>> m_algoNameToAlgoNodeMap;
705 std::unordered_map<std::string, std::unique_ptr<DecisionNode>> m_decisionNameToDecisionHubMap;
707 std::unordered_map<DataObjID, std::unique_ptr<DataNode>, DataObjID_Hasher> m_dataPathToDataNodeMap;
709 std::unordered_map<std::string, DataObjIDColl> m_algoNameToAlgoInputsMap;
710 std::unordered_map<std::string, DataObjIDColl> m_algoNameToAlgoOutputsMap;
711
713 unsigned int m_nodeCounter = 0;
715 unsigned int m_algoCounter = 0;
716
719 const std::string m_name;
720
723 std::map<std::string, precedence::AlgoTraceVertex> m_prec_trace_map;
724 bool m_enableAnalysis{ false };
727
730 };
731
732} // 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
MSG::Level setUpMessaging() const override final
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 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.
void dumpPrecRules(const std::filesystem::path &, const EventSlot &slot)
dump to file the 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.
void dumpPrecTrace(const std::filesystem::path &, const EventSlot &slot)
dump to file the precedence trace
const std::string & name() const override
Retrieve name of the service.
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
@ 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< PrecTrace >::vertex_descriptor AlgoTraceVertex
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
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
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)
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