Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:49:54

0001 #ifndef DataFormats_GEMDigi_GEMOptoHybrid_h
0002 #define DataFormats_GEMDigi_GEMOptoHybrid_h
0003 #include "GEMVFAT.h"
0004 #include <vector>
0005 
0006 class GEMOptoHybrid {
0007 public:
0008   union GEBchamberHeader {
0009     uint64_t word;
0010     // v301 dataformat
0011     struct {
0012       uint64_t : 10;            // unused
0013       uint64_t BxmVvV : 1;      // 1st bit BX mismatch VFAT vs VFAT
0014       uint64_t BxmAvV : 1;      // BX mismatch AMC vs VFAT
0015       uint64_t OOScVvV : 1;     // Out of Sync (EC mismatch) VFAT vs VFAT
0016       uint64_t OOScAvV : 1;     // Out of Sync (EC mismatch) AMC vs VFAT
0017       uint64_t Inv : 1;         // Invalid event
0018       uint64_t EvtSzW : 1;      // Event size warning
0019       uint64_t L1aNF : 1;       // L1A FIFO near full
0020       uint64_t InNF : 1;        // Input FIFO near full
0021       uint64_t EvtNF : 1;       // Event FIFO near full
0022       uint64_t EvtSzOFW : 1;    // Event size overflow
0023       uint64_t L1aF : 1;        // L1A FIFO full
0024       uint64_t InF : 1;         // Input FIFO full
0025       uint64_t EvtF : 1;        // Event FIFO full
0026       uint64_t VfWdCnt : 12;    // VFAT word count (in number of 64-bit words)
0027       uint64_t InputID : 5;     // Input link ID
0028       uint64_t CALIB_CHAN : 7;  // Calibration channel number
0029       uint64_t : 17;            // unused
0030     };
0031     // v302 dataformat
0032     struct {
0033       uint64_t : 10;                // unused
0034       uint64_t BxmVvVv302 : 1;      // 1st bit BX mismatch VFAT vs VFAT
0035       uint64_t BxmAvVv302 : 1;      // BX mismatch AMC vs VFAT
0036       uint64_t OOScVvVv302 : 1;     // Out of Sync (EC mismatch) VFAT vs VFAT
0037       uint64_t OOScAvVv302 : 1;     // Out of Sync (EC mismatch) AMC vs VFAT
0038       uint64_t InvV302 : 1;         // Invalid event
0039       uint64_t EvtSzWv302 : 1;      // Event size warning
0040       uint64_t : 1;                 // unused
0041       uint64_t InNFv302 : 1;        // Input FIFO near full
0042       uint64_t EvtNFv302 : 1;       // Event FIFO near full
0043       uint64_t EvtSzOFWv302 : 1;    // Event size overflow
0044       uint64_t : 1;                 // unused
0045       uint64_t InFv302 : 1;         // Input FIFO full
0046       uint64_t EvtFv302 : 1;        // Event FIFO full
0047       uint64_t VfWdCntV302 : 12;    // VFAT word count (in number of 64-bit words)
0048       uint64_t InputIDv302 : 5;     // Input link ID
0049       uint64_t CALIB_CHANv302 : 7;  // Calibration channel number
0050       uint64_t : 17;                // unused
0051     };
0052   };
0053 
0054   union GEBchamberTrailer {
0055     uint64_t word;
0056     // v301 dataformat
0057     struct {
0058       uint64_t ecOH : 20;      // NOT USED - OptoHybrid event counter
0059       uint64_t bcOH : 13;      // NOT USED - OptoHybrid bunch crossing
0060       uint64_t InUfw : 1;      // Input FIFO underflow
0061       uint64_t SkD : 1;        // NOT USED - Stuck data
0062       uint64_t EvUfw : 1;      // NOT USED - Event FIFO underflow
0063       uint64_t VfWdCntT : 12;  // VFAT word count (in number of 64-bit words)
0064       uint64_t crc16 : 16;     // CRC of OptoHybrid data (currently not available – filled with 0)
0065     };
0066     // v302 dataformat
0067     struct {
0068       uint64_t VFATMask : 24;      // Enabled VFAT, Set 1 if the VFAT is enabled
0069       uint64_t ZSMask : 24;        // Zero-suppressed VFAT, Set 1 if the VFAT payload has been zero-suppressed
0070       uint64_t : 3;                // unused
0071       uint64_t InUfwV302 : 1;      // Input FIFO underflow
0072       uint64_t VfWdCntTv302 : 12;  // VFAT word count (in number of 64-bit words)
0073     };
0074   };
0075 
0076   GEMOptoHybrid() : ch_(0), ct_(0), existVFATs_(0){};
0077   ~GEMOptoHybrid() { vfatd_.clear(); }
0078 
0079   void setVersion(uint8_t i) { ver_ = i; }
0080   uint8_t version() const { return ver_; }
0081 
0082   //!Read chamberHeader from the block.
0083   void setChamberHeader(uint64_t word) { ch_ = word; }
0084   void setChamberHeader(uint16_t vfatWordCnt, uint8_t inputID) {
0085     GEBchamberHeader u{0};
0086     u.VfWdCnt = vfatWordCnt;
0087     u.InputID = inputID;
0088     ch_ = u.word;
0089   }
0090   uint64_t getChamberHeader() const { return ch_; }
0091 
0092   //!Read chamberTrailer from the block.
0093   void setChamberTrailer(uint64_t word) { ct_ = word; }
0094   void setChamberTrailer(uint32_t ecOH, uint16_t bcOH, uint16_t vfatWordCntT) {
0095     GEBchamberTrailer u{0};
0096     u.ecOH = ecOH;
0097     u.bcOH = bcOH;
0098     u.VfWdCntT = vfatWordCntT;
0099     ct_ = u.word;
0100   }
0101   uint64_t getChamberTrailer() const { return ct_; }
0102 
0103   // v301
0104   uint16_t vfatWordCnt() const {
0105     if (ver_ == 0)
0106       return GEBchamberHeader{ch_}.VfWdCnt;
0107     return GEBchamberHeader{ch_}.VfWdCntV302;
0108   }
0109   uint8_t inputID() const {
0110     if (ver_ == 0)
0111       return GEBchamberHeader{ch_}.InputID;
0112     return GEBchamberHeader{ch_}.InputIDv302;
0113   }
0114   uint16_t vfatWordCntT() const {
0115     if (ver_ == 0)
0116       return GEBchamberTrailer{ct_}.VfWdCntT;
0117     return GEBchamberTrailer{ct_}.VfWdCntTv302;
0118   }
0119 
0120   bool bxmVvV() const { return GEBchamberHeader{ch_}.BxmVvV; }
0121   bool bxmAvV() const { return GEBchamberHeader{ch_}.BxmAvV; }
0122   bool oOScVvV() const { return GEBchamberHeader{ch_}.OOScVvV; }
0123   bool oOScAvV() const { return GEBchamberHeader{ch_}.OOScAvV; }
0124   bool inv() const { return GEBchamberHeader{ch_}.Inv; }
0125   bool evtSzW() const { return GEBchamberHeader{ch_}.EvtSzW; }
0126   bool inNF() const { return GEBchamberHeader{ch_}.InNF; }
0127   bool evtNF() const { return GEBchamberHeader{ch_}.EvtNF; }
0128   bool evtSzOFW() const { return GEBchamberHeader{ch_}.EvtSzOFW; }
0129   bool inF() const { return GEBchamberHeader{ch_}.InF; }
0130   bool evtF() const { return GEBchamberHeader{ch_}.EvtF; }
0131   bool inUfw() const {
0132     if (ver_ == 0)
0133       return GEBchamberTrailer{ct_}.InUfw;
0134     return GEBchamberTrailer{ct_}.InUfwV302;
0135   }
0136 
0137   bool noVFAT() const { return false; }     // to be removed
0138   bool stuckData() const { return false; }  // to be removed
0139   bool evUfw() const { return false; }      // to be removed
0140 
0141   // v301
0142   bool l1aNF() const { return GEBchamberHeader{ch_}.L1aNF; }
0143   bool l1aF() const { return GEBchamberHeader{ch_}.L1aF; }
0144 
0145   // v302
0146   uint32_t vfatMask() const { return GEBchamberTrailer{ct_}.VFATMask; }
0147   uint32_t zsMask() const { return GEBchamberTrailer{ct_}.ZSMask; }
0148 
0149   //!Adds VFAT data to the vector
0150   void addVFAT(GEMVFAT v) {
0151     existVFATs_ = existVFATs_ | (0x1 << v.vfatId());
0152     vfatd_.push_back(v);
0153   }
0154   //!Returns the vector of VFAT data
0155   const std::vector<GEMVFAT>* vFATs() const { return &vfatd_; }
0156   uint32_t existVFATs() const { return existVFATs_; }
0157   //!Clear the vector rof VFAT data
0158   void clearVFATs() { vfatd_.clear(); }
0159 
0160   static const int sizeGebID = 5;
0161 
0162 private:
0163   uint8_t ver_;  // Data Format version
0164 
0165   uint64_t ch_;  // GEBchamberHeader
0166   uint64_t ct_;  // GEBchamberTrailer
0167 
0168   uint32_t existVFATs_;
0169 
0170   std::vector<GEMVFAT> vfatd_;
0171 };
0172 #endif