CMS 3D CMS Logo

SiStripFEDBufferComponents.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <ostream>
3 #include <sstream>
4 #include <cstring>
7 
8 namespace sistrip {
9 
10  void printHexValue(const uint8_t value, std::ostream& os) {
11  const std::ios_base::fmtflags originalFormatFlags = os.flags();
12  os << std::hex << std::setfill('0') << std::setw(2);
13  os << uint16_t(value);
14  os.flags(originalFormatFlags);
15  }
16 
17  void printHexWord(const uint8_t* pointer, const size_t lengthInBytes, std::ostream& os) {
18  size_t i = lengthInBytes - 1;
19  do {
20  printHexValue(pointer[i], os);
21  if (i != 0)
22  os << " ";
23  } while (i-- != 0);
24  }
25 
26  void printHex(const void* pointer, const size_t lengthInBytes, std::ostream& os) {
27  const uint8_t* bytePointer = reinterpret_cast<const uint8_t*>(pointer);
28  //if there is one 64 bit word or less, print it out
29  if (lengthInBytes <= 8) {
30  printHexWord(bytePointer, lengthInBytes, os);
31  }
32  //otherwise, print word numbers etc
33  else {
34  //header
35  os << "word\tbyte\t \t\tbyte" << std::endl;
36  ;
37  const size_t words = lengthInBytes / 8;
38  const size_t extraBytes = lengthInBytes - 8 * words;
39  //print full words
40  for (size_t w = 0; w < words; w++) {
41  const size_t startByte = w * 8;
42  os << w << '\t' << startByte + 8 << '\t';
43  printHexWord(bytePointer + startByte, 8, os);
44  os << "\t\t" << startByte << std::endl;
45  }
46  //print part word, if any
47  if (extraBytes) {
48  const size_t startByte = words * 8;
49  os << words << '\t' << startByte + 8 << '\t';
50  //padding
51  size_t p = 8;
52  while (p-- > extraBytes) {
53  os << "00 ";
54  }
55  printHexWord(bytePointer + startByte, extraBytes, os);
56  os << "\t\t" << startByte << std::endl;
57  }
58  os << std::endl;
59  }
60  }
61 
62  uint16_t calculateFEDBufferCRC(const uint8_t* buffer, const size_t lengthInBytes) {
63  uint16_t crc = 0xFFFF;
64  for (size_t i = 0; i < lengthInBytes - 8; i++) {
65  crc = evf::compute_crc_8bit(crc, buffer[i ^ 7]);
66  }
67  for (size_t i = lengthInBytes - 8; i < lengthInBytes; i++) {
68  uint8_t byte;
69  //set CRC bytes to zero since these were not set when CRC was calculated
70  if (i == lengthInBytes - 4 || i == lengthInBytes - 3)
71  byte = 0x00;
72  else
73  byte = buffer[i ^ 7];
74  crc = evf::compute_crc_8bit(crc, byte);
75  }
76  return crc;
77  }
78 
79  std::ostream& operator<<(std::ostream& os, const FEDBufferFormat& value) {
80  switch (value) {
82  os << "Old VME";
83  break;
85  os << "Old S-Link";
86  break;
87  case BUFFER_FORMAT_NEW:
88  os << "New";
89  break;
91  os << "Invalid";
92  break;
93  default:
94  os << "Unrecognized";
95  os << " (";
96  printHexValue(value, os);
97  os << ")";
98  break;
99  }
100  return os;
101  }
102 
103  std::ostream& operator<<(std::ostream& os, const FEDHeaderType& value) {
104  switch (value) {
106  os << "Full debug";
107  break;
109  os << "APV error";
110  break;
111  case HEADER_TYPE_NONE:
112  os << "None";
113  break;
114  case HEADER_TYPE_INVALID:
115  os << "Invalid";
116  break;
117  default:
118  os << "Unrecognized";
119  os << " (";
120  printHexValue(value, os);
121  os << ")";
122  break;
123  }
124  return os;
125  }
126 
127  std::ostream& operator<<(std::ostream& os, const FEDLegacyReadoutMode& value) {
128  switch (value) {
130  os << "(L) Scope mode";
131  break;
133  os << "(L) Virgin raw (real)";
134  break;
136  os << "(L) Virgin raw (fake)";
137  break;
139  os << "(L) Processed raw (real)";
140  break;
142  os << "(L) Processed raw (fake)";
143  break;
145  os << "(L) Zero suppressed (real)";
146  break;
148  os << "(L) Zero suppressed (fake)";
149  break;
151  os << "(L) Zero suppressed lite (real)";
152  break;
154  os << "(L) Zero suppressed lite (fake)";
155  break;
157  os << "(L) Spy channel";
158  break;
160  os << "(L) PreMix raw";
161  break;
163  os << "(L) Invalid";
164  break;
165  default:
166  os << "(L) Unrecognized";
167  os << " (";
168  printHexValue(value, os);
169  os << ")";
170  break;
171  }
172  return os;
173  }
174 
175  std::ostream& operator<<(std::ostream& os, const FEDReadoutMode& value) {
176  switch (value) {
177  case READOUT_MODE_SCOPE:
178  os << "Scope mode";
179  break;
181  os << "Virgin raw";
182  break;
184  os << "Processed raw";
185  break;
187  os << "Zero suppressed";
188  break;
190  os << "Zero suppressed (fake)";
191  break;
193  os << "Zero suppressed lite";
194  break;
195  case READOUT_MODE_SPY:
196  os << "Spy channel";
197  break;
198  /*case READOUT_MODE_ZERO_SUPPRESSED_CMOVERRIDE:
199  os << "Zero suppressed CM Override";
200  break;*/
202  os << "Zero suppressed lite CM Override";
203  break;
205  os << "Zero suppressed lite (8 bit, top-stripped)";
206  break;
208  os << "Zero suppressed lite CM Override (8 bit, top-stripped)";
209  break;
211  os << "Zero suppressed lite (8 bit, bottom-stripped)";
212  break;
214  os << "Zero suppressed lite CM Override (8 bit, bottom-stripped)";
215  break;
217  os << "Zero suppressed lite (8 bit, top/bottom-stripped)";
218  break;
220  os << "Zero suppressed lite CM Override (8 bit, top/bottom-stripped)";
221  break;
223  os << "PreMix raw";
224  break;
226  os << "Invalid";
227  break;
228  default:
229  os << "Unrecognized";
230  os << " (";
231  printHexValue(value, os);
232  os << ")";
233  break;
234  }
235  return os;
236  }
237 
238  std::ostream& operator<<(std::ostream& os, const FEDDAQEventType& value) {
239  switch (value) {
241  os << "Physics trigger";
242  break;
244  os << "Calibration trigger";
245  break;
246  case DAQ_EVENT_TYPE_TEST:
247  os << "Test trigger";
248  break;
250  os << "Technical trigger";
251  break;
253  os << "Simulated event";
254  break;
256  os << "Traced event";
257  break;
259  os << "Error";
260  break;
262  os << "Unknown";
263  break;
264  default:
265  os << "Unrecognized";
266  os << " (";
267  printHexValue(value, os);
268  os << ")";
269  break;
270  }
271  return os;
272  }
273 
274  std::ostream& operator<<(std::ostream& os, const FEDTTSBits& value) {
275  switch (value) {
276  case TTS_DISCONNECTED0:
277  os << "Disconected 0";
278  break;
279  case TTS_WARN_OVERFLOW:
280  os << "Warning overflow";
281  break;
282  case TTS_OUT_OF_SYNC:
283  os << "Out of sync";
284  break;
285  case TTS_BUSY:
286  os << "Busy";
287  break;
288  case TTS_READY:
289  os << "Ready";
290  break;
291  case TTS_ERROR:
292  os << "Error";
293  break;
294  case TTS_INVALID:
295  os << "Invalid";
296  break;
297  case TTS_DISCONNECTED1:
298  os << "Disconected 1";
299  break;
300  default:
301  os << "Unrecognized";
302  os << " (";
303  printHexValue(value, os);
304  os << ")";
305  break;
306  }
307  return os;
308  }
309 
310  std::ostream& operator<<(std::ostream& os, const FEDBufferState& value) {
311  switch (value) {
312  case BUFFER_STATE_UNSET:
313  os << "Unset";
314  break;
315  case BUFFER_STATE_EMPTY:
316  os << "Empty";
317  break;
319  os << "Partial Full";
320  break;
321  case BUFFER_STATE_FULL:
322  os << "Full";
323  break;
324  default:
325  os << "Unrecognized";
326  os << " (";
327  printHexValue(value, os);
328  os << ")";
329  break;
330  }
331  return os;
332  }
333 
334  std::ostream& operator<<(std::ostream& os, const FEDChannelStatus& value) {
335  if (!(value & CHANNEL_STATUS_LOCKED))
336  os << "Unlocked ";
337  if (!(value & CHANNEL_STATUS_IN_SYNC))
338  os << "Out-of-sync ";
340  os << "APV 1 bad address ";
342  os << "APV 1 error ";
344  os << "APV 0 bad address ";
346  os << "APV 0 error ";
348  os << "No errors";
349  return os;
350  }
351 
352  std::ostream& operator<<(std::ostream& os, const FEDBufferStatusCode& value) {
353  switch (value) {
355  os << "SUCCESS";
356  break;
358  os << "Buffer pointer is NULL.";
359  break;
361  os << "Buffer is too small. Min size is 24.";
362  break;
364  os << "Buffer format not recognized. ";
365  break;
367  os << "Unpacking of spy channel data with FEDBuffer is not supported";
368  break;
370  os << "Buffer is not from spy channel";
371  break;
373  os << "No or invalid header type";
374  break;
377  os << "Channel does not fit into buffer";
378  break;
380  os << "Channel is too short";
381  break;
382  }
383  return os;
384  }
385 
387  if ((bufferFormatString == "OLD_VME") || (bufferFormatString == "BUFFER_FORMAT_OLD_VME") ||
388  (bufferFormatString == "Old VME")) {
389  return BUFFER_FORMAT_OLD_VME;
390  }
391  if ((bufferFormatString == "OLD_SLINK") || (bufferFormatString == "BUFFER_FORMAT_OLD_SLINK") ||
392  (bufferFormatString == "Old S-Link")) {
394  }
395  if ((bufferFormatString == "NEW") || (bufferFormatString == "BUFFER_FORMAT_NEW") || (bufferFormatString == "New")) {
396  return BUFFER_FORMAT_NEW;
397  }
398  //if it was none of the above then return invalid
399  return BUFFER_FORMAT_INVALID;
400  }
401 
403  if ((headerTypeString == "FULL_DEBUG") || (headerTypeString == "HEADER_TYPE_FULL_DEBUG") ||
404  (headerTypeString == "Full debug")) {
405  return HEADER_TYPE_FULL_DEBUG;
406  }
407  if ((headerTypeString == "APV_ERROR") || (headerTypeString == "HEADER_TYPE_APV_ERROR") ||
408  (headerTypeString == "APV error")) {
409  return HEADER_TYPE_APV_ERROR;
410  }
411  if ((headerTypeString == "None") || (headerTypeString == "none")) {
412  return HEADER_TYPE_NONE;
413  }
414  //if it was none of the above then return invalid
415  return HEADER_TYPE_INVALID;
416  }
417 
419  if ((readoutModeString == "READOUT_MODE_SCOPE") || (readoutModeString == "SCOPE") ||
420  (readoutModeString == "SCOPE_MODE") || (readoutModeString == "Scope mode")) {
421  return READOUT_MODE_SCOPE;
422  }
423  if ((readoutModeString == "READOUT_MODE_VIRGIN_RAW") || (readoutModeString == "VIRGIN_RAW") ||
424  (readoutModeString == "Virgin raw")) {
426  }
427  if ((readoutModeString == "READOUT_MODE_PROC_RAW") || (readoutModeString == "PROC_RAW") ||
428  (readoutModeString == "PROCESSED_RAW") || (readoutModeString == "Processed raw")) {
429  return READOUT_MODE_PROC_RAW;
430  }
431  if ((readoutModeString == "READOUT_MODE_ZERO_SUPPRESSED") || (readoutModeString == "ZERO_SUPPRESSED") ||
432  (readoutModeString == "Zero suppressed")) {
434  }
435  if ((readoutModeString == "READOUT_MODE_ZERO_SUPPRESSED_LITE8") || (readoutModeString == "ZERO_SUPPRESSED_LITE8") ||
436  (readoutModeString == "Zero suppressed lite8")) {
438  }
439  if ((readoutModeString == "READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT") ||
440  (readoutModeString == "ZERO_SUPPRESSED_LITE8_TOPBOT") ||
441  (readoutModeString == "Zero suppressed lite8 TopBot")) {
443  }
444  if ((readoutModeString == "READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT") ||
445  (readoutModeString == "ZERO_SUPPRESSED_LITE8_BOTBOT") ||
446  (readoutModeString == "Zero suppressed lite8 BotBot")) {
448  }
449  if ((readoutModeString == "READOUT_MODE_ZERO_SUPPRESSED_LITE10") ||
450  (readoutModeString == "ZERO_SUPPRESSED_LITE10") || (readoutModeString == "Zero suppressed lite10")) {
452  }
453  if ((readoutModeString == "READOUT_MODE_PREMIX_RAW") || (readoutModeString == "PREMIX_RAW") ||
454  (readoutModeString == "PreMix Raw")) {
456  }
457  if ((readoutModeString == "READOUT_MODE_SPY") || (readoutModeString == "SPY") ||
458  (readoutModeString == "Spy channel")) {
459  return READOUT_MODE_SPY;
460  }
461  //if it was none of the above then return invalid
462  return READOUT_MODE_INVALID;
463  }
464  uint8_t packetCodeFromString(const std::string& packetCode, FEDReadoutMode mode) {
466  if (packetCode == "ZERO_SUPPRESSED" || packetCode == "Zero suppressed") {
468  } else if (packetCode == "ZERO_SUPPRESSED10" || packetCode == "Zero suppressed 10") {
470  } else if (packetCode == "ZERO_SUPPRESSED8_BOTBOT" || packetCode == "Zero suppressed 8 BOTBOT") {
472  } else if (packetCode == "ZERO_SUPPRESSED8_TOPBOT" || packetCode == "Zero suppressed 8 TOPBOT") {
474  } else {
475  throw cms::Exception("FEDBuffer")
476  << "'" << packetCode << "' cannot be converted into a valid packet code for FEDReadoutMode ZERO_SUPPRESSED";
477  }
478  } else if (mode == READOUT_MODE_VIRGIN_RAW) {
479  if (packetCode == "VIRGIN_RAW" || packetCode == "Virgin raw") {
480  return PACKET_CODE_VIRGIN_RAW;
481  } else if (packetCode == "VIRGIN_RAW10" || packetCode == "Virgin raw 10") {
483  } else if (packetCode == "VIRGIN_RAW8_BOTBOT" || packetCode == "Virgin raw 8 BOTBOT") {
485  } else if (packetCode == "VIRGIN_RAW8_TOPBOT" || packetCode == "Virgin raw 8 TOPBOT") {
487  } else {
488  throw cms::Exception("FEDBuffer")
489  << "'" << packetCode << "' cannot be converted into a valid packet code for FEDReadoutMode VIRGIN_RAW";
490  }
491  } else if (mode == READOUT_MODE_PROC_RAW) {
492  if (packetCode == "PROC_RAW" || packetCode == "Processed raw") {
493  return PACKET_CODE_PROC_RAW;
494  } else if (packetCode == "PROC_RAW10" || packetCode == "Processed raw 10") {
495  return PACKET_CODE_PROC_RAW10;
496  } else if (packetCode == "PROC_RAW8_BOTBOT" || packetCode == "Processed raw 8 BOTBOT") {
498  } else if (packetCode == "PROC_RAW8_TOPBOT" || packetCode == "Processed raw 8 TOPBOT") {
500  } else {
501  throw cms::Exception("FEDBuffer")
502  << "'" << packetCode << "' cannot be converted into a valid packet code for FEDReadoutMode PROC_RAW";
503  }
504  } else if (mode == READOUT_MODE_SCOPE) {
505  if (packetCode == "SCOPE" || packetCode == "Scope" || packetCode.empty()) { // default
506  return PACKET_CODE_SCOPE;
507  } else {
508  throw cms::Exception("FEDBuffer")
509  << "'" << packetCode << "' cannot be converted into a valid packet code for FEDReadoutMode SCOPE";
510  }
511  } else {
512  if (!packetCode.empty()) {
513  throw cms::Exception("FEDBuffer") << "Packet codes are only needed for zero-suppressed (non-lite), virgin raw, "
514  "processed raw and spy data. FEDReadoutMode="
515  << mode << " and packetCode='" << packetCode << "'";
516  }
517  return 0;
518  }
519  }
520 
522  if ((daqEventTypeString == "PHYSICS") || (daqEventTypeString == "DAQ_EVENT_TYPE_PHYSICS") ||
523  (daqEventTypeString == "Physics trigger")) {
524  return DAQ_EVENT_TYPE_PHYSICS;
525  }
526  if ((daqEventTypeString == "CALIBRATION") || (daqEventTypeString == "DAQ_EVENT_TYPE_CALIBRATION") ||
527  (daqEventTypeString == "Calibration trigger")) {
529  }
530  if ((daqEventTypeString == "TEST") || (daqEventTypeString == "DAQ_EVENT_TYPE_TEST") ||
531  (daqEventTypeString == "Test trigger")) {
532  return DAQ_EVENT_TYPE_TEST;
533  }
534  if ((daqEventTypeString == "TECHNICAL") || (daqEventTypeString == "DAQ_EVENT_TYPE_TECHNICAL") ||
535  (daqEventTypeString == "Technical trigger")) {
537  }
538  if ((daqEventTypeString == "SIMULATED") || (daqEventTypeString == "DAQ_EVENT_TYPE_SIMULATED") ||
539  (daqEventTypeString == "Simulated trigger")) {
541  }
542  if ((daqEventTypeString == "TRACED") || (daqEventTypeString == "DAQ_EVENT_TYPE_TRACED") ||
543  (daqEventTypeString == "Traced event")) {
544  return DAQ_EVENT_TYPE_TRACED;
545  }
546  if ((daqEventTypeString == "ERROR") || (daqEventTypeString == "DAQ_EVENT_TYPE_ERROR") ||
547  (daqEventTypeString == "Error")) {
548  return DAQ_EVENT_TYPE_ERROR;
549  }
550  //if it was none of the above then return invalid
551  return DAQ_EVENT_TYPE_INVALID;
552  }
553 
554  void FEDStatusRegister::printFlags(std::ostream& os) const {
555  if (slinkFullFlag())
556  os << "SLINK_FULL ";
558  os << "HEADER_MONITOR_READY ";
559  if (qdrMemoryFullFlag())
560  os << "QDR_FULL ";
562  os << "QDR_PARTIAL_FULL ";
563  if (qdrMemoryEmptyFlag())
564  os << "QDR_EMPTY ";
565  if (l1aBxFIFOFullFlag())
566  os << "L1A_FULL ";
568  os << "L1A_PARTIAL_FULL ";
569  if (l1aBxFIFOEmptyFlag())
570  os << "L1A_EMPTY ";
571  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
572  if (feDataMissingFlag(iFE))
573  os << "FEUNIT" << uint16_t(iFE) << "MISSING ";
574  }
575  }
576 
578  uint8_t result(0x00);
579  if (qdrMemoryFullFlag())
583  if (qdrMemoryEmptyFlag())
585  return FEDBufferState(result);
586  }
587 
589  uint8_t result(0x00);
590  if (l1aBxFIFOFullFlag())
594  if (l1aBxFIFOEmptyFlag())
596  return FEDBufferState(result);
597  }
598 
599  void FEDStatusRegister::setBit(const uint8_t num, const bool bitSet) {
600  const uint16_t mask = (0x0001 << num);
601  if (bitSet)
602  data_ |= mask;
603  else
604  data_ &= (~mask);
605  }
606 
608  switch (state) {
609  case BUFFER_STATE_FULL:
611  case BUFFER_STATE_EMPTY:
612  case BUFFER_STATE_UNSET:
613  break;
614  default:
615  std::ostringstream ss;
616  ss << "Invalid buffer state: ";
617  printHex(&state, 1, ss);
618  throw cms::Exception("FEDBuffer") << ss.str();
619  }
623  return *this;
624  }
625 
627  switch (state) {
628  case BUFFER_STATE_FULL:
630  case BUFFER_STATE_EMPTY:
631  case BUFFER_STATE_UNSET:
632  break;
633  default:
634  std::ostringstream ss;
635  ss << "Invalid buffer state: ";
636  printHex(&state, 1, ss);
637  throw cms::Exception("FEDBuffer") << ss.str();
638  }
642  return *this;
643  }
644 
645  void FEDBackendStatusRegister::printFlags(std::ostream& os) const {
646  if (internalFreezeFlag())
647  os << "INTERNAL_FREEZE ";
648  if (slinkDownFlag())
649  os << "SLINK_DOWN ";
650  if (slinkFullFlag())
651  os << "SLINK_FULL ";
652  if (backpressureFlag())
653  os << "BACKPRESSURE ";
654  if (ttcReadyFlag())
655  os << "TTC_READY ";
657  os << "HEADER_MONITOR_READY ";
658  printFlagsForBuffer(qdrMemoryState(), "QDR", os);
659  printFlagsForBuffer(frameAddressFIFOState(), "FRAME_ADDRESS", os);
660  printFlagsForBuffer(totalLengthFIFOState(), "TOTAL_LENGTH", os);
661  printFlagsForBuffer(trackerHeaderFIFOState(), "TRACKER_HEADER", os);
662  printFlagsForBuffer(l1aBxFIFOState(), "L1ABX", os);
663  printFlagsForBuffer(feEventLengthFIFOState(), "FE_LENGTH", os);
665  }
666 
668  const std::string name,
669  std::ostream& os) const {
670  if (bufferState & BUFFER_STATE_EMPTY)
671  os << name << "_EMPTY ";
672  if (bufferState & BUFFER_STATE_PARTIAL_FULL)
673  os << name << "_PARTIAL_FULL ";
674  if (bufferState & BUFFER_STATE_FULL)
675  os << name << "_FULL ";
676  if (bufferState == BUFFER_STATE_UNSET)
677  os << name << "_UNSET ";
678  }
679 
680  FEDBufferState FEDBackendStatusRegister::getBufferState(const uint8_t bufferPosition) const {
681  uint8_t result = 0x00;
682  if (getBit(bufferPosition + STATE_OFFSET_EMPTY))
684  if (getBit(bufferPosition + STATE_OFFSET_PARTIAL_FULL))
686  if (getBit(bufferPosition + STATE_OFFSET_FULL))
688  return FEDBufferState(result);
689  }
690 
691  void FEDBackendStatusRegister::setBufferSate(const uint8_t bufferPosition, const FEDBufferState state) {
692  switch (state) {
693  case BUFFER_STATE_FULL:
695  case BUFFER_STATE_EMPTY:
696  case BUFFER_STATE_UNSET:
697  break;
698  default:
699  std::ostringstream ss;
700  ss << "Invalid buffer state: ";
701  printHex(&state, 1, ss);
702  throw cms::Exception("FEDBuffer") << ss.str();
703  }
704  setBit(bufferPosition + STATE_OFFSET_EMPTY, state & BUFFER_STATE_EMPTY);
706  setBit(bufferPosition + STATE_OFFSET_FULL, state & BUFFER_STATE_FULL);
707  }
708 
709  void FEDBackendStatusRegister::setBit(const uint8_t num, const bool bitSet) {
710  const uint32_t mask = (0x00000001 << num);
711  if (bitSet)
712  data_ |= mask;
713  else
714  data_ &= (~mask);
715  }
716 
718  const FEDBufferState frameAddressFIFOBufferState,
719  const FEDBufferState totalLengthFIFOBufferState,
720  const FEDBufferState trackerHeaderFIFOBufferState,
721  const FEDBufferState l1aBxFIFOBufferState,
722  const FEDBufferState feEventLengthFIFOBufferState,
723  const FEDBufferState feFPGABufferState,
724  const bool backpressure,
725  const bool slinkFull,
726  const bool slinkDown,
727  const bool internalFreeze,
728  const bool trackerHeaderMonitorDataReady,
729  const bool ttcReady)
730  : data_(0) {
731  setInternalFreezeFlag(internalFreeze);
732  setSLinkDownFlag(slinkDown);
733  setSLinkFullFlag(slinkFull);
734  setBackpressureFlag(backpressure);
735  setTTCReadyFlag(ttcReady);
736  setTrackerHeaderMonitorDataReadyFlag(trackerHeaderMonitorDataReady);
737  setQDRMemoryState(qdrMemoryBufferState);
738  setFrameAddressFIFOState(frameAddressFIFOBufferState);
739  setTotalLengthFIFOState(totalLengthFIFOBufferState);
740  setTrackerHeaderFIFOState(trackerHeaderFIFOBufferState);
741  setL1ABXFIFOState(l1aBxFIFOBufferState);
742  setFEEventLengthFIFOState(feEventLengthFIFOBufferState);
744  }
745 
746  TrackerSpecialHeader::TrackerSpecialHeader(const uint8_t* headerPointer) {
747  //the buffer format byte is one of the valid values if we assume the buffer is not swapped
748  const bool validFormatByteWhenNotWordSwapped = ((headerPointer[BUFFERFORMAT] == BUFFER_FORMAT_CODE_NEW) ||
749  (headerPointer[BUFFERFORMAT] == BUFFER_FORMAT_CODE_OLD));
750  //the buffer format byte is the old value if we assume the buffer is swapped
751  const bool validFormatByteWhenWordSwapped = (headerPointer[BUFFERFORMAT ^ 4] == BUFFER_FORMAT_CODE_OLD);
752  //if the buffer format byte is valid if the buffer is not swapped or it is never valid
753  if (validFormatByteWhenNotWordSwapped || (!validFormatByteWhenNotWordSwapped && !validFormatByteWhenWordSwapped)) {
754  memcpy(specialHeader_, headerPointer, 8);
755  wordSwapped_ = false;
756  } else {
757  memcpy(specialHeader_, headerPointer + 4, 4);
758  memcpy(specialHeader_ + 4, headerPointer, 4);
759  wordSwapped_ = true;
760  }
761  }
762 
765  return BUFFER_FORMAT_NEW;
767  if (wordSwapped_)
768  return BUFFER_FORMAT_OLD_VME;
769  else
771  } else
772  return BUFFER_FORMAT_INVALID;
773  }
774 
776  const uint8_t eventTypeNibble = trackerEventTypeNibble();
777  const uint8_t mode = (eventTypeNibble & 0xF);
778  switch (mode) {
787  return FEDLegacyReadoutMode(mode);
788  default:
790  }
791  }
792 
794  //check if order in buffer is different
795  if (((bufferFormat() == BUFFER_FORMAT_OLD_VME) && (newBufferFormat != BUFFER_FORMAT_OLD_VME)) ||
796  ((bufferFormat() != BUFFER_FORMAT_OLD_VME) && (newBufferFormat == BUFFER_FORMAT_OLD_VME))) {
798  }
799  //set appropriate code
800  setBufferFormatByte(newBufferFormat);
801  return *this;
802  }
803 
805  switch (newBufferFormat) {
809  break;
810  case BUFFER_FORMAT_NEW:
812  break;
813  default:
814  std::ostringstream ss;
815  ss << "Invalid buffer format: ";
816  printHex(&newBufferFormat, 1, ss);
817  throw cms::Exception("FEDBuffer") << ss.str();
818  }
819  }
820 
822  switch (headerType) {
825  case HEADER_TYPE_NONE:
827  return *this;
828  default:
829  std::ostringstream ss;
830  ss << "Invalid header type: ";
831  printHex(&headerType, 1, ss);
832  throw cms::Exception("FEDBuffer") << ss.str();
833  }
834  }
835 
837  switch (readoutMode) {
838  case READOUT_MODE_SCOPE:
841  case READOUT_MODE_SPY:
854  break;
855  default:
856  std::ostringstream ss;
857  ss << "Invalid readout mode: ";
858  printHex(&readoutMode, 1, ss);
859  throw cms::Exception("FEDBuffer") << ss.str();
860  }
861  return *this;
862  }
863 
865  const bool error) {
866  const uint8_t mask = 0x1 << internalFEUnitNum;
867  const uint8_t result = ((apvAddressErrorRegister() & (~mask)) | (error ? mask : 0x00));
869  return *this;
870  }
871 
873  const bool enabled) {
874  const uint8_t mask = 0x1 << internalFEUnitNum;
875  const uint8_t result = ((feEnableRegister() & (~mask)) | (enabled ? mask : 0x00));
877  return *this;
878  }
879 
881  const bool overflow) {
882  const uint8_t mask = 0x1 << internalFEUnitNum;
883  const uint8_t result = ((feOverflowRegister() & (~mask)) | (overflow ? mask : 0x00));
885  return *this;
886  }
887 
889  const FEDReadoutMode readoutMode,
890  const FEDHeaderType headerType,
891  const uint8_t address,
892  const uint8_t addressErrorRegister,
893  const uint8_t feEnableRegister,
894  const uint8_t feOverflowRegister,
895  const FEDStatusRegister fedStatusRegister) {
896  memset(specialHeader_, 0x00, 8);
897  //determine if order is swapped in real buffer
899  //set fields
903  setAPVEAddress(address);
904  setAPVEAddressErrorRegister(addressErrorRegister);
908  }
909 
911  switch (eventTypeNibble()) {
914  case DAQ_EVENT_TYPE_TEST:
920  default:
921  return DAQ_EVENT_TYPE_INVALID;
922  }
923  }
924 
926  header_[7] = ((header_[7] & 0xF0) | evtType);
927  return *this;
928  }
929 
930  FEDDAQHeader& FEDDAQHeader::setL1ID(const uint32_t l1ID) {
931  header_[4] = (l1ID & 0x000000FF);
932  header_[5] = ((l1ID & 0x0000FF00) >> 8);
933  header_[6] = ((l1ID & 0x00FF0000) >> 16);
934  return *this;
935  }
936 
937  FEDDAQHeader& FEDDAQHeader::setBXID(const uint16_t bxID) {
938  header_[3] = ((bxID & 0x0FF0) >> 4);
939  header_[2] = ((header_[2] & 0x0F) | ((bxID & 0x000F) << 4));
940  return *this;
941  }
942 
943  FEDDAQHeader& FEDDAQHeader::setSourceID(const uint16_t sourceID) {
944  header_[2] = ((header_[2] & 0xF0) | ((sourceID & 0x0F00) >> 8));
945  header_[1] = (sourceID & 0x00FF);
946  return *this;
947  }
948 
949  FEDDAQHeader::FEDDAQHeader(const uint32_t l1ID,
950  const uint16_t bxID,
951  const uint16_t sourceID,
952  const FEDDAQEventType evtType) {
953  //clear everything (FOV,H,x,$ all set to 0)
954  memset(header_, 0x0, 8);
955  //set the BoE nibble to indicate this is the last fragment
956  header_[7] = 0x50;
957  //set variable fields vith values supplied
958  setEventType(evtType);
959  setL1ID(l1ID);
960  setBXID(bxID);
962  }
963 
965  switch (ttsNibble()) {
966  case TTS_DISCONNECTED0:
967  case TTS_WARN_OVERFLOW:
968  case TTS_OUT_OF_SYNC:
969  case TTS_BUSY:
970  case TTS_READY:
971  case TTS_ERROR:
972  case TTS_DISCONNECTED1:
973  return FEDTTSBits(ttsNibble());
974  default:
975  return TTS_INVALID;
976  }
977  }
978 
979  FEDDAQTrailer::FEDDAQTrailer(const uint32_t eventLengthIn64BitWords,
980  const uint16_t crc,
981  const FEDTTSBits ttsBits,
982  const bool slinkTransmissionError,
983  const bool badFEDID,
984  const bool slinkCRCError,
985  const uint8_t eventStatusNibble) {
986  //clear everything (T,x,$ all set to 0)
987  memset(trailer_, 0x0, 8);
988  //set the EoE nibble to indicate this is the last fragment
989  trailer_[7] = 0xA0;
990  //set variable fields vith values supplied
994  setCRC(crc);
996  setBadSourceIDBit(badFEDID);
998  }
999 
1000  FEDDAQTrailer& FEDDAQTrailer::setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords) {
1001  trailer_[4] = (eventLengthIn64BitWords & 0x000000FF);
1002  trailer_[5] = ((eventLengthIn64BitWords & 0x0000FF00) >> 8);
1003  trailer_[6] = ((eventLengthIn64BitWords & 0x00FF0000) >> 16);
1004  return *this;
1005  }
1006 
1007  FEDDAQTrailer& FEDDAQTrailer::setCRC(const uint16_t crc) {
1008  trailer_[2] = (crc & 0x00FF);
1009  trailer_[3] = ((crc >> 8) & 0x00FF);
1010  return *this;
1011  }
1012 
1014  if (bitSet)
1015  trailer_[1] |= 0x80;
1016  else
1017  trailer_[1] &= (~0x80);
1018  return *this;
1019  }
1020 
1022  if (bitSet)
1023  trailer_[1] |= 0x40;
1024  else
1025  trailer_[1] &= (~0x40);
1026  return *this;
1027  }
1028 
1030  if (bitSet)
1031  trailer_[0] |= 0x04;
1032  else
1033  trailer_[0] &= (~0x40);
1034  return *this;
1035  }
1036 
1037  FEDDAQTrailer& FEDDAQTrailer::setEventStatusNibble(const uint8_t eventStatusNibble) {
1038  trailer_[1] = ((trailer_[1] & 0xF0) | (eventStatusNibble & 0x0F));
1039  return *this;
1040  }
1041 
1043  trailer_[0] = ((trailer_[0] & 0x0F) | (ttsBits & 0xF0));
1044  return *this;
1045  }
1046 
1048 
1050 
1052 
1054 
1055  bool FEDAPVErrorHeader::checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const {
1056  //3 bytes per FE unit, channel order is reversed in FE unit data, 2 bits per channel
1057  const uint16_t bitNumber = (internalFEDChannelNum / FEDCH_PER_FEUNIT) * 24 +
1058  (FEDCH_PER_FEUNIT - 1 - (internalFEDChannelNum % FEDCH_PER_FEUNIT)) * 2 + apvNum;
1059  //bit high means no error
1060  return (header_[bitNumber / 8] & (0x01 << (bitNumber % 8)));
1061  }
1062 
1065  }
1066 
1067  const uint8_t* FEDAPVErrorHeader::data() const { return header_; }
1068 
1069  FEDAPVErrorHeader::FEDAPVErrorHeader(const std::vector<bool>& apvsGood) {
1070  memset(header_, 0x00, APV_ERROR_HEADER_SIZE_IN_BYTES);
1071  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
1072  setAPVStatusBit(iCh, 0, apvsGood[iCh * 2]);
1073  setAPVStatusBit(iCh, 1, apvsGood[iCh * 2 + 1]);
1074  }
1075  }
1076 
1078  const uint8_t apvNum,
1079  const bool apvGood) {
1080  //3 bytes per FE unit, channel order is reversed in FE unit data, 2 bits per channel
1081  const uint16_t bitNumber = (internalFEDChannelNum / FEDCH_PER_FED) * 24 +
1082  (FEDCH_PER_FED - 1 - (internalFEDChannelNum % FEDCH_PER_FED)) * 2 + apvNum;
1083  const uint8_t byteNumber = bitNumber / 8;
1084  const uint8_t bitInByte = bitNumber % 8;
1085  const uint8_t mask = (0x01 << bitInByte);
1086  header_[byteNumber] = ((header_[byteNumber] & (~mask)) | (apvGood ? mask : 0x00));
1087  return *this;
1088  }
1089 
1091  //if channel is unlocked then set both APV bits bad
1095  return;
1096  } else {
1099  } else {
1101  }
1104  } else {
1106  }
1107  }
1108  }
1109 
1110  //These methods do nothing as the values in question are in present in the APV Error header.
1111  //The methods exist so that users of the base class can set the values without caring which type of header they have and so if they are needed.
1112  void FEDAPVErrorHeader::setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) { return; }
1113  void FEDAPVErrorHeader::setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister) { return; }
1114  void FEDAPVErrorHeader::setDAQRegister(const uint32_t daqRegister) { return; }
1115  void FEDAPVErrorHeader::setDAQRegister2(const uint32_t daqRegister2) { return; }
1116  void FEDAPVErrorHeader::set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) {
1117  return;
1118  }
1119  void FEDAPVErrorHeader::setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) { return; }
1120 
1122 
1124 
1126 
1128 
1129  bool FEDFullDebugHeader::checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const {
1132  }
1133 
1135  //return ( !unlockedFromBit(internalFEDChannelNum) &&
1136  // !outOfSyncFromBit(internalFEDChannelNum) &&
1137  // !apvErrorFromBit(internalFEDChannelNum,0) &&
1138  // !apvAddressErrorFromBit(internalFEDChannelNum,0) &&
1139  // !apvErrorFromBit(internalFEDChannelNum,1) &&
1140  // !apvAddressErrorFromBit(internalFEDChannelNum,1) );
1142  }
1143 
1145  const uint8_t* pFEWord = feWord(internalFEDChannelNum / FEDCH_PER_FEUNIT);
1146  const uint8_t feUnitChanNum = internalFEDChannelNum % FEDCH_PER_FEUNIT;
1147  const uint8_t startByteInFEWord = (FEDCH_PER_FEUNIT - 1 - feUnitChanNum) * 6 / 8;
1148  switch ((FEDCH_PER_FEUNIT - 1 - feUnitChanNum) % 4) {
1149  case 0:
1150  return FEDChannelStatus(pFEWord[startByteInFEWord] & 0x3F);
1151  case 1:
1152  return FEDChannelStatus(((pFEWord[startByteInFEWord] & 0xC0) >> 6) |
1153  ((pFEWord[startByteInFEWord + 1] & 0x0F) << 2));
1154  case 2:
1155  return FEDChannelStatus(((pFEWord[startByteInFEWord] & 0xF0) >> 4) |
1156  ((pFEWord[startByteInFEWord + 1] & 0x03) << 4));
1157  case 3:
1158  return FEDChannelStatus((pFEWord[startByteInFEWord] & 0xFC) >> 2);
1159  //stop compiler warning
1160  default:
1161  return FEDChannelStatus(0);
1162  }
1163  /*const uint8_t feUnitChanNum = internalFEDChannelNum / FEDCH_PER_FEUNIT;
1164  const uint8_t* pFEWord = feWord(feUnitChanNum);
1165  const uint8_t startByteInFEWord = feUnitChanNum * 3 / 4;
1166  //const uint8_t shift = ( 6 - ((feUnitChanNum-1)%4) );
1167  //const uint16_t mask = ( 0x003F << shift );
1168  //uint8_t result = ( (pFEWord[startByteInFEWord] & (mask&0x00FF)) >> shift );
1169  //result |= ( (pFEWord[startByteInFEWord+1] & (mask>>8)) << (8-shift) );
1170  switch (feUnitChanNum % 4) {
1171  case 0:
1172  return FEDChannelStatus( pFEWord[startByteInFEWord] & 0x3F );
1173  case 1:
1174  return FEDChannelStatus( ((pFEWord[startByteInFEWord] & 0xC0) >> 6) | ((pFEWord[startByteInFEWord+1] & 0x0F) << 2) );
1175  case 2:
1176  return FEDChannelStatus( ((pFEWord[startByteInFEWord] & 0xF0) >> 4) | ((pFEWord[startByteInFEWord+1] & 0x03) << 4) );
1177  case 3:
1178  return FEDChannelStatus( (pFEWord[startByteInFEWord] & 0xFC) >> 2 );
1179  //stop compiler warning
1180  default:
1181  return FEDChannelStatus(0);
1182  }*/
1183  }
1184 
1185  const uint8_t* FEDFullDebugHeader::data() const { return header_; }
1186 
1187  FEDFullDebugHeader::FEDFullDebugHeader(const std::vector<uint16_t>& feUnitLengths,
1188  const std::vector<uint8_t>& feMajorityAddresses,
1189  const std::vector<FEDChannelStatus>& channelStatus,
1190  const FEDBackendStatusRegister beStatusRegister,
1191  const uint32_t daqRegister,
1192  const uint32_t daqRegister2) {
1197  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
1198  setFEUnitLength(iFE, feUnitLengths[iFE]);
1199  setFEUnitMajorityAddress(iFE, feMajorityAddresses[iFE]);
1200  }
1201  for (uint8_t iCh = 0; iCh < FEDCH_PER_FED; iCh++) {
1202  setChannelStatus(iCh, channelStatus[iCh]);
1203  }
1204  }
1205 
1213  }
1214 
1215  void FEDFullDebugHeader::setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) {
1216  feWord(internalFEUnitNum)[9] = address;
1217  }
1218 
1221  }
1222 
1223  void FEDFullDebugHeader::setDAQRegister(const uint32_t daqRegister) { set32BitWordAt(feWord(7) + 10, daqRegister); }
1224 
1225  void FEDFullDebugHeader::setDAQRegister2(const uint32_t daqRegister2) {
1227  }
1228 
1229  //used by DigiToRaw to copy reserved registers in internalFEUnit buffers 1 through 5
1230  void FEDFullDebugHeader::set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) {
1231  set32BitWordAt(feWord(internalFEUnitNum) + 10, reservedRegister);
1232  }
1233 
1234  void FEDFullDebugHeader::setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) {
1235  feWord(internalFEUnitNum)[15] = ((length & 0xFF00) >> 8);
1236  feWord(internalFEUnitNum)[14] = (length & 0x00FF);
1237  }
1238 
1239  void FEDFullDebugHeader::setBit(const uint8_t internalFEDChannelNum, const uint8_t bit, const bool value) {
1240  const uint8_t bitInFeWord = (FEDCH_PER_FEUNIT - 1 - (internalFEDChannelNum % FEDCH_PER_FEUNIT)) * 6 + bit;
1241  uint8_t& byte = *(feWord(internalFEDChannelNum / FEDCH_PER_FEUNIT) + (bitInFeWord / 8));
1242  const uint8_t mask = (0x1 << bitInFeWord % 8);
1243  byte = ((byte & (~mask)) | (value ? mask : 0x0));
1244  }
1245 
1247 
1249  : channels_(FEDCH_PER_FED, FEDChannel(nullptr, 0, 0)),
1250  originalBuffer_(fedBuffer.data()),
1251  bufferSize_(fedBuffer.size()) {
1252  init();
1253  }
1254 
1255  FEDBufferBase::FEDBufferBase(const FEDRawData& fedBuffer, const bool fillChannelVector)
1256  : originalBuffer_(fedBuffer.data()), bufferSize_(fedBuffer.size()) {
1257  init();
1258  if (fillChannelVector)
1259  channels_.assign(FEDCH_PER_FED, FEDChannel(nullptr, 0, 0));
1260  }
1261 
1263  //construct tracker special header using second 64 bit word
1265 
1266  //check the buffer format
1268  //swap the buffer words so that the whole buffer is in slink ordering
1270  uint8_t* newBuffer = new uint8_t[bufferSize_];
1271  const uint32_t* originalU32 = reinterpret_cast<const uint32_t*>(originalBuffer_);
1272  const size_t sizeU32 = bufferSize_ / 4;
1273  uint32_t* newU32 = reinterpret_cast<uint32_t*>(newBuffer);
1275  //swap whole buffer
1276  for (size_t i = 0; i < sizeU32; i += 2) {
1277  newU32[i] = originalU32[i + 1];
1278  newU32[i + 1] = originalU32[i];
1279  }
1280  }
1282  //copy DAQ header
1283  memcpy(newU32, originalU32, 8);
1284  //copy DAQ trailer
1285  memcpy(newU32 + sizeU32 - 2, originalU32 + sizeU32 - 2, 8);
1286  //swap the payload
1287  for (size_t i = 2; i < sizeU32 - 2; i += 2) {
1288  newU32[i] = originalU32[i + 1];
1289  newU32[i + 1] = originalU32[i];
1290  }
1291  }
1292  orderedBuffer_ = newBuffer;
1293  } //if ( (bufferFormat == BUFFER_FORMAT_OLD_VME) || (bufferFormat == BUFFER_FORMAT_NEW) )
1294  else {
1296  }
1297 
1298  //construct header object at begining of buffer
1300  //construct trailer object using last 64 bit word of buffer
1302  }
1303 
1305  //if the buffer was coppied and swapped then delete the copy
1307  delete[] orderedBuffer_;
1308  }
1309 
1310  void FEDBufferBase::print(std::ostream& os) const {
1311  os << "buffer format: " << bufferFormat() << std::endl;
1312  os << "Buffer size: " << bufferSize() << " bytes" << std::endl;
1313  os << "Event length from DAQ trailer: " << daqEventLengthInBytes() << " bytes" << std::endl;
1314  os << "Source ID: " << daqSourceID() << std::endl;
1315  os << "Header type: " << headerType() << std::endl;
1316  os << "Readout mode: " << readoutMode() << std::endl;
1317  os << "DAQ event type: " << daqEventType() << std::endl;
1318  os << "TTS state: " << daqTTSState() << std::endl;
1319  os << "L1 ID: " << daqLvl1ID() << std::endl;
1320  os << "BX ID: " << daqBXID() << std::endl;
1321  os << "FED status register flags: ";
1323  os << std::endl;
1324  os << "APVe Address: " << uint16_t(apveAddress()) << std::endl;
1325  os << "Enabled FE units: " << uint16_t(nFEUnitsEnabled()) << std::endl;
1326  }
1327 
1329  uint8_t result = 0;
1330  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
1331  if (feEnabled(iFE))
1332  result++;
1333  }
1334  return result;
1335  }
1336 
1338  return ((daqSourceID() >= FED_ID_MIN) && (daqSourceID() <= FED_ID_MAX));
1339  }
1340 
1342  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
1343  if (!feEnabled(iFE))
1344  continue;
1346  return false;
1347  }
1348  return true;
1349  }
1350 
1352  const uint8_t feUnit = internalFEDChannelNum / FEDCH_PER_FEUNIT;
1353  return (!majorityAddressErrorForFEUnit(feUnit) && feEnabled(feUnit) && !feOverflow(feUnit));
1354  }
1355 
1357  std::ostringstream summary;
1358  summary << "Check buffer type valid: " << (checkBufferFormat() ? "passed" : "FAILED") << std::endl;
1359  summary << "Check header format valid: " << (checkHeaderType() ? "passed" : "FAILED") << std::endl;
1360  summary << "Check readout mode valid: " << (checkReadoutMode() ? "passed" : "FAILED") << std::endl;
1361  //summary << "Check APVe address valid: " << ( checkAPVEAddressValid() ? "passed" : "FAILED" ) << std::endl;
1362  summary << "Check FE unit majority addresses: " << (checkMajorityAddresses() ? "passed" : "FAILED") << std::endl;
1363  if (!checkMajorityAddresses()) {
1364  summary << "FEs with majority address error: ";
1365  unsigned int badFEs = 0;
1366  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
1367  if (!feEnabled(iFE))
1368  continue;
1369  if (majorityAddressErrorForFEUnit(iFE)) {
1370  summary << uint16_t(iFE) << " ";
1371  badFEs++;
1372  }
1373  }
1374  summary << std::endl;
1375  summary << "Number of FE Units with bad addresses: " << badFEs << std::endl;
1376  }
1377  summary << "Check for FE unit buffer overflows: " << (checkNoFEOverflows() ? "passed" : "FAILED") << std::endl;
1378  if (!checkNoFEOverflows()) {
1379  summary << "FEs which overflowed: ";
1380  unsigned int badFEs = 0;
1381  for (uint8_t iFE = 0; iFE < FEUNITS_PER_FED; iFE++) {
1382  if (feOverflow(iFE)) {
1383  summary << uint16_t(iFE) << " ";
1384  badFEs++;
1385  }
1386  }
1387  summary << std::endl;
1388  summary << "Number of FE Units which overflowed: " << badFEs << std::endl;
1389  }
1390  summary << "Check for S-Link CRC errors: " << (checkNoSlinkCRCError() ? "passed" : "FAILED") << std::endl;
1391  summary << "Check for S-Link transmission error: " << (checkNoSLinkTransmissionError() ? "passed" : "FAILED")
1392  << std::endl;
1393  summary << "Check CRC: " << (checkCRC() ? "passed" : "FAILED") << std::endl;
1394  summary << "Check source ID is FED ID: " << (checkSourceIDs() ? "passed" : "FAILED") << std::endl;
1395  summary << "Check for unexpected source ID at FRL: " << (checkNoUnexpectedSourceID() ? "passed" : "FAILED")
1396  << std::endl;
1397  summary << "Check there are no extra headers or trailers: "
1398  << (checkNoExtraHeadersOrTrailers() ? "passed" : "FAILED") << std::endl;
1399  summary << "Check length from trailer: " << (checkLengthFromTrailer() ? "passed" : "FAILED") << std::endl;
1400  return summary.str();
1401  }
1402 } // namespace sistrip
FEDBufferFormat bufferFormat() const
FEDBackendStatusRegister & setFEFPGABufferState(const FEDBufferState state)
FEDBackendStatusRegister & setQDRMemoryState(const FEDBufferState state)
FEDReadoutMode readoutMode() const
size
Write out results.
FEDBackendStatusRegister & setL1ABXFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT
bool feOverflow(const uint8_t internalFEUnitNum) const
void setDAQRegister2(const uint32_t daqRegister2) override
static const size_t APV_ERROR_HEADER_SIZE_IN_BYTES
void printHexValue(const uint8_t value, std::ostream &os)
void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) override
void setBit(const uint8_t num, const bool bitSet)
static const uint16_t FED_ID_MIN
void setOutOfSync(const uint8_t internalFEDChannelNum, const bool value)
FEDBackendStatusRegister beStatusRegister() const
void setQDRMemoryEmptyFlag(const bool bitSet)
void setDAQRegister2(const uint32_t daqRegister2) override
void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) override
FEDBackendStatusRegister & setFrameAddressFIFOState(const FEDBufferState state)
TrackerSpecialHeader & setFEOverflowRegister(const uint8_t feOverflowRegister)
static const uint8_t PACKET_CODE_SCOPE
FEDBackendStatusRegister & setTrackerHeaderFIFOState(const FEDBufferState state)
FEDFullDebugHeader(const uint8_t *headerBuffer)
T w() const
static const uint8_t PACKET_CODE_PROC_RAW10
FEDDAQTrailer & setSLinkCRCErrorBit(const bool bitSet)
FEDDAQTrailer & setTTSBits(const FEDTTSBits ttsBits)
void setAPVError(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool value)
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
bool checkChannelStatusBits(const uint8_t internalFEDChannelNum) const override
TrackerSpecialHeader & setAPVEAddress(const uint8_t address)
FEDDAQTrailer & setSLinkTransmissionErrorBit(const bool bitSet)
FEDHeaderType fedHeaderTypeFromString(const std::string &headerTypeString)
bool checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const override
TrackerSpecialHeader & setBufferFormat(const FEDBufferFormat newBufferFormat)
uint16_t calculateFEDBufferCRC(const uint8_t *buffer, const size_t lengthInBytes)
void print(std::ostream &os) const override
void printFlagsForBuffer(const FEDBufferState bufferState, const std::string name, std::ostream &os) const
void setDAQRegister(const uint32_t daqRegister) override
void setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister) override
uint8_t packetCodeFromString(const std::string &packetCodeString, FEDReadoutMode mode)
virtual std::string checkSummary() const
std::ostream & operator<<(std::ostream &os, const FEDBufferFormat &value)
bool checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const override
FEDAPVErrorHeader(const uint8_t *headerBuffer)
FEDBufferFormat fedBufferFormatFromString(const std::string &bufferFormatString)
void setBit(const uint8_t num, const bool bitSet)
sistrip classes
constexpr bool enabled
Definition: SoACommon.h:71
constexpr uint32_t mask
Definition: gpuClustering.h:26
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
TrackerSpecialHeader & setHeaderType(const FEDHeaderType headerType)
bool feEnabled(const uint8_t internalFEUnitNum) const
bool feDataMissingFlag(const uint8_t internalFEUnitNum) const
FEDReadoutMode fedReadoutModeFromString(const std::string &readoutModeString)
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
FEDBackendStatusRegister(const uint32_t backendStatusRegister)
static const uint8_t PACKET_CODE_VIRGIN_RAW10
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED
FEDBackendStatusRegister & setTotalLengthFIFOState(const FEDBufferState state)
TrackerSpecialHeader & setFEEnableForFEUnit(const uint8_t internalFEUnitNum, const bool enabled)
FEDDAQTrailer & setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords)
FEDDAQTrailer & setEventStatusNibble(const uint8_t eventStatusNibble)
void setUnlocked(const uint8_t internalFEDChannelNum, const bool value)
FEDBackendStatusRegister & setTTCReadyFlag(const bool bitSet)
FEDDAQTrailer & setCRC(const uint16_t crc)
TrackerSpecialHeader & setAPVEAddressErrorRegister(const uint8_t addressErrorRegister)
TrackerSpecialHeader & setFEDStatusRegister(const FEDStatusRegister fedStatusRegister)
TrackerSpecialHeader & setAPVAddressErrorForFEUnit(const uint8_t internalFEUnitNum, const bool error)
FEDStatusRegister & setL1ABXFIFOBufferState(const FEDBufferState state)
FEDAPVErrorHeader & setAPVStatusBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool apvGood)
void setDAQRegister(const uint32_t daqRegister) override
static const uint16_t FEUNITS_PER_FED
void setQDRMemoryFullFlag(const bool bitSet)
FEDAPVErrorHeader * clone() const override
FEDDAQEventType daqEventType() const
FEDBufferState getBufferState(const uint8_t bufferPosition) const
void setL1ABXFIFOFullFlag(const bool bitSet)
static const uint8_t BUFFER_FORMAT_CODE_NEW
bool apvError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const
void setAPVAddressError(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool value)
FEDStatusRegister fedStatusRegister() const
Definition: value.py:1
void setL1ABXFIFOPartialFullFlag(const bool bitSet)
void setHeaderTypeNibble(const uint8_t value)
void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) override
static const uint8_t PACKET_CODE_VIRGIN_RAW8_TOPBOT
void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) override
FEDDAQEventType fedDAQEventTypeFromString(const std::string &daqEventTypeString)
uint8_t * feWord(const uint8_t internalFEUnitNum)
std::vector< FEDChannel > channels_
void setBufferFormatByte(const FEDBufferFormat newBufferFormat)
void print(std::ostream &os) const override
FEDDAQTrailer & setBadSourceIDBit(const bool bitSet)
FEDBufferBase(const FEDRawData &fedBuffer)
static const size_t FULL_DEBUG_HEADER_SIZE_IN_BYTES
static const uint8_t PACKET_CODE_PROC_RAW
static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT
void printHex(const void *pointer, const size_t length, std::ostream &os)
void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) override
static const uint16_t FEDCH_PER_FEUNIT
void setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister) override
bool checkChannelStatusBits(const uint8_t internalFEDChannelNum) const override
FEDBackendStatusRegister & setTrackerHeaderMonitorDataReadyFlag(const bool bitSet)
void setReadoutModeBits(const uint8_t value)
FEDDAQHeader & setEventType(const FEDDAQEventType evtType)
FEDDAQHeader & setL1ID(const uint32_t l1ID)
unsigned short compute_crc_8bit(unsigned short crc, unsigned char data)
Definition: CRC16.h:56
void setChannelStatus(const uint8_t internalFEDChannelNum, const FEDChannelStatus status) override
FEDBackendStatusRegister & setSLinkFullFlag(const bool bitSet)
FEDDAQHeader & setSourceID(const uint16_t sourceID)
const uint8_t * data() const override
void setBufferSate(const uint8_t bufferPosition, const FEDBufferState state)
FEDLegacyReadoutMode legacyReadoutMode() const
uint8_t header_[FULL_DEBUG_HEADER_SIZE_IN_BYTES]
TrackerSpecialHeader specialHeader_
virtual bool channelGood(const uint8_t internalFEDChannelNum) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static const uint16_t FEDCH_PER_FED
TrackerSpecialHeader & setFEOverflowForFEUnit(const uint8_t internalFEUnitNum, const bool overflow)
void printFlags(std::ostream &os) const
FEDStatusRegister fedStatusRegister() const
const uint8_t * data() const override
FEDBackendStatusRegister & setFEEventLengthFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_PROC_RAW8_BOTBOT
void printHexWord(const uint8_t *pointer, const size_t lengthInBytes, std::ostream &os)
static const uint16_t FED_ID_MAX
FEDDAQHeader & setBXID(const uint16_t bxID)
static const uint8_t BUFFER_FORMAT_CODE_OLD
FEDChannelStatus getChannelStatus(const uint8_t internalFEDChannelNum) const
void setBit(const uint8_t internalFEDChannelNum, const uint8_t bit, const bool value)
FEDStatusRegister & setQDRMemoryBufferState(const FEDBufferState state)
FEDDAQEventType eventType() const
bool apvAddressError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const
static void set32BitWordAt(uint8_t *startOfWord, const uint32_t value)
uint8_t header_[APV_ERROR_HEADER_SIZE_IN_BYTES]
bool unlockedFromBit(const uint8_t internalFEDChannelNum) const
FEDBackendStatusRegister & setInternalFreezeFlag(const bool bitSet)
FEDFullDebugHeader * clone() const override
static const uint8_t PACKET_CODE_PROC_RAW8_TOPBOT
void setL1ABXFIFOEmptyFlag(const bool bitSet)
FEDBackendStatusRegister & setBackpressureFlag(const bool bitSet)
static const uint8_t PACKET_CODE_VIRGIN_RAW
TrackerSpecialHeader & setReadoutMode(const FEDReadoutMode readoutMode)
bool outOfSyncFromBit(const uint8_t internalFEDChannelNum) const
void setChannelStatus(const uint8_t internalFEDChannelNum, const FEDChannelStatus status) override
void setQDRMemoryPartialFullFlag(const bool bitSet)
FEDBackendStatusRegister & setSLinkDownFlag(const bool bitSet)
TrackerSpecialHeader & setFEEnableRegister(const uint8_t feEnableRegister)
void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) override
virtual void print(std::ostream &os) const