ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
EventMessageAggregator.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
5
6#include <utility>
7
8namespace ChimeraTK {
9
10 /********************************************************************************************************************/
11
12 AggregatableMessage::AggregatableMessage(Module* owner, const std::string& name, std::string unit,
13 const std::string& description, const std::unordered_set<std::string>& tags)
14 : ScalarOutput(owner, name, std::move(unit), description, tags) {
16 }
17
18 /********************************************************************************************************************/
19 /********************************************************************************************************************/
20
21 EventMessageAggregator::Impl::Impl(ModuleGroup* owner, const std::string& name, const std::string& description,
22 const std::unordered_set<std::string>& tags)
23 : ApplicationModule(owner, name, description, tags) {
24 // Walk through the entire application to find all AggregatableMessages
25 std::vector<Model::ProcessVariableProxy> messageVars;
27 [&](const Model::ProcessVariableProxy& pv) { messageVars.push_back(pv); }, Model::depthFirstSearch,
28 Model::keepProcessVariables && Model::keepTag(AggregatableMessage::aggregatableMessageTag.data()));
29
30 // Create input for each message
31 for(const auto& pv : messageVars) {
32 _inputs.emplace_back(this, pv.getFullyQualifiedPath(), "", "");
33 }
34 }
35
36 /********************************************************************************************************************/
37
38 void EventMessageAggregator::Impl::mainLoop() {
39 size_t autoClearTimerCounter{0};
40
41 // send initial value
42 _output.writeOk();
43
44 // build map of input IDs to inputs
45 std::map<TransferElementID, ScalarRegisterAccessor<std::string>> idMap;
46 for(auto& input : _inputs) {
47 idMap[input.getId()].replace(input);
48 }
49
50 auto group = readAnyGroup();
51 while(true) {
52 // wait for change
53 auto id = group.readAny();
54
55 if(id == _clear.getId()) {
56 // clear requested
57 _output.writeOkIfDifferent();
58 }
59 else if(id == _autoClearTimer.getId()) {
60 if(_autoClearSeconds > 0 && _output._status != StatusOutput::Status::OK) {
61 // auto clear timer tick
62 ++autoClearTimerCounter;
63 if(autoClearTimerCounter == _autoClearSeconds) {
64 _output.writeOkIfDifferent();
65 }
66 }
67 }
68 else {
69 // message received
70 _output.writeIfDifferent(StatusOutput::Status::WARNING, idMap.at(id));
71 autoClearTimerCounter = 0;
72 }
73 }
74 }
75
76 /********************************************************************************************************************/
77
78} // namespace ChimeraTK
AggregatableMessage(Module *owner, const std::string &name, std::string unit, const std::string &description, const std::unordered_set< std::string > &tags={})
static constexpr std::string_view aggregatableMessageTag
Model::RootProxy getModel()
Return the root of the application model.
Definition Application.h:75
static Application & getInstance()
Obtain instance of the application.
friend class ChimeraTK::Model::Impl
auto visit(VISITOR visitor, Args... args) const
Traverse the model using the specified filter and call the visitor functor for each ModuleGroup,...
Definition Model.h:1451
std::string getFullyQualifiedPath() const
Return the fully qualified path.
Definition Model.cc:25
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition Module.h:21
InvalidityTracer application module.
Convenience class for output scalar accessors (always UpdateMode::push)