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