Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
print.cpp
Go to the documentation of this file.
1#include "print.hpp"
2
3#include <iostream>
4#include <iomanip>
5#include <sstream>
6#include <cctype>
7
9#include "structs.hpp"
10#include "datatypes.hpp"
11
12/**
13 * \author cpellegrino
14 */
15
16struct DOMID_h
17{
18 uint32_t m_val;
19 DOMID_h(uint32_t val)
20 : m_val(val)
21 {}
22};
23
24std::ostream& operator <<(std::ostream& stream, DOMID_h const& domid)
25{
26 /*
27 * The MAC address of a WR node starts with 08:00:30.
28 * The DOMID is defined by the MAC address removing the initial 08:00.
29 */
30
31 std::ostringstream oss("0800", std::ostringstream::ate);
32 oss << std::hex << domid.m_val;
33 if (oss.tellp() != 12) {
34 return stream << "undefined";
35 }
36
37 std::string const no = oss.str();
38 std::size_t const s = no.size();
39 for (std::size_t i = 0; i < s; i += 2) {
40 stream
41 << char(std::toupper(no[i]))
42 << char(std::toupper(no[i + 1]))
43 << (i != s - 2 ? ":" : "");
44 }
45
46 return stream;
47}
48
50 CLBCommonHeader const& header
51 , dom_map_type const& name_map
52) {
53 bool const valid = validTimeStamp(header);
54 bool const trailer = isTrailer(header);
55
56 std::string name("");
57 if (! name_map.empty()) {
58 dom_map_type::const_iterator const it
59 = name_map.find(header.domIdentifier());
60
61 if (it != name_map.end()) {
62 name = " - " + it->second;
63 } else {
64 name = " - unknown";
65 }
66 }
67
68 std::cout
69 << "DataType: " << header.dataType() << '\n'
70 << "RunNumber: " << header.runNumber() << '\n'
71 << "UDPSequenceNumber: " << header.udpSequenceNumber() << '\n'
72
73 << "Timestamp:\n"
74 << " Seconds: " << header.timeStamp().sec() << '\n'
75 << " Tics: " << header.timeStamp().tics() << '\n'
76 << " " << UTCTime_h(header.timeStamp(), valid) << '\n'
77
78 << "DOMIdentifier: " << header.domIdentifier()
79 << " (MAC: " << DOMID_h(header.domIdentifier()) << name << ')' << '\n'
80 << "DOMStatus 1: " << header.domStatus(1) << '\n'
81 << "DOMStatus 2: " << header.domStatus(2);
82
83 if (trailer && header.dataType() == ttdc) {
84 std::cout << " (trailer)\n";
85 } else {
86 std::cout << '\n';
87 }
88
89 std::cout
90 << "DOMStatus 3: " << header.domStatus(3) << '\n'
91 << "DOMStatus 4: " << header.domStatus(4) << std::endl;
92}
93
95 const char* const buffer,
96 ssize_t buffer_size,
97 int max_col
98) {
99 unsigned int const nhits =
100 (buffer_size - sizeof(CLBCommonHeader)) / sizeof(hit_t);
101
102 std::cout << "Number of hits: " << nhits << '\n';
103
104 if (nhits) {
105 const int printing = 20 > nhits ? nhits : 20;
106 const unsigned int n = max_col > 37 ? max_col / 37 : 1;
107
108 for (int i = 0; i < printing; ++i) {
109 const hit_t* const hit = static_cast<const hit_t* const>(
110 static_cast<const void* const>(buffer
111 + sizeof(CLBCommonHeader)
112 + i * sizeof(hit_t)));
113
114 std::cout
115 << "Hit"
116 << std::setfill('0') << std::setw(2)
117 << i
118 << ": "
119 << *hit << ' ';
120
121 if ((i + 1) % n == 0) {
122 std::cout << '\n';
123 } else {
124 std::cout << "| ";
125 }
126 }
127 }
128
129 std::cout << '\n';
130}
131
133 const char* const buffer
134 , ssize_t buffer_size
135 , int max_col
136) {
137 CLBCommonHeader const* const header = static_cast<CLBCommonHeader const*>(
138 static_cast<void const*>(buffer));
139
140 if (
141 ! header->udpSequenceNumber()
142 && is_infoword(buffer + sizeof(CLBCommonHeader))
143 ) {
144 std::cout << "InfoWord: yes\n"
145 << *static_cast<InfoWord const*>(static_cast<void const*>(
146 buffer + sizeof(CLBCommonHeader)
147 ))
148 << '\n';
149 } else {
150 std::cout << "InfoWord: no\n";
151 }
152}
153
155 const char* const buffer
156 , ssize_t buffer_size
157 , int max_col
158) {
159 const unsigned int n = max_col > 14 ? max_col / 14 : 1;
160
161 for (int i = 0; i < 31; ++i) {
162 uint32_t const* const field = static_cast<uint32_t const*>(
163 static_cast<void const*>(buffer + sizeof(CLBCommonHeader) + i * 4)
164 );
165
166 std::cout
167 << "CH"
168 << std::setfill('0') << std::setw(2)
169 << i << ": "
170 << std::setfill(' ') << std::setw(6)
171 << htonl(*field) << " ";
172
173 if ((i + 1) % n == 0) {
174 std::cout << '\n';
175 }
176 }
177
178 std::cout << '\n';
179
180 ssize_t const minimum_size = sizeof(CLBCommonHeader) + sizeof(int) * 31;
181
182 if (buffer_size > minimum_size) {
183 std::cout
184 << "SlowControl data:\n"
185 << *static_cast<SCData const*>(static_cast<void const*>(
186 buffer + minimum_size
187 ))
188 << '\n';
189 }
190}
bool isTrailer(CLBCommonHeader const &header)
bool validTimeStamp(CLBCommonHeader const &header)
static const size_t buffer_size
static const unsigned int ttdc
bool is_infoword(const void *const data)
Definition infoword.hh:93
void print_optical_data(const char *const buffer, ssize_t buffer_size, int max_col)
Definition print.cpp:94
void print_acoustic_data(const char *const buffer, ssize_t buffer_size, int max_col)
Definition print.cpp:132
std::ostream & operator<<(std::ostream &stream, DOMID_h const &domid)
Definition print.cpp:24
void print_monitoring_data(const char *const buffer, ssize_t buffer_size, int max_col)
Definition print.cpp:154
void print_header(CLBCommonHeader const &header, dom_map_type const &name_map)
Definition print.cpp:49
uint32_t dataType() const
uint32_t udpSequenceNumber() const
UTCTime timeStamp() const
uint32_t runNumber() const
uint32_t domIdentifier() const
uint32_t domStatus(int n=1) const
uint32_t m_val
Definition print.cpp:18
DOMID_h(uint32_t val)
Definition print.cpp:19
uint32_t sec() const
Definition utctime.hh:17
uint32_t tics() const
Definition utctime.hh:22