15 boost::shared_ptr<TransferElement> dataConsistencyDecorator;
17 using UserType = decltype(t);
20 for(auto& e : acc.getInternalElements()) {
21 auto dec = boost::dynamic_pointer_cast<DataConsistencyDecorator<UserType>>(e);
23 throw ChimeraTK::logic_error(
24 "accessor is already in historized DataConsistencyGroup, cannot add it to another one: " + acc.getName());
30 auto factoryF = [&](
const boost::shared_ptr<NDRegisterAccessor<UserType>>& toBeDecorated) {
31 return boost::make_shared<DataConsistencyDecorator<UserType>>(toBeDecorated,
this);
35 dataConsistencyDecorator = accImpl->decorateDeepInside(factoryF);
36 if(!dataConsistencyDecorator) {
38 dataConsistencyDecorator = factoryF(accImpl);
39 acc.
replace(dataConsistencyDecorator);
42 return dataConsistencyDecorator;
48 auto it = _targetElements.find(transferElementID);
49 assert(it != _targetElements.end());
51 auto& pElem = it->second;
52 auto vn = pElem.acc.getVersionNumber();
53 if(pElem.histLen > 0 && vn == pElem.versionNumbers[0]) {
59 bool consistent = findMatch(transferElementID);
67 if(_handleMissingPreReadsCalled) {
70 _handleMissingPreReadsCalled =
true;
71 auto resetFlag = cppext::finally([
this] { _handleMissingPreReadsCalled =
false; });
74 if(_decoratorsNeedPreRead) {
76 if(lastUpdateCall() != callerId) {
77 throw ChimeraTK::logic_error(
"updates from ReadAnyGroup must be processed by DataConsistencyGroup::update");
81 for(
auto& e : _pushElements) {
82 if(e.first != callerId) {
87 _decoratorsNeedPreRead =
false;
92 void HistorizedMatcher::handleMissingPostReads(
TransferElementID callerId,
bool updateBuffer) {
94 if(_handleMissingPostReadsCalled) {
97 _handleMissingPostReadsCalled =
true;
98 auto resetFlag = cppext::finally([
this] { _handleMissingPostReadsCalled =
false; });
106 for(
auto& e : _pushElements) {
107 if(e.first == callerId) {
110 auto& acc = e.second;
113 if(lastMatchingVersionNumber() > acc.getVersionNumber()) {
117 _decoratorsNeedPreRead =
true;
124 auto id = acc.
getId();
126 auto dataConsistencyDecorator = decorateAccessor(acc);
127 auto target = dataConsistencyDecorator->getInternalElements().front();
130 _pushElements[id] = acc;
133 for(
auto& pe : rag->push_elements) {
134 if(pe.getId() == id) {
145 if(_targetElements.find(
id) != _targetElements.end()) {
152 using UserType = decltype(argForType);
153 using UserBufferType = std::vector<std::vector<UserType>>;
155 TargetElement element0 = {acc, histLen, nullptr, typeid(UserType), {}, {}};
156 _targetElements.insert({id, element0});
158 auto* mem =
new std::vector<UserBufferType>(histLen);
160 auto& buf = getUserBuffer<UserType>(
id);
161 unsigned nChannels = buf.size();
162 assert(nChannels > 0);
163 unsigned nSamples = buf[0].size();
164 for(UserBufferType& historyElement : *mem) {
165 historyElement.resize(nChannels);
166 for(
auto& historyElementChannel : historyElement) {
167 historyElementChannel.resize(nSamples);
182 HistorizedMatcher::~HistorizedMatcher() {
183 for(
auto& x : _targetElements) {
189 using UserType = decltype(arg);
190 using UserBufferType = std::vector<std::vector<UserType>>;
191 delete getBufferVector<UserBufferType>(id);
194 catch(std::bad_cast& e) {
204 bool HistorizedMatcher::isConsistent() {
208 if(_pushElements.size() == 0) {
211 auto firstVn = _pushElements.begin()->second.getVersionNumber();
212 for(
auto x : _pushElements) {
213 if(x.second.getVersionNumber() != firstVn) {
223 auto it = _targetElements.find(transferElementID);
224 if(it == _targetElements.end()) {
231 for(
auto& pair : _targetElements) {
232 if(pair.first == transferElementID) {
243 auto pos = std::find(versionNumVector.begin(), versionNumVector.end(), vn);
244 if(pos == versionNumVector.end()) {
255 _lastMatchingVersionNumber = vn;
262 TargetElement& element = _targetElements.at(transferElementID);
272 using UserType = decltype(arg);
273 using UserBufferType = std::vector<std::vector<UserType>>;
274 auto& buf = getUserBuffer<UserType>(transferElementID);
276 auto& bufferVector = *getBufferVector<UserBufferType>(transferElementID);
277 unsigned histLen = bufferVector.size();
278 auto& versionNumVector = element.versionNumbers;
279 auto& datavalidityVector = element.dataValidities;
284 if(versionNumVector[0] > VersionNumber(nullptr)) {
285 for(unsigned i = histLen - 1; i > 0; i--) {
286 bufferVector[i].swap(bufferVector[i - 1]);
287 versionNumVector[i] = versionNumVector[i - 1];
288 datavalidityVector[i] = datavalidityVector[i - 1];
291 bufferVector[0].swap(buf);
292 versionNumVector[0] = vn;
293 datavalidityVector[0] = dv;
boost::shared_ptr< TransferElement > decorateAccessor(TransferElementAbstractor &acc)
decorate accessor by replacing its target => DataConsistencyDecorator(target), possibly at an inner l...
N-dimensional register accessor.
Base class for register accessors abstractors independent of the UserType.
ChimeraTK::VersionNumber getVersionNumber() const
Returns the version number that is associated with the last transfer (i.e.
const boost::shared_ptr< TransferElement > & getHighLevelImplElement()
Obtain the highest level implementation TransferElement.
const std::type_info & getValueType() const
Returns the std::type_info for the value type of this transfer element.
ReadAnyGroup * getReadAnyGroup() const
Obtain the ReadAnyGroup this TransferElement is part of, or nullptr if not in a ReadAnyGroup.
DataValidity dataValidity() const
Return current validity of the data.
void replace(const TransferElementAbstractor &newAccessor)
Assign a new accessor to this TransferElementAbstractor.
TransferElementID getId() const
Obtain unique ID for the actual implementation of this TransferElement.
Simple class holding a unique ID for a TransferElement.
Class for generating and holding version numbers without exposing a numeric representation.
Exception thrown when a logic error has occured.
void callForType(const std::type_info &type, LAMBDATYPE lambda)
Helper function for running code which uses some compile-time type that is specified at runtime as a ...
DataValidity
The current state of the data.
std::vector< VersionNumber > versionNumbers
TransferElementAbstractor acc
target of DataConsistencyDecorator
const std::type_info & histBufferType
unsigned lastMatchingIndex
match indices set by findMatch() in case it returns true.
std::vector< DataValidity > dataValidities