ChimeraTK-DeviceAccess  03.18.00
TwoDRegisterAccessor.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 
6 
7 #include <boost/smart_ptr.hpp>
8 
9 namespace ChimeraTK {
10 
11  /********************************************************************************************************************/
12 
16  template<class UserType>
17  class TwoDRegisterAccessor : public NDRegisterAccessorAbstractor<UserType> {
18  public:
20  // NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions)
21  TwoDRegisterAccessor(boost::shared_ptr<NDRegisterAccessor<UserType>> _accessor);
22 
30 
32  std::vector<UserType>& operator[](size_t channel) { return get()->accessChannel(channel); }
33 
35  const std::vector<UserType>& operator[](size_t channel) const { return get()->accessChannel(channel); }
36 
38  TwoDRegisterAccessor<UserType>& operator=(const std::vector<std::vector<UserType>>& other);
39 
41  [[nodiscard]] size_t getNChannels() const { return get()->getNumberOfChannels(); }
42 
44  [[nodiscard]] size_t getNElementsPerChannel() const { return get()->getNumberOfSamples(); }
45 
50  template<typename COOKED_TYPE>
51  COOKED_TYPE getAsCooked(unsigned int channel, unsigned int sample) const;
52 
57  template<typename COOKED_TYPE>
58  void setAsCooked(unsigned int channel, unsigned int sample, COOKED_TYPE value);
59 
60  friend class TransferGroup;
61 
63  };
64 
65  /********************************************************************************************************************/
66  /********************************************************************************************************************/
67 
68  template<class UserType>
70  : NDRegisterAccessorAbstractor<UserType>(_accessor) {
71  static_assert(!std::is_same<UserType, Void>::value,
72  "You cannot create TwoDRegisterAccessor<ChimeraTK::Void>! Use VoidRegisterAccessor instead.");
73  }
74 
75  /********************************************************************************************************************/
76 
77  template<class UserType>
79  static_assert(!std::is_same<UserType, Void>::value,
80  "You cannot create TwoDRegisterAccessor<ChimeraTK::Void>! Use VoidRegisterAccessor instead.");
81  }
82 
83  /********************************************************************************************************************/
84 
85  template<class UserType>
87  const std::vector<std::vector<UserType>>& other) {
88  get()->accessChannels() = other;
89  return *this;
90  }
91 
92  /********************************************************************************************************************/
93 
94  template<class UserType>
95  template<typename COOKED_TYPE>
96  COOKED_TYPE TwoDRegisterAccessor<UserType>::getAsCooked(unsigned int channel, unsigned int sample) const {
97  return get()->template getAsCooked<COOKED_TYPE>(channel, sample);
98  }
99 
100  /********************************************************************************************************************/
101 
102  template<class UserType>
103  template<typename COOKED_TYPE>
104  void TwoDRegisterAccessor<UserType>::setAsCooked(unsigned int channel, unsigned int sample, COOKED_TYPE value) {
105  return get()->template setAsCooked<COOKED_TYPE>(channel, sample, value);
106  }
107 
108  /********************************************************************************************************************/
109 
110  // Do not declare the template for all user types as extern here.
111  // This could avoid optimisation of the inline code.
112 
113 } // namespace ChimeraTK
NDRegisterAccessorAbstractor.h
ChimeraTK::TwoDRegisterAccessor
Accessor class to read and write 2D registers.
Definition: ForwardDeclarations.h:20
ChimeraTK::TwoDRegisterAccessor::TwoDRegisterAccessor
TwoDRegisterAccessor()
Placeholder constructer, to allow late initialisation of the accessor, e.g.
Definition: TwoDRegisterAccessor.h:78
ChimeraTK::TransferGroup
Group multiple data accessors to efficiently trigger data transfers on the whole group.
Definition: TransferGroup.h:26
ChimeraTK::TwoDRegisterAccessor::getAsCooked
COOKED_TYPE getAsCooked(unsigned int channel, unsigned int sample) const
Get the cooked values in case the accessor is a raw accessor (which does not do data conversion).
Definition: TwoDRegisterAccessor.h:96
ChimeraTK::TwoDRegisterAccessor::operator[]
std::vector< UserType > & operator[](size_t channel)
Operator to access individual sequences/channels.
Definition: TwoDRegisterAccessor.h:32
ChimeraTK::NDRegisterAccessorAbstractor
Base class for the register accessor abstractors (ScalarRegisterAccessor, OneDRegisterAccessor and Tw...
Definition: NDRegisterAccessorAbstractor.h:19
ChimeraTK::TwoDRegisterAccessor::operator=
TwoDRegisterAccessor< UserType > & operator=(const std::vector< std::vector< UserType >> &other)
Assignment operator to assign the entire 2D array.
Definition: TwoDRegisterAccessor.h:86
ChimeraTK::TwoDRegisterAccessor::getNChannels
size_t getNChannels() const
Return the number of channels (formerly called sequences)
Definition: TwoDRegisterAccessor.h:41
ChimeraTK::TwoDRegisterAccessor::operator[]
const std::vector< UserType > & operator[](size_t channel) const
Const operator to access individual sequences/channels.
Definition: TwoDRegisterAccessor.h:35
ChimeraTK::TwoDRegisterAccessor::getNElementsPerChannel
size_t getNElementsPerChannel() const
Return number of elements/samples per channel.
Definition: TwoDRegisterAccessor.h:44
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::TwoDRegisterAccessor::setAsCooked
void setAsCooked(unsigned int channel, unsigned int sample, COOKED_TYPE value)
Set the cooked values in case the accessor is a raw accessor (which does not do data conversion).
Definition: TwoDRegisterAccessor.h:104
ChimeraTK::NDRegisterAccessor
N-dimensional register accessor.
Definition: ForwardDeclarations.h:17