Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:12

0001 #include "DataFormats/GEMDigi/interface/GEMVFAT.h"
0002 #include <iostream>
0003 
0004 GEMVFAT::GEMVFAT() : ver_(0), phiPos_(0), fw_(0), sw_(0), tw_(0) {}
0005 
0006 GEMVFAT::GEMVFAT(const int vfatVer,
0007                  const uint16_t BC,
0008                  const uint32_t EC,
0009                  const uint16_t chipID,
0010                  const uint64_t lsDatas,
0011                  const uint64_t msDatas) {
0012   // this constructor only used for packing sim digis
0013   VFATfirst fw{0};
0014   VFATsecond sw{0};
0015   VFATthird tw{0};
0016 
0017   fw.header = 0x1E;
0018 
0019   if (vfatVer == 3) {
0020     fw.bc = BC;
0021     fw.ec = EC;
0022     fw.pos = chipID;
0023   } else {
0024     fw.chipID = chipID;
0025     fw.b1110 = 14;
0026     fw.b1100 = 12;
0027     fw.b1010 = 10;
0028     fw.ecV2 = EC;
0029     fw.bcV2 = BC;
0030   }
0031 
0032   sw.lsData1 = lsDatas >> 48;
0033   tw.lsData2 = lsDatas & 0x0000ffffffffffff;
0034 
0035   fw.msData1 = msDatas >> 48;
0036   sw.msData2 = msDatas & 0x0000ffffffffffff;
0037   ver_ = vfatVer;
0038 
0039   fw_ = fw.word;
0040   sw_ = sw.word;
0041   tw_ = tw.word;
0042   // checkCRC only works after words are set
0043   // checkCRC not yet implemented for v3
0044   tw.crc = checkCRC();
0045   // once crc is found, save new third word
0046   tw_ = tw.word;
0047 }
0048 
0049 uint8_t GEMVFAT::quality() {
0050   uint8_t q = 0;
0051   if (ver_ == 2) {
0052     if (VFATthird{tw_}.crc != checkCRC())
0053       q = 1;
0054     if (VFATfirst{fw_}.b1010 != 10)
0055       q |= 1UL << 1;
0056     if (VFATfirst{fw_}.b1100 != 12)
0057       q |= 1UL << 2;
0058     if (VFATfirst{fw_}.b1110 != 14)
0059       q |= 1UL << 3;
0060   }
0061   // quality test not yet implemented in v3
0062   return q;
0063 }
0064 
0065 uint16_t GEMVFAT::crc_cal(uint16_t crc_in, uint16_t dato) {
0066   uint16_t v = 0x0001;
0067   uint16_t mask = 0x0001;
0068   uint16_t d = 0x0000;
0069   uint16_t crc_temp = crc_in;
0070   unsigned char datalen = 16;
0071   for (int i = 0; i < datalen; i++) {
0072     if (dato & v)
0073       d = 0x0001;
0074     else
0075       d = 0x0000;
0076     if ((crc_temp & mask) ^ d)
0077       crc_temp = crc_temp >> 1 ^ 0x8408;
0078     else
0079       crc_temp = crc_temp >> 1;
0080     v <<= 1;
0081   }
0082   return crc_temp;
0083 }
0084 
0085 uint16_t GEMVFAT::checkCRC() {
0086   uint16_t vfatBlockWords[12];
0087   vfatBlockWords[11] = ((0x000f & VFATfirst{fw_}.b1010) << 12) | VFATfirst{fw_}.bcV2;
0088   vfatBlockWords[10] =
0089       ((0x000f & VFATfirst{fw_}.b1100) << 12) | ((0x00ff & VFATfirst{fw_}.ecV2) << 4) | (0x000f & VFATfirst{fw_}.flag);
0090   vfatBlockWords[9] = ((0x000f & VFATfirst{fw_}.b1110) << 12) | VFATfirst{fw_}.chipID;
0091   vfatBlockWords[8] = (0xffff000000000000 & msData()) >> 48;
0092   vfatBlockWords[7] = (0x0000ffff00000000 & msData()) >> 32;
0093   vfatBlockWords[6] = (0x00000000ffff0000 & msData()) >> 16;
0094   vfatBlockWords[5] = (0x000000000000ffff & msData());
0095   vfatBlockWords[4] = (0xffff000000000000 & lsData()) >> 48;
0096   vfatBlockWords[3] = (0x0000ffff00000000 & lsData()) >> 32;
0097   vfatBlockWords[2] = (0x00000000ffff0000 & lsData()) >> 16;
0098   vfatBlockWords[1] = (0x000000000000ffff & lsData());
0099 
0100   uint16_t crc_fin = 0xffff;
0101   for (int i = 11; i >= 1; i--) {
0102     crc_fin = crc_cal(crc_fin, vfatBlockWords[i]);
0103   }
0104   return crc_fin;
0105 }