Orion
high-rate readout
deccore.hpp
Go to the documentation of this file.
1 // ╭─╮╭─╴╷╭─╮┌─╮
2 // ╰─╯╵ ╵╰─╯╵ ╵
8 #pragma once
9 
10 #include <functional>
11 
12 #include "itk/logger.hpp"
14 
15 // #include "orion/itkpix/endec.hpp"
16 
17 namespace itk::itkpix::endec::orion {
18 
19 extern factory::DecCore makeDecCore;
20 
21 extern itk::Logger log;
22 
23 
24 template<typename T, int cb_type = 0>
25 class DecCore : public intf::EventCallback {
26 public:
27  using EventCallback = T;
28 
29  Options opt;
30  // orion::EventCallback<T, cb_type> cb;
31  EventCallback& cb;
32  intf::DecCore* dec;
33 
34  DecCore(Options opt, EventCallback& cb_evt) : opt(opt), cb(cb_evt) {
35  log.debug("orion.DecCore(opt, evt)");
36  dec = makeDecCore(opt, *this, 1);
37  }
38 
39  ~DecCore() {
40  delete dec;
41  }
42 
43  inline void initialize() {
44  log.debug("initialize()");
45  dec->initialize();
46  }
47  inline void finalize() {
48  log.debug("finalize()");
49  dec->finalize();
50  }
51  inline void decode(uint64_t data64) { dec->decode(data64); }
52  inline void decode(const uint8_t *buff, size_t size) { decode({ buff, size }); }
53  inline void decode(const uint64_t *buff64, size_t size64) { decode({ buff64, size64 }); }
54 
55  inline void decode(const std::span<const uint8_t> buff) { dec->decode(buff); }
56  inline void decode(const std::span<const uint64_t> buff64) { dec->decode(buff64); }
57 
58 private:
59  // EventCallback methods
60  void evt_init(uint8_t tag) override { cb.evt_init(tag); }
61  void evt_next(uint8_t tag) override { cb.evt_next(tag); }
62  void evt_done() override { cb.evt_done(); }
63 
64  void add_hit(uint16_t col, uint16_t row, uint16_t tot) override {
65  cb.add_hit(col, row, tot);
66  }
67  void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot) override {
68  cb.add_qcore(qcol, qrow, qtot);
69  }
70 
71  void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) override {
72  if (cb_type == 1) cb.add_hmap(qcol, qrow, hmap, tots);
73  if (cb_type == 0 || cb_type == 2) {
74  uint pix_col = qcol*8;
75  uint pix_row = qrow*2;
76 
77  uint64_t qtot = 0;
78  if (cb_type == 2) tots = ~tots;
79 
80  uint htmp = hmap;
81  while (htmp) {
82  uint i = __builtin_clz(htmp);
83  htmp ^= 0x80000000 >> i;
84  uint col = pix_col + (i - 16) % 8;
85  uint row = pix_row + (i - 16) / 8;
86  uint tot = tots >> 60;
87  tots = tots << 4;
88  if (cb_type == 0) cb.add_hit(col, row, tot);
89  if (cb_type == 2) qtot |= tot << (4*(31 - i));
90  }
91  if (cb_type == 2) {
92  qtot = ~qtot;
93  cb.add_qcore(qcol, qrow, qtot);
94  }
95  }
96  }
97 
98  uint8_t on_error(EventError error) override { return cb.on_error(error); }
99 
100 };
101 
102 
103 } // itk::itkpix::endec::orion
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 initialize()=0
Initialise decoder core.
virtual void finalize()=0
Finalise decoder core.
Callback interface for event.
Definition: evtcallback.hpp:45
Definition: deccore.hpp:25
Logger class definition, wrapper around CoreLogger, adds templated methods for different logging leve...
Definition: logger.hpp:108
void debug(fmt::format_string< Args... > fmt, Args &&...args)
Logs a message with debug level.
Definition: logger.hpp:140
uint16_t size
Definition: fragheader.hpp:5
Templates for ITkPix Decoder Core.
Logger definitions.
Callback on event decoding error.
Definition: evtcallback.hpp:15
Common encoder/decoder options.
Definition: options.hpp:10