ChimeraTK-DeviceAccess 03.25.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
32 void updateCalled(const TransferElementID& transferElementID) { _updateCalled = transferElementID; }
33
35 [[nodiscard]] const auto& getTargetElements() const { return _targetElements; }
36
37 // functions needed by DataConsistencyDecorator:
44 bool checkUpdate(const TransferElementID& transferElementID);
48 void handleMissingPostReads(TransferElementID callerId, bool updateBuffer);
49
51 void updateHistory(TransferElementID transferElementID);
55 template<typename UserType>
56 std::vector<std::vector<UserType>>& getMatchingBuffer(TransferElementID id);
57 [[nodiscard]] TransferElementID lastUpdateCall() const { return _updateCalled; }
59
60 protected:
63 boost::shared_ptr<TransferElement> decorateAccessor(TransferElementAbstractor& acc);
64
66 void setupHistory(const TransferElementAbstractor& element, unsigned histLen);
67
68 bool findMatch(TransferElementID transferElementID);
69
71 template<typename UserType>
72 std::vector<std::vector<UserType>>& getUserBuffer(TransferElementID transferElementID);
73
74 template<typename UserBufferType>
75 std::vector<UserBufferType>* getBufferVector(TransferElementID id) {
76 void* buf = _targetElements.at(id).histBuffer;
77 return static_cast<std::vector<UserBufferType>*>(buf);
78 }
79
83 unsigned histLen = 0;
84 void* histBuffer = nullptr;
85 const std::type_info& histBufferType;
86 std::vector<VersionNumber> versionNumbers;
87 std::vector<DataValidity> dataValidities;
90 unsigned lastMatchingIndex = 0;
91 };
92
96
97 std::map<TransferElementID, TargetElement> _targetElements;
99 TransferElementID _updateCalled; // only for checking usage
100 };
101
102 /********************************************************************************************************************/
103
104 template<typename UserType>
105 std::vector<std::vector<UserType>>& HistorizedMatcher::getMatchingBuffer(TransferElementID id) {
106 TargetElement& pe = _targetElements.at(id);
107 using UserBufferType = std::vector<std::vector<UserType>>;
108
109 if(pe.lastMatchingIndex > 0) {
110 auto& bufferVector = *(getBufferVector<UserBufferType>(id));
111 return bufferVector[pe.lastMatchingIndex - 1];
112 }
113 return getUserBuffer<UserType>(id);
114 }
115
116 /********************************************************************************************************************/
117
118 template<typename UserType>
119 std::vector<std::vector<UserType>>& HistorizedMatcher::getUserBuffer(TransferElementID transferElementID) {
120 // note for improvement - we could use ChimeraTK::TemplateUserTypeMap, see e.g. ConfigReader.cc how to use it
121 // this should eliminiate casting and void* pointer
122
123 const auto& impl = _targetElements.at(transferElementID).acc.getHighLevelImplElement();
124 auto acc0 = boost::dynamic_pointer_cast<NDRegisterAccessor<UserType>>(impl);
125 assert(acc0);
126 return acc0->accessChannels();
127 }
128
129 /********************************************************************************************************************/
130
131} // 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.