ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
ReverseRecoveryDecorator.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
4
5namespace ChimeraTK {
6 /********************************************************************************************************************/
7
8 template<typename UserType>
10 boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> accessor,
11 boost::shared_ptr<RecoveryHelper> recoveryHelper)
12 : ChimeraTK::NDRegisterAccessorDecorator<UserType>(std::move(accessor)), _recoveryHelper(std::move(recoveryHelper)) {
13 // Check if we are wrapping a push-type variable and forbid that
14 if(TransferElement::getAccessModeFlags().has(AccessMode::wait_for_new_data)) {
15 throw ChimeraTK::logic_error("Cannot use reverse recovery on push-type input");
16 }
17
18 // Set ourselves as wfnd:
19 TransferElement::_accessModeFlags.add(AccessMode::wait_for_new_data);
20
21 _recoveryHelper->notificationQueue = cppext::future_queue<void>(3);
23
24 // Set the read queue as continuation of the notification queue
25 this->_readQueue =
26 _recoveryHelper->notificationQueue.template then<void>([&, this]() { _target->read(); }, std::launch::deferred);
27 }
28
29 /********************************************************************************************************************/
30
31 template<typename UserType>
33 this->interrupt_impl(this->_recoveryHelper->notificationQueue);
34 }
35
36 /********************************************************************************************************************/
37
38 template<typename UserType>
40 // Skip flagging our target as being in a ReadAnyGroup (it isn't since we replace the readQueue with our own)
41 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
42 NDRegisterAccessor<UserType>::setInReadAnyGroup(rag);
43 }
44
45 /********************************************************************************************************************/
46
47 template<typename UserType>
49
50 /********************************************************************************************************************/
51
52 template<typename UserType>
53 void ReverseRecoveryDecorator<UserType>::doPostRead(TransferType, bool updateBuffer) {
54 // Do the same as NDRegisterAccessorDecorator::doPostRead() but without delegating to the target. We must
55 // not delegate, because we did not call preRead() and the entire operation is executed inside the
56 // continuation of the readQueue (see constructor implementation).
57 _target->setActiveException(this->_activeException);
58
59 // Decorators have to copy meta data even if updateDataBuffer is false
60 this->_dataValidity = _target->dataValidity();
61 this->_versionNumber = _target->getVersionNumber();
62
63 if(!updateBuffer) {
64 return;
65 }
66
67 for(size_t i = 0; i < _target->getNumberOfChannels(); ++i) {
68 this->buffer_2D[i].swap(_target->accessChannel(i));
69 }
70 }
71
72 /********************************************************************************************************************/
73
75} // namespace ChimeraTK
void doPostRead(TransferType, bool updateBuffer) override
boost::shared_ptr< RecoveryHelper > _recoveryHelper
ReverseRecoveryDecorator(boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > > accessor, boost::shared_ptr< RecoveryHelper > recoveryHelper)
void setInReadAnyGroup(ReadAnyGroup *rag) override
InvalidityTracer application module.
INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(DebugPrintAccessorDecorator)