CbmRoot
gDpbMessv100.cxx
Go to the documentation of this file.
1 #include "gDpbMessv100.h"
2 
3 // Specific headers
4 
5 // C++11 headers
6 #include <cmath>
7 
8 // std C++ lib headers
9 #include <iomanip>
10 #include <iostream>
11 #include <sstream>
12 #include <stdio.h>
13 #include <string.h>
14 
15 //#include <iostream>
16 #include <iomanip>
17 
18 //----------------------------------------------------------------------------
29 namespace gdpbv100 {
30  std::string FormatHexPrintout(uint64_t ulVal,
31  char cFill = 0,
32  uint uWidth = 0,
33  bool bUppercase = false) {
34  std::stringstream ss;
35 
37  ss << std::hex;
38 
40  if (0 != cFill) ss << std::setfill(cFill);
41  if (0 < uWidth) ss << std::setw(uWidth);
42  if (bUppercase) ss << std::uppercase;
43 
45  ss << ulVal << std::dec;
46 
48  if (0 != cFill) ss << std::setfill(' ');
49 
50  return ss.str();
51  }
52 } // namespace gdpbv100
53 
54 //----------------------------------------------------------------------------
57  uint64_t uThisTs = 0;
58  uint64_t uOtherTs = 0;
59 
60  uint32_t uThisType = this->getMessageType();
61  uint32_t uOtherType = other.getMessageType();
62 
63  // if both GET4 hit messages, use the full timestamp info
64  if (MSG_HIT == uThisType && MSG_HIT == uOtherType) {
65  uThisTs = this->getGdpbHitFullTs();
66  uOtherTs = other.getGdpbHitFullTs();
67  return uThisTs < uOtherTs;
68  } // both GET4 hit (32b or 24b)
69 
70  // First find the timestamp of the current message
71  if (MSG_HIT == uThisType) {
72  uThisTs = (this->getGdpbHitFullTs());
73  } // if Hit GET4 message (24 or 32b)
74  else
75  uThisTs = 0;
76 
77  // Then find the timestamp of the current message
78  if (MSG_HIT == uOtherType) {
79  uOtherTs = (this->getGdpbHitFullTs());
80  } // if Hit GET4 message (24 or 32b)
81  else
82  uOtherTs = 0;
83 
84  return uThisTs < uOtherTs;
85 }
86 //----------------------------------------------------------------------------
89  return this->data == other.data;
90 }
91 //----------------------------------------------------------------------------
94  return this->data != other.data;
95 }
96 //----------------------------------------------------------------------------
98 uint64_t gdpbv100::Message::getMsgFullTime(uint64_t epoch) const {
99  return std::round(getMsgFullTimeD(epoch));
100 }
101 //----------------------------------------------------------------------------
103 double gdpbv100::Message::getMsgFullTimeD(uint64_t epoch) const {
104  switch (getMessageType()) {
105  case MSG_HIT: {
106  if (getGdpbHitIs24b())
107  return (static_cast<double_t>(
108  FullTimeStamp(epoch, (getGdpbHitCoarse() << 7)))
109  + (static_cast<double_t>(getGdpbHitFineTs() - 8.)
112  else
113  return (gdpbv100::kdEpochInNs * static_cast<double_t>(epoch)
114  + static_cast<double_t>(getGdpbHitFullTs())
116  } // case MSG_HIT:
117  case MSG_EPOCH:
118  return gdpbv100::kdEpochInNs * static_cast<double_t>(getGdpbEpEpochNb());
119  case MSG_SLOWC:
120  case MSG_SYST:
121  case MSG_STAR_TRI_A:
122  case MSG_STAR_TRI_B:
123  case MSG_STAR_TRI_C:
124  case MSG_STAR_TRI_D:
125  return gdpbv100::kdEpochInNs * static_cast<double_t>(epoch);
126  default: return 0.0;
127  } // switch( getMessageType() )
128 
129  // If not already dealt with => unknown type
130  return 0.0;
131 }
132 //----------------------------------------------------------------------------
133 //----------------------------------------------------------------------------
135 
136 uint64_t gdpbv100::Message::CalcDistance(uint64_t start, uint64_t stop) {
137  if (start > stop) {
138  stop += 0x3FFFFFFFFFFFLLU;
139  if (start > stop) {
140  printf("Epochs overflow error in CalcDistance\n");
141  return 0;
142  }
143  }
144 
145  return stop - start;
146 }
147 
148 
149 //----------------------------------------------------------------------------
151 
152 double gdpbv100::Message::CalcDistanceD(double start, double stop) {
153  if (start > stop) {
154  stop += 0x3FFFFFFFFFFFLLU;
155  if (start > stop) {
156  printf("Epochs overflow error in CalcDistanceD\n");
157  return 0.;
158  }
159  }
160 
161  return stop - start;
162 }
163 
164 //----------------------------------------------------------------------------
166 
172 void gdpbv100::Message::printDataCout(unsigned kind, uint32_t epoch) const {
173  printData(msg_print_Cout, kind, epoch);
174 }
175 
176 //----------------------------------------------------------------------------
178 
185 void gdpbv100::Message::printDataLog(unsigned kind, uint32_t epoch) const {
186  printData(msg_print_FairLog, kind, epoch);
187 }
188 
189 //----------------------------------------------------------------------------
191 
215 //void gdpbv100::Message::printData(std::ostream& os, unsigned kind, uint32_t epoch) const
216 void gdpbv100::Message::printData(unsigned outType,
217  unsigned kind,
218  uint32_t epoch,
219  std::ostream& os) const {
220  char buf[256];
221  if (kind & msg_print_Hex) {
222  const uint8_t* arr = reinterpret_cast<const uint8_t*>(&data);
223  snprintf(buf,
224  sizeof(buf),
225  "BE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X LE= "
226  "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ",
227  arr[0],
228  arr[1],
229  arr[2],
230  arr[3],
231  arr[4],
232  arr[5],
233  arr[6],
234  arr[7],
235  arr[7],
236  arr[6],
237  arr[5],
238  arr[4],
239  arr[3],
240  arr[2],
241  arr[1],
242  arr[0]);
243 
244  if (msg_print_Cout == outType)
245  std::cout << buf;
246  else if (msg_print_File == outType)
247  os << buf;
248 
249  snprintf(buf, sizeof(buf), " ");
250  }
251 
252  if (kind & msg_print_Human) {
253  double timeInSec = getMsgFullTimeD(epoch) / 1.e9;
254  // int fifoFill = 0;
255 
256  switch (getMessageType()) {
257  case MSG_EPOCH:
258  snprintf(buf, sizeof(buf), "Msg:%u ", getMessageType());
259 
260  if (msg_print_Cout == outType)
261  std::cout << buf;
262  else if (msg_print_File == outType)
263  os << buf;
264 
265  snprintf(buf,
266  sizeof(buf),
267  "EPOCH @%17.11f Get4:%2d Epoche2:%10u 0x%08x Sync:%x "
268  "Dataloss:%x Epochloss:%x Epochmissmatch:%x",
269  timeInSec,
270  getGdpbGenChipId(),
271  getGdpbEpEpochNb(),
272  getGdpbEpEpochNb(),
273  getGdpbEpSync(),
274  getGdpbEpDataLoss(),
275  getGdpbEpEpochLoss(),
276  getGdpbEpMissmatch());
277 
278  if (msg_print_Cout == outType)
279  std::cout << buf << std::endl;
280  else if (msg_print_File == outType)
281  os << buf << std::endl;
282  break;
283  case MSG_HIT:
284  snprintf(buf, sizeof(buf), "Msg:%u ", getMessageType());
285 
286  if (msg_print_Cout == outType)
287  std::cout << buf;
288  else if (msg_print_File == outType)
289  os << buf;
290 
291  if (getGdpbHitIs24b()) {
292  snprintf(buf,
293  sizeof(buf),
294  "Get4 24b @%17.11f Get4:%2d Chn:%3d Edge:%1d Ts:%7d",
295  timeInSec,
296  getGdpbGenChipId(),
297  getGdpbHitChanId(),
298  getGdpbHit24Edge(),
299  getGdpbHitFullTs());
300  } // if( getGdpbHitIs24b() )
301  else {
302  snprintf(buf,
303  sizeof(buf),
304  "Get4 24b @%17.11f Get4:%2d Chn:%3d Dll:%1d Ts:%7d",
305  timeInSec,
306  getGdpbGenChipId(),
307  getGdpbHitChanId(),
308  getGdpbHit32DllLck(),
309  getGdpbHitFullTs());
310  } // else of if( getGdpbHitIs24b() )
311 
312  if (msg_print_Cout == outType)
313  std::cout << buf << std::endl;
314  else if (msg_print_File == outType)
315  os << buf << std::endl;
316  break;
317  default:
318  kind = kind & ~msg_print_Human;
319  if (kind == 0) kind = msg_print_Prefix | msg_print_Data;
320  }
321 
322  // return, if message was correctly printed in human-readable form
323  if (kind & msg_print_Human) return;
324  }
325 
326  if (kind & msg_print_Prefix) {
327  snprintf(buf, sizeof(buf), "Msg:%2u ", getMessageType());
328 
329  if (msg_print_Cout == outType)
330  std::cout << buf;
331  else if (msg_print_File == outType)
332  os << buf;
333  }
334 
335  if (kind & msg_print_Data) {
336  // const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
337  switch (getMessageType()) {
338  case MSG_HIT: {
339  if (getGdpbHitIs24b()) {
340  snprintf(buf,
341  sizeof(buf),
342  "Get4 24 bits, Get4:0x%04x Chn:%1x Edge:%1x Ts:0x%03x",
343  getGdpbGenChipId(),
344  getGdpbHitChanId(),
345  getGdpbHit24Edge(),
346  getGdpbHitFullTs());
347  } // if( getGdpbHitIs24b() )
348  else {
349  snprintf(buf,
350  sizeof(buf),
351  "Get4 32 bits, Get4:0x%04x Channel %1d Ts:0x%03x Ft:0x%02x "
352  "Tot:0x%02x Dll %1d",
353  getGdpbGenChipId(),
354  getGdpbHitChanId(),
355  getGdpbHitCoarse(),
356  getGdpbHitFineTs(),
357  getGdpbHit32Tot(),
358  getGdpbHit32DllLck());
359  } // else of if( getGdpbHitIs24b() )
360  break;
361  } // case MSG_HIT:
362  case MSG_EPOCH: {
363  snprintf(buf,
364  sizeof(buf),
365  "Get4:0x%04x Link: %1u Epoch:0x%08x Sync:%x Dataloss:%x "
366  "Epochloss:%x Epochmissmatch:%x",
367  getGdpbGenChipId(),
368  getGdpbEpLinkId(),
369  getGdpbEpEpochNb(),
370  getGdpbEpSync(),
371  getGdpbEpDataLoss(),
372  getGdpbEpEpochLoss(),
373  getGdpbEpMissmatch());
374  break;
375  } // case MSG_EPOCH:
376  case MSG_SLOWC: {
377  // GET4 slow control message, new "true" ROC support
378  snprintf(buf,
379  sizeof(buf),
380  "Get4 Slow control, Get4:0x%04x => Chan:%01d Edge:%01d "
381  "Type:%01x Data:0x%06x",
382  getGdpbGenChipId(),
383  0x0,
384  0x0,
385  0x0,
386  getGdpbSlcData());
387  break;
388  } // case MSG_SLOWC:
389  case MSG_SYST: {
390  // GET4 system message, new "true" ROC support
391  char sysbuf[256];
392 
393  switch (getGdpbSysSubType()) {
394  case SYS_GET4_ERROR: {
395  snprintf(sysbuf,
396  sizeof(sysbuf),
397  "Get4:0x%04x Ch:0x%01x Edge:%01x Unused:%06x "
398  "ErrCode:0x%02x - GET4 V1 Error Event",
399  getGdpbGenChipId(),
400  getGdpbSysErrChanId(),
401  getGdpbSysErrEdge(),
402  getGdpbSysErrUnused(),
403  getGdpbSysErrData());
404  break;
405  } //
406  case SYS_GDPB_UNKWN:
407  snprintf(sysbuf,
408  sizeof(sysbuf),
409  "Unknown GET4 message, data: 0x%08x",
410  getGdpbSysUnkwData());
411  break;
412  case SYS_GET4_SYNC_MISS:
413  if (getGdpbSysFwErrResync())
414  snprintf(sysbuf,
415  sizeof(sysbuf),
416  "GET4 Resynchronization: Get4:0x%04x",
417  getGdpbGenChipId());
418  else
419  snprintf(
420  sysbuf, sizeof(sysbuf), "GET4 SYNC synchronization error");
421  break;
422  case SYS_PATTERN:
423  snprintf(sysbuf,
424  sizeof(sysbuf),
425  "Pattern message => Type %d, Index %2d, Pattern 0x%08X",
426  getGdpbSysPattType(),
427  getGdpbSysPattIndex(),
428  getGdpbSysPattPattern());
429  break;
430  default:
431  snprintf(sysbuf,
432  sizeof(sysbuf),
433  "unknown system message type %u",
434  getGdpbSysSubType());
435  } // switch( getGdpbSysSubType() )
436  snprintf(buf, sizeof(buf), "%s", sysbuf);
437 
438  break;
439  } // case MSG_SYST:
440  case MSG_STAR_TRI_A:
441  case MSG_STAR_TRI_B:
442  case MSG_STAR_TRI_C:
443  case MSG_STAR_TRI_D: {
444  // STAR trigger token, spread over 4 messages
445  switch (getStarTrigMsgIndex()) {
446  case 0: {
447  snprintf(
448  buf,
449  sizeof(buf),
450  // "STAR token A, gDPB TS MSB bits: 0x%010llx000000",
451  // getGdpbTsMsbStarA() );
452  "STAR token A, gDPB TS MSB bits: 0x%s000000",
453  FormatHexPrintout(getGdpbTsMsbStarA(), 10, '0').c_str());
454  break;
455  } // case 1st message:
456  case 1: {
457  snprintf(
458  buf,
459  sizeof(buf),
460  // "STAR token B, gDPB TS LSB bits: 0x0000000000%06llx, STAR TS MSB bits: 0x%04llx000000000000",
461  // getGdpbTsLsbStarB(), getStarTsMsbStarB() );
462  "STAR token B, gDPB TS LSB bits: 0x0000000000%s, STAR TS MSB "
463  "bits: 0x%s000000000000",
464  FormatHexPrintout(getGdpbTsLsbStarB(), 6, '0').c_str(),
465  FormatHexPrintout(getStarTsMsbStarB(), 4, '0').c_str());
466  break;
467  } // case 2nd message:
468  case 2: {
469  snprintf(
470  buf,
471  sizeof(buf),
472  // "STAR token C, , STAR TS Mid bits: 0x0000%010llx00",
473  // getStarTsMidStarC() );
474  "STAR token C, , STAR TS Mid "
475  "bits: 0x0000%s00",
476  FormatHexPrintout(getStarTsMidStarC(), 10, '0').c_str());
477  break;
478  } // case 3rd message:
479  case 3: {
480  snprintf(
481  buf,
482  sizeof(buf),
483  // "STAR token D, , STAR TS LSB bits: 0x00000000000000%02llx"
484  "STAR token D, , STAR TS LSB "
485  "bits: 0x00000000000000%s"
486  ", Token: %03x, DAQ: %1x; TRG:%1x",
487  // getStarTsLsbStarD(),
488  FormatHexPrintout(getStarTsLsbStarD(), 2, '0').c_str(),
489  getStarTokenStarD(),
490  getStarDaqCmdStarD(),
491  getStarTrigCmdStarD());
492  break;
493  } // case 4th message:
494  } // switch( getStarTrigMsgIndex() )
495 
496  break;
497  } // case MSG_STAR_TRI_A || MSG_STAR_TRI_B || MSG_STAR_TRI_C || MSG_STAR_TRI_D:
498  default:
499  snprintf(buf,
500  sizeof(buf),
501  "Error - unexpected MessageType: %1x, full data %08X::%08X",
502  getMessageType(),
503  getField(32, 32),
504  getField(0, 32));
505  }
506  }
507 
508  if (msg_print_Cout == outType)
509  std::cout << buf << std::endl;
510  else if (msg_print_File == outType)
511  os << buf << std::endl;
512 }
513 //----------------------------------------------------------------------------
516  if (other.fulExtendedEpoch == this->fulExtendedEpoch)
517  // Same epoch => use Message (base) class ordering operator
518  return this->Message::operator<(other);
519  else
520  return this->fulExtendedEpoch < other.fulExtendedEpoch;
521 }
522 //----------------------------------------------------------------------------
524  unsigned kind) const {
525  std::cout << "Full epoch = " << std::setw(9) << fulExtendedEpoch << " ";
526  printDataCout(outType, kind);
527 }
gdpbv100::MSG_STAR_TRI_A
@ MSG_STAR_TRI_A
Definition: gDpbMessv100.h:63
gdpbv100::Message
Definition: gDpbMessv100.h:133
gdpbv100::Message::CalcDistance
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
Definition: gDpbMessv100.cxx:136
gdpbv100::Message::getMsgFullTimeD
double getMsgFullTimeD(uint64_t epoch) const
Returns expanded and adjusted time of message in double (in ns)
Definition: gDpbMessv100.cxx:103
gdpbv100::FormatHexPrintout
std::string FormatHexPrintout(uint64_t ulVal, char cFill=0, uint uWidth=0, bool bUppercase=false)
Definition: gDpbMessv100.cxx:30
gdpbv100::kdClockCycleSizeNs
const double kdClockCycleSizeNs
Definition: gDpbMessv100.h:10
gdpbv100::msg_print_Hex
@ msg_print_Hex
Definition: gDpbMessv100.h:90
gdpbv100::Message::operator!=
bool operator!=(const gdpbv100::Message &other) const
inequality operator, assumes same epoch for both messages
Definition: gDpbMessv100.cxx:93
gdpbv100::kdFtSize
const double kdFtSize
Definition: gDpbMessv100.h:26
gdpbv100::msg_print_Cout
@ msg_print_Cout
Definition: gDpbMessv100.h:95
gdpbv100::SYS_GET4_ERROR
@ SYS_GET4_ERROR
Definition: gDpbMessv100.h:70
gdpbv100::msg_print_Human
@ msg_print_Human
Definition: gDpbMessv100.h:91
gdpbv100::Message::printDataLog
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.
Definition: gDpbMessv100.cxx:185
gdpbv100::MSG_HIT
@ MSG_HIT
Definition: gDpbMessv100.h:59
gdpbv100::MSG_SLOWC
@ MSG_SLOWC
Definition: gDpbMessv100.h:61
gdpbv100::msg_print_FairLog
@ msg_print_FairLog
Definition: gDpbMessv100.h:96
gdpbv100::Message::printDataCout
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
Definition: gDpbMessv100.cxx:172
gdpbv100::MSG_STAR_TRI_D
@ MSG_STAR_TRI_D
Definition: gDpbMessv100.h:66
gdpbv100::Message::getMessageType
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
Definition: gDpbMessv100.h:206
gdpbv100::kdEpochInNs
const double kdEpochInNs
Definition: gDpbMessv100.h:37
gdpbv100::Message::operator<
bool operator<(const gdpbv100::Message &other) const
strict weak ordering operator, assumes same epoch for both messages
Definition: gDpbMessv100.cxx:56
gdpbv100::msg_print_Data
@ msg_print_Data
Definition: gDpbMessv100.h:89
gdpbv100::Message::data
uint64_t data
Definition: gDpbMessv100.h:136
gdpbv100::kdFtBinsNb
const double kdFtBinsNb
Definition: gDpbMessv100.h:27
gdpbv100::MSG_STAR_TRI_C
@ MSG_STAR_TRI_C
Definition: gDpbMessv100.h:65
gdpbv100::FullMessage::PrintMessage
void PrintMessage(unsigned outType=msg_print_Cout, unsigned kind=msg_print_Human) const
Definition: gDpbMessv100.cxx:523
gdpbv100::msg_print_Prefix
@ msg_print_Prefix
Definition: gDpbMessv100.h:88
gdpbv100::MSG_SYST
@ MSG_SYST
Definition: gDpbMessv100.h:62
gdpbv100::Message::CalcDistanceD
static double CalcDistanceD(double start, double stop)
Returns the time difference between two expanded time stamps.
Definition: gDpbMessv100.cxx:152
gDpbMessv100.h
gdpbv100::MSG_EPOCH
@ MSG_EPOCH
Definition: gDpbMessv100.h:60
gdpbv100
Definition: gDpbMessv100.cxx:29
gdpbv100::Message::printData
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.
Definition: gDpbMessv100.cxx:216
gdpbv100::Message::operator==
bool operator==(const gdpbv100::Message &other) const
equality operator, assumes same epoch for both messages
Definition: gDpbMessv100.cxx:88
gdpbv100::MSG_STAR_TRI_B
@ MSG_STAR_TRI_B
Definition: gDpbMessv100.h:64
gdpbv100::SYS_PATTERN
@ SYS_PATTERN
Definition: gDpbMessv100.h:76
gdpbv100::Message::getGdpbHitFullTs
uint32_t getGdpbHitFullTs() const
Definition: gDpbMessv100.h:220
gdpbv100::FullMessage
Definition: gDpbMessv100.h:362
gdpbv100::Message::getMsgFullTime
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
Definition: gDpbMessv100.cxx:98
gdpbv100::SYS_GET4_SYNC_MISS
@ SYS_GET4_SYNC_MISS
Definition: gDpbMessv100.h:73
gdpbv100::FullMessage::fulExtendedEpoch
uint64_t fulExtendedEpoch
Definition: gDpbMessv100.h:365
gdpbv100::FullMessage::operator<
bool operator<(const FullMessage &other) const
strict weak ordering operator, including epoch for both messages
Definition: gDpbMessv100.cxx:515
gdpbv100::SYS_GDPB_UNKWN
@ SYS_GDPB_UNKWN
Definition: gDpbMessv100.h:71
gdpbv100::msg_print_File
@ msg_print_File
Definition: gDpbMessv100.h:97