ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
ConsumingFanOut.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
5#include "FanOut.h"
6
7#include <ChimeraTK/NDRegisterAccessorDecorator.h>
8
9namespace ChimeraTK {
10
11 /********************************************************************************************************************/
12
17 template<typename UserType>
18 class ConsumingFanOut : public FanOut<UserType>, public ChimeraTK::NDRegisterAccessorDecorator<UserType> {
19 public:
20 ConsumingFanOut(boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> feedingImpl,
21 ConsumerImplementationPairs<UserType> const& consumerImplementationPairs);
22
23 void doPostRead(TransferType type, bool updateDataBuffer) override;
24
25 void interrupt() override;
26
27 protected:
28 using ChimeraTK::NDRegisterAccessor<UserType>::buffer_2D;
29 std::vector<UserType> _lastReceivedValue;
30 };
31
32 /********************************************************************************************************************/
33
34 template<typename UserType>
35 ConsumingFanOut<UserType>::ConsumingFanOut(boost::shared_ptr<ChimeraTK::NDRegisterAccessor<UserType>> feedingImpl,
36 ConsumerImplementationPairs<UserType> const& consumerImplementationPairs)
37 : FanOut<UserType>(feedingImpl), ChimeraTK::NDRegisterAccessorDecorator<UserType>(feedingImpl) {
38 assert(feedingImpl->isReadable());
39
40 _lastReceivedValue.resize(buffer_2D[0].size());
41
42 // Add the consuming accessors
43 for(auto el : consumerImplementationPairs) {
44 FanOut<UserType>::addSlave(el.first, el.second);
45 }
46 }
47
48 /********************************************************************************************************************/
49
50 template<typename UserType>
51 void ConsumingFanOut<UserType>::doPostRead(TransferType type, bool updateDataBuffer) {
52 ChimeraTK::NDRegisterAccessorDecorator<UserType>::doPostRead(type, updateDataBuffer);
53
54 if(updateDataBuffer) {
55 // We have to keep a copy to write into the slaves. There might
56 // be decorators arount this fanout which swap out buffer_2D, so it is
57 // not available any more for a second read witout updateDataBuffer (exception case).
58 _lastReceivedValue = buffer_2D[0];
59 }
60
61 // The ConsumingFanOut conceptually never has a wait_fow_new_data flags. Hence each read
62 // operation returns with "new" data, even in case of an exception. So each read
63 // always synchronises all slaves and pushes the content of the data buffer.
64 for(auto& slave : FanOut<UserType>::_slaves) { // send out copies to slaves
65 // do not send copy if no data is expected (e.g. trigger)
66 if(slave->getNumberOfSamples() != 0) {
67 slave->accessChannel(0) = _lastReceivedValue;
68 }
69 slave->setDataValidity(this->dataValidity());
70 slave->writeDestructively();
71 }
72 }
73
74 /********************************************************************************************************************/
75
76 template<typename UserType>
78 // call the interrut sequences of the fan out (interrupts for fan input and all outputs), and the ndRegisterAccessor
80 if(this->_accessModeFlags.has(AccessMode::wait_for_new_data)) {
81 ChimeraTK::NDRegisterAccessorDecorator<UserType>::interrupt();
82 }
83 }
84
85 /********************************************************************************************************************/
86
87} /* namespace ChimeraTK */
FanOut implementation which acts as a read-only (i.e.
std::vector< UserType > _lastReceivedValue
ConsumingFanOut(boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > > feedingImpl, ConsumerImplementationPairs< UserType > const &consumerImplementationPairs)
void doPostRead(TransferType type, bool updateDataBuffer) override
Base class for several implementations which distribute values from one feeder to multiple consumers.
Definition FanOut.h:42
virtual void interrupt()
Definition FanOut.h:114
virtual void addSlave(boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > > slave, VariableNetworkNode &)
Add a slave to the FanOut.
Definition FanOut.h:68
InvalidityTracer application module.
std::list< std::pair< boost::shared_ptr< ChimeraTK::NDRegisterAccessor< UserType > >, VariableNetworkNode > > ConsumerImplementationPairs
Definition FanOut.h:18