Orion
high-rate readout
enccore.hpp
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <functional>
8 
9 #include "options.hpp"
10 #include "outcallback.hpp"
11 
12 namespace itk::itkpix::endec {
13 
14 namespace intf {
15 
16 class EncCore {
17 public:
19  virtual ~EncCore() = default;
20 
22  virtual void initialize() = 0;
23 
25  virtual void finalize() = 0;
26 
29  virtual void evt_init(uint8_t tag) = 0;
30 
33  virtual void evt_next(uint8_t tag) = 0;
34 
36  virtual void evt_done() = 0;
37 
42  virtual void add_hit(uint16_t col, uint16_t row, uint16_t tot) = 0;
43 
49  virtual void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) = 0;
50 
55  virtual void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot) = 0;
56 
57 };
58 
59 } // intf
60 
61 
62 namespace concepts {
63 
64 template<typename T>
65 concept EncCore =
66  std::constructible_from<T, Options, typename T::OutputCallback&> and // (opt, cb_out)
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, uint8_t tag) {
73  { self.evt_init(tag) } -> std::same_as<void>;
74  } and
75  requires(T self) {
76  { self.evt_done() } -> std::same_as<void>;
77  } and
78  requires(T self, uint16_t col, uint16_t row, uint16_t tot) {
79  { self.add_hit(col, row, tot) } -> std::same_as<void>;
80  } and
81  requires(T self, uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) {
82  { self.add_hmap(qcol, qrow, hmap, tots) } -> std::same_as<void>;
83  } and
84  requires(T self, uint8_t qcol, uint8_t qrow, uint64_t qtot) {
85  { self.add_qcore(qcol, qrow, qtot) } -> std::same_as<void>;
86  };
87 
88 } // concepts
89 
90 
91 namespace factory {
92 
95  struct EncCore {
96 
101  inline auto operator()(Options opt, intf::OutputCallback& cb_out) { return func(opt, cb_out); }
102 
105  template<typename T>
106  static inline EncCore make() {
107  EncCore maker;
108  maker.func = [](Options opt, intf::OutputCallback& cb_out) -> auto { return new T(opt, cb_out); };
109  return maker;
110  }
111 
112  std::function<intf::EncCore* (Options opt, intf::OutputCallback& cb_out)> func;
113  };
114 
115 } // factory
116 
117 
118 namespace wrap {
119 
120 template<typename T>
121 class EncCore : public intf::EncCore {
122 public:
123  using OutputCallback = T::OutputCallback;
124 
125  EncCore(Options opt, OutputCallback& cb_out) : impl(opt, cb_out) {}
126 
127  void initialize() override { impl.initialize(); }
128  void finalize() override { impl.finalize(); }
129  void evt_init(uint8_t tag) override { impl.evt_init(tag); }
130  void evt_next(uint8_t tag) override { impl.evt_next(tag); }
131  void evt_done() override { impl.evt_done(); }
132  void add_hit(uint16_t col, uint16_t row, uint16_t tot) override {
133  impl.add_hit(col, row, tot);
134  }
135  void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) override {
136  impl.add_hmap(qcol, qrow, hmap, tots);
137  }
138  void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot) override {
139  impl.add_qcore(qcol, qrow, qtot);
140  }
141 
142  T impl;
143 };
144 
145 } // wrap
146 
147 
148 } // itk::itkpix::encoder
Definition: enccore.hpp:16
virtual void evt_next(uint8_t tag)=0
Complete the event and start the next one.
virtual void evt_init(uint8_t tag)=0
Init a new event.
virtual void finalize()=0
Finalise encoder core.
virtual void evt_done()=0
Done event.
virtual void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot)=0
Add qcore: tots are decoded to 64 bit qtot, no-hit marked as 0xF.
virtual void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots)=0
Add hitmap: hitmap is decoded, tots are not decoded.
virtual void initialize()=0
Initialise encoder core.
virtual void add_hit(uint16_t col, uint16_t row, uint16_t tot)=0
Add hit.
virtual ~EncCore()=default
Destructor.
Callback interface for output.
Definition: outcallback.hpp:39
Definition: enccore.hpp:42
Definition: enccore.hpp:121
void initialize() override
Initialise encoder core.
Definition: enccore.hpp:127
void add_hit(uint16_t col, uint16_t row, uint16_t tot) override
Add hit.
Definition: enccore.hpp:132
void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) override
Add hitmap: hitmap is decoded, tots are not decoded.
Definition: enccore.hpp:135
void finalize() override
Finalise encoder core.
Definition: enccore.hpp:128
void evt_next(uint8_t tag) override
Complete the event and start the next one.
Definition: enccore.hpp:130
void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot) override
Add qcore: tots are decoded to 64 bit qtot, no-hit marked as 0xF.
Definition: enccore.hpp:138
void evt_done() override
Done event.
Definition: enccore.hpp:131
void evt_init(uint8_t tag) override
Init a new event.
Definition: enccore.hpp:129
ITkPix common Encoder/Decoder options.
Interfaces for ITkPix encoder output callback.
Common encoder/decoder options.
Definition: options.hpp:10
Constructor for EncCore.
Definition: enccore.hpp:95
auto operator()(Options opt, intf::OutputCallback &cb_out)
Constructor.
Definition: enccore.hpp:101
static EncCore make()
Create EncCore maker.
Definition: enccore.hpp:106