CbmRoot
Loading...
Searching...
No Matches
gDpbMessv100.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 "gDpbMessv100.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 gdpbv100
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 gdpbv100
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 gdpbv100::Message::operator==(const gdpbv100::Message& other) const { return this->data == other.data; }
90//----------------------------------------------------------------------------
92bool gdpbv100::Message::operator!=(const gdpbv100::Message& other) const { return this->data != other.data; }
93//----------------------------------------------------------------------------
95uint64_t gdpbv100::Message::getMsgFullTime(uint64_t epoch) const { return std::round(getMsgFullTimeD(epoch)); }
96//----------------------------------------------------------------------------
98double gdpbv100::Message::getMsgFullTimeD(uint64_t epoch) const
99{
100 switch (getMessageType()) {
101 case MSG_HIT: {
102 if (getGdpbHitIs24b())
103 return (static_cast<double_t>(FullTimeStamp(epoch, (getGdpbHitCoarse() << 7)))
104 + (static_cast<double_t>(getGdpbHitFineTs() - 8.) * gdpbv100::kdFtSize / gdpbv100::kdFtBinsNb))
106 else
107 return (gdpbv100::kdEpochInNs * static_cast<double_t>(epoch)
108 + static_cast<double_t>(getGdpbHitFullTs()) * gdpbv100::kdClockCycleSizeNs / gdpbv100::kdFtBinsNb);
109 } // case MSG_HIT:
110 case MSG_EPOCH: return gdpbv100::kdEpochInNs * static_cast<double_t>(getGdpbEpEpochNb());
111 case MSG_SLOWC:
112 case MSG_SYST:
113 case MSG_STAR_TRI_A:
114 case MSG_STAR_TRI_B:
115 case MSG_STAR_TRI_C:
116 case MSG_STAR_TRI_D: return gdpbv100::kdEpochInNs * static_cast<double_t>(epoch);
117 default: return 0.0;
118 } // switch( getMessageType() )
119
120 // If not already dealt with => unknown type
121 return 0.0;
122}
123//----------------------------------------------------------------------------
124//----------------------------------------------------------------------------
126
127uint64_t gdpbv100::Message::CalcDistance(uint64_t start, uint64_t stop)
128{
129 if (start > stop) {
130 stop += 0x3FFFFFFFFFFFLLU;
131 if (start > stop) {
132 printf("Epochs overflow error in CalcDistance\n");
133 return 0;
134 }
135 }
136
137 return stop - start;
138}
139
140
141//----------------------------------------------------------------------------
143
144double gdpbv100::Message::CalcDistanceD(double start, double stop)
145{
146 if (start > stop) {
147 stop += 0x3FFFFFFFFFFFLLU;
148 if (start > stop) {
149 printf("Epochs overflow error in CalcDistanceD\n");
150 return 0.;
151 }
152 }
153
154 return stop - start;
155}
156
157//----------------------------------------------------------------------------
159
165void gdpbv100::Message::printDataCout(unsigned kind, uint32_t epoch) const { printData(msg_print_Cout, kind, epoch); }
166
167//----------------------------------------------------------------------------
169
176void gdpbv100::Message::printDataLog(unsigned kind, uint32_t epoch) const { printData(msg_print_FairLog, kind, epoch); }
177
178//----------------------------------------------------------------------------
180
204//void gdpbv100::Message::printData(std::ostream& os, unsigned kind, uint32_t epoch) const
205void gdpbv100::Message::printData(unsigned outType, unsigned kind, uint32_t epoch, std::ostream& os) const
206{
207 char buf[256];
208 if (kind & msg_print_Hex) {
209 const uint8_t* arr = reinterpret_cast<const uint8_t*>(&data);
210 snprintf(buf, sizeof(buf),
211 "BE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X LE= "
212 "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ",
213 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],
214 arr[2], arr[1], arr[0]);
215
216 if (msg_print_Cout == outType) std::cout << buf;
217 else if (msg_print_File == outType)
218 os << buf;
219
220 snprintf(buf, sizeof(buf), " ");
221 }
222
223 if (kind & msg_print_Human) {
224 double timeInSec = getMsgFullTimeD(epoch) / 1.e9;
225 // int fifoFill = 0;
226
227 switch (getMessageType()) {
228 case MSG_EPOCH:
229 snprintf(buf, sizeof(buf), "Msg:%u ", getMessageType());
230
231 if (msg_print_Cout == outType) std::cout << buf;
232 else if (msg_print_File == outType)
233 os << buf;
234
235 snprintf(buf, sizeof(buf),
236 "EPOCH @%17.11f Get4:%2d Epoche2:%10u 0x%08x Sync:%x "
237 "Dataloss:%x Epochloss:%x Epochmissmatch:%x",
238 timeInSec, getGdpbGenChipId(), getGdpbEpEpochNb(), getGdpbEpEpochNb(), getGdpbEpSync(),
239 getGdpbEpDataLoss(), getGdpbEpEpochLoss(), getGdpbEpMissmatch());
240
241 if (msg_print_Cout == outType) std::cout << buf << std::endl;
242 else if (msg_print_File == outType)
243 os << buf << std::endl;
244 break;
245 case MSG_HIT:
246 snprintf(buf, sizeof(buf), "Msg:%u ", getMessageType());
247
248 if (msg_print_Cout == outType) std::cout << buf;
249 else if (msg_print_File == outType)
250 os << buf;
251
252 if (getGdpbHitIs24b()) {
253 snprintf(buf, sizeof(buf), "Get4 24b @%17.11f Get4:%2d Chn:%3d Edge:%1d Ts:%7d", timeInSec,
254 getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHit24Edge(), getGdpbHitFullTs());
255 } // if( getGdpbHitIs24b() )
256 else {
257 snprintf(buf, sizeof(buf), "Get4 24b @%17.11f Get4:%2d Chn:%3d Dll:%1d Ts:%7d", timeInSec, getGdpbGenChipId(),
258 getGdpbHitChanId(), getGdpbHit32DllLck(), getGdpbHitFullTs());
259 } // else of if( getGdpbHitIs24b() )
260
261 if (msg_print_Cout == outType) std::cout << buf << std::endl;
262 else if (msg_print_File == outType)
263 os << buf << std::endl;
264 break;
265 default:
266 kind = kind & ~msg_print_Human;
267 if (kind == 0) kind = msg_print_Prefix | msg_print_Data;
268 }
269
270 // return, if message was correctly printed in human-readable form
271 if (kind & msg_print_Human) return;
272 }
273
274 if (kind & msg_print_Prefix) {
275 snprintf(buf, sizeof(buf), "Msg:%2u ", getMessageType());
276
277 if (msg_print_Cout == outType) std::cout << buf;
278 else if (msg_print_File == outType)
279 os << buf;
280 }
281
282 if (kind & msg_print_Data) {
283 // const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
284 switch (getMessageType()) {
285 case MSG_HIT: {
286 if (getGdpbHitIs24b()) {
287 snprintf(buf, sizeof(buf), "Get4 24 bits, Get4:0x%04x Chn:%1x Edge:%1x Ts:0x%03x", getGdpbGenChipId(),
288 getGdpbHitChanId(), getGdpbHit24Edge(), getGdpbHitFullTs());
289 } // if( getGdpbHitIs24b() )
290 else {
291 snprintf(buf, sizeof(buf),
292 "Get4 32 bits, Get4:0x%04x Channel %1d Ts:0x%03x Ft:0x%02x "
293 "Tot:0x%02x Dll %1d",
294 getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHitCoarse(), getGdpbHitFineTs(), getGdpbHit32Tot(),
295 getGdpbHit32DllLck());
296 } // else of if( getGdpbHitIs24b() )
297 break;
298 } // case MSG_HIT:
299 case MSG_EPOCH: {
300 snprintf(buf, sizeof(buf),
301 "Get4:0x%04x Link: %1u Epoch:0x%08x Sync:%x Dataloss:%x "
302 "Epochloss:%x Epochmissmatch:%x",
303 getGdpbGenChipId(), getGdpbEpLinkId(), getGdpbEpEpochNb(), getGdpbEpSync(), getGdpbEpDataLoss(),
304 getGdpbEpEpochLoss(), getGdpbEpMissmatch());
305 break;
306 } // case MSG_EPOCH:
307 case MSG_SLOWC: {
308 // GET4 slow control message, new "true" ROC support
309 snprintf(buf, sizeof(buf),
310 "Get4 Slow control, Get4:0x%04x => Chan:%01d Edge:%01d "
311 "Type:%01x Data:0x%06x",
312 getGdpbGenChipId(), 0x0, 0x0, 0x0, getGdpbSlcData());
313 break;
314 } // case MSG_SLOWC:
315 case MSG_SYST: {
316 // GET4 system message, new "true" ROC support
317 char sysbuf[256];
318
319 switch (getGdpbSysSubType()) {
320 case SYS_GET4_ERROR: {
321 snprintf(sysbuf, sizeof(sysbuf),
322 "Get4:0x%04x Ch:0x%01x Edge:%01x Unused:%06x "
323 "ErrCode:0x%02x - GET4 V1 Error Event",
324 getGdpbGenChipId(), getGdpbSysErrChanId(), getGdpbSysErrEdge(), getGdpbSysErrUnused(),
325 getGdpbSysErrData());
326 break;
327 } //
328 case SYS_GDPB_UNKWN:
329 snprintf(sysbuf, sizeof(sysbuf), "Unknown GET4 message, data: 0x%08x", getGdpbSysUnkwData());
330 break;
332 if (getGdpbSysFwErrResync())
333 snprintf(sysbuf, sizeof(sysbuf), "GET4 Resynchronization: Get4:0x%04x", getGdpbGenChipId());
334 else
335 snprintf(sysbuf, sizeof(sysbuf), "GET4 SYNC synchronization error");
336 break;
337 case SYS_PATTERN:
338 snprintf(sysbuf, sizeof(sysbuf), "Pattern message => Type %d, Index %2d, Pattern 0x%08X",
339 getGdpbSysPattType(), getGdpbSysPattIndex(), getGdpbSysPattPattern());
340 break;
341 default: snprintf(sysbuf, sizeof(sysbuf), "unknown system message type %u", getGdpbSysSubType());
342 } // switch( getGdpbSysSubType() )
343 snprintf(buf, sizeof(buf), "%s", sysbuf);
344
345 break;
346 } // case MSG_SYST:
347 case MSG_STAR_TRI_A:
348 case MSG_STAR_TRI_B:
349 case MSG_STAR_TRI_C:
350 case MSG_STAR_TRI_D: {
351 // STAR trigger token, spread over 4 messages
352 switch (getStarTrigMsgIndex()) {
353 case 0: {
354 snprintf(buf, sizeof(buf),
355 // "STAR token A, gDPB TS MSB bits: 0x%010llx000000",
356 // getGdpbTsMsbStarA() );
357 "STAR token A, gDPB TS MSB bits: 0x%s000000",
358 FormatHexPrintout(getGdpbTsMsbStarA(), 10, '0').c_str());
359 break;
360 } // case 1st message:
361 case 1: {
362 snprintf(
363 buf, sizeof(buf),
364 // "STAR token B, gDPB TS LSB bits: 0x0000000000%06llx, STAR TS MSB bits: 0x%04llx000000000000",
365 // getGdpbTsLsbStarB(), getStarTsMsbStarB() );
366 "STAR token B, gDPB TS LSB bits: 0x0000000000%s, STAR TS MSB "
367 "bits: 0x%s000000000000",
368 FormatHexPrintout(getGdpbTsLsbStarB(), 6, '0').c_str(),
369 FormatHexPrintout(getStarTsMsbStarB(), 4, '0').c_str());
370 break;
371 } // case 2nd message:
372 case 2: {
373 snprintf(
374 buf, sizeof(buf),
375 // "STAR token C, , STAR TS Mid bits: 0x0000%010llx00",
376 // getStarTsMidStarC() );
377 "STAR token C, , STAR TS Mid "
378 "bits: 0x0000%s00",
379 FormatHexPrintout(getStarTsMidStarC(), 10, '0').c_str());
380 break;
381 } // case 3rd message:
382 case 3: {
383 snprintf(
384 buf, sizeof(buf),
385 // "STAR token D, , STAR TS LSB bits: 0x00000000000000%02llx"
386 "STAR token D, , STAR TS LSB "
387 "bits: 0x00000000000000%s"
388 ", Token: %03x, DAQ: %1x; TRG:%1x",
389 // getStarTsLsbStarD(),
390 FormatHexPrintout(getStarTsLsbStarD(), 2, '0').c_str(), getStarTokenStarD(), getStarDaqCmdStarD(),
391 getStarTrigCmdStarD());
392 break;
393 } // case 4th message:
394 } // switch( getStarTrigMsgIndex() )
395
396 break;
397 } // case MSG_STAR_TRI_A || MSG_STAR_TRI_B || MSG_STAR_TRI_C || MSG_STAR_TRI_D:
398 default:
399 snprintf(buf, sizeof(buf), "Error - unexpected MessageType: %1x, full data %08X::%08X", getMessageType(),
400 getField(32, 32), getField(0, 32));
401 }
402 }
403
404 if (msg_print_Cout == outType) std::cout << buf << std::endl;
405 else if (msg_print_File == outType)
406 os << buf << std::endl;
407}
408//----------------------------------------------------------------------------
411{
412 if (other.fulExtendedEpoch == this->fulExtendedEpoch)
413 // Same epoch => use Message (base) class ordering operator
414 return this->Message::operator<(other);
415 else
416 return this->fulExtendedEpoch < other.fulExtendedEpoch;
417}
418//----------------------------------------------------------------------------
419void gdpbv100::FullMessage::PrintMessage(unsigned outType, unsigned kind) const
420{
421 std::cout << "Full epoch = " << std::setw(9) << fulExtendedEpoch << " ";
422 printDataCout(outType, kind);
423}
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
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
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.
double getMsgFullTimeD(uint64_t epoch) const
Returns expanded and adjusted time of message in double (in ns)
uint32_t getGdpbHitFullTs() const
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
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 gdpbv100::Message &other) const
strict weak ordering operator, assumes same epoch for both messages
bool operator!=(const gdpbv100::Message &other) const
inequality operator, assumes same epoch for both messages
bool operator==(const gdpbv100::Message &other) const
equality operator, assumes same epoch for both messages
static double CalcDistanceD(double start, double stop)
Returns the time difference between two expanded time stamps.
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
const double kdClockCycleSizeNs
const double kdFtBinsNb
const double kdFtSize
const double kdEpochInNs
@ msg_print_Prefix
@ msg_print_Human
@ msg_print_FairLog
std::string FormatHexPrintout(uint64_t ulVal, char cFill=0, uint uWidth=0, bool bUppercase=false)
@ SYS_GET4_SYNC_MISS