ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
InvalidityTracer.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#include "InvalidityTracer.h"
4
6#include "Visitor.h"
7
8namespace ChimeraTK {
9
10 namespace {
11
12 /******************************************************************************************************************/
13
14 class InvalidityTracerVisitor : public Visitor<VariableNetworkNode, ApplicationModule> {
15 public:
16 explicit InvalidityTracerVisitor(ChimeraTK::Logger::StreamProxy& myLog) : _myLog(myLog) {}
17
18 // Print invalidity information for given module. This will also call dispatch() for all inputs of the given module.
19 void dispatch(const ApplicationModule& module) override;
20
21 // Print invalidity information for given input decorated with MetaDataPropagatingRegisterDecorator. Other nodes
22 // are simply ignored.
23 void dispatch(const VariableNetworkNode& node) override;
24
25 private:
27 };
28
29 /******************************************************************************************************************/
30
31 void InvalidityTracerVisitor::dispatch(const ApplicationModule& module) {
32 auto validity = module.getDataValidity();
33 // print, if validity is faulty
34 if(validity == DataValidity::faulty) {
35 _myLog << "Module " << module.getQualifiedName()
36 << " has DataValidity::faulty (count: " << module.getDataFaultCounter() << ")";
37
38 auto hash = module.getCircularNetworkHash();
39 if(hash != 0) {
40 _myLog << " (in circular network " << hash << " with invalidity count "
42 }
43
44 // dispatch to all accessors of the module
45 for(auto& accessor : module.getAccessorListRecursive()) {
46 dispatch(accessor);
47 }
48 }
49 }
50
51 /******************************************************************************************************************/
52
53 void InvalidityTracerVisitor::dispatch(const VariableNetworkNode& node) {
54 // ignore non-application nodes
55 if(node.getType() != NodeType::Application) {
56 return;
57 }
58
59 // ignore non-inputs
60 if(node.getDirection().dir != VariableDirection::consuming) {
61 return;
62 }
63
64 // get accessor and cast into right type (all application accessors must have the
65 // MetaDataPropagatingRegisterDecorator).
66 auto accessor = boost::dynamic_pointer_cast<MetaDataPropagationFlagProvider>(
67 node.getAppAccessorNoType().getHighLevelImplElement());
68 if(!accessor) {
69 _myLog << "InvalidityTracerVisitor: The following application node does not derive from "
70 "MetaDataPropagationFlagProvider:\n";
71 node.dump(_myLog);
72 return;
73 }
74
75 // check if invalid
76 if(accessor->getLastValidity() == DataValidity::faulty) {
77 _myLog << " -> Input " << node.getQualifiedName() << " has DataValidity::faulty\n";
78 }
79 }
80
81 /******************************************************************************************************************/
82
83 } // namespace
84
85 /********************************************************************************************************************/
86
88 while(true) {
89 // wait for user to hit the button
90 printTrace.read();
91
92 // start banner
93 auto myLog = logger(Logger::Severity::info);
94 InvalidityTracerVisitor visitor(myLog);
95 myLog << "==== BEGIN InvalidityTracer trace output ============================================\n";
96
97 // dispatch to all ApplicationModules
99 auto* appModule = dynamic_cast<ApplicationModule*>(module);
100 if(!appModule) {
101 continue;
102 }
103 visitor.dispatch(*appModule);
104 }
105
106 // end banner
107 myLog << "==== END InvalidityTracer trace output ==============================================";
108 }
109 }
110
111 /********************************************************************************************************************/
112
113} // namespace ChimeraTK
size_t getCircularNetworkInvalidityCounter(size_t circularNetworkHash) const
static Application & getInstance()
Obtain instance of the application.
Logger::StreamProxy logger(Logger::Severity severity)
Convenicene function to obtain a logger stream with the given Severity.
std::list< Module * > getSubmoduleListRecursive() const
Obtain the list of submodules associated with this instance and any submodules.
Proxy for output stream, handed out to the log sources by the Logger::Module.
Definition Logger.h:39
InvalidityTracer application module.
module_ module
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ScalarPushInput< int > printTrace