ChimeraTK-ApplicationCore  04.01.00
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 
15 namespace ctk = ChimeraTK;
16 
17 // Just simulate a temperature going up and down
20 
22  ctk::ScalarOutput<double> temperature{this, "temperature", "degC", "simulated temperature"};
23 
24  void mainLoop() {
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 
50 struct ExampleApp : public ctk::Application {
51  ExampleApp() : Application("exampleApp") {
52  // show how it looks in the application (C++ hierarchy)
53  dump();
54 
55  // show how it looks on the cs side (virtual hierarchy)
56  // cs.dump();
57 
58  // show how it is connected
59  dumpConnections();
60  }
62 
63  // Create an instance of the simulation module. We name it "Simulation".
64  // There will be a variable /Simulation/temperature from this.
65  SimulationModule simulation{this, "Simulation", "temperature simulation"};
66 
67  // Now we place a monitor next to the temperature variable. First we create a module group, also with the name
68  // "Simulation". Everything in it will be placed next to the variables from the simulation module.
69  struct : ctk::ModuleGroup {
71  // Inside the module group we place the monitor. In the constructor it gets the name of the variable to monitor, and
72  // the name of the output variable. The monitor automatically connects to the input variable that is in the same
73  // hierarchy level. We add output and parameter tags (STATUS and CONFIG, respectively) for easier connetion of the
74  // variables.
75  // ctk::RangeMonitor<double> temperatureMonitor{this, "TemperatureMonitor", "monitor for the simulated temperature",
76  // "temperature", "temperatureStatus", ctk::HierarchyModifier::none, {"STATUS"}, {"CONFIG"}, {}};
77 
78  ctk::RangeMonitor<double> temperatureMonitor{this, "/TemperatureMonitor/temperature",
79  "/TemperatureMonitor/temperatureStatus", "/TemperatureMonitor", "monitor for the simulated temperature",
80  ctk::TAGS{"MON_OUTPUT"}, ctk::TAGS{"MON_PARAMS"}};
81 
82  } simulationGroup{this, "Simulation", ""};
83 
84  ctk::ConfigReader config{this, "Config", "demoStatusMonitor_config.xml"};
85  // ctk::ControlSystemModule cs;
86  // void defineConnections();
87 };
88 
90 
91 // void ExampleApp::defineConnections() {
92 // // Usually you set the dmap file here. This example does not have one.
93 
94 // // Connect everything in the app to the cs. This makes the connection of temperature from Simulation to the input of
95 // // the monitor because they are the same variable in the CS module. Also the disable variable if the monitor is
96 // // connected to the CS. Try what happens if you disable the monitor.
97 // findTag(".*").connectTo(cs);
98 
99 // /* The trick of connecting the temperature automatically only worked because we put the temperatureMonitor into the
100 // * correct place in the hierarchy by putting it into the variable group "Simulation". However, the threshold
101 // * parameters inside the monitor are not connected yet.
102 // *
103 // * When connecting the app, the config created the following variables:
104 // * /Config/TemperatureMonitor/lowerWarningThreshold
105 // * /Config/TemperatureMonitor/upperWarningThreshold
106 // * /Config/TemperatureMonitor/lowerFaultThreshold
107 // * /Config/TemperatureMonitor/upperFaultThreshold
108 // */
109 
110 // // Now we connect the parameters of the temperature monitor to the control system, right into the Config directory so
111 // // the variable names match. Like this the parameters are connected to the values coming from the configuration.
112 // findTag("CONFIG").flatten().connectTo(cs["Config"]["TemperatureMonitor"]);
113 
114 // // FIXME: At this point a status aggregator would connect everything with tag STATUS
115 
116 // // show how it looks in the application (C++ hierarchy)
117 // dump();
118 
119 // // show how it looks on the cs side (virtual hierarchy)
120 // cs.dump();
121 
122 // // show how it is connected
123 // dumpConnections();
124 //}
ChimeraTK::ConfigReader
Generic module to read an XML config file and provide the defined values as constant variables.
Definition: ConfigReader.h:113
SimulationModule
Example to simulate the working and usage of StatusMonitor.
Definition: demoStatusMonitor.cc:18
ChimeraTK::Application::shutdown
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
Definition: Application.cc:207
ChimeraTK::EntityOwner::dump
void dump(const std::string &prefix="", std::ostream &stream=std::cout) const
Print the full hierarchy to given stream.
Definition: EntityOwner.cc:108
ExampleApp
[Snippet: Class Definition Start]
Definition: ExampleApp.h:27
theExampleApp
ExampleApp theExampleApp
Definition: demoStatusMonitor.cc:89
ChimeraTK::TAGS
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
ChimeraTK::ModuleGroup
Definition: ModuleGroup.h:16
ChimeraTK::ModuleGroup::ModuleGroup
ModuleGroup()=default
Default constructor to allow late initialisation of module groups.
SimulationModule::mainLoop
void mainLoop()
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
Definition: demoStatusMonitor.cc:24
ChimeraTK::ApplicationModule::setCurrentVersionNumber
void setCurrentVersionNumber(VersionNumber versionNumber) override
Set the current version number.
Definition: ApplicationModule.cc:89
ExampleApp::config
ctk::ConfigReader config
Definition: demoStatusMonitor.cc:84
ChimeraTK::ApplicationModule
Definition: ApplicationModule.h:24
ExampleApp::temperatureMonitor
ctk::RangeMonitor< double > temperatureMonitor
Definition: demoStatusMonitor.cc:78
SimulationModule::temperature
ctk::ScalarOutput< double > temperature
The value to be monitored.
Definition: demoStatusMonitor.cc:22
ExampleApp::ExampleApp
ExampleApp()
Definition: demoStatusMonitor.cc:51
ChimeraTK::ModuleGroup::Application
friend class Application
Definition: ModuleGroup.h:47
ChimeraTK::ScalarAccessor::write
bool write(ChimeraTK::VersionNumber versionNumber)=delete
ExampleApp::simulation
SimulationModule simulation
Definition: demoStatusMonitor.cc:65
ExampleApp::~ExampleApp
~ExampleApp()
Definition: demoStatusMonitor.cc:61
ChimeraTK::ApplicationModule::ApplicationModule
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
ChimeraTK::RangeMonitor< double >
ChimeraTK
InvalidityTracer application module.
Definition: spec_dataValidityPropagation.dox:2
ChimeraTK::ScalarOutput< double >
ChimeraTK::Application
Definition: Application.h:48