File indexing completed on 2024-04-06 12:21:25
0001 #ifndef L2EGENCODER_REF_H
0002 #define L2EGENCODER_REF_H
0003
0004 #include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
0005 #include "DataFormats/L1TParticleFlow/interface/egamma.h"
0006 #include "L1Trigger/Phase2L1ParticleFlow/interface/dbgPrintf.h"
0007
0008 namespace edm {
0009 class ParameterSet;
0010 }
0011
0012 namespace l1ct {
0013
0014 struct L2EgEncoderEmulator {
0015 L2EgEncoderEmulator(unsigned int nTKELE_OUT, unsigned int nTKPHO_OUT)
0016 : nTkEleOut_(nTKELE_OUT), nTkPhoOut_(nTKPHO_OUT), nEncodedWords_(nTKELE_OUT * 1.5 + nTKPHO_OUT * 1.5) {
0017 assert(nTkEleOut_ % 2 == 0);
0018 assert(nTkPhoOut_ % 2 == 0);
0019 };
0020
0021 L2EgEncoderEmulator(const edm::ParameterSet& iConfig);
0022
0023 void toFirmware(const std::vector<ap_uint<64>>& encoded_in, ap_uint<64> encoded_fw[]) const;
0024
0025 std::vector<ap_uint<64>> encodeLayer2EgObjs(const std::vector<EGIsoObjEmu>& photons,
0026 const std::vector<EGIsoEleObjEmu>& electrons) const {
0027 std::vector<ap_uint<64>> ret;
0028
0029 auto encoded_photons = encodeLayer2(photons);
0030 encoded_photons.resize(nTkPhoOut_, {0});
0031 auto encoded_eles = encodeLayer2(electrons);
0032 encoded_eles.resize(nTkEleOut_, {0});
0033
0034 encodeLayer2To64bits(encoded_eles, ret);
0035 encodeLayer2To64bits(encoded_photons, ret);
0036 return ret;
0037 }
0038
0039 template <class T>
0040 std::vector<ap_uint<64>> encodeLayer2EgObjs_trivial(const std::vector<T>& egs, int n) const {
0041 std::vector<ap_uint<64>> ret;
0042
0043 auto encoded_egs = encodeLayer2_trivial<T>(egs);
0044 encoded_egs.resize(n, {0});
0045
0046 encodeLayer2To64bits(encoded_egs, ret);
0047
0048 return ret;
0049 }
0050
0051 private:
0052 template <class T>
0053 ap_uint<96> encodeLayer2(const T& egiso) const {
0054 return egiso.toGT().pack();
0055 }
0056
0057 template <class T>
0058 std::vector<ap_uint<96>> encodeLayer2(const std::vector<T>& egisos) const {
0059 std::vector<ap_uint<96>> ret;
0060 ret.reserve(egisos.size());
0061 for (const auto& egiso : egisos) {
0062 ret.push_back(encodeLayer2(egiso));
0063 }
0064 return ret;
0065 }
0066
0067 template <class T>
0068 ap_uint<96> encodeLayer2_trivial(const T& egiso) const {
0069 ap_uint<96> ret = 0;
0070 ret(T::BITWIDTH - 1, 0) = egiso.pack();
0071 return ret;
0072 }
0073
0074 template <class T>
0075 std::vector<ap_uint<96>> encodeLayer2_trivial(const std::vector<T>& egisos) const {
0076 std::vector<ap_uint<96>> ret;
0077 for (const auto& egiso : egisos) {
0078 ret.push_back(encodeLayer2_trivial(egiso));
0079 }
0080 return ret;
0081 }
0082
0083 void encodeLayer2To64bits(const std::vector<ap_uint<96>>& packed96, std::vector<ap_uint<64>>& packed64) const {
0084 for (unsigned int i = 0; i < packed96.size(); i += 2) {
0085 packed64.push_back(packed96[i](63, 0));
0086 packed64.push_back((ap_uint<32>(packed96[i + 1](95, 64)), ap_uint<32>(packed96[i](95, 64))));
0087 packed64.push_back(packed96[i + 1](63, 0));
0088 }
0089 }
0090
0091 unsigned int nTkEleOut_;
0092 unsigned int nTkPhoOut_;
0093 unsigned int nEncodedWords_;
0094 };
0095
0096 }
0097 #endif