StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StETofMessageFormat.cxx
1 /***************************************************************************
2  *
3  * $Id: StETofMessageFormat.cxx,v 1.2 2019/02/19 20:18:27 fseck Exp $
4  *
5  * Author: Pierre-Alain Loizeau, January 2018
6  ***************************************************************************
7  *
8  * Description: DAQ stream eTOF message format
9  * for 2018 taken from
10  * https://lxcbmredmine01.gsi.de/projects/cbmroot/repository/entry/trunk/fles/star2018/unpacker/rocMess_wGet4v2.cxx
11  * message format is contained in the namespaces gdbp and get4v2x
12  *
13  * for 2019 (and later) taken from
14  * https://lxcbmredmine01.gsi.de/projects/cbmroot/repository/entry/trunk/fles/mcbm2018/dataformat/gDpbMessv100.cxx
15  * message format is contained in the namespace gdbpv100
16  *
17  ***************************************************************************
18  *
19  * $Log: StETofMessageFormat.cxx,v $
20  * Revision 1.2 2019/02/19 20:18:27 fseck
21  * update to include new message format for 2019+
22  *
23  * Revision 1.1 2018/07/25 14:34:40 jeromel
24  * First version, reviewed Raghav+Jerome
25  *
26  *
27  ***************************************************************************/
28 #include "StETofMessageFormat.h"
29 
30 // Specific headers
31 
32 // C++11 headers
33 #include <cmath>
34 
35 // std C++ lib headers
36 #include <stdio.h>
37 #include <string.h>
38 
39 //#include <iostream>
40 #include <iomanip>
41 
42 //----------------------------------------------------------------------------
43 //
44 // ***** format for year 2019 and later: namespace gdpbv100 *****
45 //
46 //----------------------------------------------------------------------------
47 
48 //----------------------------------------------------------------------------
51 {
52  uint64_t uThisTs = 0;
53  uint64_t uOtherTs = 0;
54 
55  uint32_t uThisType = this->getMessageType();
56  uint32_t uOtherType = other.getMessageType();
57 
58  // if both GET4 hit messages, use the full timestamp info
59  if( MSG_HIT == uThisType && MSG_HIT == uOtherType )
60  {
61  uThisTs = this->getGdpbHitFullTs();
62  uOtherTs = other.getGdpbHitFullTs();
63  return uThisTs < uOtherTs;
64  } // both GET4 hit (32b or 24b)
65 
66  // First find the timestamp of the current message
67  if( MSG_HIT == uThisType )
68  {
69  uThisTs = ( this->getGdpbHitFullTs() );
70  } // if Hit GET4 message (24 or 32b)
71  else uThisTs = 0;
72 
73  // Then find the timestamp of the current message
74  if( MSG_HIT == uOtherType )
75  {
76  uOtherTs = ( this->getGdpbHitFullTs() );
77  } // if Hit GET4 message (24 or 32b)
78  else uOtherTs = 0;
79 
80  return uThisTs < uOtherTs;
81 }
82 //----------------------------------------------------------------------------
85 {
86  return this->data == other.data;
87 }
88 //----------------------------------------------------------------------------
91 {
92  return this->data != other.data;
93 }
94 //----------------------------------------------------------------------------
96 uint64_t gdpbv100::Message::getMsgFullTime(uint64_t epoch) const
97 {
98  return std::round( getMsgFullTimeD( epoch ) );
99 }
100 //----------------------------------------------------------------------------
102 double gdpbv100::Message::getMsgFullTimeD(uint64_t epoch) const
103 {
104  switch( getMessageType() )
105  {
106  case MSG_HIT:
107  {
108  if( getGdpbHitIs24b() )
109  return ( static_cast<double_t>(FullTimeStamp(epoch, (getGdpbHitCoarse() << 7)))
110  + ( static_cast<double_t>(getGdpbHitFineTs() - 8. ) * gdpbv100::kdFtSize /gdpbv100::kdFtBinsNb) )
111  * (gdpbv100::kdClockCycleSizeNs / gdpbv100::kdFtSize);
112  else return ( gdpbv100::kdEpochInNs * static_cast<double_t>( epoch )
113  + static_cast<double_t>( getGdpbHitFullTs() ) * gdpbv100::kdClockCycleSizeNs / gdpbv100::kdFtBinsNb );
114  } // case MSG_HIT:
115  case MSG_EPOCH:
116  return gdpbv100::kdEpochInNs * static_cast<double_t>( getGdpbEpEpochNb() );
117  case MSG_SLOWC:
118  case MSG_SYST:
119  case MSG_STAR_TRI_A:
120  case MSG_STAR_TRI_B:
121  case MSG_STAR_TRI_C:
122  case MSG_STAR_TRI_D:
123  return gdpbv100::kdEpochInNs * static_cast<double_t>( epoch );
124  default:
125  return 0.0;
126  } // switch( getMessageType() )
127 
128  // If not already dealt with => unknown type
129  return 0.0;
130 }
131 //----------------------------------------------------------------------------
132 //----------------------------------------------------------------------------
134 
135 uint64_t gdpbv100::Message::CalcDistance(uint64_t start, uint64_t stop)
136 {
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 {
154  if (start>stop) {
155  stop += 0x3FFFFFFFFFFFLLU;
156  if (start>stop) {
157  printf("Epochs overflow error in CalcDistanceD\n");
158  return 0.;
159  }
160  }
161 
162  return stop - start;
163 }
164 
165 //----------------------------------------------------------------------------
167 
173 void gdpbv100::Message::printDataCout(unsigned kind, uint32_t epoch) const
174 {
175  printData(msg_print_Cout, kind, epoch);
176 }
177 
178 //----------------------------------------------------------------------------
180 
187 void gdpbv100::Message::printDataLog(unsigned kind, uint32_t epoch) const
188 {
189  printData(msg_print_FairLog, kind, epoch);
190 }
191 
192 //----------------------------------------------------------------------------
194 
218 //void gdpbv100::Message::printData(std::ostream& os, unsigned kind, uint32_t epoch) const
219 void gdpbv100::Message::printData(unsigned outType, unsigned kind, uint32_t epoch, std::ostream& os) const
220 {
221  char buf[256];
222  if (kind & msg_print_Hex) {
223  const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
224  snprintf(buf, sizeof(buf), "BE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X LE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ",
225  arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7],
226  arr[7], arr[6], arr[5], arr[4], arr[3], arr[2], arr[1], arr[0] );
227 
228  if( msg_print_Cout == outType)
229  std::cout << buf;
230  else if( msg_print_File == outType )
231  os << buf;
232 
233  snprintf(buf, sizeof(buf), " ");
234  }
235 
236  if (kind & msg_print_Human) {
237  double timeInSec = getMsgFullTimeD(epoch)/1.e9;
238  //int fifoFill = 0;
239 
240  switch (getMessageType()) {
241  case MSG_EPOCH:
242  snprintf(buf, sizeof(buf),
243  "Msg:%u ", getMessageType());
244 
245  if( msg_print_Cout == outType)
246  std::cout << buf;
247  else if( msg_print_File == outType )
248  os << buf;
249 
250  snprintf(buf, sizeof(buf),
251  "EPOCH @%17.11f Get4:%2d Epoche2:%10u 0x%08x Sync:%x Dataloss:%x Epochloss:%x Epochmissmatch:%x",
252  timeInSec, getGdpbGenChipId(), getGdpbEpEpochNb(), getGdpbEpEpochNb(),
253  getGdpbEpSync(), getGdpbEpDataLoss(), getGdpbEpEpochLoss(), getGdpbEpMissmatch());
254 
255  if( msg_print_Cout == outType)
256  std::cout << buf << std::endl;
257  else if( msg_print_File == outType )
258  os << buf << std::endl;
259  break;
260  case MSG_HIT:
261  snprintf(buf, sizeof(buf),
262  "Msg:%u ", getMessageType());
263 
264  if( msg_print_Cout == outType)
265  std::cout << buf;
266  else if( msg_print_File == outType )
267  os << buf;
268 
269  if( getGdpbHitIs24b() )
270  {
271  snprintf(buf, sizeof(buf),
272  "Get4 24b @%17.11f Get4:%2d Chn:%3d Edge:%1d Ts:%7d",
273  timeInSec, getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHit24Edge(), getGdpbHitFullTs() );
274  } // if( getGdpbHitIs24b() )
275  else
276  {
277  snprintf(buf, sizeof(buf),
278  "Get4 24b @%17.11f Get4:%2d Chn:%3d Dll:%1d Ts:%7d",
279  timeInSec, getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHit32DllLck(), getGdpbHitFullTs() );
280  } // else of if( getGdpbHitIs24b() )
281 
282  if( msg_print_Cout == outType)
283  std::cout << buf << std::endl;
284  else if( msg_print_File == outType )
285  os << buf << std::endl;
286  break;
287  default:
288  kind = kind & ~msg_print_Human;
289  if (kind==0) kind = msg_print_Prefix | msg_print_Data;
290  }
291 
292  // return, if message was correctly printed in human-readable form
293  if (kind & msg_print_Human) return;
294  }
295 
296  if (kind & msg_print_Prefix) {
297  snprintf(buf, sizeof(buf), "Msg:%2u ", getMessageType() );
298 
299  if( msg_print_Cout == outType)
300  std::cout << buf;
301  else if( msg_print_File == outType )
302  os << buf;
303  }
304 
305  if (kind & msg_print_Data) {
306  //const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
307  switch (getMessageType()) {
308  case MSG_HIT:
309  {
310  if( getGdpbHitIs24b() )
311  {
312  snprintf(buf, sizeof(buf), "Get4 24 bits, Get4:0x%04x Chn:%1x Edge:%1x Ts:0x%03x",
313  getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHit24Edge(), getGdpbHitFullTs() );
314  } // if( getGdpbHitIs24b() )
315  else
316  {
317  snprintf(buf, sizeof(buf),
318  "Get4 32 bits, Get4:0x%04x Channel %1d Ts:0x%03x Ft:0x%02x Tot:0x%02x Dll %1d",
319  getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHitCoarse(),
320  getGdpbHitFineTs(), getGdpbHit32Tot(), getGdpbHit32DllLck() );
321  } // else of if( getGdpbHitIs24b() )
322  break;
323  } // case MSG_HIT:
324  case MSG_EPOCH:
325  {
326  snprintf(buf, sizeof(buf), "Get4:0x%04x Link: %1u Epoch:0x%08x Sync:%x Dataloss:%x Epochloss:%x Epochmissmatch:%x",
327  getGdpbGenChipId(), getGdpbEpLinkId(), getGdpbEpEpochNb(), getGdpbEpSync(),
328  getGdpbEpDataLoss(), getGdpbEpEpochLoss(), getGdpbEpMissmatch());
329  break;
330  } // case MSG_EPOCH:
331  case MSG_SLOWC:
332  {
333  // GET4 slow control message, new "true" ROC support
334  snprintf(buf, sizeof(buf),
335  "Get4 Slow control, Get4:0x%04x => Chan:%01d Edge:%01d Type:%01x Data:0x%06x",
336  getGdpbGenChipId(), 0x0, 0x0, 0x0, getGdpbSlcData() );
337  break;
338  } // case MSG_SLOWC:
339  case MSG_SYST:
340  {
341  // GET4 system message, new "true" ROC support
342  char sysbuf[256];
343 
344  switch( getGdpbSysSubType() )
345  {
346  case SYS_GET4_ERROR:
347  {
348  snprintf(sysbuf, sizeof(sysbuf),
349  "Get4:0x%04x Ch:0x%01x Edge:%01x Unused:%06x ErrCode:0x%02x - GET4 V1 Error Event",
350  getGdpbGenChipId(), getGdpbSysErrChanId(), getGdpbSysErrEdge(), getGdpbSysErrUnused(), getGdpbSysErrData());
351  break;
352  } //
353  case SYS_GDPB_UNKWN:
354  snprintf(sysbuf, sizeof(sysbuf), "Unknown GET4 message, data: 0x%08x", getGdpbSysUnkwData());
355  break;
356  case SYS_GET4_SYNC_MISS:
357  snprintf(sysbuf, sizeof(sysbuf), "GET4 SYNC synchronization error");
358  break;
359  case SYS_PATTERN:
360  snprintf(sysbuf, sizeof(sysbuf), "Pattern message => Type %d, Index %2d, Pattern 0x%08X",
361  getGdpbSysPattType(), getGdpbSysPattIndex(), getGdpbSysPattPattern() );
362  break;
363  default:
364  snprintf(sysbuf, sizeof(sysbuf), "unknown system message type %u", getGdpbSysSubType());
365  } // switch( getGdpbSysSubType() )
366  snprintf(buf, sizeof(buf), "%s", sysbuf);
367 
368  break;
369  } // case MSG_SYST:
370  case MSG_STAR_TRI_A:
371  case MSG_STAR_TRI_B:
372  case MSG_STAR_TRI_C:
373  case MSG_STAR_TRI_D:
374  {
375  // STAR trigger token, spread over 4 messages
376  switch( getStarTrigMsgIndex() )
377  {
378  case 0:
379  {
380  snprintf(buf, sizeof(buf),
381  "STAR token A, gDPB TS MSB bits: 0x%010llx000000",
382  (unsigned long long) getGdpbTsMsbStarA() );
383  break;
384  } // case 1st message:
385  case 1:
386  {
387  snprintf(buf, sizeof(buf),
388  "STAR token B, gDPB TS LSB bits: 0x0000000000%06llx, STAR TS MSB bits: 0x%04llx000000000000",
389  (unsigned long long) getGdpbTsLsbStarB(), (unsigned long long) getStarTsMsbStarB() );
390  break;
391  } // case 2nd message:
392  case 2:
393  {
394  snprintf(buf, sizeof(buf),
395  "STAR token C, , STAR TS Mid bits: 0x0000%010llx00",
396  (unsigned long long) getStarTsMidStarC() );
397  break;
398  } // case 3rd message:
399  case 3:
400  {
401  snprintf(buf, sizeof(buf),
402  "STAR token D, , STAR TS LSB bits: 0x00000000000000%02llx"
403  ", Token: %03x, DAQ: %1x; TRG:%1x",
404  (unsigned long long) getStarTsLsbStarD(), getStarTokenStarD(), getStarDaqCmdStarD(), getStarTrigCmdStarD() );
405  break;
406  } // case 4th message:
407  } // switch( getStarTrigMsgIndex() )
408 
409  break;
410  } // case MSG_STAR_TRI_A || MSG_STAR_TRI_B || MSG_STAR_TRI_C || MSG_STAR_TRI_D:
411  default:
412  snprintf(buf, sizeof(buf), "Error - unexpected MessageType: %1x, full data %08X::%08X",
413  getMessageType(), getField(32, 32), getField(0, 32) );
414  }
415  }
416 
417  if( msg_print_Cout == outType)
418  std::cout << buf << std::endl;
419  else if( msg_print_File == outType )
420  os << buf << std::endl;
421 }
422 //----------------------------------------------------------------------------
425 {
426  if( other.fulExtendedEpoch == this->fulExtendedEpoch )
427  // Same epoch => use Message (base) class ordering operator
428  return this->Message::operator<( other );
429  else return this->fulExtendedEpoch < other.fulExtendedEpoch;
430 
431 }
432 //----------------------------------------------------------------------------
433 void gdpbv100::FullMessage::PrintMessage( unsigned outType, unsigned kind) const
434 {
435  std::cout << "Full epoch = " << std::setw(9) << fulExtendedEpoch << " ";
436  printDataCout( outType, kind );
437 }
438 //----------------------------------------------------------------------------
439 
440 
441 
442 
443 
444 
445 
446 
447 //----------------------------------------------------------------------------
448 //
449 // ***** format for year 2018: namespace get4v2x and gdpb *****
450 //
451 //----------------------------------------------------------------------------
452 
453 //----------------------------------------------------------------------------
455 bool gdpb::Message::operator<(const gdpb::Message& other) const
456 {
457  uint64_t uThisTs = 0;
458  uint64_t uOtherTs = 0;
459 
460  uint32_t uThisType = this->getMessageType();
461  uint32_t uOtherType = other.getMessageType();
462 
463  // if both GET4 hit messages, use the full timestamp info
464  if( (MSG_GET4_32B == uThisType || MSG_GET4 == uThisType )&&
465  (MSG_GET4_32B == uOtherType || MSG_GET4 == uOtherType ) )
466  {
467  uThisTs = this->getGdpbHitFullTs();
468  uOtherTs = other.getGdpbHitFullTs();
469  return uThisTs < uOtherTs;
470  } // both GET4 hit (32b or 24b)
471 
472  // First find the timestamp of the current message
473  if( MSG_GET4_32B == uThisType || MSG_GET4 == uThisType )
474  {
475  uThisTs = ( this->getGdpbHitFullTs() ) / 20 + 512;
476  } // if Hit GET4 message (24 or 32b)
477  else if( MSG_GET4_SLC == uThisType || MSG_GET4_SYS == uThisType )
478  {
479  uThisTs = 0;
480  } // if SLC or SYS GET4 message
481  else uThisTs = this->getMsgFullTime( 0 );
482 
483  // Then find the timestamp of the current message
484  if( MSG_GET4_32B == uOtherType || MSG_GET4 == uOtherType )
485  {
486  uOtherTs = ( this->getGdpbHitFullTs() ) / 20 + 512;
487  } // if Hit GET4 message (24 or 32b)
488  else if( MSG_GET4_SLC == uOtherType || MSG_GET4_SYS == uOtherType )
489  {
490  uOtherTs = 0;
491  } // if SLC or SYS GET4 message
492  else uOtherTs = other.getMsgFullTime( 0 );
493 
494  return uThisTs < uOtherTs;
495 }
496 //----------------------------------------------------------------------------
504 uint64_t gdpb::Message::getMsgFullTime(uint64_t epoch) const
505 {
506  return std::round( getMsgFullTimeD( epoch ) );
507 }
508 //----------------------------------------------------------------------------
512 double gdpb::Message::getMsgFullTimeD(uint64_t epoch) const
513 {
514  switch( getMessageType() )
515  {
516  case MSG_EPOCH2:
517  return get4v2x::kdEpochInNs * static_cast<double_t>( getEpoch2Number() );
518  case MSG_GET4:
519  return ( static_cast<double_t>(FullTimeStamp2(epoch, (getGdpbHitCoarse() << 7))) + ( static_cast<double_t>(getGdpbHitFineTs() - 8. ) * 128. /112.) )
520  * (6.25 / 128.);
521  case MSG_SYS:
522  if( SYSMSG_GET4_EVENT == getGdpbSysSubType() )
523  return get4v2x::kdEpochInNs * static_cast<double_t>( epoch ); // Use epoch period of TOF!!
524  case MSG_GET4_32B:
525  return ( get4v2x::kdEpochInNs * static_cast<double_t>( epoch ) + static_cast<double_t>( getGdpbHitFullTs() ) * get4v2x::kdClockCycleSizeNs / 112. );
526  case MSG_GET4_SLC:
527  case MSG_GET4_SYS:
528  return FullTimeStamp2(epoch, 0) * (6.25 / 128.);
529  default:
530  return 0.0;
531  } // switch( getMessageType() )
532 
533  // If not already dealt with => unknown type
534  return 0.0;
535 }
536 //----------------------------------------------------------------------------
537 //----------------------------------------------------------------------------
539 
540 uint64_t gdpb::Message::CalcDistance(uint64_t start, uint64_t stop)
541 {
542  if (start>stop) {
543  stop += 0x3FFFFFFFFFFFLLU;
544  if (start>stop) {
545  printf("Epochs overflow error in CalcDistance\n");
546  return 0;
547  }
548  }
549 
550  return stop - start;
551 }
552 
553 
554 //----------------------------------------------------------------------------
556 
557 double gdpb::Message::CalcDistanceD(double start, double stop)
558 {
559  if (start>stop) {
560  stop += 0x3FFFFFFFFFFFLLU;
561  if (start>stop) {
562  printf("Epochs overflow error in CalcDistanceD\n");
563  return 0.;
564  }
565  }
566 
567  return stop - start;
568 }
569 
570 
571 
572 //----------------------------------------------------------------------------
574 
580 void gdpb::Message::printDataCout(unsigned kind, uint32_t epoch) const
581 {
582  printData(msg_print_Cout, kind, epoch);
583 }
584 
585 //----------------------------------------------------------------------------
587 
594 void gdpb::Message::printDataLog(unsigned kind, uint32_t epoch) const
595 {
596  printData(msg_print_FairLog, kind, epoch);
597 }
598 
599 //----------------------------------------------------------------------------
601 
651 //void gdpb::Message::printData(std::ostream& os, unsigned kind, uint32_t epoch) const
652 void gdpb::Message::printData(unsigned outType, unsigned kind, uint32_t epoch, std::ostream& os) const
653 {
654  char buf[256];
655  if (kind & msg_print_Hex) {
656  const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
657  snprintf(buf, sizeof(buf), "BE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X LE= %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X ",
658  arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6], arr[7],
659  arr[7], arr[6], arr[5], arr[4], arr[3], arr[2], arr[1], arr[0] );
660 // os << buf;
661  if( msg_print_Cout == outType)
662  std::cout << buf;
663  else if( msg_print_File == outType )
664  os << buf;
665 
666  snprintf(buf, sizeof(buf), " ");
667  }
668 
669  if (kind & msg_print_Human) {
670  double timeInSec = getMsgFullTimeD(epoch)/1.e9;
671  //int fifoFill = 0;
672 
673  switch (getMessageType()) {
674  case MSG_EPOCH2:
675  snprintf(buf, sizeof(buf),
676  "Msg:%u Roc:%04x ", getMessageType(), getRocNumber());
677 // os << buf;
678  if( msg_print_Cout == outType)
679  std::cout << buf;
680  else if( msg_print_File == outType )
681  os << buf;
682 
683  snprintf(buf, sizeof(buf),
684  "EPO2 @%17.11f Get4:%2d Epoche2:%10u 0x%08x StampTime:%2d Sync:%x Dataloss:%x Epochloss:%x Epochmissmatch:%x",
685  timeInSec, getEpoch2ChipNumber(), getEpoch2Number(), getEpoch2Number(),
686  getEpoch2StampTime(), getEpoch2Sync(), getEpoch2DataLost(), getEpoch2EpochLost(), getEpoch2EpochMissmatch());
687 // os << buf << std::endl;
688  if( msg_print_Cout == outType)
689  std::cout << buf << std::endl;
690  else if( msg_print_File == outType )
691  os << buf << std::endl;
692  break;
693  case MSG_GET4:
694  snprintf(buf, sizeof(buf),
695  "Msg:%u Roc:%04x ", getMessageType(), getRocNumber());
696 // os << buf;
697  if( msg_print_Cout == outType)
698  std::cout << buf;
699  else if( msg_print_File == outType )
700  os << buf;
701 
702  snprintf(buf, sizeof(buf),
703  "Get4 @%17.11f Get4:%2d Chn:%3d Edge:%1d Ts:%7d CRC8:%3d",
704  timeInSec, getGet4Number(), getGet4ChNum(), getGet4Edge(), getGet4Ts(), getGet4CRC() );
705 // os << buf << std::endl;
706  if( msg_print_Cout == outType)
707  std::cout << buf << std::endl;
708  else if( msg_print_File == outType )
709  os << buf << std::endl;
710  break;
711  default:
712  kind = kind & ~msg_print_Human;
713  if (kind==0) kind = msg_print_Prefix | msg_print_Data;
714  }
715 
716  // return, if message was correctly printed in human-readable form
717  if (kind & msg_print_Human) return;
718  }
719 
720  if (kind & msg_print_Prefix) {
721  snprintf(buf, sizeof(buf), "Msg:%2u Roc:%04x ", getMessageType(), getRocNumber());
722 // os << buf;
723  if( msg_print_Cout == outType)
724  std::cout << buf;
725  else if( msg_print_File == outType )
726  os << buf;
727  }
728 
729  if (kind & msg_print_Data) {
730  const uint8_t* arr = reinterpret_cast<const uint8_t*> ( &data );
731  switch (getMessageType()) {
732  case MSG_NOP:
733  snprintf(buf, sizeof(buf), "NOP (raw %02X:%02X:%02X:%02X:%02X:%02X)",
734  arr[0], arr[1], arr[2], arr[3], arr[4], arr[5]);
735  break;
736  case MSG_EPOCH2:
737  snprintf(buf, sizeof(buf), "Get4:0x%02x Link: %1u Epoche2:0x%08x StampTime:0x%x Sync:%x Dataloss:%x Epochloss:%x Epochmissmatch:%x",
738  getGdpbGenChipId(), getGdpbEpLinkId(), getGdpbEpEpochNb(), getGdpbEpStampTs(), getGdpbEpSync(),
739  getGdpbEpDataLoss(), getGdpbEpEpochLoss(), getGdpbEpMissmatch());
740  break;
741  case MSG_GET4:
742  snprintf(buf, sizeof(buf), "Get4:0x%02x Chn:%1x Edge:%1x Ts:0x%05x CRC8:0x%02x",
743  getGdpbGenChipId(), getGdpbHitChanId(), getGdpbHit24Edge(), getGdpbHitFullTs(), getGdpbHitCrc() );
744  break;
745  case MSG_SYS: {
746  char sysbuf[256];
747 
748  switch (getSysMesType()) {
749  case SYSMSG_DAQ_START:
750  snprintf(sysbuf, sizeof(sysbuf), "DAQ started");
751  break;
752  case SYSMSG_DAQ_FINISH:
753  snprintf(sysbuf, sizeof(sysbuf), "DAQ finished");
754  break;
755  case SYSMSG_SYNC_PARITY:
756  snprintf(sysbuf, sizeof(sysbuf), "SYNC parity error ");
757  break;
758  case SYSMSG_DAQ_RESUME:
759  snprintf(sysbuf, sizeof(sysbuf), "DAQ resume after high/low water");
760  break;
761  case SYSMSG_FIFO_RESET:
762  snprintf(sysbuf, sizeof(sysbuf), "FIFO reset");
763  break;
764  case SYSMSG_USER: {
765  const char* subtyp = "";
766  if (getSysMesData()==SYSMSG_USER_CALIBR_ON) subtyp = "Calibration ON"; else
767  if (getSysMesData()==SYSMSG_USER_CALIBR_OFF) subtyp = "Calibration OFF"; else
768  if (getSysMesData()==SYSMSG_USER_RECONFIGURE) subtyp = "Reconfigure";
769  snprintf(sysbuf, sizeof(sysbuf), "User message 0x%08x %s", getSysMesData(), subtyp);
770  break;
771  }
772  case SYSMSG_PACKETLOST:
773  snprintf(sysbuf, sizeof(sysbuf), "Packet lost");
774  break;
775  case SYSMSG_GET4_EVENT:
776  {
777  break;
778  } //
779  case SYSMSG_CLOSYSYNC_ERROR:
780  snprintf(sysbuf, sizeof(sysbuf), "Closy synchronization error");
781  break;
782  case SYSMSG_TS156_SYNC:
783  snprintf(sysbuf, sizeof(sysbuf), "156.25MHz timestamp reset");
784  break;
785  case SYSMSG_GET4V1_32BIT_0:
786  case SYSMSG_GET4V1_32BIT_1:
787  case SYSMSG_GET4V1_32BIT_2:
788  case SYSMSG_GET4V1_32BIT_3:
789  case SYSMSG_GET4V1_32BIT_4:
790  case SYSMSG_GET4V1_32BIT_5:
791  case SYSMSG_GET4V1_32BIT_6:
792  case SYSMSG_GET4V1_32BIT_7:
793  case SYSMSG_GET4V1_32BIT_8:
794  case SYSMSG_GET4V1_32BIT_9:
795  case SYSMSG_GET4V1_32BIT_10:
796  case SYSMSG_GET4V1_32BIT_11:
797  case SYSMSG_GET4V1_32BIT_12:
798  case SYSMSG_GET4V1_32BIT_13:
799  case SYSMSG_GET4V1_32BIT_14:
800  case SYSMSG_GET4V1_32BIT_15:
801  {
802  break;
803  } // case SYSMSG_GET4V1_32BIT + channel!
804  default:
805  snprintf(sysbuf, sizeof(sysbuf), "unknown system message type ");
806  } // switch (getSysMesType())
807 
808  snprintf(buf, sizeof(buf), "SysType:%2x Data:%8x : %s", getSysMesType(), getSysMesData(), sysbuf);
809 
810  break;
811  } // case MSG_SYS:
812  case MSG_GET4_SLC:
813  {
814  // GET4 slow control message, new "true" ROC support
815  snprintf(buf, sizeof(buf),
816  "Get4 Slow control, chip %02d => Chan:%01d Edge:%01d Type:%01x Data:0x%06x CRC:0x%02x",
817  getGdpbGenChipId(), 0x0, 0x0, 0x0, getGdpbSlcData(), getGdpbSlcCrc() );
818  break;
819  } // case MSG_GET4_SLC:
820  case MSG_GET4_32B:
821  {
822  // 32b GET4 data event, new "true" ROC support
823  snprintf(buf, sizeof(buf),
824  "Get4 32 bits, Chip:0x%02x Dll %1d Channel %1d Ts:0x%03x Ft:0x%02x Tot:0x%02x",
825  getGdpbGenChipId(), getGdpbHit32DllLck(), getGdpbHitChanId(),
826  getGdpbHitCoarse(), getGdpbHitFineTs(), getGdpbHit32Tot() );
827 
828  break;
829  } // case MSG_GET4_32B:
830  case MSG_GET4_SYS:
831  {
832  // GET4 system message, new "true" ROC support
833  char sysbuf[256];
834 
835  switch( getGdpbSysSubType() )
836  {
837  case SYSMSG_GET4_EVENT:
838  {
839  snprintf(sysbuf, sizeof(sysbuf),
840  "Get4:0x%02x Ch:0x%01x Edge:%01x Unused:%06x ErrCode:0x%02x - GET4 V1 Error Event",
841  getGdpbGenChipId(), getGdpbSysErrChanId(), getGdpbSysErrEdge(), getGdpbSysErrUnused(), getGdpbSysErrData());
842  break;
843  } //
844  case SYSMSG_CLOSYSYNC_ERROR:
845  snprintf(sysbuf, sizeof(sysbuf), "Closy synchronization error");
846  break;
847  case SYSMSG_TS156_SYNC:
848  snprintf(sysbuf, sizeof(sysbuf), "156.25MHz timestamp reset");
849  break;
850  case SYSMSG_GDPB_UNKWN:
851  snprintf(sysbuf, sizeof(sysbuf), "Unknown GET4 message, data: 0x%08x", getGdpbSysUnkwData());
852  break;
853  default:
854  snprintf(sysbuf, sizeof(sysbuf), "unknown system message type %u", getGdpbSysSubType());
855  } // switch( getGdpbSysSubType() )
856  snprintf(buf, sizeof(buf), "%s", sysbuf);
857 
858  break;
859  } // case MSG_GET4_SYS:
860  case MSG_STAR_TRI:
861  {
862  // STAR trigger token, spread over 4 messages
863  switch( getStarTrigMsgIndex() )
864  {
865  case 0:
866  {
867  snprintf(buf, sizeof(buf),
868  "STAR token A, gDPB TS MSB bits: 0x%010llx000000",
869  (unsigned long long) getGdpbTsMsbStarA() );
870  break;
871  } // case 1st message:
872  case 1:
873  {
874  snprintf(buf, sizeof(buf),
875  "STAR token B, gDPB TS LSB bits: 0x0000000000%06llx, STAR TS MSB bits: 0x%04llx000000000000",
876  (unsigned long long) getGdpbTsLsbStarB(), (unsigned long long) getStarTsMsbStarB() );
877  break;
878  } // case 2nd message:
879  case 2:
880  {
881  snprintf(buf, sizeof(buf),
882  "STAR token C, , STAR TS Mid bits: 0x0000%010llx00",
883  (unsigned long long) getStarTsMidStarC() );
884  break;
885  } // case 3rd message:
886  case 3:
887  {
888  snprintf(buf, sizeof(buf),
889  "STAR token D, , STAR TS LSB bits: 0x00000000000000%02llx"
890  ", Token: %03x, DAQ: %1x; TRG:%1x",
891  (unsigned long long) getStarTsLsbStarD(), getStarTokenStarD(), getStarDaqCmdStarD(), getStarTrigCmdStarD() );
892  break;
893  } // case 4th message:
894  } // switch( getStarTrigMsgIndex() )
895 
896  break;
897  } // case MSG_STAR_TRI:
898  default:
899  snprintf(buf, sizeof(buf), "Error - unexpected MessageType: %1x, full data %08X::%08X",
900  getMessageType(), getField(32, 32), getField(0, 32) );
901  }
902  }
903 
904 // os << buf << std::endl;
905  if( msg_print_Cout == outType)
906  std::cout << buf << std::endl;
907  else if( msg_print_File == outType )
908  os << buf << std::endl;
909 // else LOG(INFO) << sLogBuff << buf << FairLogger::endl;
910 }
911 
912 uint32_t gdpb::Message::RawSize(int fmt)
913 {
914  switch (fmt) {
915  case formatNormal: return 8;
916  default:
917  std::cerr << "gdpb::Message::RawSize => "
918  << " Deprecated format, nothing done!!"
919  << std::endl;
920  return 0;
921  }
922  return 8;
923 }
924 
925 bool gdpb::Message::assign(void* src, int fmt)
926 {
927  switch (fmt) {
928  case formatNormal:
929  memcpy(&data, src, 8);
930  return true;
931  default:
932  std::cerr << "gdpb::Message::assign => "
933  << " Deprecated format, nothing done!!"
934  << std::endl;
935  return false;
936  }
937 
938  return false;
939 }
940 
941 bool gdpb::Message::copyto(void* tgt, int fmt)
942 {
943  switch (fmt) {
944  case formatNormal:
945  memcpy(tgt, &data, 8);
946  return true;
947  default:
948  std::cerr << "gdpb::Message::assign => "
949  << " Deprecated format, nothing done!!"
950  << std::endl;
951  return false;
952  }
953 
954  return false;
955 
956 }
957 
958 //----------------------------------------------------------------------------
961 {
962  if( other.fulExtendedEpoch == this->fulExtendedEpoch )
963  // Same epoch => use Message (base) class ordering operator
964  return this->Message::operator<( other );
965  else return this->fulExtendedEpoch < other.fulExtendedEpoch;
966 
967 }
968 //----------------------------------------------------------------------------
969 void gdpb::FullMessage::PrintMessage( unsigned outType, unsigned kind) const
970 {
971  std::cout << "Full epoch = " << std::setw(9) << fulExtendedEpoch << " ";
972  printDataCout( outType, kind );
973 }
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
bool operator<(const FullMessage &other) const
strict weak ordering operator, including epoch for both messages
uint64_t getMsgFullTime(uint64_t epoch) const
bool operator<(const FullMessage &other) const
strict weak ordering operator, including epoch for both messages
static double CalcDistanceD(double start, double stop)
Returns the time difference between two expanded time stamps.
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.
uint64_t getMsgFullTime(uint64_t epoch) const
Returns expanded and adjusted time of message (in ns)
void printDataCout(unsigned kind=msg_print_Prefix|msg_print_Data, uint32_t epoch=0) const
Print message in human readable format to cout.
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
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.
bool operator<(const gdpb::Message &other) const
strict weak ordering operator, assumes same epoch for both messages
uint8_t getMessageType() const
Returns the message type. Valid for all message types. 4 bit.
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.
double getMsgFullTimeD(uint64_t epoch) const
Returns expanded and adjusted time of message in double (in ns)
double getMsgFullTimeD(uint64_t epoch) const
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.
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.
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
static uint64_t CalcDistance(uint64_t start, uint64_t stop)
Returns the time difference between two expanded time stamps.
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