Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:54:14

0001 
0002 #include "L1Trigger/DemonstratorTools/interface/codecs/vertices.h"
0003 
0004 namespace l1t::demo::codecs {
0005 
0006   ap_uint<64> encodeVertex(const l1t::VertexWord& v) { return v.vertexWord(); }
0007 
0008   // Encodes vertex collection onto 1 output link
0009   std::array<std::vector<ap_uint<64>>, 1> encodeVertices(const edm::View<l1t::VertexWord>& vertices) {
0010     std::vector<ap_uint<64>> vertexWords;
0011 
0012     for (const auto& vertex : vertices)
0013       vertexWords.push_back(encodeVertex(vertex));
0014 
0015     std::array<std::vector<ap_uint<64>>, 1> linkData;
0016 
0017     for (size_t i = 0; i < linkData.size(); i++) {
0018       // Pad vertex vectors -> full packet length (48 frames, but only 10 vertices max)
0019       vertexWords.resize(10, 0);
0020       linkData.at(i) = vertexWords;
0021     }
0022 
0023     return linkData;
0024   }
0025 
0026   std::vector<l1t::VertexWord> decodeVertices(const std::vector<ap_uint<64>>& frames) {
0027     std::vector<l1t::VertexWord> vertices;
0028 
0029     for (const auto& x : frames) {
0030       if (not x.test(VertexWord::kValidLSB))
0031         break;
0032 
0033       VertexWord v(VertexWord::vtxvalid_t(1),
0034                    VertexWord::vtxz0_t(x(VertexWord::kZ0MSB, VertexWord::kZ0LSB)),
0035                    VertexWord::vtxmultiplicity_t(x(VertexWord::kNTrackInPVMSB, VertexWord::kNTrackInPVLSB)),
0036                    VertexWord::vtxsumpt_t(x(VertexWord::kSumPtMSB, VertexWord::kSumPtLSB)),
0037                    VertexWord::vtxquality_t(x(VertexWord::kQualityMSB, VertexWord::kQualityLSB)),
0038                    VertexWord::vtxinversemult_t(x(VertexWord::kNTrackOutPVMSB, VertexWord::kNTrackOutPVLSB)),
0039                    VertexWord::vtxunassigned_t(x(VertexWord::kUnassignedMSB, VertexWord::kUnassignedLSB)));
0040       vertices.push_back(v);
0041     }
0042 
0043     return vertices;
0044   }
0045 
0046 }  // namespace l1t::demo::codecs