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  std::stringstream out;
11  headerToStream(out);
12  contentsToStream(out);
13  out << "}" << std::endl;
14  output << out.str();
15 }
16 
17 void
18 l1t::MicroGMTLUT::load(const std::string& inFileName) {
19  std::ifstream fstream;
20  fstream.open(edm::FileInPath(inFileName.c_str()).fullPath());
21  if (!fstream.good()) {
22  fstream.close();
23  throw cms::Exception("FileOpenError") << "Failed to open LUT file: " << inFileName;
24  }
25 
26 
27  std::string lineID = "";
28 
29  while (!fstream.eof()) {
30  // read until either end of file is reached or the CONTENT line is found
31  lineID = "";
32  fstream >> lineID;
33  if (lineID.find("CONTENT_VECTOR") != std::string::npos) break;
34  }
35 
36  if (fstream.eof()) {
37  fstream.close();
38  throw cms::Exception("FileOpenError") << "Failed to find LUT contents";
39  }
40 
41  for (int cntr = 0; cntr < (1 << m_totalInWidth); ++cntr) {
42  fstream >> m_contents[cntr];
43  }
44  m_initialized = true;
45  fstream.close();
46 }
47 
48 int
50 {
51  // sort to make sure the hash is correct?
52  if (m_initialized) {
53  return m_contents.at(input);
54  }
55  throw cms::Exception("Unitialized") << "If you're not loading a LUT from file you need to implement lookupPacked.";
56  return 0;
57 }
58 
59 void
61 {
62  for (int in = 0; in < (1 << m_totalInWidth); ++in) {
63  int out = lookupPacked(in);
64  m_contents[in] = out;
65  }
66  m_initialized = true;
67 }
68 
69 int
70 l1t::MicroGMTLUT::checkedInput(unsigned in, unsigned maxWidth) const
71 {
72  unsigned maxIn = (1 << maxWidth) - 1;
73  return (in < maxIn ? in : maxIn);
74 }
75 
76 void
77 l1t::MicroGMTLUT::contentsToStream(std::stringstream& stream)
78 {
79  stream << "\"CONTENT\" : [ ";
80 
81  int maxVal = (1<<m_totalInWidth);
82  for (int in = 0; in < maxVal; ++in) {
83  stream << lookupPacked(in);
84  if (in != maxVal - 1) {
85  stream << ", ";
86  }
87  }
88  stream << "] " << std::endl;
89 }
90 
91 void
92 l1t::MicroGMTLUT::headerToStream(std::stringstream& stream) const
93 {
94  stream << "{" << std::endl;
95  stream << "\"NAME\" : \"Name of the LUT\","<< std::endl;
96  stream << "\"INSTNACES\" : \"List (space separated) of instances of this LUT (differing contents but same in/output)\"," << std::endl;
97  stream << "\"INPUTS\" : \"List (space separated) of inputs in format <input_name>(<input_width>)\"," << std::endl;
98  stream << "\"OUTPUTS\" : \"List (space separated) of outputs in format <output_name>(<output_width>)\"," << std::endl;
99  stream << "\"IPBUS_ADD\" : \"Address for access via IPBus\"," << std::endl;
100  stream << "\"CONTENT_X\" : \"List (space separated) of outputs from packed int for zero-indexed instance X\"," << std::endl;
101 }
void contentsToStream(std::stringstream &stream)
Definition: MicroGMTLUT.cc:77
virtual int lookupPacked(int input) const
Definition: MicroGMTLUT.cc:49
int checkedInput(unsigned in, unsigned maxWidth) const
Definition: MicroGMTLUT.cc:70
static std::string const input
Definition: EdmProvDump.cc:43
void headerToStream(std::stringstream &stream) const
Definition: MicroGMTLUT.cc:92
tuple out
Definition: dbtoconf.py:99
void load(const std::string &inFileName)
Definition: MicroGMTLUT.cc:18
void save(std::ofstream &output)
Definition: MicroGMTLUT.cc:8