CbmRoot
Loading...
Searching...
No Matches
CriGet4Mess001.cxx
Go to the documentation of this file.
1/* Copyright (C) 2018-2020 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Pierre-Alain Loizeau [committer] */
4
5#include "CriGet4Mess001.h"
6
7// Specific headers
8
9// C++11 headers
10#include <cstdio>
11#include <cstring>
12
13#include <cmath>
14
15// std C++ lib headers
16#include <iomanip>
17#include <iostream>
18#include <sstream>
19
20//#include <iostream>
21#include <iomanip>
22
23//----------------------------------------------------------------------------
34namespace critof001
35{
36 std::string FormatHexPrintout(uint64_t ulVal, char cFill = 0, uint uWidth = 0, bool bUppercase = false)
37 {
38 std::stringstream ss;
39
41 ss << std::hex;
42
44 if (0 != cFill) ss << std::setfill(cFill);
45 if (0 < uWidth) ss << std::setw(uWidth);
46 if (bUppercase) ss << std::uppercase;
47
49 ss << ulVal << std::dec;
50
52 if (0 != cFill) ss << std::setfill(' ');
53
54 return ss.str();
55 }
56} // namespace critof001
57
58//----------------------------------------------------------------------------
61{
62 uint64_t uThisTs = 0;
63 uint64_t uOtherTs = 0;
64
65 uint32_t uThisType = this->getMessageType();
66 uint32_t uOtherType = other.getMessageType();
67
68 // if both GET4 hit messages, use the full timestamp info
69 if (MSG_HIT == uThisType && MSG_HIT == uOtherType) {
70 uThisTs = this->getGdpbHitFullTs();
71 uOtherTs = other.getGdpbHitFullTs();
72 return uThisTs < uOtherTs;
73 } // both GET4 hit (32b or 24b)
74
75 // First find the timestamp of the current message
76 if (MSG_HIT == uThisType) { uThisTs = (this->getGdpbHitFullTs()); } // if Hit GET4 message (24 or 32b)
77 else
78 uThisTs = 0;
79
80 // Then find the timestamp of the current message
81 if (MSG_HIT == uOtherType) { uOtherTs = (this->getGdpbHitFullTs()); } // if Hit GET4 message (24 or 32b)
82 else
83 uOtherTs = 0;
84
85 return uThisTs < uOtherTs;
86}
87//----------------------------------------------------------------------------
89bool critof001::Message::operator==(const critof001::Message& other) const { return this->data == other.data; }
90//----------------------------------------------------------------------------
92bool critof001::Message::operator!=(const critof001::Message& other) const { return this->data != other.data; }
93//----------------------------------------------------------------------------
95uint64_t critof001::Message::getMsgFullTime(uint64_t epoch) const { return std::round(getMsgFullTimeD(epoch)); }
96//----------------------------------------------------------------------------
98double critof001::Message::getMsgFullTimeD(uint64_t epoch) const
99{
100 switch (getMessageType()) {
101 case MSG_HIT: {
102 return (critof001::kdEpochInNs * static_cast<double_t>(epoch)
103 + static_cast<double_t>(getGdpbHitFullTs()) * critof001::kdClockCycleSizeNs / critof001::kdFtBinsNb);
104 } // case MSG_HIT:
105 case MSG_EPOCH: {
106 return critof001::kdEpochInNs * static_cast<double_t>(getGdpbEpEpochNb());
107 }
108 case MSG_SLOWC:
109 case MSG_SYST:
110 default: return 0.0;
111 } // switch( getMessageType() )
112
113 // If not already dealt with => unknown type
114 return 0.0;
115}
116//----------------------------------------------------------------------------
117//----------------------------------------------------------------------------
119
120uint64_t critof001::Message::CalcDistance(uint64_t start, uint64_t stop)
121{
122 if (start > stop) {
123 stop += 0x3FFFFFFFFFFFLLU;
124 if (start > stop) {
125 printf("Epochs overflow error in CalcDistance\n");
126 return 0;
127 }
128 }
129
130 return stop - start;
131}
132
133
134//----------------------------------------------------------------------------
136
137double critof001::Message::CalcDistanceD(double start, double stop)
138{
139 if (start > stop) {
140 stop += 0x3FFFFFFFFFFFLLU;
141 if (start > stop) {
142 printf("Epochs overflow error in CalcDistanceD\n");
143 return 0.;
144 }
145 }
146
147 return stop - start;
148}
149
150//----------------------------------------------------------------------------
152
158void critof001::Message::printDataCout(unsigned kind, uint32_t epoch) const { printData(msg_print_Cout, kind, epoch); }
159
160//----------------------------------------------------------------------------
162
169void critof001::Message::printDataLog(unsigned kind, uint32_t epoch) const
170{
171 printData(msg_print_FairLog, kind, epoch);
172}
173
174//----------------------------------------------------------------------------
176
200//void critof001::Message::printData(std::ostream& os, unsigned kind, uint32_t epoch) const
201void critof001::Message::printData(unsigned outType, unsigned kind, uint32_t epoch, std::ostream& os) const
202{
203 char buf[256];
204 if (kind & msg_print_Hex) {
205 const uint8_t* arr = reinterpret_cast<const uint8_t*>(&data);
206 /*
207 snprintf(buf, sizeof(buf),
208 "BE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X LE= "
209 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ",
210 arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7], arr[7], arr[6], arr[5], arr[4], arr[3],
211 arr[2], arr[1], arr[0]);
212 */
213 snprintf(buf, sizeof(buf), "LE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ", arr[7], arr[6], arr[5], arr[4], arr[3],
214 arr[2], arr[1], arr[0]);
215
216
217 if (msg_print_Cout == outType) std::cout << buf;
218 else if (msg_print_File == outType)
219 os << buf;
220
221 snprintf(buf, sizeof(buf), " ");
222 }
223
224 if (kind & msg_print_Human) {
225 double timeInSec = getMsgFullTimeD(epoch) / 1.e9;
226 // int fifoFill = 0;
227
228 switch (getMessageType()) {
229 case MSG_EPOCH:
230 snprintf(buf, sizeof(buf), "Msg:%u ", getMessageType());
231
232 if (msg_print_Cout == outType) std::cout << buf;
233 else if (msg_print_File == outType)
234 os << buf;
235
236 snprintf(buf, sizeof(buf),
237 "EPOCH @%17.11f Get4:%2d Epoche2:%10u 0x%08x Sync:%x "
238 "Dataloss:%x Epochloss:%x Epochmissmatch:%x",
239 timeInSec, getGet4Idx(), getGdpbEpEpochNb(), getGdpbEpEpochNb(), getGdpbEpSync(), getGdpbEpDataLoss(),
240 getGdpbEpEpochLoss(), getGdpbEpMissmatch());
241
242 if (msg_print_Cout == outType) std::cout << buf << std::endl;
243 else if (msg_print_File == outType)
244 os << buf << std::endl;
245 break;
246 case MSG_HIT:
247 snprintf(buf, sizeof(buf), "Msg:%u ", getMessageType());
248
249 if (msg_print_Cout == outType) std::cout << buf;
250 else if (msg_print_File == outType)
251 os << buf;
252
253 snprintf(buf, sizeof(buf), "Get4 24b @%17.11f Get4:%2d Chn:%3d Dll:%1d Ts:%7d", timeInSec, getGet4Idx(),
254 getGdpbHitChanId(), getGdpbHit32DllLck(), getGdpbHitFullTs());
255
256 if (msg_print_Cout == outType) std::cout << buf << std::endl;
257 else if (msg_print_File == outType)
258 os << buf << std::endl;
259 break;
260 default:
261 kind = kind & ~msg_print_Human;
262 if (kind == 0) kind = msg_print_Prefix | msg_print_Data;
263 }
264
265 // return, if message was correctly printed in human-readable form
266 if (kind & msg_print_Human) return;
267 }
268
269 if (kind & msg_print_Prefix) {
270 snprintf(buf, sizeof(buf), "Msg:%2u ", getMessageType());
271
272 if (msg_print_Cout == outType) std::cout << buf;
273 else if (msg_print_File == outType)
274 os << buf;
275 }
276
277 if (kind & msg_print_Data) {
278 // const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
279 switch (getMessageType()) {
280 /*
281 case MSG_HIT: {
282 snprintf(buf, sizeof(buf),
283 "Get4 32 bits, Get4:%3d Channel %1d Ts:0x%03x Ft:0x%02x "
284 "Tot:0x%02x Dll %1d",
285 getGet4Idx(), getGdpbHitChanId(), getGdpbHitCoarse(), getGdpbHitFineTs(), getGdpbHit32Tot(),
286 getGdpbHit32DllLck());
287 break;
288 } // case MSG_HIT:
289 case MSG_EPOCH: {
290 snprintf(buf, sizeof(buf),
291 "Get4:%3d Link: %1u Epoch:0x%08x Sync:%x",
292 getGet4Idx(), getGdpbEpLinkId(), getGdpbEpEpochNb(), getGdpbEpSync());
293
294 break;
295 } // case MSG_EPOCH:
296 case MSG_SLOWC: {
297 // GET4 slow control message, new "true" ROC support
298 snprintf(buf, sizeof(buf),
299 "Get4 Slow control, Get4:%3d => Chan:%01d Edge:%01d "
300 "Type:%01x Data:0x%06x",
301 getGet4Idx(), 0x0, 0x0, 0x0, getGdpbSlcData());
302 break;
303 } // case MSG_SLOWC:
304 case MSG_ERROR: {
305 // GET4 Error message, new "true" ROC support
306 break;
307 } // case MSG_SYST:
308*/
309 default:
310 snprintf(buf, sizeof(buf), "Error - unexpected MessageType: %1x, full data %08X::%08X", getMessageType(),
311 getField(32, 32), getField(0, 32));
312 }
313 }
314
315 if (msg_print_Cout == outType) std::cout << buf << std::endl;
316 else if (msg_print_File == outType)
317 os << buf << std::endl;
318}
319//----------------------------------------------------------------------------
322{
323 if (other.fulExtendedEpoch == this->fulExtendedEpoch)
324 // Same epoch => use Message (base) class ordering operator
325 return this->Message::operator<(other);
326 else
327 return this->fulExtendedEpoch < other.fulExtendedEpoch;
328}
329//----------------------------------------------------------------------------
330void critof001::FullMessage::PrintMessage(unsigned outType, unsigned kind) const
331{
332 std::cout << "Full epoch = " << std::setw(9) << fulExtendedEpoch << " ";
333 printDataCout(outType, kind);
334}
void PrintMessage(unsigned outType=msg_print_Cout, unsigned kind=msg_print_Human) const
bool operator<(const FullMessage &other) const
strict weak ordering operator, including epoch for both messages
uint32_t getGdpbHitFullTs() const
bool operator==(const critof001::Message &other) const
equality operator, assumes same epoch for both messages
bool operator!=(const critof001::Message &other) const
inequality operator, assumes same epoch for both messages
void printDataLog(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to the Fairroot logger.
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 2 bit.
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
void printData(unsigned outType=msg_print_Cout, unsigned kind=msg_print_Human, uint32_t epoch=0, std::ostream &os=std::cout) const
Print message in binary or human readable format to a stream.
bool operator<(const critof001::Message &other) const
strict weak ordering operator, assumes same epoch for both messages
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
static double CalcDistanceD(double start, double stop)
Returns the time difference between two expanded time stamps.
double getMsgFullTimeD(uint64_t epoch) const
Returns expanded and adjusted time of message in double (in ns)
const double kdFtBinsNb
const double kdEpochInNs
std::string FormatHexPrintout(uint64_t ulVal, char cFill=0, uint uWidth=0, bool bUppercase=false)
const double kdClockCycleSizeNs