ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
StatusMonitor.h
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#pragma once
4
32#include "ApplicationModule.h"
33#include "ScalarAccessor.h"
34#include "StatusAccessor.h"
35
36namespace ChimeraTK {
37
38 /********************************************************************************************************************/
39 /* Declaration of MonitorBase **************************************************************************************/
40 /********************************************************************************************************************/
42 // make constructors protected not to allow of instantiancion of this object - this is just a base class for other monitors
43 protected:
44 MonitorBase(ModuleGroup* owner, const std::string& description, const std::string& outputPath,
45 const std::string& disablePath, const std::unordered_set<std::string>& outputTags = {},
46 const std::unordered_set<std::string>& parameterTags = {});
47
48 MonitorBase() = default;
49
50 public:
55
56 protected:
57 DataValidity _lastStatusValidity = DataValidity::ok;
58 void setStatus(StatusOutput::Status newStatus);
59 };
60
61 /********************************************************************************************************************/
62 /* Declaration of MaxMonitor ***************************************************************************************/
63 /********************************************************************************************************************/
64
66 template<typename T>
68 MaxMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
69 const std::string& parameterPath, const std::string& description,
70 const std::unordered_set<std::string>& outputTags = {},
71 const std::unordered_set<std::string>& parameterTags = {});
72
73 MaxMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
74 const std::string& warningThresholdPath, const std::string& faultThresholdPath, const std::string& disablePath,
75 const std::string& description, const std::unordered_set<std::string>& outputTags = {},
76 const std::unordered_set<std::string>& parameterTags = {});
77
78 MaxMonitor() = default;
79
82
85
88
95 void mainLoop() override;
96 };
97
98 /********************************************************************************************************************/
99 /* Declaration of MinMonitor ***************************************************************************************/
100 /********************************************************************************************************************/
101
103 template<typename T>
105 MinMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
106 const std::string& parameterPath, const std::string& description,
107 const std::unordered_set<std::string>& outputTags = {},
108 const std::unordered_set<std::string>& parameterTags = {});
109
110 MinMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
111 const std::string& warningThresholdPath, const std::string& faultThresholdPath, const std::string& disablePath,
112 const std::string& description, const std::unordered_set<std::string>& outputTags = {},
113 const std::unordered_set<std::string>& parameterTags = {});
114
115 MinMonitor() = default;
116
119
122
125
127 void mainLoop() override;
128 };
129
130 /********************************************************************************************************************/
131 /* Declaration of RangeMonitor *************************************************************************************/
132 /********************************************************************************************************************/
133
141 template<typename T>
143 RangeMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
144 const std::string& parameterPath, const std::string& description,
145 const std::unordered_set<std::string>& outputTags = {},
146 const std::unordered_set<std::string>& parameterTags = {});
147
148 RangeMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
149 const std::string& warningLowerThresholdPath, const std::string& warningUpperThresholdPath,
150 const std::string& faultLowerThresholdPath, const std::string& faultUpperThresholdPath,
151 const std::string& disablePath, const std::string& description,
152 const std::unordered_set<std::string>& outputTags = {},
153 const std::unordered_set<std::string>& parameterTags = {});
154
155 RangeMonitor() = default;
156
159
165
171
173 void mainLoop() override;
174 };
175
176 /********************************************************************************************************************/
177 /* Declaration of ExactMonitor *************************************************************************************/
178 /********************************************************************************************************************/
179
190 template<typename T>
201 ExactMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
202 const std::string& parameterPath, const std::string& description,
203 const std::unordered_set<std::string>& outputTags = {},
204 const std::unordered_set<std::string>& parameterTags = {});
205
216 ExactMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
217 const std::string& requiredValuePath, const std::string& disablePath, const std::string& description,
218 const std::unordered_set<std::string>& outputTags = {},
219 const std::unordered_set<std::string>& parameterTags = {});
220
221 ExactMonitor() = default;
222
225
228
230 void mainLoop() override;
231 };
232
233 /********************************************************************************************************************/
234 /* Implementation starts here **************************************************************************************/
235 /********************************************************************************************************************/
236
237 /********************************************************************************************************************/
238 /* Implementation of MaxMonitor ************************************************************************************/
239 /********************************************************************************************************************/
240 template<typename T>
241 MaxMonitor<T>::MaxMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
242 const std::string& parameterPath, const std::string& description,
243 const std::unordered_set<std::string>& outputTags, const std::unordered_set<std::string>& parameterTags)
244 : MaxMonitor(owner, inputPath, outputPath, parameterPath + "/upperWarningThreshold",
245 parameterPath + "/upperFaultThreshold", parameterPath + "/disable", description, outputTags, parameterTags) {}
246
247 /********************************************************************************************************************/
248 template<typename T>
249 MaxMonitor<T>::MaxMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
250 const std::string& warningThresholdPath, const std::string& faultThresholdPath, const std::string& disablePath,
251 const std::string& description, const std::unordered_set<std::string>& outputTags,
252 const std::unordered_set<std::string>& parameterTags)
253 : MonitorBase(owner, description, outputPath, disablePath, outputTags, parameterTags),
254 watch(this, inputPath, "", "Value to monitor"),
255 warningThreshold(this, warningThresholdPath, "", "Warning threshold to compare with", parameterTags),
256 faultThreshold(this, faultThresholdPath, "", "Fault threshold to compare with", parameterTags) {}
257
258 /********************************************************************************************************************/
259 template<typename T>
261 // If there is a change either in value monitored or in requiredValue, the status is re-evaluated
262 ReadAnyGroup group{watch, disable, warningThreshold, faultThreshold};
263
264 while(true) {
265 if(disable) {
266 setStatus(StatusOutput::Status::OFF);
267 }
268 else if(watch >= faultThreshold) {
269 setStatus(StatusOutput::Status::FAULT);
270 }
271 else if(watch >= warningThreshold) {
272 setStatus(StatusOutput::Status::WARNING);
273 }
274 else {
275 setStatus(StatusOutput::Status::OK);
276 }
277 group.readAny();
278 }
279 }
280
281 /********************************************************************************************************************/
282 /* Implementation of MinMonitor ************************************************************************************/
283 /********************************************************************************************************************/
284 template<typename T>
285 MinMonitor<T>::MinMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
286 const std::string& parameterPath, const std::string& description,
287 const std::unordered_set<std::string>& outputTags, const std::unordered_set<std::string>& parameterTags)
288 : MinMonitor(owner, inputPath, outputPath, parameterPath + "/lowerWarningThreshold",
289 parameterPath + "/lowerFaultThreshold", parameterPath + "/disable", description, outputTags, parameterTags) {}
290
291 /********************************************************************************************************************/
292 template<typename T>
293 MinMonitor<T>::MinMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
294 const std::string& warningThresholdPath, const std::string& faultThresholdPath, const std::string& disablePath,
295 const std::string& description, const std::unordered_set<std::string>& outputTags,
296 const std::unordered_set<std::string>& parameterTags)
297 : MonitorBase(owner, description, outputPath, disablePath, outputTags, parameterTags),
298 watch(this, inputPath, "", "Value to monitor"),
299 warningThreshold(this, warningThresholdPath, "", "Warning threshold to compare with", parameterTags),
300 faultThreshold(this, faultThresholdPath, "", "Fault threshold to compare with", parameterTags) {}
301
302 /********************************************************************************************************************/
303 template<typename T>
305 // If there is a change either in value monitored or in requiredValue, the status is re-evaluated
306 ReadAnyGroup group{watch, disable, warningThreshold, faultThreshold};
307
308 while(true) {
309 if(disable) {
310 setStatus(StatusOutput::Status::OFF);
311 }
312 else if(watch <= faultThreshold) {
313 setStatus(StatusOutput::Status::FAULT);
314 }
315 else if(watch <= warningThreshold) {
316 setStatus(StatusOutput::Status::WARNING);
317 }
318 else {
319 setStatus(StatusOutput::Status::OK);
320 }
321 group.readAny();
322 }
323 }
324
325 /********************************************************************************************************************/
326 /* Implementation of RangeMonitor **********************************************************************************/
327 /********************************************************************************************************************/
328 template<typename T>
329 RangeMonitor<T>::RangeMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
330 const std::string& parameterPath, const std::string& description,
331 const std::unordered_set<std::string>& outputTags, const std::unordered_set<std::string>& parameterTags)
332 : RangeMonitor(owner, inputPath, outputPath, parameterPath + "/lowerWarningThreshold",
333 parameterPath + "/upperWarningThreshold", parameterPath + "/lowerFaultThreshold",
334 parameterPath + "/upperFaultThreshold", parameterPath + "/disable", description, outputTags, parameterTags) {}
335
336 /********************************************************************************************************************/
337 template<typename T>
338 RangeMonitor<T>::RangeMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
339 const std::string& warningLowerThresholdPath, const std::string& warningUpperThresholdPath,
340 const std::string& faultLowerThresholdPath, const std::string& faultUpperThresholdPath,
341 const std::string& disablePath, const std::string& description, const std::unordered_set<std::string>& outputTags,
342 const std::unordered_set<std::string>& parameterTags)
343 : MonitorBase(owner, description, outputPath, disablePath, outputTags, parameterTags),
344 watch(this, inputPath, "", "Value to monitor"), warningLowerThreshold(this, warningLowerThresholdPath, "",
345 "Lower warning threshold to compare with", parameterTags),
346 warningUpperThreshold(
347 this, warningUpperThresholdPath, "", "Upper warning threshold to compare with", parameterTags),
348 faultLowerThreshold(this, faultLowerThresholdPath, "", "Lower fault threshold to compare with", parameterTags),
349 faultUpperThreshold(this, faultUpperThresholdPath, "", "Upper fault threshold to compare with", parameterTags) {}
350
351 /********************************************************************************************************************/
352 template<typename T>
354 // If there is a change either in value monitored or in requiredValue, the status is re-evaluated
355 ReadAnyGroup group{
356 watch, disable, warningLowerThreshold, warningUpperThreshold, faultLowerThreshold, faultUpperThreshold};
357
358 while(true) {
359 if(disable) {
360 setStatus(StatusOutput::Status::OFF);
361 }
362 // Check for fault limits first. Like this they supersede the warning,
363 // even if they are stricter then the warning limits (mis-configuration)
364 else if(watch <= faultLowerThreshold || watch >= faultUpperThreshold) {
365 setStatus(StatusOutput::Status::FAULT);
366 }
367 else if(watch <= warningLowerThreshold || watch >= warningUpperThreshold) {
368 setStatus(StatusOutput::Status::WARNING);
369 }
370 else {
371 setStatus(StatusOutput::Status::OK);
372 }
373 group.readAny();
374 }
375 }
376
377 /********************************************************************************************************************/
378 /* Implementation of ExactMonitor **********************************************************************************/
379 /********************************************************************************************************************/
380 template<typename T>
381 ExactMonitor<T>::ExactMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
382 const std::string& parameterPath, const std::string& description,
383 const std::unordered_set<std::string>& outputTags, const std::unordered_set<std::string>& parameterTags)
384 : ExactMonitor(owner, inputPath, outputPath, parameterPath + "/requiredValue", parameterPath + "/disable",
385 description, outputTags, parameterTags) {}
386
387 /********************************************************************************************************************/
388 template<typename T>
389 ExactMonitor<T>::ExactMonitor(ModuleGroup* owner, const std::string& inputPath, const std::string& outputPath,
390 const std::string& requiredValuePath, const std::string& disablePath, const std::string& description,
391 const std::unordered_set<std::string>& outputTags, const std::unordered_set<std::string>& parameterTags)
392 : MonitorBase(owner, description, outputPath, disablePath, outputTags, parameterTags),
393 watch(this, inputPath, "", "Value to monitor"),
394 requiredValue(this, requiredValuePath, "", "Value to compare with", parameterTags) {}
395
396 /********************************************************************************************************************/
397 template<typename T>
399 // If there is a change either in value monitored or in requiredValue, the status is re-evaluated
400 ReadAnyGroup group{watch, disable, requiredValue};
401
402 while(true) {
403 if(disable) {
404 setStatus(StatusOutput::Status::OFF);
405 }
406 else if(watch != requiredValue) {
407 setStatus(StatusOutput::Status::FAULT);
408 }
409 else {
410 setStatus(StatusOutput::Status::OK);
411 }
412 group.readAny();
413 }
414 }
415
416} // namespace ChimeraTK
Convenience class for input scalar accessors with UpdateMode::push.
InvalidityTracer application module.
Module for status monitoring of an exact value.
ScalarPushInput< T > requiredValue
The required value to compare with.
void mainLoop() override
This is where state evaluation is done.
ScalarPushInput< T > watch
Variable to monitor.
Module for status monitoring depending on a maximum threshold value.
void mainLoop() override
Disable the monitor.
ScalarPushInput< T > faultThreshold
FAULT state to be reported if threshold is reached or exceeded.
ScalarPushInput< T > warningThreshold
WARNING state to be reported if threshold is reached or exceeded.
ScalarPushInput< T > watch
Variable to monitor.
Module for status monitoring depending on a minimum threshold value.
void mainLoop() override
This is where state evaluation is done.
ScalarPushInput< T > warningThreshold
WARNING state to be reported if threshold is reached or exceeded.
ScalarPushInput< T > faultThreshold
FAULT state to be reported if threshold is reached or exceeded.
ScalarPushInput< T > watch
Variable to monitor.
void setStatus(StatusOutput::Status newStatus)
ScalarPushInput< ChimeraTK::Boolean > disable
Disable/enable the entire status monitor.
DataValidity _lastStatusValidity
StatusOutput status
Result of the monitor.
Module for status monitoring depending on range of threshold values.
RangeMonitor(ModuleGroup *owner, const std::string &inputPath, const std::string &outputPath, const std::string &parameterPath, const std::string &description, const std::unordered_set< std::string > &outputTags={}, const std::unordered_set< std::string > &parameterTags={})
ScalarPushInput< T > faultUpperThreshold
RangeMonitor(ModuleGroup *owner, const std::string &inputPath, const std::string &outputPath, const std::string &warningLowerThresholdPath, const std::string &warningUpperThresholdPath, const std::string &faultLowerThresholdPath, const std::string &faultUpperThresholdPath, const std::string &disablePath, const std::string &description, const std::unordered_set< std::string > &outputTags={}, const std::unordered_set< std::string > &parameterTags={})
ScalarPushInput< T > faultLowerThreshold
FAULT state to be reported if value is in between the upper and lower threshold including the start a...
ScalarPushInput< T > warningUpperThreshold
ScalarPushInput< T > watch
Variable to monitor.
void mainLoop() override
This is where state evaluation is done.
ScalarPushInput< T > warningLowerThreshold
WARNING state to be reported if value is in between the upper and lower threshold including the start...
Special ScalarOutput which represents a status which can be aggregated by the StatusAggregator.