File indexing completed on 2024-04-06 12:04:12
0001 #ifndef DataFormats_GEMDigi_GEMAMC13Status_h
0002 #define DataFormats_GEMDigi_GEMAMC13Status_h
0003 #include "GEMAMC13.h"
0004 #include "GEMAMC.h"
0005 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0006 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0007 #include <bitset>
0008 #include <ostream>
0009
0010 class GEMAMC13Status {
0011 public:
0012 union Errors {
0013 uint8_t codes;
0014 struct {
0015 uint8_t InValidSize : 1;
0016 uint8_t failTrailerCheck : 1;
0017 uint8_t failFragmentLength : 1;
0018 uint8_t failTrailerMatch : 1;
0019 uint8_t moreTrailers : 1;
0020 uint8_t crcModified : 1;
0021 uint8_t slinkError : 1;
0022 uint8_t wrongFedId : 1;
0023 };
0024 };
0025 union Warnings {
0026 uint8_t wcodes;
0027 struct {
0028 uint8_t InValidAMC : 1;
0029 };
0030 };
0031
0032 GEMAMC13Status() {}
0033 GEMAMC13Status(const FEDRawData& fedData) {
0034 Errors error{0};
0035 if ((fedData.size() / sizeof(uint64_t)) < 5) {
0036 error.InValidSize = 1;
0037 } else {
0038 FEDTrailer trailer(fedData.data() + fedData.size() - FEDTrailer::length);
0039 error.failTrailerCheck = !trailer.check();
0040 error.failFragmentLength = (trailer.fragmentLength() * sizeof(uint64_t) != fedData.size());
0041 error.moreTrailers = trailer.moreTrailers();
0042 error.crcModified = trailer.crcModified();
0043 error.slinkError = trailer.slinkError();
0044 error.wrongFedId = trailer.wrongFedId();
0045 }
0046 errors_ = error.codes;
0047
0048 Warnings warn{0};
0049 warnings_ = warn.wcodes;
0050 }
0051 void inValidAMC() {
0052 Warnings warn{warnings_};
0053 warn.InValidAMC = 1;
0054 warnings_ = warn.wcodes;
0055 }
0056
0057 bool isBad() const { return errors_ != 0; }
0058 uint8_t errors() const { return errors_; }
0059 uint8_t warnings() const { return warnings_; }
0060
0061 private:
0062 uint8_t errors_;
0063 uint8_t warnings_;
0064 };
0065
0066 inline std::ostream& operator<<(std::ostream& out, const GEMAMC13Status& status) {
0067 out << "GEMAMC13Status errors " << std::bitset<8>(status.errors()) << " warnings "
0068 << std::bitset<8>(status.warnings());
0069 return out;
0070 }
0071
0072 #endif