Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_GEMDigi_GEMVFATStatus_h
0002 #define DataFormats_GEMDigi_GEMVFATStatus_h
0003 #include "GEMAMC.h"
0004 #include "GEMOptoHybrid.h"
0005 #include "GEMVFAT.h"
0006 #include <bitset>
0007 #include <ostream>
0008 
0009 class GEMVFATStatus {
0010 public:
0011   union Errors {
0012     uint8_t codes;
0013     struct {
0014       uint8_t vc : 1;  // VFAT CRC error
0015       uint8_t InValidHeader : 1;
0016       uint8_t EC : 1;        // does not match AMC EC
0017       uint8_t BC : 1;        // does not match AMC BC
0018       uint8_t vfatMask : 1;  // VFAT mask error
0019       uint8_t zsMask : 1;    // Zero Suppression mask error
0020     };
0021   };
0022   union Warnings {
0023     uint8_t wcodes;
0024     struct {
0025       uint8_t basicOFW : 1;    // Basic overflow warning
0026       uint8_t zeroSupOFW : 1;  // Zero-sup overflow warning
0027     };
0028   };
0029 
0030   GEMVFATStatus() {}
0031   GEMVFATStatus(const GEMAMC& amc, const GEMOptoHybrid& oh, const GEMVFAT& vfat, int chamberType, bool readMultiBX)
0032       : chamberType_(chamberType) {
0033     Errors error{0};
0034     Warnings warn{0};
0035 
0036     error.EC = vfat.ec() != amc.lv1Idt();
0037     if (!readMultiBX)
0038       error.BC = vfat.bc() != amc.bunchCrossing();
0039 
0040     if (oh.version() != 0) {
0041       error.vfatMask = (oh.vfatMask() >> vfat.vfatId()) ^ 0x1;
0042       error.zsMask = (oh.zsMask() >> vfat.vfatId()) & 0x1;
0043     }
0044 
0045     if (vfat.version() > 2) {
0046       error.vc = vfat.vc();
0047       if (vfat.header() == 0x1E)
0048         warn.basicOFW = 0;
0049       else if (vfat.header() == 0x5E)
0050         warn.basicOFW = 1;
0051       else if (vfat.header() == 0x1A)
0052         warn.zeroSupOFW = 0;
0053       else if (vfat.header() == 0x56)
0054         warn.zeroSupOFW = 1;
0055       else
0056         error.InValidHeader = 1;
0057     }
0058     vfatPosition_ = vfat.vfatId();
0059 
0060     errors_ = error.codes;
0061     warnings_ = warn.wcodes;
0062   }
0063 
0064   uint16_t vfatPosition() const { return vfatPosition_; }
0065   bool isBad() const { return errors_ != 0; }
0066   uint8_t errors() const { return errors_; }
0067   uint8_t warnings() const { return warnings_; }
0068   int chamberType() const { return chamberType_; }
0069 
0070 private:
0071   int chamberType_;
0072   uint16_t vfatPosition_;
0073   uint8_t errors_;
0074   uint8_t warnings_;
0075 };
0076 
0077 inline std::ostream& operator<<(std::ostream& out, const GEMVFATStatus& status) {
0078   out << "GEMVFATStatus errors " << std::bitset<8>(status.errors()) << " warnings "
0079       << std::bitset<8>(status.warnings());
0080   return out;
0081 }
0082 #endif