Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include "L1Trigger/DemonstratorTools/interface/codecs/tkjets.h"
0003 
0004 namespace l1t::demo::codecs {
0005 
0006   ap_uint<64> encodeTkJet(const l1t::TkJetWord& j) { return j.tkJetWord(); }
0007 
0008   // Encodes vertex collection onto 1 output link
0009   std::array<std::vector<ap_uint<64>>, 1> encodeTkJets(const edm::View<l1t::TkJetWord>& tkJets) {
0010     std::vector<ap_uint<64>> tkJetWords;
0011 
0012     for (const auto& tkJet : tkJets) {
0013       tkJetWords.push_back(encodeTkJet(tkJet));
0014       tkJetWords.push_back(ap_uint<64>(0));
0015     }
0016 
0017     std::array<std::vector<ap_uint<64>>, 1> linkData;
0018 
0019     for (size_t i = 0; i < linkData.size(); i++) {
0020       // Pad TkJet vectors -> full packet length (48 frames, but only 12 TkJets max, two words per jet)
0021       tkJetWords.resize(24, 0);
0022       linkData.at(i) = tkJetWords;
0023     }
0024 
0025     return linkData;
0026   }
0027 
0028   std::vector<l1t::TkJetWord> decodeTkJets(const std::vector<ap_uint<64>>& frames) {
0029     std::vector<l1t::TkJetWord> tkJets;
0030 
0031     for (size_t f = 0; f < frames.size(); f += 2) {
0032       // There is no valid bit in the definition right now.
0033       // Uncomment the next two lines when this is available.
0034       //if (not x.test(TkJetWord::kValidLSB))
0035       //  break;
0036 
0037       TkJetWord j(
0038           TkJetWord::pt_t(frames[f](TkJetWord::TkJetBitLocations::kPtMSB, TkJetWord::TkJetBitLocations::kPtLSB)),
0039           TkJetWord::glbphi_t(
0040               frames[f](TkJetWord::TkJetBitLocations::kGlbPhiMSB, TkJetWord::TkJetBitLocations::kGlbPhiLSB)),
0041           TkJetWord::glbeta_t(
0042               frames[f](TkJetWord::TkJetBitLocations::kGlbEtaMSB, TkJetWord::TkJetBitLocations::kGlbEtaLSB)),
0043           TkJetWord::z0_t(frames[f](TkJetWord::TkJetBitLocations::kZ0MSB, TkJetWord::TkJetBitLocations::kZ0LSB)),
0044           TkJetWord::nt_t(frames[f](TkJetWord::TkJetBitLocations::kNtMSB, TkJetWord::TkJetBitLocations::kNtLSB)),
0045           TkJetWord::nx_t(frames[f](TkJetWord::TkJetBitLocations::kXtMSB, TkJetWord::TkJetBitLocations::kXtLSB)),
0046           TkJetWord::dispflag_t(
0047               frames[f](TkJetWord::TkJetBitLocations::kDispFlagMSB, TkJetWord::TkJetBitLocations::kDispFlagLSB)),
0048           TkJetWord::tkjetunassigned_t(
0049               frames[f](TkJetWord::TkJetBitLocations::kUnassignedMSB, TkJetWord::TkJetBitLocations::kUnassignedLSB)));
0050       tkJets.push_back(j);
0051     }
0052 
0053     return tkJets;
0054   }
0055 
0056 }  // namespace l1t::demo::codecs