Orion
high-rate readout
deccore.hpp
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <span>
8 #include <functional>
9 
10 #include "options.hpp"
11 #include "evtcallback.hpp"
12 
13 
14 namespace itk::itkpix::endec {
15 
16 namespace intf {
17 
22 class DecCore {
23 public:
24 
26  virtual ~DecCore() = default;
27 
29  virtual void initialize() = 0;
30 
32  virtual void finalize() = 0;
33 
36  virtual void decode(uint64_t data) = 0;
37 
41  virtual void decode(const std::span<const uint8_t> buff) = 0;
42 
45  virtual void decode(const std::span<const uint64_t> buff64) = 0;
46 
51  inline void decode(const uint8_t *buff, size_t size) { decode({ buff, size }); }
52 
56  inline void decode(const uint64_t *buff64, size_t size64) { decode({ buff64, size64 }); }
57 
58 };
59 
60 } // intf
61 
62 namespace concepts {
63 
64 template<typename T>
65 concept DecCore =
66  std::constructible_from<T, Options, typename T::EventCallback&> and // (opt, cb_evt)
67  std::destructible<T> and
68  requires(T self) {
69  { self.initialize() } -> std::same_as<void>;
70  { self.finalize() } -> std::same_as<void>;
71  } and
72  requires(T self, uint64_t data) {
73  { self.decode(data) } -> std::same_as<void>;
74  } and
75  requires(T self, const uint8_t *buff, size_t size) {
76  { self.decode(buff, size) } -> std::same_as<void>;
77  } and
78  requires(T self, const uint64_t *buff, size_t size) {
79  { self.decode(buff, size) } -> std::same_as<void>;
80  } and
81  requires(T self, const std::span<const uint8_t> buff) {
82  { self.decode(buff) } -> std::same_as<void>;
83  } and
84  requires(T self, const std::span<const uint64_t> buff) {
85  { self.decode(buff) } -> std::same_as<void>;
86  };
87 
88 } // concepts
89 
90 
91 namespace factory {
92 
95 struct DecCore {
96 
102  inline auto operator()(Options opt, intf::EventCallback& cb_evt, int cb_type = 0) {
103  return func(opt, cb_evt, cb_type);
104  }
105 
108  template<template <int> class T>
109  static inline DecCore make() {
110  DecCore maker;
111  maker.func = [](Options opt, intf::EventCallback& cb_evt, int cb_type) -> auto {
112  if (cb_type == 0) return static_cast<intf::DecCore*>(new T<0>(opt, cb_evt));
113  if (cb_type == 1) return static_cast<intf::DecCore*>(new T<1>(opt, cb_evt));
114  if (cb_type == 2) return static_cast<intf::DecCore*>(new T<2>(opt, cb_evt));
115  return static_cast<intf::DecCore*>(nullptr);
116  };
117  return maker;
118  }
119 
120  std::function<intf::DecCore* (Options opt, intf::EventCallback& cb_evt, int cb_type)> func;
121 };
122 
123 } // factory
124 
125 namespace wrap {
126 
127 template<typename T>
128 class DecCore : public intf::DecCore {
129 public:
130 
131  using EventCallback = T::EventCallback;
132 
133  DecCore(Options opt, EventCallback& cb_evt) : impl(opt, cb_evt) {}
134 
135  void initialize() override { impl.initialize(); }
136  void finalize() override { impl.finalize(); }
137  void decode(uint64_t data) override { impl.decode(data); }
138  // void decode(const uint8_t *buff, size_t size) override { impl.decode(buff, size); }
139  // void decode(const uint64_t *buff64, size_t size64) override { impl.decode(buff64, size64); }
140  void decode(const std::span<const uint8_t> buff) override { impl.decode(buff.data(), buff.size()); }
141  void decode(const std::span<const uint64_t> buff64) override { impl.decode(buff64.data(), buff64.size()); }
142 
143  T impl;
144 };
145 
146 } // libso
147 
148 } // itk::itkpix::decoder
149 
Definition: test_enc_dec.cpp:117
Core decoding interface.
Definition: deccore.hpp:22
virtual void decode(uint64_t data)=0
Decode single 64-bit data frame.
virtual void decode(const std::span< const uint8_t > buff)=0
Decode data packet as received from FELIX. When reinterpreting as 64-bit words requires swapping of 3...
virtual void decode(const std::span< const uint64_t > buff64)=0
Decode data packet.
virtual void initialize()=0
Initialise decoder core.
virtual ~DecCore()=default
Destructor.
void decode(const uint8_t *buff, size_t size)
Decode data packet as received from FELIX. When reinterpreting as 64-bit words requires swapping of 3...
Definition: deccore.hpp:51
virtual void finalize()=0
Finalise decoder core.
void decode(const uint64_t *buff64, size_t size64)
Decode data packet.
Definition: deccore.hpp:56
Callback interface for event.
Definition: evtcallback.hpp:45
Definition: deccore.hpp:128
void finalize() override
Finalise decoder core.
Definition: deccore.hpp:136
void decode(const std::span< const uint64_t > buff64) override
Decode data packet.
Definition: deccore.hpp:141
void initialize() override
Initialise decoder core.
Definition: deccore.hpp:135
void decode(const std::span< const uint8_t > buff) override
Decode data packet as received from FELIX. When reinterpreting as 64-bit words requires swapping of 3...
Definition: deccore.hpp:140
void decode(uint64_t data) override
Decode single 64-bit data frame.
Definition: deccore.hpp:137
Interfaces for ITkPix decoder event callback.
uint16_t size
Definition: fragheader.hpp:5
ITkPix common Encoder/Decoder options.
Common encoder/decoder options.
Definition: options.hpp:10
Constructor for DecCore.
Definition: deccore.hpp:95
static DecCore make()
Create DecCore maker.
Definition: deccore.hpp:109
auto operator()(Options opt, intf::EventCallback &cb_evt, int cb_type=0)
Constructor.
Definition: deccore.hpp:102