Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:11

0001 #ifndef EventFilter_Phase2TrackerRawToDigi_Phase2TrackerFEDDAQTrailer_H  // {
0002 #define EventFilter_Phase2TrackerRawToDigi_Phase2TrackerFEDDAQTrailer_H
0003 
0004 #include <cstring>
0005 #include "EventFilter/Phase2TrackerRawToDigi/interface/utils.h"
0006 
0007 namespace Phase2Tracker {
0008 
0009   //
0010   // Constants
0011   //
0012 
0013   //enum values are values which appear in buffer. DO NOT CHANGE!
0014   //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
0015   enum FEDTTSBits {
0016     TTS_DISCONNECTED0 = 0x0,
0017     TTS_WARN_OVERFLOW = 0x1,
0018     TTS_OUT_OF_SYNC = 0x2,
0019     TTS_BUSY = 0x4,
0020     TTS_READY = 0x8,
0021     TTS_ERROR = 0x12,
0022     TTS_DISCONNECTED1 = 0xF,
0023     TTS_INVALID = INVALID
0024   };
0025 
0026   //to make enums printable
0027   inline std::ostream& operator<<(std::ostream& os, const FEDTTSBits& value);
0028 
0029   //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
0030   class FEDDAQTrailer {
0031   public:
0032     FEDDAQTrailer() {}
0033     explicit FEDDAQTrailer(const uint8_t* trailer);
0034 
0035     // getters
0036     //0xA in first fragment
0037     uint8_t eoeNibble() const;
0038     uint32_t eventLengthIn64BitWords() const;
0039     uint32_t eventLengthInBytes() const;
0040     uint16_t crc() const;
0041     //set to 1 if FRL detects a transmission error over S-link
0042     bool cBit() const;
0043     bool slinkTransmissionError() const { return cBit(); }
0044     //set to 1 if the FED ID is not the one expected by the FRL
0045     bool fBit() const;
0046     bool badSourceID() const { return fBit(); }
0047     uint8_t eventStatusNibble() const;
0048     uint8_t ttsNibble() const;
0049     FEDTTSBits ttsBits() const;
0050     //0 if the current trailer is the last, 1 otherwise
0051     bool tBit() const;
0052     bool lastTrailer() const { return !tBit(); }
0053     //set to 1 if the S-link sender card detects a CRC error
0054     // (the CRC it computes is put in the CRC field)
0055     bool rBit() const;
0056     bool slinkCRCError() const { return rBit(); }
0057     void print(std::ostream& os) const;
0058     //used by digi2Raw
0059     const uint8_t* data() const;
0060 
0061     // setters
0062     void setEventLengthIn64BitWords(const uint32_t eventLengthIn64BitWords);
0063     void setCRC(const uint16_t crc);
0064     void setSLinkTransmissionErrorBit(const bool bitSet);
0065     void setBadSourceIDBit(const bool bitSet);
0066     void setSLinkCRCErrorBit(const bool bitSet);
0067     void setEventStatusNibble(const uint8_t eventStatusNibble);
0068     void setTTSBits(const FEDTTSBits ttsBits);
0069     FEDDAQTrailer(const uint32_t eventLengthIn64BitWords,
0070                   const uint16_t crc = 0,
0071                   const FEDTTSBits ttsBits = TTS_READY,
0072                   const bool slinkTransmissionError = false,
0073                   const bool badFEDID = false,
0074                   const bool slinkCRCError = false,
0075                   const uint8_t eventStatusNibble = 0);
0076 
0077   private:
0078     uint8_t trailer_[8];
0079 
0080   };  // end of FEDDAQTrailer class
0081 
0082   //FEDDAQTrailer methods definintions {
0083 
0084   //FEDDAQTrailer
0085 
0086   inline FEDDAQTrailer::FEDDAQTrailer(const uint8_t* trailer) { memcpy(trailer_, trailer, 8); }
0087 
0088   inline uint8_t FEDDAQTrailer::eoeNibble() const { return ((trailer_[7] & 0xF0) >> 4); }
0089 
0090   inline uint32_t FEDDAQTrailer::eventLengthIn64BitWords() const {
0091     return (trailer_[4] | (trailer_[5] << 8) | (trailer_[6] << 16));
0092   }
0093 
0094   inline uint32_t FEDDAQTrailer::eventLengthInBytes() const { return eventLengthIn64BitWords() * 8; }
0095 
0096   inline uint16_t FEDDAQTrailer::crc() const { return (trailer_[2] | (trailer_[3] << 8)); }
0097 
0098   inline bool FEDDAQTrailer::cBit() const { return (trailer_[1] & 0x80); }
0099 
0100   inline bool FEDDAQTrailer::fBit() const { return (trailer_[1] & 0x40); }
0101 
0102   inline uint8_t FEDDAQTrailer::eventStatusNibble() const { return (trailer_[1] & 0x0F); }
0103 
0104   inline uint8_t FEDDAQTrailer::ttsNibble() const { return ((trailer_[0] & 0xF0) >> 4); }
0105 
0106   inline bool FEDDAQTrailer::tBit() const { return (trailer_[0] & 0x08); }
0107 
0108   inline bool FEDDAQTrailer::rBit() const { return (trailer_[0] & 0x04); }
0109 
0110   inline void FEDDAQTrailer::print(std::ostream& os) const { printHex(trailer_, 8, os); }
0111 
0112   inline const uint8_t* FEDDAQTrailer::data() const { return trailer_; }
0113 
0114   // End of method definitions }
0115 
0116 }  // namespace Phase2Tracker
0117 
0118 #endif  // } end def EventFilter_Phase2TrackerRawToDigi_Phase2TrackerFEDDAQHeader_H