CMS 3D CMS Logo

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