Orion
high-rate readout
print_utils.hpp
1 #pragma once
2 
3 #include <iomanip>
4 #include <iostream>
5 #include <string>
6 
7 namespace itk::itkpix::endec::codec {
8 
9 template <bool enable>
10 struct print {
11  void tag(uint64_t value) {
12  if constexpr (!enable) return;
13  std::cout << BLUE;
14  bits(value, 8);
15  std::cout << "(" << value << ")" << RESET;
16  }
17  void internal_tag(uint64_t value) {
18  if constexpr (!enable) return;
19  std::cout << BLUE;
20  bits(value, 11);
21  std::cout << "(" << value << ")" << RESET;
22  }
23 
24  void ccol(uint64_t value) {
25  if constexpr (!enable) return;
26  std::cout << YELLOW;
27  bits(value, 6);
28  std::cout << "(" << value << ")" << RESET;
29  }
30  void qrow(uint64_t value) {
31  if constexpr (!enable) return;
32  std::cout << GREEN;
33  bits(value, 8);
34  std::cout << "(" << value << ")" << RESET;
35  }
36  void hitmap(uint64_t value, size_t length, uint64_t decoded) {
37  if constexpr (!enable) return;
38  std::cout << RED;
39  bits(value, length);
40  std::cout << "(";
41  bits(decoded, 16);
42  std::cout << ")";
43  std::cout << RESET;
44  }
45  void tot(uint64_t value, size_t length) {
46  if constexpr (!enable) return;
47  std::cout << ORANGE;
48  bits(value, length*4);
49  std::cout << "(";
50  for (int i = 0; i < length; i++) {
51  std::cout << std::setw(2) << (value >> (i * 4) & 0xf);
52  }
53  std::cout << ")" << RESET;
54  }
55  void ctrl(uint64_t value) {
56  if constexpr (!enable) return;
57  std::cout << CYAN;
58  bits(value >> 1, 1);
59  std::cout << MAGENTA;
60  bits(value & 1, 1);
61  std::cout << RESET;
62  }
63  void bits(uint64_t value, size_t length) {
64  if constexpr (!enable) return;
65  for (int i = length - 1; i >= 0; --i) {
66  std::cout << ((value >> i) & 1);
67  }
68  }
69 
70  private:
71  static inline const std::string RED = "\033[31m";
72  static inline const std::string GREEN = "\033[32m";
73  static inline const std::string YELLOW = "\033[33m";
74  static inline const std::string BLUE = "\033[34m";
75  static inline const std::string MAGENTA = "\033[35m";
76  static inline const std::string CYAN = "\033[36m";
77  static inline const std::string RESET = "\033[0m";
78  const std::string ORANGE = "\033[38;5;214m";
79 };
80 
81 } // itk::itkpix::endec::codec
Definition: print_utils.hpp:10