ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
demoStatusMonitor.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
10#include <ChimeraTK/ApplicationCore/ApplicationCore.h>
11#include <ChimeraTK/ApplicationCore/EnableXMLGenerator.h>
12#include <ChimeraTK/ApplicationCore/ModuleGroup.h>
13#include <ChimeraTK/ApplicationCore/StatusMonitor.h>
14
15namespace ctk = ChimeraTK;
16
17// Just simulate a temperature going up and down
19 using ctk::ApplicationModule::ApplicationModule;
20
22 ctk::ScalarOutput<double> temperature{this, "temperature", "degC", "simulated temperature"};
23
24 void mainLoop() override {
26 temperature = 0;
28 double direction = 1;
29
30 while(true) {
31 // go down with the temperature if too hot
32 if(temperature > 50) {
33 direction = -1;
34 }
35 // go up with the temperature if too cold
36 if(temperature < -50) {
37 direction = 1;
38 }
39
40 temperature += direction * 1; // one dregree steps
41 setCurrentVersionNumber({}); // We generate data without trigger or other input.
42 // So we must update the version number manually.
43 // This automatically updates the time stamp as well.
45 usleep(100000);
46 }
47 }
48};
49
50struct ExampleApp : public ctk::Application {
51 ExampleApp() : Application("exampleApp") {}
52 ~ExampleApp() override { shutdown(); }
53
54 // Create an instance of the simulation module. We name it "Simulation".
55 // There will be a variable /Simulation/temperature from this.
56 SimulationModule simulation{this, "Simulation", "temperature simulation"};
57
58 // Now we place a monitor next to the temperature variable. First we create a module group, also with the name
59 // "Simulation". Everything in it will be placed next to the variables from the simulation module.
60 struct : ctk::ModuleGroup {
61 using ctk::ModuleGroup::ModuleGroup;
62 // Inside the module group we place the monitor. In the constructor it gets the name of the variable to monitor, and
63 // the name of the output variable. The monitor automatically connects to the input variable that is in the same
64 // hierarchy level. We add output and parameter tags (STATUS and CONFIG, respectively) for easier connetion of the
65 // variables.
66 // ctk::RangeMonitor<double> temperatureMonitor{this, "TemperatureMonitor", "monitor for the simulated temperature",
67 // "temperature", "temperatureStatus", ctk::HierarchyModifier::none, {"STATUS"}, {"CONFIG"}, {}};
68
69 ctk::RangeMonitor<double> temperatureMonitor{this, "/TemperatureMonitor/temperature",
70 "/TemperatureMonitor/temperatureStatus", "/TemperatureMonitor", "monitor for the simulated temperature",
71 ctk::TAGS{"MON_OUTPUT"}, ctk::TAGS{"MON_PARAMS"}};
72
73 } simulationGroup{this, "Simulation", ""};
74
75 ctk::ConfigReader config{this, "Config", "demoStatusMonitor_config.xml"};
76};
77
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
void setCurrentVersionNumber(VersionNumber versionNumber) override
Set the current version number.
Generic module to read an XML config file and provide the defined values as constant variables.
friend class Application
Definition ModuleGroup.h:47
bool write(ChimeraTK::VersionNumber versionNumber)=delete
[Snippet: Class Definition Start]
Definition ExampleApp.h:27
~ExampleApp() override
ctk::RangeMonitor< double > temperatureMonitor
SimulationModule simulation
ctk::ConfigReader config
ExampleApp theExampleApp
InvalidityTracer application module.
const std::unordered_set< std::string > TAGS
Convenience type definition which can optionally be used as a shortcut for the type which defines a l...
Definition EntityOwner.h:27
Module for status monitoring depending on range of threshold values.
Convenience class for output scalar accessors (always UpdateMode::push)
Example to simulate the working and usage of StatusMonitor.
ctk::ScalarOutput< double > temperature
The value to be monitored.
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...