CMS 3D CMS Logo

SiStripFEDBufferComponents.h
Go to the documentation of this file.
1 #ifndef EventFilter_SiStripRawToDigi_SiStripFEDBufferComponents_H
2 #define EventFilter_SiStripRawToDigi_SiStripFEDBufferComponents_H
3 
4 #include <ostream>
5 #include <memory>
6 #include <cstring>
7 #include <vector>
12 #include <cstdint>
13 
14 namespace sistrip {
15 
16  //
17  // Constants
18  //
19 
20  static const uint8_t INVALID = 0xFF;
21 
22  static const uint8_t APV_MAX_ADDRESS = 192;
23 
24  static const uint16_t SCOPE_MODE_MAX_SCOPE_LENGTH = 1022;
25 
31  };
32  //these are the values which appear in the buffer.
33  static const uint8_t BUFFER_FORMAT_CODE_OLD = 0xED;
34  static const uint8_t BUFFER_FORMAT_CODE_NEW = 0xC5;
35 
36  //enum values are values which appear in buffer. DO NOT CHANGE!
41  HEADER_TYPE_NONE = 4 //spy channel
42  };
43 
44  //enum values are values which appear in buffer. DO NOT CHANGE!
62  };
63 
77  };
78 
79  static const uint8_t PACKET_CODE_SCOPE = 0xE1;
80  static const uint8_t PACKET_CODE_VIRGIN_RAW = 0xE6;
81  static const uint8_t PACKET_CODE_VIRGIN_RAW10 = 0x86;
82  static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT = 0xC6; //FIXME need to implement this!
83  static const uint8_t PACKET_CODE_VIRGIN_RAW8_TOPBOT = 0xA6;
84  static const uint8_t PACKET_CODE_PROC_RAW = 0xF2;
85  static const uint8_t PACKET_CODE_PROC_RAW10 = 0x92; //FIXME need to implement this!
86  static const uint8_t PACKET_CODE_PROC_RAW8_BOTBOT = 0xCA;
87  static const uint8_t PACKET_CODE_PROC_RAW8_TOPBOT = 0xB2;
88  static const uint8_t PACKET_CODE_ZERO_SUPPRESSED = 0xEA;
89  static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10 = 0x8A;
90  static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT = 0xCA;
91  static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_TOPBOT = 0xAA;
92 
93  //enum values are values which appear in buffer. DO NOT CHANGE!
94  //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
104  };
105 
106  //enum values are values which appear in buffer. DO NOT CHANGE!
107  //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
108  enum FEDTTSBits {
112  TTS_BUSY = 0x4,
113  TTS_READY = 0x8,
114  TTS_ERROR = 0x12,
117  };
118 
119  //enum values are values which appear in buffer. DO NOT CHANGE!
125  };
126 
127  //enum values are values which appear in buffer. DO NOT CHANGE!
138  };
139 
140  enum class FEDBufferStatusCode {
141  // for FEDBufferBase
142  SUCCESS = 0,
143  BUFFER_NULL,
146  // for FEDBuffer and FEDSpyBuffer
148  EXPECT_SPY,
149  // for FEDBuffer
154  };
155 
156  //
157  // Global function declarations
158  //
159 
160  //used by these classes
161  uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum);
162  void printHex(const void* pointer, const size_t length, std::ostream& os);
163  //calculate the CRC for a FED buffer
164  uint16_t calculateFEDBufferCRC(const uint8_t* buffer, const size_t lengthInBytes);
165  //to make enums printable
166  std::ostream& operator<<(std::ostream& os, const FEDBufferFormat& value);
167  std::ostream& operator<<(std::ostream& os, const FEDHeaderType& value);
168  std::ostream& operator<<(std::ostream& os, const FEDLegacyReadoutMode& value);
169  std::ostream& operator<<(std::ostream& os, const FEDReadoutMode& value);
170  std::ostream& operator<<(std::ostream& os, const FEDDAQEventType& value);
171  std::ostream& operator<<(std::ostream& os, const FEDTTSBits& value);
172  std::ostream& operator<<(std::ostream& os, const FEDBufferState& value);
173  std::ostream& operator<<(std::ostream& os, const FEDChannelStatus& value);
174  std::ostream& operator<<(std::ostream& os, const FEDBufferStatusCode& value);
175  //convert name of an element of enum to enum value (useful for getting values from config)
176  FEDBufferFormat fedBufferFormatFromString(const std::string& bufferFormatString);
177  FEDHeaderType fedHeaderTypeFromString(const std::string& headerTypeString);
178  FEDReadoutMode fedReadoutModeFromString(const std::string& readoutModeString);
179  uint8_t packetCodeFromString(const std::string& packetCodeString, FEDReadoutMode mode);
180  FEDDAQEventType fedDAQEventTypeFromString(const std::string& daqEventTypeString);
181 
182  //
183  // Class definitions
184  //
185 
186  //handles conversion between order of data in buffer in VR/PR modes (readout order) and strip order (physical order)
188  public:
189  //convert strip/sample index in channel (ie 0-255) between physical and readout order
190  static uint8_t physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel);
191  static uint8_t readoutOrderForStripInChannel(const uint8_t physicalOrderStripIndexInChannel);
192  //convert strip/sample index in APV (ie 0-127) between physical and readout order
193  static uint8_t physicalOrderForStripInAPV(const uint8_t readoutOrderStripIndexInAPV);
194  static uint8_t readoutOrderForStripInAPV(const uint8_t physicalOrderStripIndexInAPV);
195  };
196 
197  //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
198  class FEDDAQHeader {
199  public:
201  explicit FEDDAQHeader(const uint8_t* header);
202  //0x5 in first fragment
203  uint8_t boeNibble() const;
204  uint8_t eventTypeNibble() const;
205  FEDDAQEventType eventType() const;
206  uint32_t l1ID() const;
207  uint16_t bxID() const;
208  uint16_t sourceID() const;
209  uint8_t version() const;
210  //0 if current header word is last, 1 otherwise
211  bool hBit() const;
212  bool lastHeader() const;
213  void print(std::ostream& os) const;
214  //used by digi2Raw
215  const uint8_t* data() const;
216  FEDDAQHeader& setEventType(const FEDDAQEventType evtType);
217  FEDDAQHeader& setL1ID(const uint32_t l1ID);
218  FEDDAQHeader& setBXID(const uint16_t bxID);
219  FEDDAQHeader& setSourceID(const uint16_t sourceID);
220  FEDDAQHeader(const uint32_t l1ID,
221  const uint16_t bxID,
222  const uint16_t sourceID,
223  const FEDDAQEventType evtType = DAQ_EVENT_TYPE_PHYSICS);
224 
225  private:
226  uint8_t header_[8];
227  };
228 
229  //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
231  public:
233  explicit FEDDAQTrailer(const uint8_t* trailer);
234  //0xA in first fragment
235  uint8_t eoeNibble() const;
236  uint32_t eventLengthIn64BitWords() const;
237  uint32_t eventLengthInBytes() const;
238  uint16_t crc() const;
239  //set to 1 if FRL detects a transmission error over S-link
240  bool cBit() const;
241  bool slinkTransmissionError() const { return cBit(); }
242  //set to 1 if the FED ID is not the one expected by the FRL
243  bool fBit() const;
244  bool badSourceID() const { return fBit(); }
245  uint8_t eventStatusNibble() const;
246  uint8_t ttsNibble() const;
247  FEDTTSBits ttsBits() const;
248  //0 if the current trailer is the last, 1 otherwise
249  bool tBit() const;
250  bool lastTrailer() const { return !tBit(); }
251  //set to 1 if the S-link sender card detects a CRC error (the CRC it computes is put in the CRC field)
252  bool rBit() const;
253  bool slinkCRCError() const { return rBit(); }
254  void print(std::ostream& os) const;
255  //used by digi2Raw
256  const uint8_t* data() const;
258  FEDDAQTrailer& setCRC(const uint16_t crc);
259  FEDDAQTrailer& setSLinkTransmissionErrorBit(const bool bitSet);
260  FEDDAQTrailer& setBadSourceIDBit(const bool bitSet);
261  FEDDAQTrailer& setSLinkCRCErrorBit(const bool bitSet);
264  FEDDAQTrailer(const uint32_t eventLengthIn64BitWords,
265  const uint16_t crc = 0,
266  const FEDTTSBits ttsBits = TTS_READY,
267  const bool slinkTransmissionError = false,
268  const bool badFEDID = false,
269  const bool slinkCRCError = false,
270  const uint8_t eventStatusNibble = 0);
271 
272  private:
273  uint8_t trailer_[8];
274  };
275 
277  public:
278  FEDStatusRegister(const uint16_t fedStatusRegister);
279  bool slinkFullFlag() const;
281  bool qdrMemoryFullFlag() const;
282  bool qdrMemoryPartialFullFlag() const;
283  bool qdrMemoryEmptyFlag() const;
284  bool l1aBxFIFOFullFlag() const;
285  bool l1aBxFIFOPartialFullFlag() const;
286  bool l1aBxFIFOEmptyFlag() const;
289  bool feDataMissingFlag(const uint8_t internalFEUnitNum) const;
290  void print(std::ostream& os) const;
291  void printFlags(std::ostream& os) const;
292  operator uint16_t() const;
293  //used by digi2Raw
294  FEDStatusRegister& setSLinkFullFlag(const bool bitSet);
298  FEDStatusRegister(const FEDBufferState qdrMemoryBufferState = BUFFER_STATE_UNSET,
299  const FEDBufferState l1aBxFIFOBufferState = BUFFER_STATE_UNSET,
300  const bool trackerHeaderMonitorDataReadyFlagSet = false,
301  const bool slinkFullFlagSet = false);
302 
303  private:
304  bool getBit(const uint8_t num) const;
305  void setBit(const uint8_t num, const bool bitSet);
306  void setQDRMemoryFullFlag(const bool bitSet);
307  void setQDRMemoryPartialFullFlag(const bool bitSet);
308  void setQDRMemoryEmptyFlag(const bool bitSet);
309  void setL1ABXFIFOFullFlag(const bool bitSet);
310  void setL1ABXFIFOPartialFullFlag(const bool bitSet);
311  void setL1ABXFIFOEmptyFlag(const bool bitSet);
312  uint16_t data_;
313  };
314 
316  public:
318  //construct with a pointer to the data. The data will be coppied and swapped if necessary.
319  explicit TrackerSpecialHeader(const uint8_t* headerPointer);
320  uint8_t bufferFormatByte() const;
322  uint8_t headerTypeNibble() const;
323  FEDHeaderType headerType() const;
324  uint8_t trackerEventTypeNibble() const;
325  FEDReadoutMode readoutMode() const;
327  uint8_t apveAddress() const;
328  uint8_t apvAddressErrorRegister() const;
329  bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const;
330  uint8_t feEnableRegister() const;
331  bool feEnabled(const uint8_t internalFEUnitNum) const;
332  uint8_t feOverflowRegister() const;
333  bool feOverflow(const uint8_t internalFEUnitNum) const;
334  uint16_t fedStatusRegisterWord() const;
336  void print(std::ostream& os) const;
337  //used by digi2Raw
338  //returns ordered buffer (ie this may need to be swapped to get original order)
339  const uint8_t* data() const;
340  bool wasSwapped() const;
341  TrackerSpecialHeader& setBufferFormat(const FEDBufferFormat newBufferFormat);
344  TrackerSpecialHeader& setAPVEAddress(const uint8_t address);
345  TrackerSpecialHeader& setAPVEAddressErrorRegister(const uint8_t addressErrorRegister);
346  TrackerSpecialHeader& setAPVAddressErrorForFEUnit(const uint8_t internalFEUnitNum, const bool error);
348  TrackerSpecialHeader& setFEEnableForFEUnit(const uint8_t internalFEUnitNum, const bool enabled);
350  TrackerSpecialHeader& setFEOverflowForFEUnit(const uint8_t internalFEUnitNum, const bool overflow);
355  const uint8_t address = 0x00,
356  const uint8_t addressErrorRegister = 0x00,
357  const uint8_t feEnableRegister = 0xFF,
358  const uint8_t feOverflowRegister = 0x00,
360 
361  // detect the buffer format without constructing the full header
362  static FEDBufferFormat bufferFormat(const uint8_t* headerPointer) {
363  if (headerPointer[BUFFERFORMAT] == BUFFER_FORMAT_CODE_NEW) {
364  return BUFFER_FORMAT_NEW;
365  } else if (headerPointer[BUFFERFORMAT] == BUFFER_FORMAT_CODE_OLD) {
367  } else if (headerPointer[BUFFERFORMAT ^ 4] == BUFFER_FORMAT_CODE_OLD) {
368  // same case as used to detect "wordSwapped_" in the constructor
369  return BUFFER_FORMAT_OLD_VME;
370  } else {
371  return BUFFER_FORMAT_INVALID;
372  }
373  }
374 
375  private:
376  void setBufferFormatByte(const FEDBufferFormat newBufferFormat);
377  void setHeaderTypeNibble(const uint8_t value);
378  void setReadoutModeBits(const uint8_t value);
382  FEENABLE = 3,
387  };
388  //copy of header, 32 bit word swapped if needed
389  uint8_t specialHeader_[8];
390  //was the header word swapped wrt order in buffer?
392  };
393 
395  public:
396  FEDBackendStatusRegister(const uint32_t backendStatusRegister);
397  bool internalFreezeFlag() const;
398  bool slinkDownFlag() const;
399  bool slinkFullFlag() const;
400  bool backpressureFlag() const;
401  bool ttcReadyFlag() const;
410  void print(std::ostream& os) const;
411  void printFlags(std::ostream& os) const;
412  operator uint32_t() const;
413  //used by digi2Raw
415  FEDBackendStatusRegister& setSLinkDownFlag(const bool bitSet);
416  FEDBackendStatusRegister& setSLinkFullFlag(const bool bitSet);
417  FEDBackendStatusRegister& setBackpressureFlag(const bool bitSet);
418  FEDBackendStatusRegister& setTTCReadyFlag(const bool bitSet);
427  FEDBackendStatusRegister(const FEDBufferState qdrMemoryBufferState = BUFFER_STATE_UNSET,
428  const FEDBufferState frameAddressFIFOBufferState = BUFFER_STATE_UNSET,
429  const FEDBufferState totalLengthFIFOBufferState = BUFFER_STATE_UNSET,
430  const FEDBufferState trackerHeaderFIFOBufferState = BUFFER_STATE_UNSET,
431  const FEDBufferState l1aBxFIFOBufferState = BUFFER_STATE_UNSET,
432  const FEDBufferState feEventLengthFIFOBufferState = BUFFER_STATE_UNSET,
434  const bool backpressure = false,
435  const bool slinkFull = false,
436  const bool slinkDown = false,
437  const bool internalFreeze = false,
438  const bool trackerHeaderMonitorDataReady = false,
439  const bool ttcReady = true);
440 
441  private:
442  bool getBit(const uint8_t num) const;
443  void setBit(const uint8_t num, const bool bitSet);
444  //get the state of the buffer in position 'bufferPosition'
445  FEDBufferState getBufferState(const uint8_t bufferPosition) const;
446  //set the state of the buffer in position 'bufferPosition' to state 'state'
447  void setBufferSate(const uint8_t bufferPosition, const FEDBufferState state);
448  void printFlagsForBuffer(const FEDBufferState bufferState, const std::string name, std::ostream& os) const;
449  //constants marking order of flags in buffer
450  //eg. bit offset for L1A/BX FIFO Partial full flag is STATE_OFFSET_PARTIAL_FULL+BUFFER_POSITION_L1ABX_FIFO
451  // bit offset for total length FIFO empty flag is STATE_OFFSET_EMPTY+BUFFER_POSITION_TOTAL_LENGTH_FIFO
452  //see BE FPGA technical description
461  };
463  uint32_t data_;
464  };
465 
466  class FEDFEHeader {
467  public:
468  //factory function: allocates new FEDFEHeader derrivative of appropriate type
469  static std::unique_ptr<FEDFEHeader> newFEHeader(const FEDHeaderType headerType, const uint8_t* headerBuffer);
470  //used by digi2Raw
471  static std::unique_ptr<FEDFEHeader> newFEHeader(const FEDHeaderType headerType);
472  //create a buffer to use with digi2Raw
473  static std::unique_ptr<FEDFEHeader> newFEFakeHeader(const FEDHeaderType headerType);
474  virtual ~FEDFEHeader();
475  //the length of the header
476  virtual size_t lengthInBytes() const = 0;
477  //check that there are no errors indicated in which ever error bits are available in the header
478  //check bits for both APVs on a channel
479  bool checkChannelStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum) const;
480  virtual bool checkChannelStatusBits(const uint8_t internalFEDChannelNum) const = 0;
481  //check bits for one APV
482  bool checkStatusBits(const uint8_t internalFEUnitNum,
483  const uint8_t internalFEUnitChannelNum,
484  const uint8_t apvNum) const;
485  virtual bool checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const = 0;
486  virtual void print(std::ostream& os) const = 0;
487  virtual FEDFEHeader* clone() const = 0;
488  //used by digi2Raw
489  virtual const uint8_t* data() const = 0;
490  virtual void setChannelStatus(const uint8_t internalFEDChannelNum, const FEDChannelStatus status) = 0;
491  virtual void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) = 0;
492  virtual void setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister) = 0;
493  virtual void setDAQRegister(const uint32_t daqRegister) = 0;
494  virtual void setDAQRegister2(const uint32_t daqRegister2) = 0;
495  virtual void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) = 0;
496  virtual void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) = 0;
497  void setChannelStatus(const uint8_t internalFEUnitNum,
498  const uint8_t internalFEUnitChannelNum,
499  const FEDChannelStatus status);
500  };
501 
502  class FEDAPVErrorHeader final : public FEDFEHeader {
503  public:
504  explicit FEDAPVErrorHeader(const uint8_t* headerBuffer);
505  ~FEDAPVErrorHeader() override;
506  size_t lengthInBytes() const override;
507  bool checkChannelStatusBits(const uint8_t internalFEDChannelNum) const override;
508  bool checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const override;
509  void print(std::ostream& os) const override;
510  FEDAPVErrorHeader* clone() const override;
511  //used by digi2Raw
512  const uint8_t* data() const override;
513  FEDAPVErrorHeader& setAPVStatusBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool apvGood);
514  FEDAPVErrorHeader& setAPVStatusBit(const uint8_t internalFEUnitNum,
515  const uint8_t internalFEUnitChannelNum,
516  const uint8_t apvNum,
517  const bool apvGood);
518  FEDAPVErrorHeader(const std::vector<bool>& apvsGood = std::vector<bool>(APVS_PER_FED, true));
519  //Information which is not present in APVError mode is allowed to be set here so that the methods can be called on the base class without caring
520  //if the values need to be set.
521  void setChannelStatus(const uint8_t internalFEDChannelNum, const FEDChannelStatus status) override;
522  void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) override;
523  void setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister) override;
524  void setDAQRegister(const uint32_t daqRegister) override;
525  void setDAQRegister2(const uint32_t daqRegister2) override;
526  void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) override;
527  void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) override;
528 
529  private:
530  static const size_t APV_ERROR_HEADER_SIZE_IN_64BIT_WORDS = 3;
533  };
534 
535  class FEDFullDebugHeader final : public FEDFEHeader {
536  public:
537  explicit FEDFullDebugHeader(const uint8_t* headerBuffer);
538  ~FEDFullDebugHeader() override;
539  size_t lengthInBytes() const override;
540  bool checkChannelStatusBits(const uint8_t internalFEDChannelNum) const override;
541  bool checkStatusBits(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const override;
542  void print(std::ostream& os) const override;
543  FEDFullDebugHeader* clone() const override;
544 
545  uint8_t feUnitMajorityAddress(const uint8_t internalFEUnitNum) const;
547  uint32_t daqRegister() const;
548  uint32_t daqRegister2() const;
549  uint16_t feUnitLength(const uint8_t internalFEUnitNum) const;
550  bool fePresent(const uint8_t internalFEUnitNum) const;
551 
553  FEDChannelStatus getChannelStatus(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum) const;
554 
555  //These methods return true if there was an error of the appropriate type (ie if the error bit is 0).
556  //They return false if the error could not occur due to a more general error.
557  //was channel unlocked
558  bool unlocked(const uint8_t internalFEDChannelNum) const;
559  bool unlocked(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum) const;
560  //was channel out of sync if it was unlocked
561  bool outOfSync(const uint8_t internalFEDChannelNum) const;
562  bool outOfSync(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum) const;
563  //was there an internal APV error if it was in sync
564  bool apvError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const;
565  bool apvError(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum, const uint8_t apvNum) const;
566  //was the APV address wrong if it was in sync (does not depend on APV internal error bit)
567  bool apvAddressError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const;
568  bool apvAddressError(const uint8_t internalFEUnitNum,
569  const uint8_t internalFEUnitChannelNum,
570  const uint8_t apvNum) const;
571 
572  //used by digi2Raw
573  const uint8_t* data() const override;
574  void setChannelStatus(const uint8_t internalFEDChannelNum, const FEDChannelStatus status) override;
575  void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) override;
577  void setDAQRegister(const uint32_t daqRegister) override;
578  void setDAQRegister2(const uint32_t daqRegister2) override;
579  void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) override;
580  void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) override;
581  static uint32_t get32BitWordFrom(const uint8_t* startOfWord);
582  uint8_t* feWord(const uint8_t internalFEUnitNum);
583  const uint8_t* feWord(const uint8_t internalFEUnitNum) const;
584  FEDFullDebugHeader(const std::vector<uint16_t>& feUnitLengths = std::vector<uint16_t>(FEUNITS_PER_FED, 0),
585  const std::vector<uint8_t>& feMajorityAddresses = std::vector<uint8_t>(FEUNITS_PER_FED, 0),
586  const std::vector<FEDChannelStatus>& channelStatus =
587  std::vector<FEDChannelStatus>(FEDCH_PER_FED, CHANNEL_STATUS_NO_PROBLEMS),
589  const uint32_t daqRegister = 0,
590  const uint32_t daqRegister2 = 0);
591 
592  private:
593  bool getBit(const uint8_t internalFEDChannelNum, const uint8_t bit) const;
594  static void set32BitWordAt(uint8_t* startOfWord, const uint32_t value);
595  void setBit(const uint8_t internalFEDChannelNum, const uint8_t bit, const bool value);
596 
597  //These methods return true if there was an error of the appropriate type (ie if the error bit is 0).
598  //They ignore any previous errors which make the status bits meaningless and return the value of the bit anyway.
599  //In general, the methods above which only return an error for the likely cause are more useful.
600  bool unlockedFromBit(const uint8_t internalFEDChannelNum) const;
601  bool outOfSyncFromBit(const uint8_t internalFEDChannelNum) const;
602  bool apvErrorFromBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const;
603  bool apvAddressErrorFromBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const;
604 
605  //following methods set the bits to 1 (no error) if value is false
606  void setUnlocked(const uint8_t internalFEDChannelNum, const bool value);
607  void setOutOfSync(const uint8_t internalFEDChannelNum, const bool value);
608  void setAPVAddressError(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool value);
609  void setAPVError(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool value);
613  };
614 
615  //holds information about position of a channel in the buffer for use by unpacker
616  class FEDChannel {
617  public:
618  FEDChannel(const uint8_t* const data, const uint32_t offset, const uint16_t length);
619  //gets length from first 2 bytes (assuming normal FED channel)
620  FEDChannel(const uint8_t* const data, const uint32_t offset);
621  uint16_t length() const;
622  const uint8_t* data() const;
623  uint32_t offset() const;
631  uint16_t cmMedian(const uint8_t apvIndex) const;
632  //third byte of channel data for normal FED channels
633  uint8_t packetCode() const;
634 
635  private:
636  friend class FEDBuffer;
637  const uint8_t* data_;
638  uint32_t offset_;
639  uint16_t length_;
640  };
641 
642  //base class for sistrip FED buffers which have a DAQ header/trailer and tracker special header
644  public:
653  explicit FEDBufferBase(const FEDRawData& fedBuffer);
654  virtual ~FEDBufferBase();
655  //dump buffer to stream
656  void dump(std::ostream& os) const;
657  //dump original buffer before word swapping
658  void dumpOriginalBuffer(std::ostream& os) const;
659  virtual void print(std::ostream& os) const;
660  //calculate the CRC from the buffer
661  uint16_t calcCRC() const;
662 
663  //methods to get parts of the buffer
664  FEDDAQHeader daqHeader() const;
665  FEDDAQTrailer daqTrailer() const;
666  size_t bufferSize() const;
668  //methods to get info from DAQ header
670  uint32_t daqLvl1ID() const;
671  uint16_t daqBXID() const;
672  uint16_t daqSourceID() const;
673  uint16_t sourceID() const;
674  //methods to get info from DAQ trailer
675  uint32_t daqEventLengthIn64bitWords() const;
676  uint32_t daqEventLengthInBytes() const;
677  uint16_t daqCRC() const;
678  FEDTTSBits daqTTSState() const;
679  //methods to get info from the tracker special header
681  FEDHeaderType headerType() const;
683  FEDReadoutMode readoutMode() const;
684  uint8_t packetCode(bool legacy = false, const uint8_t internalFEDChannelNum = 0) const;
685  uint8_t apveAddress() const;
686  bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const;
687  bool feEnabled(const uint8_t internalFEUnitNum) const;
688  uint8_t nFEUnitsEnabled() const;
689  bool feOverflow(const uint8_t internalFEUnitNum) const;
691 
692  //check that channel has no errors
693  virtual bool channelGood(const uint8_t internalFEDChannelNum) const;
694  bool channelGood(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const;
695  //return channel object for channel
696  const FEDChannel& channel(const uint8_t internalFEDChannelNum) const;
697  const FEDChannel& channel(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const;
698 
699  //summary checks
700  //check that tracker special header is valid (does not check for FE unit errors indicated in special header)
701  bool doTrackerSpecialHeaderChecks() const;
702  //check for errors in DAQ heaqder and trailer (not including bad CRC)
703  bool doDAQHeaderAndTrailerChecks() const;
704  //do both
705  bool doChecks() const;
706  //print the result of all detailed checks
707  virtual std::string checkSummary() const;
708 
709  //detailed checks
710  bool checkCRC() const;
711  bool checkMajorityAddresses() const;
712  //methods to check tracker special header
713  bool checkBufferFormat() const;
714  bool checkHeaderType() const;
715  bool checkReadoutMode() const;
716  bool checkAPVEAddressValid() const;
717  bool checkNoFEOverflows() const;
718  //methods to check daq header and trailer
719  bool checkNoSlinkCRCError() const;
720  bool checkNoSLinkTransmissionError() const;
721  bool checkSourceIDs() const;
722  bool checkNoUnexpectedSourceID() const;
723  bool checkNoExtraHeadersOrTrailers() const;
724  bool checkLengthFromTrailer() const;
725 
726  protected:
727  const uint8_t* getPointerToDataAfterTrackerSpecialHeader() const;
728  const uint8_t* getPointerToByteAfterEndOfPayload() const;
729  FEDBufferBase(const FEDRawData& fedBuffer, const bool fillChannelVector);
730  std::vector<FEDChannel> channels_;
731 
732  private:
733  void init();
734  const uint8_t* originalBuffer_;
735  const uint8_t* orderedBuffer_;
736  const size_t bufferSize_;
740  };
741 
742  //
743  // Inline function definitions
744  //
745 
758  bool checkRecognizedFormat = true) {
759  if (!fedBuffer.data())
761  //min buffer length. DAQ header, DAQ trailer, tracker special header.
762  static const size_t MIN_BUFFER_SIZE = 8 + 8 + 8;
763  //check size is non zero
764  if (fedBuffer.size() < MIN_BUFFER_SIZE) {
765  LogDebug("FEDBuffer") << "Buffer is too small. Min size is " << MIN_BUFFER_SIZE << ". Buffer size is "
766  << fedBuffer.size() << ". ";
768  }
769  if (checkRecognizedFormat) {
771  LogDebug("FEDBuffer") << "Buffer format not recognized. Tracker special header: "
772  << TrackerSpecialHeader(fedBuffer.data() + 8);
774  }
775  }
777  }
778 
779  inline std::ostream& operator<<(std::ostream& os, const FEDBufferBase& obj) {
780  obj.print(os);
781  os << obj.checkSummary();
782  return os;
783  }
784 
785  inline uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum) {
786  return (internalFEUnitNum * FEDCH_PER_FEUNIT + internalFEUnitChannelNum);
787  }
788 
789  inline std::ostream& operator<<(std::ostream& os, const FEDDAQHeader& obj) {
790  obj.print(os);
791  return os;
792  }
793  inline std::ostream& operator<<(std::ostream& os, const FEDDAQTrailer& obj) {
794  obj.print(os);
795  return os;
796  }
797  inline std::ostream& operator<<(std::ostream& os, const TrackerSpecialHeader& obj) {
798  obj.print(os);
799  return os;
800  }
801  inline std::ostream& operator<<(std::ostream& os, const FEDStatusRegister& obj) {
802  obj.print(os);
803  return os;
804  }
805  inline std::ostream& operator<<(std::ostream& os, const FEDFEHeader& obj) {
806  obj.print(os);
807  return os;
808  }
809 
810  //FEDStripOrdering
811 
812  inline uint8_t FEDStripOrdering::physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel) {
813  return physicalOrderForStripInAPV(readoutOrderStripIndexInChannel / 2) +
814  (readoutOrderStripIndexInChannel % 2) * STRIPS_PER_APV;
815  }
816 
817  inline uint8_t FEDStripOrdering::readoutOrderForStripInChannel(const uint8_t physicalOrderStripIndexInChannel) {
818  return (readoutOrderForStripInAPV(physicalOrderStripIndexInChannel % 128) * 2 +
819  (physicalOrderStripIndexInChannel / 128));
820  }
821 
822  inline uint8_t FEDStripOrdering::physicalOrderForStripInAPV(const uint8_t readout_order) {
823  return ((32 * (readout_order % 4)) + (8 * static_cast<uint16_t>(static_cast<float>(readout_order) / 4.0)) -
824  (31 * static_cast<uint16_t>(static_cast<float>(readout_order) / 16.0)));
825  }
826 
827  inline uint8_t FEDStripOrdering::readoutOrderForStripInAPV(const uint8_t physical_order) {
828  return (4 * ((static_cast<uint16_t>((static_cast<float>(physical_order) / 8.0))) % 4) +
829  static_cast<uint16_t>(static_cast<float>(physical_order) / 32.0) + 16 * (physical_order % 8));
830  }
831 
832  //TrackerSpecialHeader
833 
835 
837 
838  inline uint8_t TrackerSpecialHeader::headerTypeNibble() const { return ((specialHeader_[BUFFERTYPE] & 0xF0) >> 4); }
839 
841  const auto nibble = headerTypeNibble();
842  switch (nibble) {
845  case HEADER_TYPE_NONE:
846  return FEDHeaderType(nibble);
847  default:
848  return HEADER_TYPE_INVALID;
849  }
850  }
851 
852  inline uint8_t TrackerSpecialHeader::trackerEventTypeNibble() const { return (specialHeader_[BUFFERTYPE] & 0x0F); }
853 
855  const auto nibble = trackerEventTypeNibble();
856  //if it is scope mode then return as is (it cannot be fake data)
857  //if it is premix then return as is: stripping last bit would make it spy data !
858  if ((nibble == READOUT_MODE_SCOPE) || (nibble == READOUT_MODE_PREMIX_RAW)) // 0x or 0xf
859  return FEDReadoutMode(nibble);
860  //if not then ignore the last bit which indicates if it is real or fake
861  else {
862  const uint8_t mode = (nibble & 0xF);
863  switch (mode) {
869  //case READOUT_MODE_ZERO_SUPPRESSED_CMOVERRIDE:
877  case READOUT_MODE_SPY:
878  return FEDReadoutMode(mode);
879  default:
880  return READOUT_MODE_INVALID;
881  }
882  }
883  }
884 
886 
888 
889  inline bool TrackerSpecialHeader::majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const {
890  return (!(readoutMode() == READOUT_MODE_SCOPE) && !((0x1 << internalFEUnitNum) & apvAddressErrorRegister()));
891  }
892 
894 
895  inline bool TrackerSpecialHeader::feEnabled(const uint8_t internalFEUnitNum) const {
896  return ((0x1 << internalFEUnitNum) & feEnableRegister());
897  }
898 
900 
901  inline bool TrackerSpecialHeader::feOverflow(const uint8_t internalFEUnitNum) const {
902  return ((0x1 << internalFEUnitNum) & feOverflowRegister());
903  }
904 
906  //get 16 bits
907  uint16_t statusRegister = ((specialHeader_[(FEDSTATUS + 1)] << 8) | specialHeader_[FEDSTATUS]);
908  return statusRegister;
909  }
910 
913  }
914 
915  inline void TrackerSpecialHeader::print(std::ostream& os) const { printHex(specialHeader_, 8, os); }
916 
917  inline const uint8_t* TrackerSpecialHeader::data() const { return specialHeader_; }
918 
919  inline bool TrackerSpecialHeader::wasSwapped() const { return wordSwapped_; }
920 
922  specialHeader_[BUFFERTYPE] = ((specialHeader_[BUFFERTYPE] & 0x0F) | ((value << 4) & 0xF0));
923  }
924 
925  inline void TrackerSpecialHeader::setReadoutModeBits(const uint8_t value) {
926  specialHeader_[BUFFERTYPE] = ((specialHeader_[BUFFERTYPE] & (~0x0F)) | (value & 0x0F));
927  }
928 
930  specialHeader_[APVEADDRESS] = address;
931  return *this;
932  }
933 
934  inline TrackerSpecialHeader& TrackerSpecialHeader::setAPVEAddressErrorRegister(const uint8_t addressErrorRegister) {
935  specialHeader_[ADDRESSERROR] = addressErrorRegister;
936  return *this;
937  }
938 
939  inline TrackerSpecialHeader& TrackerSpecialHeader::setFEEnableRegister(const uint8_t feEnableRegister) {
941  return *this;
942  }
943 
944  inline TrackerSpecialHeader& TrackerSpecialHeader::setFEOverflowRegister(const uint8_t feOverflowRegister) {
946  return *this;
947  }
948 
950  specialHeader_[FEDSTATUS] = (static_cast<uint16_t>(fedStatusRegister) & 0x00FF);
951  specialHeader_[FEDSTATUS + 1] = ((static_cast<uint16_t>(fedStatusRegister) & 0xFF00) >> 8);
952  return *this;
953  }
954 
955  //FEDStatusRegister
956 
957  inline FEDStatusRegister::FEDStatusRegister(const uint16_t fedStatusRegister) : data_(fedStatusRegister) {}
958 
959  inline FEDStatusRegister::operator uint16_t() const { return data_; }
960 
961  inline bool FEDStatusRegister::getBit(const uint8_t num) const { return ((0x1 << num) & (data_)); }
962 
963  inline bool FEDStatusRegister::slinkFullFlag() const { return getBit(0); }
964 
966 
967  inline bool FEDStatusRegister::qdrMemoryFullFlag() const { return getBit(2); }
968 
969  inline bool FEDStatusRegister::qdrMemoryPartialFullFlag() const { return getBit(3); }
970 
971  inline bool FEDStatusRegister::qdrMemoryEmptyFlag() const { return getBit(4); }
972 
973  inline bool FEDStatusRegister::l1aBxFIFOFullFlag() const { return getBit(5); }
974 
975  inline bool FEDStatusRegister::l1aBxFIFOPartialFullFlag() const { return getBit(6); }
976 
977  inline bool FEDStatusRegister::l1aBxFIFOEmptyFlag() const { return getBit(7); }
978 
979  inline bool FEDStatusRegister::feDataMissingFlag(const uint8_t internalFEUnitNum) const {
980  return getBit(8 + internalFEUnitNum);
981  }
982 
983  inline void FEDStatusRegister::print(std::ostream& os) const { printHex(&data_, 2, os); }
984 
986  setBit(0, bitSet);
987  return *this;
988  }
989 
991  setBit(1, bitSet);
992  return *this;
993  }
994 
995  inline void FEDStatusRegister::setQDRMemoryFullFlag(const bool bitSet) { setBit(2, bitSet); }
996 
997  inline void FEDStatusRegister::setQDRMemoryPartialFullFlag(const bool bitSet) { setBit(3, bitSet); }
998 
999  inline void FEDStatusRegister::setQDRMemoryEmptyFlag(const bool bitSet) { setBit(4, bitSet); }
1000 
1001  inline void FEDStatusRegister::setL1ABXFIFOFullFlag(const bool bitSet) { setBit(5, bitSet); }
1002 
1003  inline void FEDStatusRegister::setL1ABXFIFOPartialFullFlag(const bool bitSet) { setBit(6, bitSet); }
1004 
1005  inline void FEDStatusRegister::setL1ABXFIFOEmptyFlag(const bool bitSet) { setBit(7, bitSet); }
1006 
1007  inline FEDStatusRegister::FEDStatusRegister(const FEDBufferState qdrMemoryBufferState,
1008  const FEDBufferState l1aBxFIFOBufferState,
1009  const bool trackerHeaderMonitorDataReadyFlagSet,
1010  const bool slinkFullFlagSet)
1011  : data_(0x0000) {
1012  setSLinkFullFlag(slinkFullFlagSet);
1013  setTrackerHeaderMonitorDataReadyFlag(trackerHeaderMonitorDataReadyFlagSet);
1014  setQDRMemoryBufferState(qdrMemoryBufferState);
1015  setL1ABXFIFOBufferState(l1aBxFIFOBufferState);
1016  }
1017 
1018  //FEDBackendStatusRegister
1019 
1020  inline FEDBackendStatusRegister::FEDBackendStatusRegister(const uint32_t backendStatusRegister)
1021  : data_(backendStatusRegister) {}
1022 
1023  inline FEDBackendStatusRegister::operator uint32_t() const { return data_; }
1024 
1025  inline void FEDBackendStatusRegister::print(std::ostream& os) const { printHex(&data_, 4, os); }
1026 
1027  inline bool FEDBackendStatusRegister::getBit(const uint8_t num) const { return ((0x1 << num) & (data_)); }
1028 
1029  inline bool FEDBackendStatusRegister::internalFreezeFlag() const { return getBit(1); }
1030 
1031  inline bool FEDBackendStatusRegister::slinkDownFlag() const { return getBit(2); }
1032 
1033  inline bool FEDBackendStatusRegister::slinkFullFlag() const { return getBit(3); }
1034 
1035  inline bool FEDBackendStatusRegister::backpressureFlag() const { return getBit(4); }
1036 
1037  inline bool FEDBackendStatusRegister::ttcReadyFlag() const { return getBit(6); }
1038 
1040 
1042  setBit(1, bitSet);
1043  return *this;
1044  }
1045 
1047  setBit(2, bitSet);
1048  return *this;
1049  }
1050 
1052  setBit(3, bitSet);
1053  return *this;
1054  }
1055 
1057  setBit(4, bitSet);
1058  return *this;
1059  }
1060 
1062  setBit(6, bitSet);
1063  return *this;
1064  }
1065 
1067  setBit(7, bitSet);
1068  return *this;
1069  }
1070 
1073  }
1074 
1077  }
1078 
1081  }
1082 
1085  }
1086 
1089  }
1090 
1093  }
1094 
1097  }
1098 
1101  return *this;
1102  }
1103 
1106  return *this;
1107  }
1108 
1111  return *this;
1112  }
1113 
1116  return *this;
1117  }
1118 
1121  return *this;
1122  }
1123 
1126  return *this;
1127  }
1128 
1131  return *this;
1132  }
1133 
1134  //FEDFEHeader
1135 
1136  inline std::unique_ptr<FEDFEHeader> FEDFEHeader::newFEHeader(const FEDHeaderType headerType,
1137  const uint8_t* headerBuffer) {
1138  switch (headerType) {
1140  return std::unique_ptr<FEDFEHeader>(new FEDFullDebugHeader(headerBuffer));
1141  case HEADER_TYPE_APV_ERROR:
1142  return std::unique_ptr<FEDFEHeader>(new FEDAPVErrorHeader(headerBuffer));
1143  default:
1144  return std::unique_ptr<FEDFEHeader>();
1145  }
1146  }
1147 
1148  inline std::unique_ptr<FEDFEHeader> FEDFEHeader::newFEHeader(const FEDHeaderType headerType) {
1149  switch (headerType) {
1151  return std::unique_ptr<FEDFEHeader>(new FEDFullDebugHeader());
1152  case HEADER_TYPE_APV_ERROR:
1153  return std::unique_ptr<FEDFEHeader>(new FEDAPVErrorHeader());
1154  default:
1155  return std::unique_ptr<FEDFEHeader>();
1156  }
1157  }
1158 
1159  inline std::unique_ptr<FEDFEHeader> FEDFEHeader::newFEFakeHeader(const FEDHeaderType headerType) {
1160  switch (headerType) {
1162  return std::unique_ptr<FEDFEHeader>(new FEDFullDebugHeader);
1163  case HEADER_TYPE_APV_ERROR:
1164  return std::unique_ptr<FEDFEHeader>(new FEDAPVErrorHeader);
1165  default:
1166  return std::unique_ptr<FEDFEHeader>();
1167  }
1168  }
1169 
1170  inline bool FEDFEHeader::checkChannelStatusBits(const uint8_t internalFEUnitNum,
1171  const uint8_t internalFEUnitChannelNum) const {
1172  return checkChannelStatusBits(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum));
1173  }
1174 
1175  inline bool FEDFEHeader::checkStatusBits(const uint8_t internalFEUnitNum,
1176  const uint8_t internalFEUnitChannelNum,
1177  const uint8_t apvNum) const {
1178  return checkStatusBits(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum), apvNum);
1179  }
1180 
1181  inline void FEDFEHeader::setChannelStatus(const uint8_t internalFEUnitNum,
1182  const uint8_t internalFEUnitChannelNum,
1183  const FEDChannelStatus status) {
1184  this->setChannelStatus(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum), status);
1185  }
1186 
1187  inline FEDAPVErrorHeader::FEDAPVErrorHeader(const uint8_t* headerBuffer) {
1188  memcpy(header_, headerBuffer, APV_ERROR_HEADER_SIZE_IN_BYTES);
1189  }
1190 
1191  inline FEDAPVErrorHeader& FEDAPVErrorHeader::setAPVStatusBit(const uint8_t internalFEUnitNum,
1192  const uint8_t internalFEUnitChannelNum,
1193  const uint8_t apvNum,
1194  const bool apvGood) {
1195  return setAPVStatusBit(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum), apvNum, apvGood);
1196  }
1197 
1198  inline FEDFullDebugHeader::FEDFullDebugHeader(const uint8_t* headerBuffer) {
1199  memcpy(header_, headerBuffer, FULL_DEBUG_HEADER_SIZE_IN_BYTES);
1200  }
1201 
1202  inline uint8_t FEDFullDebugHeader::feUnitMajorityAddress(const uint8_t internalFEUnitNum) const {
1203  return feWord(internalFEUnitNum)[9];
1204  }
1205 
1208  }
1209 
1210  inline uint32_t FEDFullDebugHeader::daqRegister() const { return get32BitWordFrom(feWord(7) + 10); }
1211 
1212  inline uint32_t FEDFullDebugHeader::daqRegister2() const { return get32BitWordFrom(feWord(6) + 10); }
1213 
1214  inline uint16_t FEDFullDebugHeader::feUnitLength(const uint8_t internalFEUnitNum) const {
1215  return ((feWord(internalFEUnitNum)[15] << 8) | (feWord(internalFEUnitNum)[14]));
1216  }
1217 
1218  inline bool FEDFullDebugHeader::fePresent(const uint8_t internalFEUnitNum) const {
1219  return (feUnitLength(internalFEUnitNum) != 0);
1220  }
1221 
1222  inline bool FEDFullDebugHeader::unlocked(const uint8_t internalFEDChannelNum) const {
1224  }
1225 
1226  inline bool FEDFullDebugHeader::unlocked(const uint8_t internalFEUnitNum,
1227  const uint8_t internalFEUnitChannelNum) const {
1228  return unlocked(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum));
1229  }
1230 
1231  inline bool FEDFullDebugHeader::outOfSync(const uint8_t internalFEDChannelNum) const {
1233  }
1234 
1235  inline bool FEDFullDebugHeader::outOfSync(const uint8_t internalFEUnitNum,
1236  const uint8_t internalFEUnitChannelNum) const {
1237  return outOfSync(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum));
1238  }
1239 
1240  inline bool FEDFullDebugHeader::apvError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const {
1243  }
1244 
1245  inline bool FEDFullDebugHeader::apvError(const uint8_t internalFEUnitNum,
1246  const uint8_t internalFEUnitChannelNum,
1247  const uint8_t apvNum) const {
1248  return apvError(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum), apvNum);
1249  }
1250 
1251  inline bool FEDFullDebugHeader::apvAddressError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const {
1254  }
1255 
1256  inline bool FEDFullDebugHeader::apvAddressError(const uint8_t internalFEUnitNum,
1257  const uint8_t internalFEUnitChannelNum,
1258  const uint8_t apvNum) const {
1259  return apvAddressError(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum), apvNum);
1260  }
1261 
1262  inline FEDChannelStatus FEDFullDebugHeader::getChannelStatus(const uint8_t internalFEUnitNum,
1263  const uint8_t internalFEUnitChannelNum) const {
1264  return getChannelStatus(internalFEDChannelNum(internalFEUnitNum, internalFEUnitChannelNum));
1265  }
1266 
1268  return !getBit(internalFEDChannelNum, 5);
1269  }
1270 
1272  return !getBit(internalFEDChannelNum, 4);
1273  }
1274 
1275  inline bool FEDFullDebugHeader::apvErrorFromBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const {
1276  //Discovered March 2012: two bits inverted in firmware. Decided
1277  //to update documentation but keep firmware identical for
1278  //backward compatibility. So status bit order is actually:
1279  //apvErr1 - apvAddrErr0 - apvErr0 - apvAddrErr1 - OOS - unlocked.
1280  //Before, it was: return !getBit(internalFEDChannelNum,0+2*apvNum);
1281 
1282  return !getBit(internalFEDChannelNum, 0 + 2 * (1 - apvNum));
1283  }
1284 
1286  const uint8_t apvNum) const {
1287  return !getBit(internalFEDChannelNum, 1 + 2 * apvNum);
1288  }
1289 
1290  inline bool FEDFullDebugHeader::getBit(const uint8_t internalFEDChannelNum, const uint8_t bit) const {
1291  const uint8_t* pFEWord = feWord(internalFEDChannelNum / FEDCH_PER_FEUNIT);
1292  const uint8_t bitInFeWord = ((FEDCH_PER_FEUNIT - 1) - (internalFEDChannelNum % FEDCH_PER_FEUNIT)) * 6 + bit;
1293  return (pFEWord[bitInFeWord / 8] & (0x1 << (bitInFeWord % 8)));
1294  }
1295 
1296  inline uint32_t FEDFullDebugHeader::get32BitWordFrom(const uint8_t* startOfWord) {
1297  return (startOfWord[0] | (startOfWord[1] << 8) | (startOfWord[2] << 16) | (startOfWord[3] << 24));
1298  }
1299 
1300  inline void FEDFullDebugHeader::set32BitWordAt(uint8_t* startOfWord, const uint32_t value) {
1301  memcpy(startOfWord, &value, 4);
1302  }
1303 
1304  inline const uint8_t* FEDFullDebugHeader::feWord(const uint8_t internalFEUnitNum) const {
1305  return header_ + internalFEUnitNum * 2 * 8;
1306  }
1307 
1308  //re-use const method
1309  inline uint8_t* FEDFullDebugHeader::feWord(const uint8_t internalFEUnitNum) {
1310  return const_cast<uint8_t*>(std::as_const(*this).feWord(internalFEUnitNum));
1311  }
1312 
1313  inline void FEDFullDebugHeader::setUnlocked(const uint8_t internalFEDChannelNum, const bool value) {
1315  }
1316 
1317  inline void FEDFullDebugHeader::setOutOfSync(const uint8_t internalFEDChannelNum, const bool value) {
1319  }
1320 
1322  const uint8_t apvNum,
1323  const bool value) {
1324  setBit(internalFEDChannelNum, 1 + 2 * apvNum, !value);
1325  }
1326 
1328  const uint8_t apvNum,
1329  const bool value) {
1330  //Discovered March 2012: two bits inverted in firmware. Decided
1331  //to update documentation but keep firmware identical for
1332  //backward compatibility. So status bit order is actually:
1333  //apvErr1 - apvAddrErr0 - apvErr0 - apvAddrErr1 - OOS - unlocked.
1334  //Before, it was: return !getBit(internalFEDChannelNum,0+2*apvNum);
1335 
1336  setBit(internalFEDChannelNum, 0 + 2 * (1 - apvNum), !value);
1337  }
1338 
1339  //FEDDAQHeader
1340 
1341  inline FEDDAQHeader::FEDDAQHeader(const uint8_t* header) { memcpy(header_, header, 8); }
1342 
1343  inline uint8_t FEDDAQHeader::boeNibble() const { return ((header_[7] & 0xF0) >> 4); }
1344 
1345  inline uint8_t FEDDAQHeader::eventTypeNibble() const { return (header_[7] & 0x0F); }
1346 
1347  inline uint32_t FEDDAQHeader::l1ID() const { return (header_[4] | (header_[5] << 8) | (header_[6] << 16)); }
1348 
1349  inline uint16_t FEDDAQHeader::bxID() const { return ((header_[3] << 4) | ((header_[2] & 0xF0) >> 4)); }
1350 
1351  inline uint16_t FEDDAQHeader::sourceID() const { return (((header_[2] & 0x0F) << 8) | header_[1]); }
1352 
1353  inline uint8_t FEDDAQHeader::version() const { return ((header_[0] & 0xF0) >> 4); }
1354 
1355  inline bool FEDDAQHeader::hBit() const { return (header_[0] & 0x8); }
1356 
1357  inline bool FEDDAQHeader::lastHeader() const { return !hBit(); }
1358 
1359  inline const uint8_t* FEDDAQHeader::data() const { return header_; }
1360 
1361  inline void FEDDAQHeader::print(std::ostream& os) const { printHex(header_, 8, os); }
1362 
1363  //FEDDAQTrailer
1364 
1365  inline FEDDAQTrailer::FEDDAQTrailer(const uint8_t* trailer) { memcpy(trailer_, trailer, 8); }
1366 
1367  inline uint8_t FEDDAQTrailer::eoeNibble() const { return ((trailer_[7] & 0xF0) >> 4); }
1368 
1369  inline uint32_t FEDDAQTrailer::eventLengthIn64BitWords() const {
1370  return (trailer_[4] | (trailer_[5] << 8) | (trailer_[6] << 16));
1371  }
1372 
1373  inline uint32_t FEDDAQTrailer::eventLengthInBytes() const { return eventLengthIn64BitWords() * 8; }
1374 
1375  inline uint16_t FEDDAQTrailer::crc() const { return (trailer_[2] | (trailer_[3] << 8)); }
1376 
1377  inline bool FEDDAQTrailer::cBit() const { return (trailer_[1] & 0x80); }
1378 
1379  inline bool FEDDAQTrailer::fBit() const { return (trailer_[1] & 0x40); }
1380 
1381  inline uint8_t FEDDAQTrailer::eventStatusNibble() const { return (trailer_[1] & 0x0F); }
1382 
1383  inline uint8_t FEDDAQTrailer::ttsNibble() const { return ((trailer_[0] & 0xF0) >> 4); }
1384 
1385  inline bool FEDDAQTrailer::tBit() const { return (trailer_[0] & 0x08); }
1386 
1387  inline bool FEDDAQTrailer::rBit() const { return (trailer_[0] & 0x04); }
1388 
1389  inline void FEDDAQTrailer::print(std::ostream& os) const { printHex(trailer_, 8, os); }
1390 
1391  inline const uint8_t* FEDDAQTrailer::data() const { return trailer_; }
1392 
1393  //FEDBufferBase
1394 
1395  inline void FEDBufferBase::dump(std::ostream& os) const { printHex(orderedBuffer_, bufferSize_, os); }
1396 
1397  inline void FEDBufferBase::dumpOriginalBuffer(std::ostream& os) const { printHex(originalBuffer_, bufferSize_, os); }
1398 
1400 
1402 
1404 
1405  inline size_t FEDBufferBase::bufferSize() const { return bufferSize_; }
1406 
1408 
1410 
1411  inline uint32_t FEDBufferBase::daqLvl1ID() const { return daqHeader_.l1ID(); }
1412 
1413  inline uint16_t FEDBufferBase::daqBXID() const { return daqHeader_.bxID(); }
1414 
1415  inline uint16_t FEDBufferBase::daqSourceID() const { return daqHeader_.sourceID(); }
1416 
1418 
1420 
1421  inline uint16_t FEDBufferBase::daqCRC() const { return daqTrailer_.crc(); }
1422 
1424 
1426 
1428 
1430 
1432 
1433  inline bool FEDBufferBase::doChecks() const {
1435  }
1436 
1437  inline uint8_t FEDBufferBase::packetCode(bool legacy, const uint8_t internalFEDChannelNum) const {
1438  if (legacy) {
1440  switch (mode) {
1442  return PACKET_CODE_SCOPE;
1445  return PACKET_CODE_VIRGIN_RAW;
1448  return PACKET_CODE_PROC_RAW;
1457  default:
1458  return 0;
1459  }
1460  } else {
1462  switch (mode) {
1463  case READOUT_MODE_SCOPE:
1464  return PACKET_CODE_SCOPE;
1467  case READOUT_MODE_PROC_RAW:
1468  return PACKET_CODE_PROC_RAW;
1480  case READOUT_MODE_SPY:
1481  case READOUT_MODE_INVALID:
1482  default:
1483  return 0;
1484  }
1485  }
1486  }
1487 
1488  inline uint8_t FEDBufferBase::apveAddress() const { return specialHeader_.apveAddress(); }
1489 
1490  inline bool FEDBufferBase::majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const {
1491  return (specialHeader_.majorityAddressErrorForFEUnit(internalFEUnitNum) && (specialHeader_.apveAddress() != 0x00));
1492  }
1493 
1494  inline bool FEDBufferBase::feEnabled(const uint8_t internalFEUnitNum) const {
1495  return specialHeader_.feEnabled(internalFEUnitNum);
1496  }
1497 
1498  inline bool FEDBufferBase::feOverflow(const uint8_t internalFEUnitNum) const {
1499  return specialHeader_.feOverflow(internalFEUnitNum);
1500  }
1501 
1503 
1504  inline bool FEDBufferBase::channelGood(const uint8_t internalFEUnitNum, const uint8_t internalChannelNum) const {
1505  return channelGood(internalFEDChannelNum(internalFEUnitNum, internalChannelNum));
1506  }
1507 
1508  inline const FEDChannel& FEDBufferBase::channel(const uint8_t internalFEDChannelNum) const {
1510  }
1511 
1512  inline const FEDChannel& FEDBufferBase::channel(const uint8_t internalFEUnitNum,
1513  const uint8_t internalChannelNum) const {
1514  return channel(internalFEDChannelNum(internalFEUnitNum, internalChannelNum));
1515  }
1516 
1518  return (checkBufferFormat() && checkHeaderType() && checkReadoutMode() &&
1519  //checkAPVEAddressValid() &&
1520  checkNoFEOverflows());
1521  }
1522 
1526  }
1527 
1528  inline bool FEDBufferBase::checkCRC() const { return (checkNoSlinkCRCError() && (calcCRC() == daqCRC())); }
1529 
1531 
1532  inline bool FEDBufferBase::checkHeaderType() const { return (headerType() != HEADER_TYPE_INVALID); }
1533 
1535 
1537 
1539 
1541 
1543 
1545 
1547  return ((daqHeader_.boeNibble() == 0x5) && (daqTrailer_.eoeNibble() == 0xA));
1548  }
1549 
1551 
1552  inline const uint8_t* FEDBufferBase::getPointerToDataAfterTrackerSpecialHeader() const { return orderedBuffer_ + 16; }
1553 
1555  return orderedBuffer_ + bufferSize_ - 8;
1556  }
1557 
1558  //FEDChannel
1559 
1560  inline FEDChannel::FEDChannel(const uint8_t* const data, const uint32_t offset) : data_(data), offset_(offset) {
1561  length_ = (data_[(offset_) ^ 7] + (data_[(offset_ + 1) ^ 7] << 8));
1562  }
1563 
1564  inline FEDChannel::FEDChannel(const uint8_t* const data, const uint32_t offset, const uint16_t length)
1565  : data_(data), offset_(offset), length_(length) {}
1566 
1567  inline uint16_t FEDChannel::length() const { return length_; }
1568 
1569  inline uint8_t FEDChannel::packetCode() const { return data_[(offset_ + 2) ^ 7]; }
1570 
1571  inline uint16_t FEDChannel::cmMedian(const uint8_t apvIndex) const {
1572  uint16_t result = 0;
1573  //CM median is 10 bits with lowest order byte first. First APV CM median starts in 4th byte of channel data
1574  result |= data_[(offset_ + 3 + 2 * apvIndex) ^ 7];
1575  result |= (((data_[(offset_ + 4 + 2 * apvIndex) ^ 7]) << 8) & 0x300);
1576  return result;
1577  }
1578 
1579  inline const uint8_t* FEDChannel::data() const { return data_; }
1580 
1581  inline uint32_t FEDChannel::offset() const { return offset_; }
1582 } // namespace sistrip
1583 
1584 #endif //ndef EventFilter_SiStripRawToDigi_FEDBufferComponents_H
FEDBufferFormat bufferFormat() const
static uint8_t physicalOrderForStripInChannel(const uint8_t readoutOrderStripIndexInChannel)
FEDBackendStatusRegister & setFEFPGABufferState(const FEDBufferState state)
FEDBackendStatusRegister & setQDRMemoryState(const FEDBufferState state)
FEDReadoutMode readoutMode() const
FEDBackendStatusRegister & setL1ABXFIFOState(const FEDBufferState state)
FEDLegacyReadoutMode legacyReadoutMode() const
virtual void setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister)=0
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED8_BOTBOT
virtual size_t lengthInBytes() const =0
bool feOverflow(const uint8_t internalFEUnitNum) const
void setDAQRegister2(const uint32_t daqRegister2) override
const uint8_t * data() const
static const size_t APV_ERROR_HEADER_SIZE_IN_BYTES
void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) override
void setBit(const uint8_t num, const bool bitSet)
void setOutOfSync(const uint8_t internalFEDChannelNum, const bool value)
FEDBackendStatusRegister beStatusRegister() const
void setQDRMemoryEmptyFlag(const bool bitSet)
uint16_t sourceID() const
void setDAQRegister2(const uint32_t daqRegister2) override
void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister) override
FEDStatusRegister & setTrackerHeaderMonitorDataReadyFlag(const bool bitSet)
FEDBackendStatusRegister & setFrameAddressFIFOState(const FEDBufferState state)
TrackerSpecialHeader & setFEOverflowRegister(const uint8_t feOverflowRegister)
void print(std::ostream &os) const
static const uint8_t PACKET_CODE_SCOPE
FEDBackendStatusRegister & setTrackerHeaderFIFOState(const FEDBufferState state)
FEDFullDebugHeader(const uint8_t *headerBuffer)
static FEDBufferFormat bufferFormat(const uint8_t *headerPointer)
FEDChannel(const uint8_t *const data, const uint32_t offset, const uint16_t length)
bool checkStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum, const uint8_t apvNum) const
static std::unique_ptr< FEDFEHeader > newFEHeader(const FEDHeaderType headerType, const uint8_t *headerBuffer)
static const uint8_t PACKET_CODE_PROC_RAW10
FEDDAQTrailer & setSLinkCRCErrorBit(const bool bitSet)
FEDDAQTrailer & setTTSBits(const FEDTTSBits ttsBits)
FEDStatusRegister(const uint16_t fedStatusRegister)
static uint32_t get32BitWordFrom(const uint8_t *startOfWord)
void print(std::ostream &os) const
void setAPVError(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool value)
FEDStatusRegister & setSLinkFullFlag(const bool bitSet)
uint8_t internalFEDChannelNum(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum)
bool fePresent(const uint8_t internalFEUnitNum) const
bool checkChannelStatusBits(const uint8_t internalFEDChannelNum) const override
bool apvErrorFromBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
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
const uint8_t * getPointerToDataAfterTrackerSpecialHeader() const
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)
bool getBit(const uint8_t internalFEDChannelNum, const uint8_t bit) const
FEDBufferFormat fedBufferFormatFromString(const std::string &bufferFormatString)
void setBit(const uint8_t num, const bool bitSet)
sistrip classes
void dumpOriginalBuffer(std::ostream &os) const
virtual void set32BitReservedRegister(const uint8_t internalFEUnitNum, const uint32_t reservedRegister)=0
constexpr bool enabled
Definition: SoACommon.h:71
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
const uint8_t * getPointerToByteAfterEndOfPayload() 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 uint8_t readoutOrderForStripInChannel(const uint8_t physicalOrderStripIndexInChannel)
static const uint8_t PACKET_CODE_ZERO_SUPPRESSED10
FEDBackendStatusRegister(const uint32_t backendStatusRegister)
static const uint8_t PACKET_CODE_VIRGIN_RAW10
bool checkChannelStatusBits(const uint8_t internalFEUnitNum, const uint8_t internalFEUnitChannelNum) const
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)
bool feEnabled(const uint8_t internalFEUnitNum) const
FEDBackendStatusRegister & setTTCReadyFlag(const bool bitSet)
FEDDAQTrailer & setCRC(const uint16_t crc)
TrackerSpecialHeader & setAPVEAddressErrorRegister(const uint8_t addressErrorRegister)
TrackerSpecialHeader & setFEDStatusRegister(const FEDStatusRegister fedStatusRegister)
bool getBit(const uint8_t num) const
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 dump(std::ostream &os) const
void setQDRMemoryFullFlag(const bool bitSet)
FEDAPVErrorHeader * clone() const override
FEDDAQEventType daqEventType() const
virtual void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length)=0
FEDBufferState getBufferState(const uint8_t bufferPosition) const
virtual void setChannelStatus(const uint8_t internalFEDChannelNum, const FEDChannelStatus status)=0
void setL1ABXFIFOFullFlag(const bool bitSet)
static const uint8_t BUFFER_FORMAT_CODE_NEW
bool apvError(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const
virtual void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address)=0
void setAPVAddressError(const uint8_t internalFEDChannelNum, const uint8_t apvNum, const bool value)
bool majorityAddressErrorForFEUnit(const uint8_t internalFEUnitNum) const
void print(std::ostream &os) const
static const size_t APV_ERROR_HEADER_SIZE_IN_64BIT_WORDS
static const uint8_t APV_MAX_ADDRESS
FEDStatusRegister fedStatusRegister() const
Definition: value.py:1
void setL1ABXFIFOPartialFullFlag(const bool bitSet)
void setHeaderTypeNibble(const uint8_t value)
virtual void setDAQRegister2(const uint32_t daqRegister2)=0
bool unlocked(const uint8_t internalFEDChannelNum) const
void setFEUnitMajorityAddress(const uint8_t internalFEUnitNum, const uint8_t address) override
static const uint8_t INVALID
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_
uint16_t feUnitLength(const uint8_t internalFEUnitNum) const
void setBufferFormatByte(const FEDBufferFormat newBufferFormat)
void print(std::ostream &os) const override
uint16_t cmMedian(const uint8_t apvIndex) const
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 uint16_t APVS_PER_FED
bool apvAddressErrorFromBit(const uint8_t internalFEDChannelNum, const uint8_t apvNum) const
void print(std::ostream &os) const
static const uint8_t PACKET_CODE_VIRGIN_RAW8_BOTBOT
virtual void print(std::ostream &os) const =0
void printHex(const void *pointer, const size_t length, std::ostream &os)
void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) override
static uint8_t physicalOrderForStripInAPV(const uint8_t readoutOrderStripIndexInAPV)
virtual void setDAQRegister(const uint32_t daqRegister)=0
static const uint16_t FEDCH_PER_FEUNIT
const FEDChannel & channel(const uint8_t internalFEDChannelNum) const
void setBEStatusRegister(const FEDBackendStatusRegister beStatusRegister) override
Constants and enumerated types for FED/FEC systems.
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)
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)
virtual const uint8_t * data() const =0
FEDLegacyReadoutMode legacyReadoutMode() const
uint8_t header_[FULL_DEBUG_HEADER_SIZE_IN_BYTES]
static std::unique_ptr< FEDFEHeader > newFEFakeHeader(const FEDHeaderType headerType)
TrackerSpecialHeader specialHeader_
virtual bool channelGood(const uint8_t internalFEDChannelNum) const
bool feOverflow(const uint8_t internalFEUnitNum) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static const uint16_t FEDCH_PER_FED
static const uint16_t STRIPS_PER_APV
TrackerSpecialHeader & setFEOverflowForFEUnit(const uint8_t internalFEUnitNum, const bool overflow)
void printFlags(std::ostream &os) const
__host__ __device__ std::uint32_t apvIndex(fedId_t fed, fedCh_t channel, stripId_t strip)
FEDStatusRegister fedStatusRegister() const
static const size_t FULL_DEBUG_HEADER_SIZE_IN_64BIT_WORDS
const uint8_t * data() const override
virtual FEDFEHeader * clone() const =0
const uint8_t * data() const
uint8_t feUnitMajorityAddress(const uint8_t internalFEUnitNum) const
FEDBackendStatusRegister & setFEEventLengthFIFOState(const FEDBufferState state)
static const uint8_t PACKET_CODE_PROC_RAW8_BOTBOT
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
TrackerSpecialHeader trackerSpecialHeader() const
bool outOfSync(const uint8_t internalFEDChannelNum) const
FEDDAQHeader & setBXID(const uint16_t bxID)
static const uint8_t BUFFER_FORMAT_CODE_OLD
FEDBufferStatusCode preconstructCheckFEDBufferBase(const FEDRawData &fedBuffer, bool checkRecognizedFormat=true)
FEDChannelStatus getChannelStatus(const uint8_t internalFEDChannelNum) const
void setBit(const uint8_t internalFEDChannelNum, const uint8_t bit, const bool value)
static const uint16_t SCOPE_MODE_MAX_SCOPE_LENGTH
static uint8_t readoutOrderForStripInAPV(const uint8_t physicalOrderStripIndexInAPV)
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)
#define LogDebug(id)
TrackerSpecialHeader & setFEEnableRegister(const uint8_t feEnableRegister)
void setFEUnitLength(const uint8_t internalFEUnitNum, const uint16_t length) override
uint8_t packetCode(bool legacy=false, const uint8_t internalFEDChannelNum=0) const
virtual void print(std::ostream &os) const