ChimeraTK-DeviceAccess 03.26.00
Loading...
Searching...
No Matches
DataConsistencyGroupHistorizedMatcher.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
7
8namespace ChimeraTK {
9
10 class ReadAnyGroup;
11 class DataConsistencyGroup;
12} // namespace ChimeraTK
13
15
16 /********************************************************************************************************************/
17
22 public:
23 HistorizedMatcher() = default;
24 ~HistorizedMatcher() override;
25
30 void add(TransferElementAbstractor& acc, unsigned histLen);
31 [[nodiscard]] bool isConsistent();
32
33 void updateCalled(const TransferElementID& transferElementID) { _updateCalled = transferElementID; }
34
36 [[nodiscard]] const auto& getTargetElements() const { return _targetElements; }
37
38 // functions needed by DataConsistencyDecorator:
45 bool checkUpdate(const TransferElementID& transferElementID);
49 void handleMissingPostReads(TransferElementID callerId, bool updateBuffer);
50
52 void updateHistory(TransferElementID transferElementID);
56 template<typename UserType>
57 std::vector<std::vector<UserType>>& getMatchingBuffer(TransferElementID id);
58 [[nodiscard]] TransferElementID lastUpdateCall() const { return _updateCalled; }
60
61 protected:
64 boost::shared_ptr<TransferElement> decorateAccessor(TransferElementAbstractor& acc);
65
67 void setupHistory(const TransferElementAbstractor& element, unsigned histLen);
68
69 bool findMatch(TransferElementID transferElementID);
70
72 template<typename UserType>
73 std::vector<std::vector<UserType>>& getUserBuffer(TransferElementID transferElementID);
74
75 template<typename UserBufferType>
76 std::vector<UserBufferType>* getBufferVector(TransferElementID id) {
77 void* buf = _targetElements.at(id).histBuffer;
78 return static_cast<std::vector<UserBufferType>*>(buf);
79 }
80
84 unsigned histLen = 0;
85 void* histBuffer = nullptr;
86 const std::type_info& histBufferType;
87 std::vector<VersionNumber> versionNumbers;
88 std::vector<DataValidity> dataValidities;
91 unsigned lastMatchingIndex = 0;
92 };
93
97
98 std::map<TransferElementID, TargetElement> _targetElements;
100 TransferElementID _updateCalled; // only for checking usage
101 };
102
103 /********************************************************************************************************************/
104
105 template<typename UserType>
106 std::vector<std::vector<UserType>>& HistorizedMatcher::getMatchingBuffer(TransferElementID id) {
107 TargetElement& pe = _targetElements.at(id);
108 using UserBufferType = std::vector<std::vector<UserType>>;
109
110 if(pe.lastMatchingIndex > 0) {
111 auto& bufferVector = *(getBufferVector<UserBufferType>(id));
112 return bufferVector[pe.lastMatchingIndex - 1];
113 }
114 return getUserBuffer<UserType>(id);
115 }
116
117 /********************************************************************************************************************/
118
119 template<typename UserType>
120 std::vector<std::vector<UserType>>& HistorizedMatcher::getUserBuffer(TransferElementID transferElementID) {
121 // note for improvement - we could use ChimeraTK::TemplateUserTypeMap, see e.g. ConfigReader.cc how to use it
122 // this should eliminiate casting and void* pointer
123
124 const auto& impl = _targetElements.at(transferElementID).acc.getHighLevelImplElement();
125 auto acc0 = boost::dynamic_pointer_cast<NDRegisterAccessor<UserType>>(impl);
126 assert(acc0);
127 return acc0->accessChannels();
128 }
129
130 /********************************************************************************************************************/
131
132} // namespace ChimeraTK::DataConsistencyGroupDetail
Data consistency matching via history of available data.
void setupHistory(const TransferElementAbstractor &element, unsigned histLen)
element must be target, i.e. not DataConsistencyDecorator
void handleMissingPostReads(TransferElementID callerId, bool updateBuffer)
bool checkUpdate(const TransferElementID &transferElementID)
To be called from DataConsistencyDecorator.
boost::shared_ptr< TransferElement > decorateAccessor(TransferElementAbstractor &acc)
decorate accessor by replacing its target => DataConsistencyDecorator(target), possibly at an inner l...
void add(TransferElementAbstractor &acc, unsigned histLen)
Add a push element.
void handleMissingPreReads(TransferElementID callerId)
since after DiscardValueException, ReadAnyGroup does not call preRead at following operation,...
void updateHistory(TransferElementID transferElementID)
swap data of target buffer into history
std::vector< UserBufferType > * getBufferVector(TransferElementID id)
std::vector< std::vector< UserType > > & getUserBuffer(TransferElementID transferElementID)
return reference to target's user buffer of transfer element of this group
void getMatchingInfo(TransferElementID id, VersionNumber &vs, DataValidity &dv)
returns meta data of last match
std::vector< std::vector< UserType > > & getMatchingBuffer(TransferElementID id)
returns user buffer of last match
Base class for matcher implementations; will not be instantiated directly.
Base class for register accessors abstractors independent of the UserType.
Simple class holding a unique ID for a TransferElement.
Class for generating and holding version numbers without exposing a numeric representation.
DataValidity
The current state of the data.
unsigned lastMatchingIndex
match indices set by findMatch() in case it returns true.