ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
TriggeredPollDistributor.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 "../ScalarRegisterAccessor.h"
6#include "../TransferGroup.h"
10
11#include <memory>
12
13namespace ChimeraTK::async {
20 public:
21 TriggeredPollDistributor(boost::shared_ptr<DeviceBackend> backend,
22 boost::shared_ptr<SubDomain<std::nullptr_t>> parent, boost::shared_ptr<Domain> asyncDomain);
23
25 bool prepareIntermediateBuffers() override;
26
27 template<typename UserType>
28 std::unique_ptr<AsyncVariable> createAsyncVariable(AccessorInstanceDescriptor const& descriptor);
29
30 VersionNumber getVersion() const { return _version; }
31
32 bool getForceFaulty() const { return _forceFaulty; }
33
34 protected:
36 boost::shared_ptr<SubDomain<std::nullptr_t>> _parent;
37 std::shared_ptr<DataConsistencyRealm> _dataConsistencyRealm;
39 bool _forceFaulty{false};
41 };
42
43 /********************************************************************************************************************/
44
47 template<typename UserType>
48 struct PolledAsyncVariable : public AsyncVariableImpl<UserType> {
49 void fillSendBuffer() final;
50
52 explicit PolledAsyncVariable(
53 boost::shared_ptr<NDRegisterAccessor<UserType>> syncAccessor_, TriggeredPollDistributor& owner);
54
55 unsigned int getNumberOfChannels() override { return _syncAccessor->getNumberOfChannels(); }
56 unsigned int getNumberOfSamples() override { return _syncAccessor->getNumberOfSamples(); }
57 const std::string& getUnit() override { return _syncAccessor->getUnit(); }
58 const std::string& getDescription() override { return _syncAccessor->getDescription(); }
59
60 protected:
61 boost::shared_ptr<NDRegisterAccessor<UserType>> _syncAccessor;
62
64 };
65
66 /********************************************************************************************************************/
67 // Implementations
68 /********************************************************************************************************************/
69
70 template<typename UserType>
71 std::unique_ptr<AsyncVariable> TriggeredPollDistributor::createAsyncVariable(
72 AccessorInstanceDescriptor const& descriptor) {
73 auto synchronousFlags = descriptor.flags;
74 synchronousFlags.remove(AccessMode::wait_for_new_data);
75 // Don't call backend->getSyncRegisterAccessor() here. It might skip the overriding of a backend.
76 auto syncAccessor = _backend->getRegisterAccessor<UserType>(
77 descriptor.name, descriptor.numberOfWords, descriptor.wordOffsetInRegister, synchronousFlags);
78 // read the initial value before adding it to the transfer group
79 if(_asyncDomain->unsafeGetIsActive()) {
80 try {
81 syncAccessor->read();
82 }
84 // Nothing to do here. The backend's setException() has already been called by the syncAccessor.
85 }
86 }
87
88 _transferGroup.addAccessor(syncAccessor);
89 return std::make_unique<PolledAsyncVariable<UserType>>(syncAccessor, *this);
90 }
91
92 /********************************************************************************************************************/
93 template<typename UserType>
95 this->_sendBuffer.versionNumber = _owner.getVersion();
96 this->_sendBuffer.dataValidity = !_owner.getForceFaulty() ? _syncAccessor->dataValidity() : DataValidity::faulty;
97 this->_sendBuffer.value.swap(_syncAccessor->accessChannels());
98 }
99
100 /********************************************************************************************************************/
101 template<typename UserType>
103 boost::shared_ptr<NDRegisterAccessor<UserType>> syncAccessor_, TriggeredPollDistributor& owner)
104 : AsyncVariableImpl<UserType>(syncAccessor_->getNumberOfChannels(), syncAccessor_->getNumberOfSamples()),
105 _syncAccessor(syncAccessor_), _owner(owner) {}
106
107} // namespace ChimeraTK::async
void remove(AccessMode flag)
Remove the given flag from the set.
Definition AccessMode.cc:56
N-dimensional register accessor.
Accessor class to read and write scalar registers transparently by using the accessor object like a v...
Group multiple data accessors to efficiently trigger data transfers on the whole group.
void addAccessor(TransferElementAbstractor &accessor)
Add a register accessor to the group.
Class for generating and holding version numbers without exposing a numeric representation.
boost::shared_ptr< DeviceBackend > _backend
Send backend-specific asynchronous data to different distributors:
Definition SubDomain.h:33
The TriggeredPollDistributor has std::nullptr_t source data type and is polling the data for the Asyn...
std::shared_ptr< DataConsistencyRealm > _dataConsistencyRealm
ScalarRegisterAccessor< DataConsistencyKey::BaseType > _dataConsistencyKeyAccessor
boost::shared_ptr< SubDomain< std::nullptr_t > > _parent
bool prepareIntermediateBuffers() override
Poll all sync variables.
std::unique_ptr< AsyncVariable > createAsyncVariable(AccessorInstanceDescriptor const &descriptor)
Exception thrown when a runtime error has occured.
Definition Exception.h:18
@ faulty
The data is considered valid.
@ wait_for_new_data
Make any read blocking until new data has arrived since the last read.
Helper class to have a complete descriton to create an Accessor.
AsyncVariableImpl contains a weak pointer to an AsyncNDRegisterAccessor<UserType> and a send buffer N...
Implementation of the PolledAsyncVariable for the concrete UserType.
unsigned int getNumberOfChannels() override
Helper functions for the creation of an AsyncNDRegisterAccessor.
const std::string & getDescription() override
PolledAsyncVariable(boost::shared_ptr< NDRegisterAccessor< UserType > > syncAccessor_, TriggeredPollDistributor &owner)
The constructor takes an already created synchronous accessor and a reference to the owing distributo...
void fillSendBuffer() final
Fill the send buffer with data and version number.
boost::shared_ptr< NDRegisterAccessor< UserType > > _syncAccessor