The Gaudi Framework  v32r2 (46d42edc)
PrecedenceRulesGraph.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_PRECEDENCERULESGRAPH_H
2 #define GAUDIHIVE_PRECEDENCERULESGRAPH_H
3 
4 // std includes
5 #include <algorithm>
6 #include <memory>
7 #include <sstream>
8 #include <unordered_map>
9 #include <variant>
10 #include <vector>
11 
12 #include <boost/filesystem.hpp>
13 #include <boost/graph/adjacency_list.hpp>
14 #include <boost/graph/graphml.hpp>
15 
16 // fwk includes
17 #include "../AlgsExecutionStates.h"
18 #include "../EventSlot.h"
20 #include "GaudiKernel/DataObject.h"
21 #include "GaudiKernel/ICondSvc.h"
24 #include "GaudiKernel/TaggedBool.h"
25 #include "Visitors/IGraphVisitor.h"
26 #include <Gaudi/Algorithm.h>
27 
28 namespace concurrency {
29  using Concurrent = Gaudi::tagged_bool<class Concurrent_tag>;
30  using PromptDecision = Gaudi::tagged_bool<class PromptDecision_tag>;
31  using ModeOr = Gaudi::tagged_bool<class ModeOr_tag>;
32  using AllPass = Gaudi::tagged_bool<class AllPass_tag>;
33  using Inverted = Gaudi::tagged_bool<class Inverted_tag>;
34 } // namespace concurrency
35 
36 namespace precedence {
37 
38  // Precedence trace utilities ==============================================
39  struct AlgoTraceProps {
41  AlgoTraceProps( const std::string& name, int index, int rank, double runtime )
42  : m_name( name ), m_index( index ), m_rank( rank ), m_runtime( runtime ) {}
44  int m_index{-1};
45  int m_rank{-1};
46  int m_runtime{-1}; // ns
47  int m_eccentricity{-1};
48  };
49 
50  using PrecTrace = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps>;
51  using AlgoTraceVertex = boost::graph_traits<PrecTrace>::vertex_descriptor;
52 
53  // Precedence rules utilities ==============================================
54  struct AlgoProps {
55  AlgoProps() {}
56  AlgoProps( Gaudi::Algorithm* algo, uint nodeIndex, uint algoIndex, bool inverted, bool allPass )
57  : m_name( algo->name() )
58  , m_nodeIndex( nodeIndex )
59  , m_algoIndex( algoIndex )
60  , m_algorithm( algo )
61  , m_inverted( inverted )
62  , m_allPass( allPass )
63  , m_isIOBound( algo->isIOBound() ) {}
64 
66  int m_nodeIndex{-1};
67  int m_algoIndex{-1};
68  int m_rank{-1};
71 
73  bool m_inverted{false};
75  bool m_allPass{false};
77  bool m_isIOBound{false};
78  };
79 
81  DecisionHubProps( const std::string& name, uint nodeIndex, concurrency::Concurrent modeConcurrent,
82  concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR,
83  concurrency::AllPass allPass, concurrency::Inverted isInverted )
84  : m_name( name )
85  , m_nodeIndex( nodeIndex )
86  , m_modeConcurrent( modeConcurrent )
87  , m_modePromptDecision( modePromptDecision )
88  , m_inverted( isInverted )
89  , m_modeOR( modeOR )
90  , m_allPass( allPass ) {}
91 
94 
101  bool m_inverted{false};
103  bool m_modeOR;
105  bool m_allPass;
106  };
107 
108  struct DataProps {
109  DataProps( const DataObjID& id ) : m_id( id ) {}
110 
112  };
113 
115  CondDataProps( const DataObjID& id ) : DataProps( id ) {}
116  };
117 
118  // Vertex unpacking ========================================================
119 
120  struct VertexName {
121  std::string operator()( const AlgoProps& props ) const { return props.m_name; }
122 
123  std::string operator()( const DecisionHubProps& props ) const { return props.m_name; }
124 
125  std::string operator()( const DataProps& props ) const { return props.m_id.fullKey(); }
126  };
127 
128  struct GroupMode {
129  std::string operator()( const AlgoProps& ) const { return ""; }
130 
131  std::string operator()( const DecisionHubProps& props ) const {
132  return props.m_modeConcurrent ? "Concurrent" : "Sequential";
133  }
134 
135  std::string operator()( const DataProps& ) const { return ""; }
136  };
137 
138  struct GroupLogic {
139  std::string operator()( const AlgoProps& ) const { return ""; }
140 
141  std::string operator()( const DecisionHubProps& props ) const { return props.m_modeOR ? "OR" : "AND"; }
142 
143  std::string operator()( const DataProps& ) const { return ""; }
144  };
145 
146  struct GroupExit {
147  std::string operator()( const AlgoProps& ) const { return ""; }
148 
149  std::string operator()( const DecisionHubProps& props ) const {
150  return props.m_modePromptDecision ? "Early" : "Late";
151  }
152 
153  std::string operator()( const DataProps& ) const { return ""; }
154  };
155 
157  std::string operator()( const AlgoProps& props ) const { return props.m_inverted ? "Inverted" : "Non-inverted"; }
158 
159  std::string operator()( const DecisionHubProps& ) const { return ""; }
160 
161  std::string operator()( const DataProps& ) const { return ""; }
162  };
163 
164  struct AllPass {
165  std::string operator()( const AlgoProps& props ) const { return props.m_allPass ? "Optimist" : "Realist"; }
166 
167  std::string operator()( const DecisionHubProps& props ) const { return props.m_allPass ? "Optimist" : "Realist"; }
168 
169  std::string operator()( const DataProps& ) const { return ""; }
170  };
171 
172  struct CFDecision {
173  CFDecision( const EventSlot& slot ) : m_slot( slot ) {}
174 
175  std::string operator()( const AlgoProps& props ) const {
177  }
178 
179  std::string operator()( const DecisionHubProps& props ) const {
181  }
182 
183  std::string operator()( const DataProps& ) const { return ""; }
184 
186  };
187 
188  struct EntityState {
189  EntityState( const EventSlot& slot, SmartIF<ISvcLocator>& svcLocator, bool conditionsEnabled )
190  : m_slot( slot ), m_conditionsEnabled( conditionsEnabled ) {
192  MsgStream log{msgSvc, "EntityState.Getter"};
193 
194  // Figure if we can discover the data object states
195  m_whiteboard = svcLocator->service<IHiveWhiteBoard>( "EventDataSvc", false );
196  if ( !m_whiteboard.isValid() ) {
197  log << MSG::WARNING << "Failed to locate EventDataSvc: no way to add DO "
198  << "states to the TTT dump " << endmsg;
199  }
200 
201  if ( m_conditionsEnabled ) {
202  // Figure if we can discover Condition data object states
203  m_condSvc = svcLocator->service<ICondSvc>( "CondSvc", false );
204  if ( !m_condSvc.isValid() )
205  log << MSG::WARNING << "Failed to locate CondSvc: no way to add Condition DO "
206  << "states to the TTT dump " << endmsg;
207  }
208 
209  if ( !m_slot.eventContext->valid() )
210  log << MSG::WARNING << "Event context is invalid: no way to add DO states"
211  << " in the TTT dump" << endmsg;
212  }
213 
214  // Returns algorithm's FSM state
215  std::string operator()( const AlgoProps& props ) const {
216  std::ostringstream oss;
217  oss << m_slot.algsStates[props.m_algoIndex];
218  return oss.str();
219  }
220 
221  std::string operator()( const DecisionHubProps& ) const { return ""; }
222 
223  std::string operator()( const DataProps& props ) const {
225 
227  if ( m_whiteboard->selectStore( m_slot.eventContext->slot() ).isSuccess() )
228  state = m_whiteboard->exists( props.m_id ) ? "Produced" : "Missing";
229 
230  return state;
231  }
232 
233  std::string operator()( const CondDataProps& props ) const {
235 
236  if ( m_condSvc.isValid() && m_slot.eventContext->valid() )
237  state = m_condSvc->isValidID( *( m_slot.eventContext ), props.m_id ) ? "Produced" : "Missing";
238 
239  return state;
240  }
241 
243 
246  bool m_conditionsEnabled{false};
247  };
248 
249  struct StartTime {
252  MsgStream log{msgSvc, "StartTime.Getter"};
253 
254  // Figure if we can discover the algorithm timings
255  m_timelineSvc = svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
256  if ( !m_timelineSvc.isValid() ) {
257  log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to "
258  << "add algorithm start time to the TTT dumps" << endmsg;
259  }
260  }
261 
262  std::string operator()( const AlgoProps& props ) const {
263 
264  std::string startTime;
265 
266  if ( m_timelineSvc.isValid() ) {
267 
268  TimelineEvent te{};
269  te.algorithm = props.m_name;
270  te.slot = m_slot.eventContext->slot();
271  te.event = m_slot.eventContext->evt();
272 
274  startTime = std::to_string(
275  std::chrono::duration_cast<std::chrono::nanoseconds>( te.start.time_since_epoch() ).count() );
276  }
277 
278  return startTime;
279  }
280 
281  std::string operator()( const DecisionHubProps& ) const { return ""; }
282 
283  std::string operator()( const DataProps& ) const { return ""; }
284 
287  };
288 
289  struct EndTime {
292  MsgStream log{msgSvc, "EndTime.Getter"};
293 
294  // Figure if we can discover the algorithm timings
295  m_timelineSvc = svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
296  if ( !m_timelineSvc.isValid() )
297  log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to add "
298  << "algorithm completion time to the TTT dumps" << endmsg;
299  }
300 
301  std::string operator()( const AlgoProps& props ) const {
302 
303  std::string endTime;
304 
305  if ( m_timelineSvc.isValid() ) {
306 
307  TimelineEvent te{};
308  te.algorithm = props.m_name;
309  te.slot = m_slot.eventContext->slot();
310  te.event = m_slot.eventContext->evt();
311 
313  endTime =
314  std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end.time_since_epoch() ).count() );
315  }
316 
317  return endTime;
318  }
319 
320  std::string operator()( const DecisionHubProps& ) const { return ""; }
321 
322  std::string operator()( const DataProps& ) const { return ""; }
323 
326  };
327 
328  struct Duration {
331  MsgStream log{msgSvc, "Duration.Getter"};
332 
333  // Figure if we can discover the algorithm timings
334  m_timelineSvc = svcLocator->service<ITimelineSvc>( "TimelineSvc", false );
335  if ( !m_timelineSvc.isValid() )
336  log << MSG::WARNING << "Failed to locate the TimelineSvc: no way to add "
337  << "algorithm's runtimes to the TTT dumps" << endmsg;
338  }
339 
340  std::string operator()( const AlgoProps& props ) const {
341 
343 
344  if ( m_timelineSvc.isValid() ) {
345 
346  TimelineEvent te;
347  te.algorithm = props.m_name;
348  te.slot = m_slot.eventContext->slot();
349  te.event = m_slot.eventContext->evt();
350 
352  time = std::to_string( std::chrono::duration_cast<std::chrono::nanoseconds>( te.end - te.start ).count() );
353  }
354 
355  return time;
356  }
357 
358  std::string operator()( const DecisionHubProps& ) const { return ""; }
359 
360  std::string operator()( const DataProps& ) const { return ""; }
361 
364  };
365 
366  struct Operations {
367  std::string operator()( const AlgoProps& props ) const { return props.m_isIOBound ? "IO-bound" : "CPU-bound"; }
368 
369  std::string operator()( const DecisionHubProps& ) const { return ""; }
370 
371  std::string operator()( const DataProps& ) const { return ""; }
372  };
373 
374  static inline std::ostream& operator<<( std::ostream& os, const AlgoProps& ) { return os << "Algorithm"; }
375  static inline std::ostream& operator<<( std::ostream& os, const DecisionHubProps& ) { return os << "DecisionHub"; }
376  static inline std::ostream& operator<<( std::ostream& os, const DataProps& ) { return os << "Data"; }
377  static inline std::ostream& operator<<( std::ostream& os, const CondDataProps& ) { return os << "ConditionData"; }
378 
379  //=========================================================================
380 
381  using VariantVertexProps = std::variant<AlgoProps, DecisionHubProps, DataProps, CondDataProps>;
382  using PRGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps>;
383  using PRVertexDesc = boost::graph_traits<PRGraph>::vertex_descriptor;
384 
385 } // namespace precedence
386 
387 struct Cause final {
388  enum class source { Root, Task };
389 
392 };
393 
394 namespace concurrency {
395  class PrecedenceRulesGraph;
396 
397  using precedence::AlgoProps;
399  using precedence::DataProps;
403 
404  // ==========================================================================
406  public:
408  ControlFlowNode( PrecedenceRulesGraph& graph, unsigned int nodeIndex, const std::string& name )
409  : m_graph( &graph ), m_nodeIndex( nodeIndex ), m_nodeName( name ) {}
411  virtual ~ControlFlowNode() = default;
412 
414  virtual bool accept( IGraphVisitor& visitor ) = 0;
416  virtual void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const = 0;
418  const unsigned int& getNodeIndex() const { return m_nodeIndex; }
420  const std::string& getNodeName() const { return m_nodeName; }
421 
422  public:
424 
425  protected:
426  unsigned int m_nodeIndex;
428  };
429 
430  class DecisionNode final : public ControlFlowNode {
431  public:
433  DecisionNode( PrecedenceRulesGraph& graph, unsigned int nodeIndex, const std::string& name,
434  Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass,
435  Inverted isInverted )
436  : ControlFlowNode( graph, nodeIndex, name )
437  , m_modeConcurrent( modeConcurrent )
438  , m_modePromptDecision( modePromptDecision )
439  , m_modeOR( modeOR )
440  , m_allPass( allPass )
441  , m_inverted( isInverted ) {}
442 
444  bool accept( IGraphVisitor& visitor ) override;
446  void addParentNode( DecisionNode* node );
448  void addDaughterNode( ControlFlowNode* node );
452  void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const override;
453 
454  public:
461  bool m_modeOR;
463  bool m_allPass;
465  bool m_inverted{false};
470  };
471 
472  // ==========================================================================
473  class DataNode;
474 
475  class AlgorithmNode final : public ControlFlowNode {
476  public:
478  AlgorithmNode( PrecedenceRulesGraph& graph, Gaudi::Algorithm* algoPtr, unsigned int nodeIndex,
479  unsigned int algoIndex, bool inverted, bool allPass )
480  : ControlFlowNode( graph, nodeIndex, algoPtr->name() )
481  , m_algorithm( algoPtr )
482  , m_algoIndex( algoIndex )
483  , m_algoName( algoPtr->name() )
484  , m_inverted( inverted )
485  , m_allPass( allPass )
486  , m_isIOBound( algoPtr->isIOBound() ){};
487 
489  bool accept( IGraphVisitor& visitor ) override;
490 
492  void addParentNode( DecisionNode* node );
495 
497  void addOutputDataNode( DataNode* node );
499  void addInputDataNode( DataNode* node );
504 
506  void setRank( float& rank ) { m_rank = rank; }
508  const float& getRank() const { return m_rank; }
509 
513  const unsigned int& getAlgoIndex() const { return m_algoIndex; }
514 
516  void setIOBound( bool value ) { m_isIOBound = value; }
518  bool isIOBound() const { return m_isIOBound; }
519 
521  bool isOptimist() const { return m_allPass; };
523  bool isLiar() const { return m_inverted; };
524 
526  void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const override;
527 
528  public:
531 
532  private:
536  unsigned int m_algoIndex;
542  bool m_allPass;
544  float m_rank = -1;
547 
552  };
553 
554  // ==========================================================================
555  class DataNode {
556  public:
559 
561  virtual ~DataNode() = default;
562 
563  const DataObjID& getPath() { return m_data_object_path; }
564 
566  virtual bool accept( IGraphVisitor& visitor ) {
567  return visitor.visitEnter( *this ) ? visitor.visit( *this ) : true;
568  }
571  if ( std::find( m_producers.begin(), m_producers.end(), node ) == m_producers.end() )
572  m_producers.push_back( node );
573  }
576  if ( std::find( m_consumers.begin(), m_consumers.end(), node ) == m_consumers.end() )
577  m_consumers.push_back( node );
578  }
583 
584  public:
586 
587  private:
591  };
592 
593  class ConditionNode final : public DataNode {
594  public:
597  : DataNode( graph, path ), m_condSvc( condSvc ) {}
598 
602  bool accept( IGraphVisitor& visitor ) override {
603  return visitor.visitEnter( *this ) ? visitor.visit( *this ) : true;
604  }
605 
606  public:
607  // Service for Conditions handling
609  };
610 
611  // ==========================================================================
612 
614  virtual ~IPrecedenceRulesGraph() = default;
615  };
616 
617  class PrecedenceRulesGraph : public CommonMessaging<IPrecedenceRulesGraph> {
618  public:
621  // make sure that CommonMessaging is initialized
622  setUpMessaging();
623  }
624 
627 
629  void accept( IGraphVisitor& visitor ) const;
630 
632  StatusCode addDataNode( const DataObjID& dataPath );
634  DataNode* getDataNode( const DataObjID& dataPath ) const { return m_dataPathToDataNodeMap.at( dataPath ).get(); }
636  void registerIODataObjects( const Gaudi::Algorithm* algo );
639 
644  DecisionNode* getHeadNode() const { return m_headNode; };
646  StatusCode addAlgorithmNode( Gaudi::Algorithm* daughterAlgo, const std::string& parentName, bool inverted,
647  bool allPass );
649  AlgorithmNode* getAlgorithmNode( const std::string& algoName ) const {
650  return m_algoNameToAlgoNodeMap.at( algoName ).get();
651  }
653  StatusCode addDecisionHubNode( Gaudi::Algorithm* daughterAlgo, const std::string& parentName,
657  unsigned int getControlFlowNodeCounter() const { return m_nodeCounter; }
658 
660  void rankAlgorithms( IGraphVisitor& ranker ) const;
661 
663  const std::string& name() const override { return m_name; }
665  SmartIF<ISvcLocator>& serviceLocator() const override { return m_svcLocator; }
668  void printState( std::stringstream& output, EventSlot& slot, const unsigned int& recursionLevel ) const {
669  if ( slot.parentSlot ) {
670  // Start at sub-slot entry point
671  m_decisionNameToDecisionHubMap.at( slot.entryPoint )->printState( output, slot, recursionLevel );
672  } else {
673  // Start at the head node for whole-event slots
674  m_headNode->printState( output, slot, recursionLevel );
675  }
676  }
677 
679  void enableAnalysis() { m_enableAnalysis = true; };
680  PRVertexDesc node( const std::string& ) const;
681 
683  std::string dumpDataFlow() const;
687  void dumpPrecRules( const boost::filesystem::path&, const EventSlot& slot );
689  void dumpPrecTrace( const boost::filesystem::path& );
691  void addEdgeToPrecTrace( const AlgorithmNode* u, const AlgorithmNode* v );
693  void dumpControlFlow( std::ostringstream&, ControlFlowNode*, const int& ) const;
694 
695  private:
707 
709  unsigned int m_nodeCounter = 0;
711  unsigned int m_algoCounter = 0;
712 
716 
720  bool m_enableAnalysis{false};
723 
726  };
727 
728 } // namespace concurrency
729 #endif
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoInputsMap
Indexes: maps of algorithm's name to algorithm's inputs/outputs.
std::string operator()(const DecisionHubProps &) const
std::vector< DataNode * > m_outputs
Algorithm outputs (DataNodes)
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VariantVertexProps > PRGraph
std::string operator()(const DecisionHubProps &props) const
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::string operator()(const DataProps &) const
std::string entryPoint
Event Views bookkeeping (TODO: optimize view bookkeeping)
Definition: EventSlot.h:84
Class representing an event slot.
Definition: EventSlot.h:14
ContextID_t slot() const
Definition: EventContext.h:41
std::vector< DecisionNode * > m_parents
Direct parent nodes.
AlgoTraceProps(const std::string &name, int index, int rank, double runtime)
ControlFlowNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name)
Constructor.
const std::string & getNodeName() const
Get node name.
unsigned int m_algoIndex
The index of the algorithm.
bool m_inverted
Whether the selection result is negated or not.
AlgorithmNode * getAlgorithmNode(const std::string &algoName) const
Get the AlgorithmNode from by algorithm name using graph index.
std::string operator()(const AlgoProps &props) const
std::string operator()(const DataProps &) const
precedence::PrecTrace m_precTrace
facilities for algorithm precedence tracing
AlgorithmNode(PrecedenceRulesGraph &graph, Gaudi::Algorithm *algoPtr, unsigned int nodeIndex, unsigned int algoIndex, bool inverted, bool allPass)
Constructor.
void setIOBound(bool value)
Set the I/O-boundness flag.
CondDataProps(const DataObjID &id)
ContextEvt_t evt() const
Definition: EventContext.h:40
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.
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
boost::graph_traits< PRGraph >::vertex_descriptor PRVertexDesc
std::string operator()(const DataProps &props) const
std::string m_algoName
The name of the algorithm.
StatusCode addAlgorithmNode(Gaudi::Algorithm *daughterAlgo, const std::string &parentName, bool inverted, bool allPass)
Add algorithm node.
std::string operator()(const DecisionHubProps &props) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
virtual bool visit(DecisionNode &)
Definition: IGraphVisitor.h:16
std::string operator()(const DecisionHubProps &props) const
void setRank(float &rank)
Set Algorithm rank.
std::vector< ControlFlowNode * > m_children
All direct daughter nodes in the tree.
virtual bool visitEnter(DecisionNode &) const
Definition: IGraphVisitor.h:15
Gaudi::Algorithm * getAlgorithm() const
get Algorithm representatives
void dumpPrecRules(const boost::filesystem::path &, const EventSlot &slot)
dump to file the precedence rules
EntityState(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator, bool conditionsEnabled)
std::string operator()(const CondDataProps &props) const
T to_string(T... args)
DataProps(const DataObjID &id)
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
std::string operator()(const DecisionHubProps &props) const
std::map< std::string, precedence::AlgoTraceVertex > m_prec_trace_map
std::vector< DecisionNode * > m_parents
Control flow parents of an AlgorithmNode (DecisionNodes)
std::string operator()(const DecisionHubProps &) const
virtual bool getTimelineEvent(TimelineEvent &) const =0
bool m_isIOBound
If an algorithm is blocking.
SmartIF< ITimelineSvc > m_timelineSvc
std::string algorithm
Definition: ITimelineSvc.h:21
std::vector< int > controlFlowState
State of the control flow.
Definition: EventSlot.h:77
unsigned int m_algoCounter
Total number of algorithm nodes in the graph.
bool m_allPass
Whether always passing regardless of daughter results.
virtual bool accept(IGraphVisitor &visitor)=0
Visitor entry point.
virtual bool exists(const DataObjID &)=0
Check if a data object exists in store.
std::string operator()(const DataProps &) const
StatusCode addDataNode(const DataObjID &dataPath)
Add DataNode that represents DataObject.
bool m_inverted
Whether the selection result is negated or not.
bool m_allPass
Whether always passing regardless of daughter results.
std::string operator()(const AlgoProps &props) const
bool valid() const
Definition: EventContext.h:44
std::string operator()(const AlgoProps &props) const
std::string operator()(const AlgoProps &props) const
std::unordered_map< DataObjID, std::unique_ptr< DataNode >, DataObjID_Hasher > m_dataPathToDataNodeMap
Index: map of data path to DataNode.
std::string fullKey() const
Definition: DataObjID.cpp:88
virtual ~IPrecedenceRulesGraph()=default
bool isOptimist() const
Check if positive control flow decision is enforced.
Gaudi::tagged_bool< class ModeOr_tag > ModeOr
MSG::Level setUpMessaging() const
Set up local caches.
const std::vector< AlgorithmNode * > & getConsumers() const
Get all data object consumers.
SmartIF< ITimelineSvc > m_timelineSvc
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
std::string operator()(const DataProps &) const
STL class.
const unsigned int & getAlgoIndex() const
Get algorithm index.
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
T at(T... args)
std::string operator()(const DecisionHubProps &props) const
time_point end
Definition: ITimelineSvc.h:24
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
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.
const std::vector< AlgorithmNode * > & getProducers() const
Get all data object producers.
SmartIF< ITimelineSvc > m_timelineSvc
void dumpPrecTrace(const boost::filesystem::path &)
dump to file the precedence trace
Duration(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
bool m_conditionsRealmEnabled
Enable conditions realm of precedence rules.
std::string operator()(const DecisionHubProps &props) const
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given 'slot' for all subsequent calls within the same thread id.
std::string operator()(const AlgoProps &) const
precedence::PRGraph m_PRGraph
BGL-based graph of precedence rules.
bool isIOBound() const
Check if algorithm is I/O-bound.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const
Print a string representing the control flow state.
GAUDI_API ISvcLocator * svcLocator()
PrecedenceRulesGraph * m_graph
Gaudi::tagged_bool< class Inverted_tag > Inverted
void enableAnalysis()
BGL-based facilities.
const DataObjID & getPath()
DecisionNode * m_headNode
the head node of the control flow graph
std::string operator()(const DataProps &) const
std::vector< AlgorithmNode * > m_consumers
SmartIF< ICondSvc > m_condSvc
DecisionNode(PrecedenceRulesGraph &graph, unsigned int nodeIndex, const std::string &name, Concurrent modeConcurrent, PromptDecision modePromptDecision, ModeOr modeOR, AllPass allPass, Inverted isInverted)
Constructor.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
std::string dumpControlFlow() const
Print out control flow of Algorithms and Sequences.
virtual bool accept(IGraphVisitor &visitor)
Entry point for a visitor.
virtual bool isValidID(const EventContext &ctx, const DataObjID &id) const =0
check to see if a specific condition object ID is valid for this event
std::string operator()(const DecisionHubProps &) const
std::string operator()(const DecisionHubProps &) const
const EventSlot & m_slot
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, AlgoTraceProps > PrecTrace
T str(T... args)
EndTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
const float & getRank() const
Get Algorithm rank.
DataNode(PrecedenceRulesGraph &graph, const DataObjID &path)
Constructor.
unsigned int getControlFlowNodeCounter() const
Get total number of control flow graph nodes.
bool m_modePromptDecision
Whether to evaluate the hub decision ASA its child decisions allow to do that.
void registerIODataObjects(const Gaudi::Algorithm *algo)
Register algorithm in the Data Dependency index.
Interface for the Condition Service.
Definition: ICondSvc.h:28
std::unordered_map< std::string, DataObjIDColl > m_algoNameToAlgoOutputsMap
bool m_allPass
Whether the selection result is relevant or always "pass".
bool m_inverted
Whether the selection result is negated or not.
std::string operator()(const DataProps &props) const
PrecedenceRulesGraph(const std::string &name, SmartIF< ISvcLocator > svc)
Constructor.
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.
time_point start
Definition: ITimelineSvc.h:23
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
float m_rank
Algorithm rank of any kind.
std::string operator()(const DataProps &) const
virtual ~ControlFlowNode()=default
Destructor.
void addOutputDataNode(DataNode *node)
Associate an AlgorithmNode, which is a data supplier for this one.
Gaudi::Algorithm * m_algorithm
Algorithm representative behind the AlgorithmNode.
T find(T... args)
std::unordered_map< std::string, std::unique_ptr< DecisionNode > > m_decisionNameToDecisionHubMap
Index: map of decision's name to DecisionHub.
std::string operator()(const DataProps &) const
STL class.
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.
SmartIF< IHiveWhiteBoard > m_whiteboard
std::string operator()(const DecisionHubProps &) const
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.
AlgoProps(Gaudi::Algorithm *algo, uint nodeIndex, uint algoIndex, bool inverted, bool allPass)
DecisionNode * getHeadNode() const
Get head node.
const std::string & name() const override
Retrieve name of the service.
std::string operator()(const AlgoProps &) const
std::vector< AlgorithmNode * > m_producers
virtual ~DataNode()=default
Destructor.
unsigned int m_nodeCounter
Total number of nodes in the graph.
const std::vector< DataNode * > & getOutputDataNodes() const
Get all supplier nodes.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
std::string operator()(const AlgoProps &) const
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
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:86
void addParentNode(DecisionNode *node)
Add a parent node.
bool m_inverted
Whether the selection result is negated or not.
DecisionHubProps(const std::string &name, uint nodeIndex, concurrency::Concurrent modeConcurrent, concurrency::PromptDecision modePromptDecision, concurrency::ModeOr modeOR, concurrency::AllPass allPass, concurrency::Inverted isInverted)
std::string operator()(const DecisionHubProps &) const
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.
PrecedenceRulesGraph * m_graph
bool isLiar() const
Check if control flow logic is always inverted.
std::string operator()(const DataProps &) const
bool m_modeOR
Whether acting as "and" (false) or "or" node (true)
std::string operator()(const DataProps &) const
std::string operator()(const DataProps &) const
bool m_modeConcurrent
Whether all daughters will be evaluated concurrently or sequentially.
const unsigned int & getNodeIndex() const
Get node index.
StatusCode buildDataDependenciesRealm()
Build data dependency realm WITH data object nodes participating.
void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const override
Print a string representing the control flow state.
const EventSlot & m_slot
STL class.
bool accept(IGraphVisitor &visitor) override
Need to hide the (identical) base method with this one so that visitEnter(ConditionNode&) and visit(C...
bool m_isIOBound
If an algorithm is blocking.
StartTime(const EventSlot &slot, SmartIF< ISvcLocator > &svcLocator)
virtual void printState(std::stringstream &output, EventSlot &slot, const unsigned int &recursionLevel) const =0
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.
Definition: MsgStream.h:192
std::unique_ptr< EventContext > eventContext
Cache for the eventContext.
Definition: EventSlot.h:73
std::string m_sourceName
bool m_allPass
Whether the selection result is relevant or always "pass".
void addProducerNode(AlgorithmNode *node)
Add relationship to producer AlgorithmNode.
void addHeadNode(const std::string &headName, concurrency::Concurrent, concurrency::PromptDecision, concurrency::ModeOr, concurrency::AllPass, concurrency::Inverted)
Add a node, which has no parents.
AlgsExecutionStates algsStates
Vector of algorithms states.
Definition: EventSlot.h:75
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:132
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
ConditionNode(PrecedenceRulesGraph &graph, const DataObjID &path, SmartIF< ICondSvc > condSvc)
Constructor.
void rankAlgorithms(IGraphVisitor &ranker) const
Rank Algorithm nodes by the number of data outputs.
CFDecision(const EventSlot &slot)
void addConsumerNode(AlgorithmNode *node)
Add relationship to consumer AlgorithmNode.