Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:36:15

0001 #ifndef RctDataDecoder_hh
0002 #define RctDataDecoder_hh
0003 
0004 #include <cstdint>
0005 #include <vector>
0006 #include "EventFilter/RctRawToDigi/src/RCTInfo.hh"
0007 
0008 /*
0009  * Extract RCT Object Info from oRSC Output Fibers
0010  * Primarily intended for use on CTP7/MP7
0011  */
0012 
0013 class RctDataDecoder {
0014 public:
0015   bool decodeLinks(const std::vector<unsigned int> evenFiberData,
0016                    const std::vector<unsigned int> oddFiberData,
0017                    std::vector<RCTInfo> &rctInfoData) {
0018     // Ensure that there is data to process
0019     unsigned int nWordsToProcess = evenFiberData.size();
0020     unsigned int remainder = nWordsToProcess % 6;
0021     if (nWordsToProcess != oddFiberData.size()) {
0022       //std::cerr << "RCTInfoFactory::produce -- even and odd fiber sizes are different!" << std::endl;
0023       return false;
0024     }
0025     if (nWordsToProcess == 0 || nWordsToProcess / 6 == 0) {
0026       //std::cerr << "RCTInfoFactory::produce -- evenFiberData is null :(" << std::endl;
0027       return false;
0028     } else if ((nWordsToProcess % 6) != 0) {
0029       nWordsToProcess = nWordsToProcess - remainder;
0030     }
0031 
0032     // Extract RCTInfo
0033 
0034     unsigned int nBXToProcess = nWordsToProcess / 6;
0035 
0036     for (unsigned int iBX = 0; iBX < nBXToProcess; iBX++) {
0037       RCTInfo rctInfo;
0038       // We extract into rctInfo the data from RCT crate
0039       // Bit field description can be found in the spreadsheet:
0040       // https://twiki.cern.ch/twiki/pub/CMS/ORSCOperations/oRSCFiberDataSpecificationV5.xlsx
0041       // Even fiber bits contain 4x4 region information
0042       rctInfo.rgnEt[0][0] = (evenFiberData[iBX * 6 + 0] & 0x0003FF00) >> 8;
0043       rctInfo.rgnEt[0][1] = (evenFiberData[iBX * 6 + 0] & 0x0FFC0000) >> 18;
0044       rctInfo.rgnEt[1][0] = (evenFiberData[iBX * 6 + 0] & 0xF0000000) >> 28;
0045       rctInfo.rgnEt[1][0] |= (evenFiberData[iBX * 6 + 1] & 0x0000003F) << 4;
0046       rctInfo.rgnEt[1][1] = (evenFiberData[iBX * 6 + 1] & 0x0000FFC0) >> 6;
0047       rctInfo.rgnEt[2][0] = (evenFiberData[iBX * 6 + 1] & 0x03FF0000) >> 16;
0048       rctInfo.rgnEt[2][1] = (evenFiberData[iBX * 6 + 1] & 0xFC000000) >> 26;
0049       rctInfo.rgnEt[2][1] |= (evenFiberData[iBX * 6 + 2] & 0x0000000F) << 6;
0050       rctInfo.rgnEt[3][0] = (evenFiberData[iBX * 6 + 2] & 0x00003FF0) >> 4;
0051       rctInfo.rgnEt[3][1] = (evenFiberData[iBX * 6 + 2] & 0x00FFC000) >> 14;
0052       rctInfo.rgnEt[4][0] = (evenFiberData[iBX * 6 + 2] & 0xFF000000) >> 24;
0053       rctInfo.rgnEt[4][0] |= (evenFiberData[iBX * 6 + 3] & 0x00000003) << 8;
0054       rctInfo.rgnEt[4][1] = (evenFiberData[iBX * 6 + 3] & 0x00000FFC) >> 2;
0055       rctInfo.rgnEt[5][0] = (evenFiberData[iBX * 6 + 3] & 0x003FF000) >> 12;
0056       rctInfo.rgnEt[5][1] = (evenFiberData[iBX * 6 + 3] & 0xFFC00000) >> 22;
0057       rctInfo.rgnEt[6][0] = (evenFiberData[iBX * 6 + 4] & 0x000003FF) >> 0;
0058       rctInfo.rgnEt[6][1] = (evenFiberData[iBX * 6 + 4] & 0x000FFC00) >> 10;
0059       rctInfo.tBits = (evenFiberData[iBX * 6 + 4] & 0xFFF00000) >> 20;
0060       rctInfo.tBits |= (evenFiberData[iBX * 6 + 5] & 0x00000003) << 12;  //bug? 4 to 5
0061       rctInfo.oBits = (evenFiberData[iBX * 6 + 5] & 0x0000FFFC) >> 2;
0062       rctInfo.c4BC0 = (evenFiberData[iBX * 6 + 5] & 0x000C0000) >> 18;
0063       rctInfo.c5BC0 = (evenFiberData[iBX * 6 + 5] & 0x00300000) >> 20;
0064       rctInfo.c6BC0 = (evenFiberData[iBX * 6 + 5] & 0x00C00000) >> 22;
0065       // Odd fiber bits contain 2x1, HF and other miscellaneous information
0066       rctInfo.hfEt[0][0] = (oddFiberData[iBX * 6 + 0] & 0x0000FF00) >> 8;
0067       rctInfo.hfEt[0][1] = (oddFiberData[iBX * 6 + 0] & 0x00FF0000) >> 16;
0068       rctInfo.hfEt[1][0] = (oddFiberData[iBX * 6 + 0] & 0xFF000000) >> 24;
0069       rctInfo.hfEt[1][1] = (oddFiberData[iBX * 6 + 1] & 0x000000FF) >> 0;
0070       rctInfo.hfEt[0][2] = (oddFiberData[iBX * 6 + 1] & 0x0000FF00) >> 8;
0071       rctInfo.hfEt[0][3] = (oddFiberData[iBX * 6 + 1] & 0x00FF0000) >> 16;
0072       rctInfo.hfEt[1][2] = (oddFiberData[iBX * 6 + 1] & 0xFF000000) >> 24;
0073       rctInfo.hfEt[1][3] = (oddFiberData[iBX * 6 + 2] & 0x000000FF) >> 0;
0074       rctInfo.hfQBits = (oddFiberData[iBX * 6 + 2] & 0x0000FF00) >> 8;
0075       rctInfo.ieRank[0] = (oddFiberData[iBX * 6 + 2] & 0x003F0000) >> 16;
0076       rctInfo.ieRegn[0] = (oddFiberData[iBX * 6 + 2] & 0x00400000) >> 22;
0077       rctInfo.ieCard[0] = (oddFiberData[iBX * 6 + 2] & 0x03800000) >> 23;  //bug? 25 to 23
0078       rctInfo.ieRank[1] = (oddFiberData[iBX * 6 + 2] & 0xFC000000) >> 26;
0079       rctInfo.ieRegn[1] = (oddFiberData[iBX * 6 + 3] & 0x00000001) >> 0;
0080       rctInfo.ieCard[1] = (oddFiberData[iBX * 6 + 3] & 0x0000000E) >> 1;
0081       rctInfo.ieRank[2] = (oddFiberData[iBX * 6 + 3] & 0x000003F0) >> 4;
0082       rctInfo.ieRegn[2] = (oddFiberData[iBX * 6 + 3] & 0x00000400) >> 10;
0083       rctInfo.ieCard[2] = (oddFiberData[iBX * 6 + 3] & 0x00003800) >> 11;
0084       rctInfo.ieRank[3] = (oddFiberData[iBX * 6 + 3] & 0x000FC000) >> 14;
0085       rctInfo.ieRegn[3] = (oddFiberData[iBX * 6 + 3] & 0x00100000) >> 20;
0086       rctInfo.ieCard[3] = (oddFiberData[iBX * 6 + 3] & 0x00E00000) >> 21;
0087       rctInfo.neRank[0] = (oddFiberData[iBX * 6 + 3] & 0x3F000000) >> 24;
0088       rctInfo.neRegn[0] = (oddFiberData[iBX * 6 + 3] & 0x40000000) >> 30;
0089       rctInfo.neCard[0] = (oddFiberData[iBX * 6 + 3] & 0x80000000) >> 31;
0090       rctInfo.neCard[0] |= (oddFiberData[iBX * 6 + 4] & 0x00000003) << 1;  //bug? >> 0 to << 1
0091       rctInfo.neRank[1] = (oddFiberData[iBX * 6 + 4] & 0x000000FC) >> 2;
0092       rctInfo.neRegn[1] = (oddFiberData[iBX * 6 + 4] & 0x00000100) >> 8;
0093       rctInfo.neCard[1] = (oddFiberData[iBX * 6 + 4] & 0x00000E00) >> 9;
0094       rctInfo.neRank[2] = (oddFiberData[iBX * 6 + 4] & 0x0003F000) >> 12;
0095       rctInfo.neRegn[2] = (oddFiberData[iBX * 6 + 4] & 0x00040000) >> 18;
0096       rctInfo.neCard[2] = (oddFiberData[iBX * 6 + 4] & 0x00380000) >> 19;
0097       rctInfo.neRank[3] = (oddFiberData[iBX * 6 + 4] & 0x0FC00000) >> 22;
0098       rctInfo.neRegn[3] = (oddFiberData[iBX * 6 + 4] & 0x10000000) >> 28;
0099       rctInfo.neCard[3] = (oddFiberData[iBX * 6 + 4] & 0xE0000000) >> 29;
0100       rctInfo.mBits = (oddFiberData[iBX * 6 + 5] & 0x00003FFF) >> 0;
0101       rctInfo.c1BC0 = (oddFiberData[iBX * 6 + 5] & 0x00030000) >> 16;
0102       rctInfo.c2BC0 = (oddFiberData[iBX * 6 + 5] & 0x000C0000) >> 18;
0103       rctInfo.c3BC0 = (oddFiberData[iBX * 6 + 5] & 0x00300000) >> 20;
0104       rctInfoData.push_back(rctInfo);
0105     }
0106     return true;
0107   }
0108 
0109   bool setRCTInfoCrateID(std::vector<RCTInfo> &rctInfoVector, unsigned int crateID) {
0110     for (unsigned int i = 0; i < rctInfoVector.size(); i++) {
0111       rctInfoVector.at(i).crateID = crateID;
0112     }
0113 
0114     return true;
0115   }
0116 
0117   bool decodeLinkID(const uint32_t inputValue, uint32_t &crateNumber, bool &even) {
0118     uint32_t linkNumber;
0119     //if crateNumber not valid set to 0xFF
0120     crateNumber = (inputValue >> 8) & 0xFF;
0121     if (crateNumber > 17)
0122       crateNumber = 0xFF;
0123 
0124     //if linkNumber not valid set to 0xFF
0125     linkNumber = (inputValue) & 0xFF;
0126 
0127     if (linkNumber > 12)
0128       linkNumber = 0xFF;
0129 
0130     if ((linkNumber & 0x1) == 0)
0131       even = true;
0132     else
0133       even = false;
0134 
0135     return true;
0136   };
0137 
0138   bool getExpectedLinkID(const uint32_t iLink, uint32_t &crateID, bool &even) {
0139     if (iLink == 0)  //: 90a
0140     {
0141       crateID = 9;
0142       even = true;
0143     } else if (iLink == 1)  //a0a
0144     {
0145       crateID = 10;
0146       even = true;
0147     } else if (iLink == 2)  // 60a
0148     {
0149       crateID = 6;
0150       even = true;
0151     } else if (iLink == 3)  // 90b
0152     {
0153       crateID = 9;
0154       even = false;
0155     } else if (iLink == 4)  // 60b
0156     {
0157       crateID = 6;
0158       even = false;
0159     } else if (iLink == 5)  // 706
0160     {
0161       crateID = 7;
0162       even = true;
0163     } else if (iLink == 6)  // b0a
0164     {
0165       crateID = 11;
0166       even = true;
0167     } else if (iLink == 7)  // 70b
0168     {
0169       crateID = 7;
0170       even = false;
0171     } else if (iLink == 8)  // 80b
0172     {
0173       crateID = 8;
0174       even = false;
0175     } else if (iLink == 9)  // a0b
0176     {
0177       crateID = 10;
0178       even = false;
0179     } else if (iLink == 10)  // 80a
0180     {
0181       crateID = 8;
0182       even = true;
0183     } else if (iLink == 11)  // b0b
0184     {
0185       crateID = 11;
0186       even = false;
0187     } else if (iLink == 12)  // 30a
0188     {
0189       crateID = 3;
0190       even = true;
0191     } else if (iLink == 13)  // 40a
0192     {
0193       crateID = 4;
0194       even = true;
0195     } else if (iLink == 14)  // 30b
0196     {
0197       crateID = 3;
0198       even = false;
0199     } else if (iLink == 15)  // a
0200     {
0201       crateID = 0;
0202       even = true;
0203     } else if (iLink == 16)  // b
0204     {
0205       crateID = 0;
0206       even = false;
0207     } else if (iLink == 17)  // 50a
0208     {
0209       crateID = 5;
0210       even = true;
0211     } else if (iLink == 18)  // 10a
0212     {
0213       crateID = 1;
0214       even = true;
0215     } else if (iLink == 19)  // 10b
0216     {
0217       crateID = 1;
0218       even = false;
0219     } else if (iLink == 20)  // 20a
0220     {
0221       crateID = 2;
0222       even = true;
0223     } else if (iLink == 21)  // 20b
0224     {
0225       crateID = 2;
0226       even = false;
0227     } else if (iLink == 22)  // 50b
0228     {
0229       crateID = 5;
0230       even = false;
0231     } else if (iLink == 23)  // 40b
0232     {
0233       crateID = 4;
0234       even = false;
0235     } else if (iLink == 24)  // f0a
0236     {
0237       crateID = 15;
0238       even = true;
0239     } else if (iLink == 25)  // 100a
0240     {
0241       crateID = 16;
0242       even = true;
0243     } else if (iLink == 26)  // f0b
0244     {
0245       crateID = 15;
0246       even = false;
0247     } else if (iLink == 27)  // c0a
0248     {
0249       crateID = 12;
0250       even = true;
0251     } else if (iLink == 28)  // c0b
0252     {
0253       crateID = 12;
0254       even = false;
0255     } else if (iLink == 29)  // 110a
0256     {
0257       crateID = 17;
0258       even = true;
0259     } else if (iLink == 30)  // d0a
0260     {
0261       crateID = 13;
0262       even = true;
0263     } else if (iLink == 31)  // d0b
0264     {
0265       crateID = 13;
0266       even = false;
0267     } else if (iLink == 32)  // e0a
0268     {
0269       crateID = 14;
0270       even = true;
0271     } else if (iLink == 33)  // e0b
0272     {
0273       crateID = 14;
0274       even = false;
0275     } else if (iLink == 34)  // 110b
0276     {
0277       crateID = 17;
0278       even = false;
0279     } else if (iLink == 35)  // 100b
0280     {
0281       crateID = 16;
0282       even = false;
0283     }
0284     return true;
0285   };
0286 };
0287 
0288 #endif