Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-06 07:38:22

0001 #ifndef DataFormats_GEMDigi_GEMAMC_h
0002 #define DataFormats_GEMDigi_GEMAMC_h
0003 #include "GEMOptoHybrid.h"
0004 #include <vector>
0005 
0006 class GEMAMC {
0007 public:
0008   union AMCheader1 {
0009     uint64_t word;
0010     struct {
0011       uint64_t dataLength : 20;  // Always 0xfffff, use trailer dataLengthT
0012       uint64_t bxID : 12;        // Bunch crossing ID
0013       uint64_t l1AID : 24;       // L1A number – basically this is like event number, but reset by resync
0014       uint64_t AMCnum : 4;       // Slot number of the AMC
0015       uint64_t reserved : 4;     // not used
0016     };
0017   };
0018   union AMCheader2 {
0019     uint64_t word;
0020     // v301 dataformat
0021     struct {
0022       uint64_t boardID : 16;   // 8bit long GLIB serial number
0023       uint64_t orbitNum : 16;  // Orbit number, Reset by EC0
0024       uint64_t param3 : 8;     // RunPar - Controlled by software, normally used only for calibrations
0025       uint64_t param2 : 8;     // RunPar - Controlled by software, normally used only for calibrations
0026       uint64_t param1 : 8;     // RunPar - Controlled by software, normally used only for calibrations
0027       uint64_t runType : 4;    // run types like physics, cosmics, threshold scan, latency scan, etc..
0028       uint64_t formatVer : 4;  // Current format version = 0x0
0029     };
0030     // v302 dataformat
0031     struct {
0032       uint64_t softSrcId : 12;     // FED ID - Configruation Error if does not match with CDF header
0033       uint64_t softSlot : 4;       // AMC slot number - Configuation Error if does not match with AMC13 AHn header
0034       uint64_t orbitNumV302 : 32;  // Orbit counter, Reset by EC0 - Error if does not match AMC BH header
0035       uint64_t : 12;               // unused
0036       uint64_t FVv302 : 4;         // Current version = 0x1
0037     };
0038   };
0039   union AMCTrailer {
0040     uint64_t word;
0041     struct {
0042       uint64_t dataLength : 20;  // Number of 64bit words in this event
0043       uint64_t : 4;              // unused
0044       uint64_t l1AID : 8;        // L1A number (first 8 bits)
0045       uint64_t crc : 32;         // CRC added by the AMC13
0046     };
0047   };
0048   union EventHeader {
0049     uint64_t word;
0050     struct {
0051       uint64_t ttsState : 4;  // GLIB TTS state at the moment when this event was built.
0052       uint64_t pType : 4;     // Payload type: can be one refering to different zero suppression schemes
0053       // in normal data taking or calibration type.
0054       // Note in calibration type the entire GCT (GEM Chamber Trailer) is skipped
0055       uint64_t pVer : 3;        // Version of the payload type
0056       uint64_t davCnt : 5;      // Number of chamber blocks in this event
0057       uint64_t buffState : 24;  // Buffer status, Always 0 in current fw
0058       uint64_t davList : 24;    // Data Available list: a bitmask indicating which chambers have data in this event
0059     };
0060   };
0061   union EventTrailer {
0062     uint64_t word;
0063     // v301 dataformat
0064     struct {
0065       uint64_t BCL : 4;  // 1st bit, BC0 locked - If 0, this is a bad condition indicating a
0066       // problem in the clock or TTC command stream (critical condition)
0067       uint64_t DR : 1;        // DAQ Ready - If 0, this means that AMC13 is not ready to take data (critical condition)
0068       uint64_t CL : 1;        // DAQ clock locked- If 0, this indicates a problem in the DAQ clock (critical condition)
0069       uint64_t ML : 1;        // MMCM locked - Should always be 1
0070       uint64_t BP : 1;        // Backpressure - If this is 1, it means that we are receiving backpressure from AMC13
0071       uint64_t oosGlib : 32;  // GLIB is out‐of‐sync (critical): L1A ID is different for
0072       // different chambers in this event (1 bit)
0073       uint64_t linkTo : 24;  // Link timeout flags (one bit for each link indicating timeout condition)
0074     };
0075     // v302 dataformat
0076     struct {
0077       uint64_t L1aNF : 1;    // L1A FIFO near full - Warning
0078       uint64_t L1aF : 1;     // L1A FIFO full - Error
0079       uint64_t : 1;          // unused
0080       uint64_t BCLv302 : 1;  // BC0 locked - If 0, this is a bad condition indicating a
0081       // problem in the clock or TTC command stream (critical condition)
0082       uint64_t DRv302 : 1;   // DAQ Ready - If 0, this means that AMC13 is not ready to take data (critical condition)
0083       uint64_t CLv302 : 1;   // DAQ clock locked- If 0, this indicates a problem in the DAQ clock (critical condition)
0084       uint64_t MLv302 : 1;   // MMCM locked - Should always be 1
0085       uint64_t BPv302 : 1;   // Backpressure - If this is 1, it means that we are receiving backpressure from AMC13
0086       uint64_t param3 : 8;   // RunPar - Controlled by software, normally used only for calibrations
0087       uint64_t param2 : 8;   // RunPar - Controlled by software, normally used only for calibrations
0088       uint64_t param1 : 8;   // RunPar - Controlled by software, normally used only for calibrations
0089       uint64_t runType : 4;  // Type of Run - Controlled by software, “physics” is assigned 0x1,
0090       // hits from events with other run types should be discarded
0091       uint64_t : 4;              // unused
0092       uint64_t linkToV302 : 24;  // Link timeout flags (one bit for each link indicating timeout condition)
0093     };
0094   };
0095 
0096   GEMAMC() : amch1_(0), amch2_(0), amct_(0), eh_(0), et_(0){};
0097   ~GEMAMC() { gebd_.clear(); }
0098 
0099   int status();
0100 
0101   void setAMCheader1(uint64_t word) { amch1_ = word; }
0102   void setAMCheader1(uint32_t dataLength, uint16_t bxID, uint32_t l1AID, uint8_t AMCnum);
0103   uint64_t getAMCheader1() const { return amch1_; }
0104 
0105   void setAMCheader2(uint64_t word) { amch2_ = word; }
0106   void setAMCheader2(uint16_t boardID, uint16_t orbitNum, uint8_t runType);
0107   uint64_t getAMCheader2() const { return amch2_; }
0108 
0109   void setAMCTrailer(uint64_t word) { amct_ = word; }
0110   uint64_t getAMCTrailer() const { return amct_; }
0111 
0112   void setGEMeventHeader(uint64_t word) { eh_ = word; }
0113   void setGEMeventHeader(uint8_t davCnt, uint32_t davList);
0114   uint64_t getGEMeventHeader() const { return eh_; }
0115 
0116   void setGEMeventTrailer(uint64_t word) { et_ = word; }
0117   uint64_t getGEMeventTrailer() const { return et_; }
0118 
0119   // v301
0120   uint32_t dataLength() const { return AMCTrailer{amct_}.dataLength; }
0121   uint16_t bunchCrossing() const { return AMCheader1{amch1_}.bxID; }
0122   uint32_t lv1Id() const { return AMCheader1{amch1_}.l1AID; }
0123   uint8_t amcNum() const { return AMCheader1{amch1_}.AMCnum; }
0124 
0125   uint16_t boardId() const { return AMCheader2{amch2_}.boardID; }
0126   uint32_t orbitNumber() const {
0127     if (formatVer() == 0)
0128       return AMCheader2{amch2_}.orbitNum;
0129     return AMCheader2{amch2_}.orbitNumV302;
0130   }
0131   uint8_t param3() const {
0132     if (formatVer() == 0)
0133       return AMCheader2{amch2_}.param3;
0134     return EventTrailer{et_}.param3;
0135   }
0136   uint8_t param2() const {
0137     if (formatVer() == 0)
0138       return AMCheader2{amch2_}.param2;
0139     return EventTrailer{et_}.param2;
0140   }
0141   uint8_t param1() const {
0142     if (formatVer() == 0)
0143       return AMCheader2{amch2_}.param1;
0144     return EventTrailer{et_}.param1;
0145   }
0146   uint8_t runType() const {
0147     if (formatVer() == 0)
0148       return AMCheader2{amch2_}.runType;
0149     return EventTrailer{et_}.runType;
0150   }
0151   // SAME in V301 and V302
0152   uint8_t formatVer() const { return AMCheader2{amch2_}.formatVer; }
0153 
0154   uint8_t lv1Idt() const { return AMCTrailer{amct_}.l1AID; }
0155   uint32_t crc() const { return AMCTrailer{amct_}.crc; }
0156 
0157   uint16_t ttsState() const { return EventHeader{eh_}.ttsState; }
0158   uint8_t davCnt() const { return EventHeader{eh_}.davCnt; }
0159   uint32_t buffState() const { return EventHeader{eh_}.buffState; }
0160   uint32_t davList() const { return EventHeader{eh_}.davList; }
0161 
0162   uint8_t bc0locked() const { return EventTrailer{et_}.BCL; }
0163   uint8_t daqReady() const { return EventTrailer{et_}.DR; }
0164   uint8_t daqClockLocked() const { return EventTrailer{et_}.CL; }
0165   uint8_t mmcmLocked() const { return EventTrailer{et_}.ML; }
0166   uint8_t backPressure() const { return EventTrailer{et_}.BP; }
0167   uint8_t oosGlib() const { return EventTrailer{et_}.oosGlib; }
0168   uint32_t linkTo() const { return EventTrailer{et_}.linkTo; }
0169 
0170   // v302
0171   uint16_t softSrcId() const { return AMCheader2{amch2_}.softSrcId; }
0172   uint8_t softSlot() const { return AMCheader2{amch2_}.softSlot; }
0173 
0174   uint8_t l1aNF() const { return EventTrailer{et_}.L1aNF; }
0175   uint8_t l1aF() const { return EventTrailer{et_}.L1aF; }
0176 
0177   //!Adds GEB data to vector
0178   void addGEB(GEMOptoHybrid g) { gebd_.push_back(g); }
0179   //!Returns a vector of GEB data
0180   const std::vector<GEMOptoHybrid>* gebs() const { return &gebd_; }
0181   //!Clear a vector of GEB data
0182   void clearGEBs() { gebd_.clear(); }
0183 
0184 private:
0185   uint64_t amch1_;
0186   uint64_t amch2_;
0187   uint64_t amct_;
0188   uint64_t eh_;
0189   uint64_t et_;
0190 
0191   std::vector<GEMOptoHybrid> gebd_;  ///<Vector of GEB data
0192 };
0193 #endif