Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-20 02:14:42

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