File indexing completed on 2024-04-06 12:20:26
0001 #ifndef L1Trigger_L1TCommon_l1t_ConvertToLUT
0002 #define L1Trigger_L1TCommon_l1t_ConvertToLUT
0003
0004 #include <vector>
0005 #include <sstream>
0006 #include "CondFormats/L1TObjects/interface/LUT.h"
0007
0008 namespace l1t {
0009
0010 inline l1t::LUT convertToLUT(const std::vector<uint64_t> &v, int padding = -1) noexcept {
0011 unsigned int addrWidth = (32 - __builtin_clz(uint32_t(v.size() - 1)));
0012 std::stringstream oss;
0013 oss << "#<header> V1 " << addrWidth << " 31 </header> " << std::endl;
0014 for (unsigned int i = 0; i < v.size(); i++)
0015 oss << i << " " << v[i] << std::endl;
0016
0017 if (padding >= 0)
0018 for (unsigned int i = v.size(); i < (size_t)(1 << addrWidth); i++)
0019 oss << i << " " << padding << std::endl;
0020
0021 l1t::LUT lut;
0022 lut.read(oss);
0023
0024 return lut;
0025 }
0026
0027 inline l1t::LUT convertToLUT(const std::vector<char> &v, int padding = -1) noexcept {
0028 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0029 }
0030 inline l1t::LUT convertToLUT(const std::vector<short> &v, int padding = -1) noexcept {
0031 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0032 }
0033 inline l1t::LUT convertToLUT(const std::vector<int> &v, int padding = -1) noexcept {
0034 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0035 }
0036 inline l1t::LUT convertToLUT(const std::vector<long> &v, int padding = -1) noexcept {
0037 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0038 }
0039 inline l1t::LUT convertToLUT(const std::vector<long long> &v, int padding = -1) noexcept {
0040 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0041 }
0042 inline l1t::LUT convertToLUT(const std::vector<unsigned char> &v, int padding = -1) noexcept {
0043 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0044 }
0045 inline l1t::LUT convertToLUT(const std::vector<unsigned short> &v, int padding = -1) noexcept {
0046 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0047 }
0048 inline l1t::LUT convertToLUT(const std::vector<unsigned int> &v, int padding = -1) noexcept {
0049 return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
0050 }
0051 }
0052
0053 #endif