CMS 3D CMS Logo

ConvertToLUT.h
Go to the documentation of this file.
1 #ifndef L1Trigger_L1TCommon_l1t_ConvertToLUT
2 #define L1Trigger_L1TCommon_l1t_ConvertToLUT
3 
4 #include <vector>
5 #include <sstream>
7 
8 namespace l1t {
9 
10  inline l1t::LUT convertToLUT(const std::vector<uint64_t> &v, int padding = -1) noexcept {
11  unsigned int addrWidth = (32 - __builtin_clz(uint32_t(v.size() - 1)));
12  std::stringstream oss;
13  oss << "#<header> V1 " << addrWidth << " 31 </header> " << std::endl; // hardcode 32 bits for data
14  for (unsigned int i = 0; i < v.size(); i++)
15  oss << i << " " << v[i] << std::endl;
16  // add padding to 2^addrWidth rows
17  if (padding >= 0)
18  for (unsigned int i = v.size(); i < (size_t)(1 << addrWidth); i++)
19  oss << i << " " << padding << std::endl;
20 
21  l1t::LUT lut;
22  lut.read(oss);
23 
24  return lut;
25  }
26 
27  inline l1t::LUT convertToLUT(const std::vector<char> &v, int padding = -1) noexcept {
28  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
29  }
30  inline l1t::LUT convertToLUT(const std::vector<short> &v, int padding = -1) noexcept {
31  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
32  }
33  inline l1t::LUT convertToLUT(const std::vector<int> &v, int padding = -1) noexcept {
34  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
35  }
36  inline l1t::LUT convertToLUT(const std::vector<long> &v, int padding = -1) noexcept {
37  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
38  }
39  inline l1t::LUT convertToLUT(const std::vector<long long> &v, int padding = -1) noexcept {
40  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
41  }
42  inline l1t::LUT convertToLUT(const std::vector<unsigned char> &v, int padding = -1) noexcept {
43  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
44  }
45  inline l1t::LUT convertToLUT(const std::vector<unsigned short> &v, int padding = -1) noexcept {
46  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
47  }
48  inline l1t::LUT convertToLUT(const std::vector<unsigned int> &v, int padding = -1) noexcept {
49  return convertToLUT(std::vector<uint64_t>(v.begin(), v.end()), padding);
50  }
51 } // namespace l1t
52 
53 #endif
delete x;
Definition: CaloConfig.h:22
int read(std::istream &stream)
Definition: LUT.cc:11
l1t::LUT convertToLUT(const std::vector< uint64_t > &v, int padding=-1) noexcept
Definition: ConvertToLUT.h:10
Definition: LUT.h:29