ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
DataConsistencyGroup.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
5
8
9namespace ChimeraTK {
10
11 /********************************************************************************************************************/
12
13 void DataConsistencyGroup::initMatcher() {
14 if(_mode == MatchingMode::historized) {
15 _impl = std::make_unique<DataConsistencyGroupDetail::HistorizedMatcher>();
16 }
17 else {
18 _impl = std::make_unique<DataConsistencyGroupDetail::SimpleMatcher>();
19 }
20 };
21
22 /********************************************************************************************************************/
23
25 initMatcher();
26 }
27
28 // move constructor required from ApplicationCore
31
32 // this line is required since otherwise compiler fails to generate destructor for std::unique_ptr<X> where X
33 // is incomplete type xxxMatcher
35
36 /********************************************************************************************************************/
37
38 DataConsistencyGroup::DataConsistencyGroup(std::initializer_list<TransferElementAbstractor> list) {
39 initMatcher();
40
41 for(const auto& element : list) {
42#pragma GCC diagnostic push
43#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44 add(element);
45#pragma GCC diagnostic pop
46 }
47 }
48
49 /********************************************************************************************************************/
50
51 DataConsistencyGroup::DataConsistencyGroup(std::initializer_list<boost::shared_ptr<TransferElement>> list) {
52 initMatcher();
53
54 for(const auto& element : list) {
55#pragma GCC diagnostic push
56#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
57 add(element);
58#pragma GCC diagnostic pop
59 }
60 }
61
62 /********************************************************************************************************************/
63
65 std::initializer_list<std::reference_wrapper<TransferElementAbstractor>> list, MatchingMode mode,
66 unsigned histLen)
67 : _mode(mode) {
68 initMatcher();
69
70 for(const auto& element : list) {
71 add(element, histLen);
72 }
73 }
74
75 /********************************************************************************************************************/
76
78 checkAccess(element);
79 if(_mode == MatchingMode::historized) {
81 "Add function with const-abstractor is deprecated and unsuitable for MatchingMode::historized");
82 }
83 _impl->getElements()[element.getId()] = element;
84 }
85
86 /********************************************************************************************************************/
87
88 void DataConsistencyGroup::add(boost::shared_ptr<TransferElement> element) {
89#pragma GCC diagnostic push
90#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
91 add(TransferElementAbstractor(std::move(element)));
92#pragma GCC diagnostic pop
93 }
94
95 /********************************************************************************************************************/
96
97 void DataConsistencyGroup::checkAccess(const TransferElementAbstractor& element) {
98 if(!element.isReadable()) {
100 "Cannot add non-readable accessor for register " + element.getName() + " to DataConsistencyGroup.");
101 }
104 "Cannot add poll type accessor for register " + element.getName() + " to DataConsistencyGroup.");
105 }
106 }
107
108 /********************************************************************************************************************/
109
110 void DataConsistencyGroup::add(TransferElementAbstractor& element, unsigned histLen) {
111 checkAccess(element);
112 if(_mode == MatchingMode::historized) {
113 dynamic_cast<DataConsistencyGroupDetail::HistorizedMatcher*>(_impl.get())->add(element, histLen);
114 }
115 else {
116 _impl->getElements()[element.getId()] = element;
117 }
118 }
119
120 /********************************************************************************************************************/
121
122 bool DataConsistencyGroup::update(const TransferElementID& transferElementID) {
123 // ignore transferElementID not in DataConsistencyGroup
124 if(_impl->getElements().find(transferElementID) == _impl->getElements().end()) {
125 return false;
126 }
127 switch(_mode) {
129 return true;
131 return dynamic_cast<DataConsistencyGroupDetail::SimpleMatcher*>(_impl.get())->update(transferElementID);
133 // no need to call HistorizedMatcher::checkUpdate here; it would return true always
134 // But to allow check of right usage (did user call DataConsistencyGroup::update?), set a flag
135 dynamic_cast<DataConsistencyGroupDetail::HistorizedMatcher*>(_impl.get())->updateCalled(transferElementID);
136 return true;
137 }
138 assert(false);
139 return false;
140 }
141
142 /********************************************************************************************************************/
143
145 // we keep the method for compatibility but allow it only for SimpleMatcher
146 // With HistorizedMatcher, it won't work since we have no chance finding all accessors that would need to be
147 // decorated.
148 if(_mode == MatchingMode::historized || newMode == MatchingMode::historized) {
149 throw ChimeraTK::logic_error("setMatchingMode cannot be used to switch to or from MatchingMode::historized");
150 }
151 _mode = newMode;
152 }
153
154 /********************************************************************************************************************/
155
156 const std::map<TransferElementID, TransferElementAbstractor>& DataConsistencyGroup::getElements() const {
157 return _impl->getElements();
158 }
159
160 /********************************************************************************************************************/
161
165
166 /********************************************************************************************************************/
167
169 switch(_mode) {
171 // if matching mode is none, always return true
172 return true;
174 return dynamic_cast<DataConsistencyGroupDetail::SimpleMatcher*>(_impl.get())->isConsistent();
176 // no need to call HistorizedMatcher::findMatch; it would return true
177 return true;
178 }
179 assert(false);
180 return false;
181 }
182
183 /********************************************************************************************************************/
184
185} // namespace ChimeraTK
bool has(AccessMode flag) const
Check if a certain flag is in the set.
Definition AccessMode.cc:20
Data consistency matching via history of available data.
Base class for matcher implementations; will not be instantiated directly.
Simple matcher implementation for DataConsistencyGroup in MatchingMode::exact.
Group several registers (= TransferElement) which ensures data consistency across multiple variables ...
const DataConsistencyGroupDetail::MatcherBase & getMatcher()
For diagnostics.
void setMatchingMode(MatchingMode newMode)
Change the matching mode.
void add(const TransferElementAbstractor &element)
Add register to group.
DataConsistencyGroup & operator=(DataConsistencyGroup &&other) noexcept
MatchingMode
Enum describing the matching mode of a DataConsistencyGroup.
@ none
No matching, effectively disable the DataConsitencyGroup. update() will always return true.
@ exact
Require an exact match of the VersionNumber of all current values of the group's members.
const std::map< TransferElementID, TransferElementAbstractor > & getElements() const
For inspection of contents.
DataConsistencyGroup(MatchingMode mode=MatchingMode::exact)
Construct empty group.
bool isConsistent() const
returns true if consistent state is reached
bool update(const TransferElementID &transferElementID)
This function must be called after an update was received from the ReadAnyGroup.
Base class for register accessors abstractors independent of the UserType.
bool isReadable() const
Check if transfer element is readable.
AccessModeFlags getAccessModeFlags() const
Return the AccessModeFlags for this TransferElement.
TransferElementID getId() const
Obtain unique ID for the actual implementation of this TransferElement.
const std::string & getName() const
Returns the name that identifies the process variable.
Simple class holding a unique ID for a TransferElement.
Exception thrown when a logic error has occured.
Definition Exception.h:51
@ wait_for_new_data
Make any read blocking until new data has arrived since the last read.