11namespace ChimeraTK::detail {
15 bool ReadCoordinator::empty()
const {
16 return _groupIndex.empty();
21 void ReadCoordinator::run(
const std::vector<uint8_t>& rawBuffer) {
22 _rawBuffer = &rawBuffer;
23 for(
auto& entry : _groups) {
24 auto& group = *entry.second;
25 if(group.consumersEmpty()) {
30 group.rawCopy(rawBuffer);
34 group.converterLoopHelper->doPostRead();
44 void ReadCoordinator::doPostReadImpl(
45 RawConverter::Converter<UserType, RawType, sc, fc, isSigned> converter,
size_t groupId) {
53 if constexpr(!std::is_same_v<RawType, ChimeraTK::Void>) {
54 auto& group =
static_cast<Group<UserType>&
>(*_groups.at(groupId));
55 const uint8_t*
raw = _rawBuffer->data();
56 for(
auto& consumer : group.consumers) {
57 if(consumer.nSamples == 0) {
60 auto* cooked = consumer.staging.data();
61 const auto* rawSample =
raw + consumer.byteOffset;
62 for(
size_t i = 0; i < consumer.nSamples; ++i) {
64 std::memcpy(&temp, rawSample + i * consumer.stride,
sizeof(RawType));
65 cooked[i] = converter.toCooked(temp);
75 void ReadCoordinator::doPreWriteImpl(
76 RawConverter::Converter<UserType, RawType, sc, fc, isSigned> ,
size_t ) {
82 template<
typename UserType>
83 ReadCoordinator::Registration<UserType>::Registration(ReadCoordinator* owner,
84 const NumericAddressedRegisterInfo& info,
bool isRaw,
size_t byteOffset,
size_t stride,
size_t nSamples)
85 : _owner(owner), _staging(
std::make_unique<
std::vector<UserType>>(
nSamples)) {
88 const auto& channel = info.channels[0];
89 GroupKey key{channel.dataType, channel.width, channel.nFractionalBits, channel.signedFlag, channel.rawType,
90 std::type_index(
typeid(UserType)), isRaw};
95 auto [groupIt, inserted] = _owner->_groupIndex.emplace(key, 0);
99 _groupId = _owner->_nextGroupId++;
100 groupIt->second = _groupId;
101 auto group = std::make_unique<Group<UserType>>();
102 group->isRaw = isRaw;
116 group->converterLoopHelper =
117 RawConverter::ConverterLoopHelper::makeConverterLoopHelper<UserType>(info, 0, _groupId, *owner);
119 _owner->_groups.emplace(_groupId, std::move(group));
122 _groupId = groupIt->second;
124 auto& group =
static_cast<Group<UserType>&
>(*_owner->_groups.at(_groupId));
125 group.consumers.push_back(Consumer<UserType>(byteOffset, stride,
nSamples, *_staging));
126 _it = std::prev(group.consumers.end());
131 template<
typename UserType>
133 ReadCoordinator::Registration<UserType>::~Registration() {
139 template<
typename UserType>
140 ReadCoordinator::Registration<UserType>::Registration(Registration&& other) noexcept
141 : _owner(other._owner), _groupId(other._groupId), _it(other._it), _staging(std::move(other._staging)) {
142 other._owner =
nullptr;
147 template<
typename UserType>
148 ReadCoordinator::Registration<UserType>& ReadCoordinator::Registration<UserType>::operator=(
149 Registration&& other)
noexcept {
154 _owner = other._owner;
155 _groupId = other._groupId;
157 _staging = std::move(other._staging);
158 other._owner =
nullptr;
164 template<
typename UserType>
165 void ReadCoordinator::Registration<UserType>::reset() {
166 if(_owner ==
nullptr) {
171 auto& group =
static_cast<Group<UserType>&
>(*_owner->_groups.at(_groupId));
172 group.consumers.erase(_it);
179 template<
typename UserType>
180 std::vector<UserType>& ReadCoordinator::Registration<UserType>::staging() {
#define INSTANTIATE_TEMPLATE_FOR_CHIMERATK_USER_TYPES(TemplateClass)
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...
constexpr size_t nSamples