The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
Validators.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#include "../../EventSlot.h"
15#include "IGraphVisitor.h"
16
17#include <algorithm>
18#include <map>
19#include <set>
20#include <sstream>
21#include <unordered_map>
22#include <vector>
23
24namespace concurrency {
25
26 //--------------------------------------------------------------------------
28 public:
31
32 bool visitEnter( AlgorithmNode& ) const override { return false; }
33 bool visitEnter( DataNode& ) const override { return false; }
34 bool visitEnter( ConditionNode& ) const override { return false; }
35
36 bool visit( DecisionNode& ) override;
37
38 std::string reply() const { return m_status.str(); }
39 bool passed() const { return !m_foundViolations; }
40 void reset() override {
41 m_foundViolations = false;
42 m_status.clear();
43 }
44
45 private:
46 std::ostringstream m_status{ " No 'Concurrent'/'Prompt' contradictions found" };
47 bool m_foundViolations{ false };
48 };
49
50 //--------------------------------------------------------------------------
52 public:
54 ActiveLineageScout( const EventSlot* slot, const ControlFlowNode& node )
55 : m_slot( slot ), m_startNode( node ), m_previousNodeName( node.name() ) {}
56
59
60 bool visitEnter( AlgorithmNode& ) const override { return false; }
61 bool visitEnter( DataNode& ) const override { return false; }
62 bool visitEnter( ConditionNode& ) const override { return false; }
63
64 bool visit( DecisionNode& ) override;
65
66 void reset() override {
67 m_active = true;
69 }
70
71 virtual bool reply() const { return m_active; }
72
73 virtual void visitParents( DecisionNode& );
74
75 protected:
78 bool m_active{ true };
79 std::string m_previousNodeName;
80 };
81
82 //--------------------------------------------------------------------------
83 class SubSlotScout final : public ActiveLineageScout {
84 public:
86 SubSlotScout( const EventSlot* slot, const ControlFlowNode& node )
87 : ActiveLineageScout( slot, node ), m_foundEntryPoint( slot->parentSlot == nullptr ) {}
88
89 void reset() override {
90 m_active = true;
91
92 // Only look for an entry point if we're in a sub-slot
93 m_foundEntryPoint = ( m_slot->parentSlot == nullptr );
95 }
96
97 bool reply() const override { return m_active && m_foundEntryPoint; }
98
99 void visitParents( DecisionNode& ) override;
100
101 private:
102 bool m_foundEntryPoint{ true };
103 };
104
105 //--------------------------------------------------------------------------
107 public:
110
111 bool visitEnter( DataNode& ) const override { return false; }
112 bool visitEnter( ConditionNode& ) const override { return false; }
113
114 bool visit( DecisionNode& ) override;
115 bool visit( AlgorithmNode& ) override;
116
117 bool positive() const { return m_positive; }
118 bool negative() const { return m_negative; }
119
120 void reset() override {
121 m_positive = false;
122 m_negative = false;
123 }
124
125 private:
126 bool m_positive{ false };
127 bool m_negative{ false };
128 };
129
130 //--------------------------------------------------------------------------
132 public:
135
136 bool visitEnter( AlgorithmNode& ) const override { return false; }
137 bool visitEnter( DecisionNode& ) const override { return false; }
138
139 bool visit( DataNode& ) override;
140 bool visit( ConditionNode& ) override;
141
142 std::string reply() const;
143 bool passed() const {
144 return std::all_of( m_unconditionalProducers.begin(), m_unconditionalProducers.end(),
145 []( const auto& pr ) { return pr.second.size() == 1; } );
146 }
147 void reset() override {
148 m_foundViolations = false;
151 }
152
153 private:
154 bool m_foundViolations{ false };
155
157 std::map<DataNode*, std::set<AlgorithmNode*, CompareNodes<AlgorithmNode*>>, CompareNodes<DataNode*>>;
160 };
161
169 public:
172
173 bool visitEnter( ConditionNode& ) const override { return false; }
174 bool visitEnter( DecisionNode& ) const override { return false; }
175 bool visitEnter( AlgorithmNode& node ) const override {
176 // check if the node was already visited
177 return m_lowlinks.find( &node ) != m_lowlinks.end() ? false : true;
178 }
179
180 bool visit( AlgorithmNode& nodeAt ) override;
181
182 bool passed() const {
183 return m_scc.empty() ||
184 !std::any_of( m_scc.begin(), m_scc.end(), []( const auto& pr ) { return pr.second.size() > 1; } );
185 }
186
187 std::string reply();
188
189 void reset() override {
190 m_nodes_count = 0;
191 m_stack.clear();
192 m_lowlinks.clear();
193 m_scc.clear();
194 m_status = std::ostringstream{ " No strongly connected components found in DF realm" };
195 }
196
197 private:
198 bool on_stack( const AlgorithmNode& node ) const {
199 return std::find( m_stack.begin(), m_stack.end(), &node ) != m_stack.end() ? true : false;
200 }
201
202 unsigned int m_nodes_count{ 0 };
203
204 std::unordered_map<AlgorithmNode*, std::pair<unsigned int, unsigned int>> m_lowlinks;
205 std::map<unsigned int, std::vector<AlgorithmNode*>> m_scc;
206 std::vector<AlgorithmNode*> m_stack;
207
208 std::ostringstream m_status{ " No strongly connected components found in DF realm" };
209 };
210
211} // namespace concurrency
virtual bool reply() const
Definition Validators.h:71
bool visitEnter(ConditionNode &) const override
Definition Validators.h:62
const ControlFlowNode & m_startNode
Definition Validators.h:77
bool visit(DecisionNode &) override
bool visitEnter(DataNode &) const override
Definition Validators.h:61
ActiveLineageScout(const EventSlot *slot, const ControlFlowNode &node)
Constructor.
Definition Validators.h:54
bool visitEnter(AlgorithmNode &) const override
Definition Validators.h:60
virtual void visitParents(DecisionNode &)
bool visitEnter(DataNode &) const override
Definition Validators.h:111
bool visitEnter(ConditionNode &) const override
Definition Validators.h:112
bool visit(DecisionNode &) override
virtual bool visit(DecisionNode &)
virtual bool visitEnter(DecisionNode &) const
bool visitEnter(AlgorithmNode &) const override
Definition Validators.h:32
bool visitEnter(ConditionNode &) const override
Definition Validators.h:34
bool visit(DecisionNode &) override
bool visitEnter(DataNode &) const override
Definition Validators.h:33
bool visitEnter(AlgorithmNode &) const override
Definition Validators.h:136
std::map< DataNode *, std::set< AlgorithmNode *, CompareNodes< AlgorithmNode * > >, CompareNodes< DataNode * > > visitor_book
Definition Validators.h:156
bool visit(DataNode &) override
bool visitEnter(DecisionNode &) const override
Definition Validators.h:137
SubSlotScout(const EventSlot *slot, const ControlFlowNode &node)
Constructor.
Definition Validators.h:86
bool reply() const override
Definition Validators.h:97
void visitParents(DecisionNode &) override
void reset() override
Definition Validators.h:89
The visitor implements the Tarjan algorithm for searching strongly connected components in the data f...
Definition Validators.h:168
bool on_stack(const AlgorithmNode &node) const
Definition Validators.h:198
std::map< unsigned int, std::vector< AlgorithmNode * > > m_scc
Definition Validators.h:205
std::unordered_map< AlgorithmNode *, std::pair< unsigned int, unsigned int > > m_lowlinks
Definition Validators.h:204
bool visitEnter(AlgorithmNode &node) const override
Definition Validators.h:175
bool visitEnter(DecisionNode &) const override
Definition Validators.h:174
bool visit(AlgorithmNode &nodeAt) override
bool visitEnter(ConditionNode &) const override
Definition Validators.h:173
std::vector< AlgorithmNode * > m_stack
Definition Validators.h:206
std::ostringstream m_status
Definition Validators.h:208
Class representing an event slot.
Definition EventSlot.h:23