ChimeraTK-DeviceAccess  03.18.00
DataConsistencyGroup.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 
6 #include "VersionNumber.h"
7 #include <unordered_set>
8 
9 namespace ChimeraTK {
10 
11  /********************************************************************************************************************/
12 
20  public:
23 
25  DataConsistencyGroup(std::initializer_list<TransferElementAbstractor> list);
26  DataConsistencyGroup(std::initializer_list<boost::shared_ptr<TransferElement>> list);
27 
28  template<typename ITERATOR>
29  DataConsistencyGroup(ITERATOR first, ITERATOR last);
30 
33  void add(const TransferElementAbstractor& element);
34  void add(boost::shared_ptr<TransferElement> element);
35 
38  bool update(const TransferElementID& transferelementid);
39 
41  enum class MatchingMode {
42  none,
43  exact
44  };
45 
47  void setMatchingMode(MatchingMode newMode) { mode = newMode; }
48 
50  MatchingMode getMatchingMode() const { return mode; };
51 
53  const std::map<TransferElementID, TransferElementAbstractor>& getElements() const { return push_elements; }
54 
56  bool isConsistent() const { return consistentElements.size() == push_elements.size(); }
57 
58  private:
60  std::unordered_set<TransferElementID> consistentElements;
61 
62  std::unordered_set<TransferElementID> lasteSateOfConsistentElements;
63 
65  VersionNumber versionNumberToBeConsistentTo{nullptr};
66 
68  std::map<TransferElementID, TransferElementAbstractor> push_elements;
69 
72  };
73 
74  /********************************************************************************************************************/
75 
76  template<typename ITERATOR>
77  DataConsistencyGroup::DataConsistencyGroup(ITERATOR first, ITERATOR last) {
78  for(auto it = first; it != last; ++it) add(*it);
79  }
80 
81  /********************************************************************************************************************/
82 
83  inline bool DataConsistencyGroup::update(const TransferElementID& transferElementID) {
84  // ignore transferElementID does not belong to DataConsistencyGroup
85  if(push_elements.find(transferElementID) == push_elements.end()) {
86  return false;
87  }
88  // if matching mode is none, always return true
89  if(mode == MatchingMode::none) return true;
90  assert(mode == MatchingMode::exact);
91 
92  auto getVNFromElement = push_elements[transferElementID].getVersionNumber();
93  assert(getVNFromElement != VersionNumber{nullptr});
94  if(getVNFromElement < versionNumberToBeConsistentTo) {
95  return false;
96  }
97  if(versionNumberToBeConsistentTo != getVNFromElement) {
98  versionNumberToBeConsistentTo = getVNFromElement;
99  consistentElements.clear();
100  }
101  consistentElements.insert(transferElementID);
102  if(consistentElements.size() == push_elements.size()) {
103  lasteSateOfConsistentElements = consistentElements;
104  return true;
105  }
106  return false;
107  }
108 
109  /********************************************************************************************************************/
110 
111 } // namespace ChimeraTK
VersionNumber.h
ChimeraTK::DataConsistencyGroup::getElements
const std::map< TransferElementID, TransferElementAbstractor > & getElements() const
For inspection of contents.
Definition: DataConsistencyGroup.h:53
ChimeraTK::DataConsistencyGroup::DataConsistencyGroup
DataConsistencyGroup()
Construct empty group.
ChimeraTK::TransferElementAbstractor
Base class for register accessors abstractors independent of the UserType.
Definition: TransferElementAbstractor.h:28
ChimeraTK::DataConsistencyGroup::add
void add(const TransferElementAbstractor &element)
Add register to group.
Definition: DataConsistencyGroup.cc:26
ChimeraTK::DataConsistencyGroup
Group several registers (= TransferElement) which ensures data consistency across multiple variables ...
Definition: DataConsistencyGroup.h:19
TransferElementAbstractor.h
ChimeraTK::DataConsistencyGroup::setMatchingMode
void setMatchingMode(MatchingMode newMode)
Change the matching mode.
Definition: DataConsistencyGroup.h:47
ChimeraTK::DataConsistencyGroup::MatchingMode::none
@ none
No matching, effectively disable the DataConsitencyGroup. update() will always return true.
ChimeraTK::DataConsistencyGroup::MatchingMode::exact
@ exact
Require an exact match of the VersionNumber of all current values of the group's members.
ChimeraTK::DataConsistencyGroup::isConsistent
bool isConsistent() const
returns true if consistent state is reached
Definition: DataConsistencyGroup.h:56
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::TransferElementID
Simple class holding a unique ID for a TransferElement.
Definition: TransferElementID.h:17
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::DataConsistencyGroup::update
bool update(const TransferElementID &transferelementid)
This function updates consistentElements, a set of TransferElementID.
Definition: DataConsistencyGroup.h:83
ChimeraTK::DataConsistencyGroup::getMatchingMode
MatchingMode getMatchingMode() const
Return the current matching mode.
Definition: DataConsistencyGroup.h:50
ChimeraTK::DataConsistencyGroup::MatchingMode
MatchingMode
Enum describing the matching mode of a DataConsistencyGroup.
Definition: DataConsistencyGroup.h:41