test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GctLut.h
Go to the documentation of this file.
1 #ifndef L1GCTLUT_H_
2 #define L1GCTLUT_H_
3 
4 #include <boost/cstdint.hpp> //for uint16_t
5 
6 #include <iomanip>
7 #include <sstream>
8 
19 template <int NAddressBits, int NDataBits>
20 class L1GctLut
21 {
22 public:
23  static const uint16_t MAX_ADDRESS_BITMASK;
24  static const uint16_t MAX_DATA_BITMASK;
25 
26  virtual ~L1GctLut();
27 
29  friend std::ostream& operator << (std::ostream& os, const L1GctLut<NAddressBits, NDataBits>& lut)
30  {
31  //----------------------------------------------------------------------------------------
32  // Define the code here for the friend template function to get around
33  // compiler/linker problems when instantiating the template class.
34  // See http://www.parashift.com/c++-faq-lite/templates.html#faq-35.16
37 
38  os << lut.printHeader();
39 
40  for (int a=0; a<=maxAddress; a += width) {
41  os << lut.printLine(a);
42  }
43  return os;
44  // End of friend function definition
45  //----------------------------------------------------------------------------------------
46  }
47 
49  uint16_t lutValue (const uint16_t lutAddress) const;
50 
52  uint16_t operator[] (const uint16_t lutAddress) const { return lutValue(lutAddress); }
53 
55  template <int KAddressBits, int KDataBits>
56  int operator==(const L1GctLut<KAddressBits, KDataBits>& rhsLut) const { return equalityCheck(rhsLut); }
57 
59  template <int KAddressBits, int KDataBits>
60  int operator!=(const L1GctLut<KAddressBits, KDataBits>& rhsLut) const { return !equalityCheck(rhsLut); }
61 
62  bool setupOk() { return m_setupOk; }
63 
65  void setVerbose() { m_verbose = true; }
66  void setTerse() { m_verbose = false; }
67 
68 protected:
69 
70  L1GctLut();
71 
72  virtual uint16_t value (const uint16_t lutAddress) const=0;
73 
74  template <int KAddressBits, int KDataBits>
76 
77  bool m_setupOk;
78  bool m_verbose;
79 
80 private:
81 
82  // For use by the friend function to print the lut contents
83  static const int printWidth;
84  std::string printHeader() const;
85  std::string printLine(const int add) const;
86 
87 };
88 
89 template <int NAddressBits, int NDataBits>
90 const uint16_t L1GctLut<NAddressBits, NDataBits>::MAX_ADDRESS_BITMASK = (1 << NAddressBits) - 1;
91 template <int NAddressBits, int NDataBits>
92 const uint16_t L1GctLut<NAddressBits, NDataBits>::MAX_DATA_BITMASK = (1 << NDataBits) - 1;
93 
94 template <int NAddressBits, int NDataBits>
96 
97 template <int NAddressBits, int NDataBits>
99 
100 template <int NAddressBits, int NDataBits>
102 
103 template <int NAddressBits, int NDataBits>
104 uint16_t L1GctLut<NAddressBits, NDataBits>::lutValue(const uint16_t lutAddress) const
105 {
106  if (!m_setupOk) return (uint16_t) 0;
107  uint16_t address=(lutAddress & MAX_ADDRESS_BITMASK);
108  uint16_t data=(value(address) & MAX_DATA_BITMASK);
109  return data;
110 }
111 
112 template <int NAddressBits, int NDataBits>
113 template <int KAddressBits, int KDataBits>
115 {
116  if (KAddressBits==NAddressBits && KDataBits==NDataBits) {
117  bool match=true;
118  for (uint16_t address=0; address<=MAX_ADDRESS_BITMASK; address++) {
119  if (this->lutValue(address)!=rhsLut.lutValue(address)) { match = false; break; }
120  }
121  return match;
122  } else {
123  return false;
124  }
125 }
126 
127 template <int NAddressBits, int NDataBits>
129 {
130  std::stringstream ss;
131  ss << std::hex << std::showbase;
132  ss << std::setw(8) << "|";
133  for (int a=0; ((a<printWidth) && (a<=MAX_ADDRESS_BITMASK)); ++a) {
134  ss << std::setw(7) << a;
135  }
136  ss << std::endl;
137  ss << std::setfill('-') << std::setw(8) << "+";
138  for (int a=0; ((a<printWidth) && (a<=MAX_ADDRESS_BITMASK)); ++a) {
139  ss << std::setw(7) << "-";
140  }
141  ss << std::endl;
142 
143  return ss.str();
144 }
145 
146 template <int NAddressBits, int NDataBits>
148 {
149  std::stringstream ss;
150  ss << std::hex << std::showbase;
151  int a=add;
152  ss << std::setw(7) << a << "|";
153  for (int c=0; ((c<printWidth) && (a<=MAX_ADDRESS_BITMASK)); ++c) {
154  uint16_t address = static_cast<uint16_t>(a++);
155  ss << std::setw(7) << lutValue(address);
156  }
157  ss << std::endl;
158 
159  return ss.str();
160 }
161 
162 #endif /*L1GCTLUT_H_*/
void setVerbose()
control output messages
Definition: L1GctLut.h:65
L1GctLut()
Definition: L1GctLut.h:98
std::string printLine(const int add) const
Definition: L1GctLut.h:147
bool setupOk()
Definition: L1GctLut.h:62
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
bool m_verbose
Definition: L1GctLut.h:78
virtual uint16_t value(const uint16_t lutAddress) const =0
uint16_t operator[](const uint16_t lutAddress) const
Access the look-up table contents for a given Address.
Definition: L1GctLut.h:52
static const uint16_t MAX_ADDRESS_BITMASK
Definition: L1GctLut.h:23
static const int printWidth
Definition: L1GctLut.h:83
Base class for LookUp Tables.
Definition: L1GctLut.h:20
virtual ~L1GctLut()
Definition: L1GctLut.h:101
int operator==(const L1GctLut< KAddressBits, KDataBits > &rhsLut) const
Equality check between look-up tables.
Definition: L1GctLut.h:56
void setTerse()
Definition: L1GctLut.h:66
bool equalityCheck(const L1GctLut< KAddressBits, KDataBits > &c) const
Definition: L1GctLut.h:114
tuple lut
Definition: lumiPlot.py:244
static const uint16_t MAX_DATA_BITMASK
Definition: L1GctLut.h:24
bool m_setupOk
Definition: L1GctLut.h:77
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
uint16_t lutValue(const uint16_t lutAddress) const
Access the look-up table contents for a given Address.
Definition: L1GctLut.h:104
double a
Definition: hdecay.h:121
int operator!=(const L1GctLut< KAddressBits, KDataBits > &rhsLut) const
Inequality check between look-up tables.
Definition: L1GctLut.h:60
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::string printHeader() const
Definition: L1GctLut.h:128
volatile std::atomic< bool > shutdown_flag false