CMS 3D CMS Logo

MicroGMTLUT.cc
Go to the documentation of this file.
1 
5 
6 l1t::MicroGMTLUT::MicroGMTLUT(l1t::LUT* lut) : m_totalInWidth(0), m_outWidth(0), m_initialized(true)
7 {
8  std::stringstream ss;
9  lut->write(ss);
10  read(ss);
11 }
12 
13 // I/O functions
14 void
16 {
17  write(output);
18 }
19 
20 int
21 l1t::MicroGMTLUT::load(const std::string& inFileName) {
22  std::ifstream fstream;
23  fstream.open(edm::FileInPath(inFileName.c_str()).fullPath());
24  if (!fstream.good()) {
25  fstream.close();
26  throw cms::Exception("FileOpenError") << "Failed to open LUT file: " << inFileName;
27  }
28  int readCode = read(fstream);
29 
30  m_initialized = true;
31  fstream.close();
32 
33  return readCode;
34 }
35 
36 int
38 {
39  if (m_initialized) {
40  return data((unsigned int) input);
41  }
42  throw cms::Exception("Uninitialized") << "If you're not loading a LUT from file you need to implement lookupPacked.";
43  return 0;
44 }
45 
46 void
48 {
49  if (empty()) {
50  std::stringstream stream;
51  stream <<"#<header> V1 "<<m_totalInWidth<<" "<<m_outWidth<<" </header> "<<std::endl;
52  for (int in = 0; in < (1 << m_totalInWidth); ++in) {
53  int out = lookupPacked(in);
54  stream << in << " " << out << std::endl;
55  }
56  read(stream);
57  }
58  m_initialized = true;
59 }
60 
61 int
62 l1t::MicroGMTLUT::checkedInput(unsigned in, unsigned maxWidth) const
63 {
64  unsigned maxIn = (1 << maxWidth) - 1;
65  return (in < maxIn ? in : maxIn);
66 }
67 
unsigned m_totalInWidth
Definition: MicroGMTLUT.h:34
void write(std::ostream &stream) const
Definition: LUT.cc:86
bool empty() const
Definition: LUT.h:54
int load(const std::string &inFileName)
Definition: MicroGMTLUT.cc:21
virtual int lookupPacked(int input) const
Definition: MicroGMTLUT.cc:37
int checkedInput(unsigned in, unsigned maxWidth) const
Definition: MicroGMTLUT.cc:62
static std::string const input
Definition: EdmProvDump.cc:44
int read(std::istream &stream)
Definition: LUT.cc:35
Definition: LUT.h:29
unsigned m_outWidth
Definition: MicroGMTLUT.h:35
void save(std::ofstream &output)
Definition: MicroGMTLUT.cc:15
int data(unsigned int address) const
Definition: LUT.h:46