Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:56

0001 #ifndef EventFilter_Phase2TrackerRawToDigi_Phase2TrackerFEDDAQHeader_H  // {
0002 #define EventFilter_Phase2TrackerRawToDigi_Phase2TrackerFEDDAQHeader_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 FEDDAQEventType {
0016     DAQ_EVENT_TYPE_PHYSICS = 0x1,
0017     DAQ_EVENT_TYPE_CALIBRATION = 0x2,
0018     DAQ_EVENT_TYPE_TEST = 0x3,
0019     DAQ_EVENT_TYPE_TECHNICAL = 0x4,
0020     DAQ_EVENT_TYPE_SIMULATED = 0x5,
0021     DAQ_EVENT_TYPE_TRACED = 0x6,
0022     DAQ_EVENT_TYPE_ERROR = 0xF,
0023     DAQ_EVENT_TYPE_INVALID = INVALID
0024   };
0025 
0026   //to make enums printable
0027   inline std::ostream& operator<<(std::ostream& os, const FEDDAQEventType& value);
0028 
0029   //see http://cmsdoc.cern.ch/cms/TRIDAS/horizontal/RUWG/DAQ_IF_guide/DAQ_IF_guide.html
0030   class FEDDAQHeader {
0031   public:
0032     FEDDAQHeader() {}
0033     explicit FEDDAQHeader(const uint8_t* header);
0034 
0035     // getters
0036     //0x5 in first fragment
0037     uint8_t boeNibble() const;
0038     uint8_t eventTypeNibble() const;
0039     FEDDAQEventType eventType() const;
0040     uint32_t l1ID() const;
0041     uint16_t bxID() const;
0042     uint16_t sourceID() const;
0043     uint8_t version() const;
0044     //0 if current header word is last, 1 otherwise
0045     bool hBit() const;
0046     bool lastHeader() const;
0047     void print(std::ostream& os) const;
0048 
0049     //used by digi2Raw
0050     const uint8_t* data() const;
0051 
0052     // setters
0053     void setEventType(const FEDDAQEventType evtType);
0054     void setL1ID(const uint32_t l1ID);
0055     void setBXID(const uint16_t bxID);
0056     void setSourceID(const uint16_t sourceID);
0057     FEDDAQHeader(const uint32_t l1ID,
0058                  const uint16_t bxID,
0059                  const uint16_t sourceID,
0060                  const FEDDAQEventType evtType = DAQ_EVENT_TYPE_PHYSICS);
0061 
0062   private:
0063     uint8_t header_[8];
0064   };  // end of FEDDAQHeader class
0065 
0066   //FEDDAQHeader
0067 
0068   inline FEDDAQHeader::FEDDAQHeader(const uint8_t* header) { memcpy(header_, header, 8); }
0069 
0070   inline uint8_t FEDDAQHeader::boeNibble() const { return ((header_[7] & 0xF0) >> 4); }
0071 
0072   inline uint8_t FEDDAQHeader::eventTypeNibble() const { return (header_[7] & 0x0F); }
0073 
0074   inline uint32_t FEDDAQHeader::l1ID() const { return (header_[4] | (header_[5] << 8) | (header_[6] << 16)); }
0075 
0076   inline uint16_t FEDDAQHeader::bxID() const { return ((header_[3] << 4) | ((header_[2] & 0xF0) >> 4)); }
0077 
0078   inline uint16_t FEDDAQHeader::sourceID() const { return (((header_[2] & 0x0F) << 8) | header_[1]); }
0079 
0080   inline uint8_t FEDDAQHeader::version() const { return ((header_[0] & 0xF0) >> 4); }
0081 
0082   inline bool FEDDAQHeader::hBit() const { return (header_[0] & 0x8); }
0083 
0084   inline bool FEDDAQHeader::lastHeader() const { return !hBit(); }
0085 
0086   inline const uint8_t* FEDDAQHeader::data() const { return header_; }
0087 
0088   inline void FEDDAQHeader::print(std::ostream& os) const { printHex(header_, 8, os); }
0089 
0090 }  // namespace Phase2Tracker
0091 
0092 #endif  // } end def EventFilter_Phase2TrackerRawToDigi_Phase2TrackerFEDDAQHeader_H