The Gaudi Framework  v33r0 (d5ea422b)
Validators.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 #ifndef VALIDATORS_H_
12 #define VALIDATORS_H_
13 
14 #include "../../EventSlot.h"
15 #include "../PrecedenceRulesGraph.h"
16 #include "IGraphVisitor.h"
17 
18 #include <algorithm>
19 #include <map>
20 #include <set>
21 #include <sstream>
22 #include <unordered_map>
23 #include <vector>
24 
25 namespace concurrency {
26 
27  //--------------------------------------------------------------------------
29  public:
32 
33  bool visitEnter( AlgorithmNode& ) const override { return false; };
34  bool visitEnter( DataNode& ) const override { return false; };
35  bool visitEnter( ConditionNode& ) const override { return false; };
36 
37  bool visit( DecisionNode& ) override;
38 
39  std::string reply() const { return m_status.str(); };
40  bool passed() const { return !m_foundViolations; };
41  void reset() override {
42  m_foundViolations = false;
43  m_status.clear();
44  }
45 
46  private:
47  std::ostringstream m_status{" No 'Concurrent'/'Prompt' contradictions found"};
48  bool m_foundViolations{false};
49  };
50 
51  //--------------------------------------------------------------------------
53  public:
55  ActiveLineageScout( const EventSlot* slot, const ControlFlowNode& node )
56  : m_slot( slot ), m_startNode( node ), m_previousNodeName( node.name() ){};
57 
60 
61  bool visitEnter( AlgorithmNode& ) const override { return false; };
62  bool visitEnter( DataNode& ) const override { return false; };
63  bool visitEnter( ConditionNode& ) const override { return false; };
64 
65  bool visit( DecisionNode& ) override;
66 
67  void reset() override {
68  m_active = true;
70  };
71 
72  virtual bool reply() const { return m_active; };
73 
74  virtual void visitParents( DecisionNode& );
75 
76  protected:
77  const EventSlot* m_slot;
79  bool m_active{true};
81  };
82 
83  //--------------------------------------------------------------------------
84  class SubSlotScout final : public ActiveLineageScout {
85  public:
87  SubSlotScout( const EventSlot* slot, const ControlFlowNode& node )
88  : ActiveLineageScout( slot, node ), m_foundEntryPoint( slot->parentSlot == nullptr ){};
89 
90  void reset() override {
91  m_active = true;
92 
93  // Only look for an entry point if we're in a sub-slot
94  m_foundEntryPoint = ( m_slot->parentSlot == nullptr );
96  };
97 
98  bool reply() const override { return m_active && m_foundEntryPoint; };
99 
100  void visitParents( DecisionNode& ) override;
101 
102  private:
103  bool m_foundEntryPoint{true};
104  };
105 
106  //--------------------------------------------------------------------------
108  public:
109  using IGraphVisitor::visit;
111 
112  bool visitEnter( DataNode& ) const override { return false; };
113  bool visitEnter( ConditionNode& ) const override { return false; };
114 
115  bool visit( DecisionNode& ) override;
116  bool visit( AlgorithmNode& ) override;
117 
118  bool positive() const { return m_positive; };
119  bool negative() const { return m_negative; };
120 
121  void reset() override {
122  m_positive = false;
123  m_negative = false;
124  };
125 
126  private:
127  bool m_positive{false};
128  bool m_negative{false};
129  };
130 
131  //--------------------------------------------------------------------------
133  public:
134  using IGraphVisitor::visit;
136 
137  bool visitEnter( AlgorithmNode& ) const override { return false; };
138  bool visitEnter( DecisionNode& ) const override { return false; };
139 
140  bool visit( DataNode& ) override;
141  bool visit( ConditionNode& ) override;
142 
143  std::string reply() const;
144  bool passed() const {
146  []( const auto& pr ) { return pr.second.size() == 1; } );
147  };
148  void reset() override {
149  m_foundViolations = false;
152  };
153 
154  private:
155  bool m_foundViolations{false};
156 
157  using visitor_book =
161  };
162 
170  public:
171  using IGraphVisitor::visit;
173 
174  bool visitEnter( ConditionNode& ) const override { return false; };
175  bool visitEnter( DecisionNode& ) const override { return false; };
176  bool visitEnter( AlgorithmNode& node ) const override {
177  // check if the node was already visited
178  return m_lowlinks.find( &node ) != m_lowlinks.end() ? false : true;
179  }
180 
181  bool visit( AlgorithmNode& nodeAt ) override;
182 
183  bool passed() const {
184  return m_scc.empty() ||
185  !std::any_of( m_scc.begin(), m_scc.end(), []( const auto& pr ) { return pr.second.size() > 1; } );
186  };
187 
188  std::string reply();
189 
190  void reset() override {
191  m_nodes_count = 0;
192  m_stack.clear();
193  m_lowlinks.clear();
194  m_scc.clear();
195  m_status = std::ostringstream{" No strongly connected components found in DF realm"};
196  };
197 
198  private:
199  bool on_stack( const AlgorithmNode& node ) const {
200  return std::find( m_stack.begin(), m_stack.end(), &node ) != m_stack.end() ? true : false;
201  }
202 
203  unsigned int m_nodes_count{0};
204 
208 
209  std::ostringstream m_status{" No strongly connected components found in DF realm"};
210  };
211 
212 } // namespace concurrency
213 
214 #endif /* VALIDATORS_H_ */
const ControlFlowNode & m_startNode
Definition: Validators.h:78
bool visit(DataNode &) override
Definition: Validators.cpp:143
virtual void visitParents(DecisionNode &)
Definition: Validators.cpp:66
bool visit(AlgorithmNode &nodeAt) override
Definition: Validators.cpp:235
Class representing an event slot.
Definition: EventSlot.h:24
SubSlotScout(const EventSlot *slot, const ControlFlowNode &node)
Constructor.
Definition: Validators.h:87
bool visit(DecisionNode &) override
Definition: Validators.cpp:18
ActiveLineageScout(const EventSlot *slot, const ControlFlowNode &node)
Constructor.
Definition: Validators.h:55
bool visitEnter(DecisionNode &) const override
Definition: Validators.h:138
virtual bool visit(DecisionNode &)
Definition: IGraphVisitor.h:26
virtual bool visitEnter(DecisionNode &) const
Definition: IGraphVisitor.h:25
bool visitEnter(DecisionNode &) const override
Definition: Validators.h:175
bool visit(DecisionNode &) override
Definition: Validators.cpp:38
bool visitEnter(ConditionNode &) const override
Definition: Validators.h:174
bool visitEnter(AlgorithmNode &) const override
Definition: Validators.h:33
std::map< DataNode *, std::set< AlgorithmNode *, CompareNodes< AlgorithmNode * > >, CompareNodes< DataNode * > > visitor_book
Definition: Validators.h:158
T end(T... args)
STL class.
STL class.
bool visitEnter(ConditionNode &) const override
Definition: Validators.h:63
std::ostringstream m_status
Definition: Validators.h:209
bool reply() const override
Definition: Validators.h:98
T str(T... args)
bool visit(DecisionNode &) override
Definition: Validators.cpp:104
std::map< unsigned int, std::vector< AlgorithmNode * > > m_scc
Definition: Validators.h:206
The visitor implements the Tarjan algorithm for searching strongly connected components in the data f...
Definition: Validators.h:169
void visitParents(DecisionNode &) override
Definition: Validators.cpp:79
T clear(T... args)
bool visitEnter(DataNode &) const override
Definition: Validators.h:62
T find(T... args)
bool on_stack(const AlgorithmNode &node) const
Definition: Validators.h:199
T size(T... args)
std::unordered_map< AlgorithmNode *, std::pair< unsigned int, unsigned int > > m_lowlinks
Definition: Validators.h:205
STL class.
bool visitEnter(ConditionNode &) const override
Definition: Validators.h:35
std::vector< AlgorithmNode * > m_stack
Definition: Validators.h:207
T begin(T... args)
bool visitEnter(ConditionNode &) const override
Definition: Validators.h:113
T all_of(T... args)
bool visitEnter(DataNode &) const override
Definition: Validators.h:34
EventSlot * parentSlot
Pointer to parent slot (null for top level)
Definition: EventSlot.h:96
bool visitEnter(DataNode &) const override
Definition: Validators.h:112
bool visitEnter(AlgorithmNode &node) const override
Definition: Validators.h:176
bool visitEnter(AlgorithmNode &) const override
Definition: Validators.h:61
bool visitEnter(AlgorithmNode &) const override
Definition: Validators.h:137
const EventSlot * m_slot
Definition: Validators.h:77
void reset() override
Definition: Validators.h:90
const std::string & name() const
Get node name.
virtual bool reply() const
Definition: Validators.h:72