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 l1t::LUT convertToLUT(const std::vector<uint64_t> &v, int padding=-1) noexcept {
11 
12  unsigned int addrWidth = ( 32 - __builtin_clz( uint32_t(v.size()-1) ) );
13  std::stringstream oss;
14  oss << "#<header> V1 " << addrWidth << " 31 </header> " << std::endl; // hardcode 32 bits for data
15  for(unsigned int i=0; i<v.size(); i++) 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 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 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 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 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 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 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 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 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 }
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
#define noexcept
Definition: LUT.h:29