Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-30 01:52:18

0001 #ifndef DataFormats_GEMDigi_GEMAMCStatus_h
0002 #define DataFormats_GEMDigi_GEMAMCStatus_h
0003 #include "GEMAMC13.h"
0004 #include "GEMAMC.h"
0005 #include <bitset>
0006 #include <ostream>
0007 
0008 class GEMAMCStatus {
0009 public:
0010   union Errors {
0011     uint16_t ecodes;
0012     struct {
0013       uint16_t badEC : 1;  // event counter
0014       uint16_t badBC : 1;  // bunch crossing
0015       uint16_t badOC : 1;  // orbit number
0016       uint16_t badRunType : 1;
0017       uint16_t badCRC : 1;
0018       uint16_t MMCMlocked : 1;
0019       uint16_t DAQclocklocked : 1;
0020       uint16_t DAQnotReday : 1;
0021       uint16_t BC0locked : 1;
0022       uint16_t badFEDId : 1;
0023       uint16_t L1AFull : 1;
0024     };
0025   };
0026   union Warnings {
0027     uint8_t wcodes;
0028     struct {
0029       uint8_t InValidOH : 1;
0030       uint8_t backPressure : 1;
0031       uint8_t L1ANearFull : 1;
0032     };
0033   };
0034 
0035   GEMAMCStatus() {}
0036   GEMAMCStatus(const GEMAMC13* amc13, const GEMAMC& amc) {
0037     amcNum_ = amc.amcNum();
0038     Errors error{0};
0039     error.badEC = (amc13->lv1Id() != amc.lv1Id());
0040     // Last BC in AMC13 is different to TCDS, AMC, and VFAT
0041     error.badBC = !((amc13->bunchCrossing() == amc.bunchCrossing()) ||
0042                     (amc13->bunchCrossing() == 0 && amc.bunchCrossing() == GEMAMC13::lastBC));
0043     error.badRunType = amc.runType() != 0x1;
0044     // Last OC in AMC13 is different to TCDS, AMC, and VFAT
0045     if (amc.formatVer() == 0)
0046       error.badOC =
0047           !((uint16_t(amc13->orbitNumber()) == amc.orbitNumber()) ||
0048             (amc13->bunchCrossing() == 0 && uint16_t(amc.orbitNumber() + 1) == uint16_t(amc13->orbitNumber())));
0049     else
0050       error.badOC = !((amc13->orbitNumber() == (amc.orbitNumber() + 1)) ||
0051                       (amc13->bunchCrossing() == 0 && amc13->orbitNumber() == (amc.orbitNumber() + 2)));
0052     error.MMCMlocked = !amc.mmcmLocked();
0053     error.DAQclocklocked = !amc.daqClockLocked();
0054     error.DAQnotReday = !amc.daqReady();
0055     error.BC0locked = !amc.bc0locked();
0056     error.badFEDId = (amc13->sourceId() != amc.softSrcId() and amc.formatVer() != 0);
0057     error.L1AFull = (amc.l1aF() and amc.formatVer() != 0);
0058     errors_ = error.ecodes;
0059 
0060     Warnings warn{0};
0061     warn.backPressure = amc.backPressure();
0062     warn.L1ANearFull = (amc.l1aNF() and amc.formatVer() != 0);
0063     warnings_ = warn.wcodes;
0064   }
0065 
0066   void inValidOH() {
0067     Warnings warn{warnings_};
0068     warn.InValidOH = 1;
0069     warnings_ = warn.wcodes;
0070   }
0071 
0072   uint8_t amcNumber() const { return amcNum_; };
0073   bool isBad() const { return errors_ != 0; }
0074   uint16_t errors() const { return errors_; }
0075   uint8_t warnings() const { return warnings_; }
0076 
0077 private:
0078   uint8_t amcNum_;
0079   uint16_t errors_;
0080   uint8_t warnings_;
0081 };
0082 
0083 inline std::ostream& operator<<(std::ostream& out, const GEMAMCStatus& status) {
0084   out << "GEMAMCStatus errors " << std::bitset<16>(status.errors()) << " warnings "
0085       << std::bitset<8>(status.warnings());
0086   return out;
0087 }
0088 
0089 #endif