Go to the documentation of this file.00001 #ifndef L1GCTLUT_H_
00002 #define L1GCTLUT_H_
00003
00004 #include <boost/cstdint.hpp>
00005
00006 #include <iostream>
00007 #include <iomanip>
00008 #include <sstream>
00009
00020 template <int NAddressBits, int NDataBits>
00021 class L1GctLut
00022 {
00023 public:
00024 static const uint16_t MAX_ADDRESS_BITMASK;
00025 static const uint16_t MAX_DATA_BITMASK;
00026
00027 virtual ~L1GctLut();
00028
00030 friend std::ostream& operator << (std::ostream& os, const L1GctLut<NAddressBits, NDataBits>& lut)
00031 {
00032
00033
00034
00035
00036 static const int maxAddress=L1GctLut<NAddressBits, NDataBits>::MAX_ADDRESS_BITMASK;
00037 static const int width=L1GctLut<NAddressBits, NDataBits>::printWidth;
00038
00039 os << lut.printHeader();
00040
00041 for (int a=0; a<=maxAddress; a += width) {
00042 os << lut.printLine(a);
00043 }
00044 return os;
00045
00046
00047 }
00048
00050 uint16_t lutValue (const uint16_t lutAddress) const;
00051
00053 uint16_t operator[] (const uint16_t lutAddress) const { return lutValue(lutAddress); }
00054
00056 template <int KAddressBits, int KDataBits>
00057 int operator==(const L1GctLut<KAddressBits, KDataBits>& rhsLut) const { return equalityCheck(rhsLut); }
00058
00060 template <int KAddressBits, int KDataBits>
00061 int operator!=(const L1GctLut<KAddressBits, KDataBits>& rhsLut) const { return !equalityCheck(rhsLut); }
00062
00063 bool setupOk() { return m_setupOk; }
00064
00066 void setVerbose() { m_verbose = true; }
00067 void setTerse() { m_verbose = false; }
00068
00069 protected:
00070
00071 L1GctLut();
00072
00073 virtual uint16_t value (const uint16_t lutAddress) const=0;
00074
00075 template <int KAddressBits, int KDataBits>
00076 bool equalityCheck(const L1GctLut<KAddressBits, KDataBits>& c) const;
00077
00078 bool m_setupOk;
00079 bool m_verbose;
00080
00081 private:
00082
00083
00084 static const int printWidth;
00085 std::string printHeader() const;
00086 std::string printLine(const int add) const;
00087
00088 };
00089
00090 template <int NAddressBits, int NDataBits>
00091 const uint16_t L1GctLut<NAddressBits, NDataBits>::MAX_ADDRESS_BITMASK = (1 << NAddressBits) - 1;
00092 template <int NAddressBits, int NDataBits>
00093 const uint16_t L1GctLut<NAddressBits, NDataBits>::MAX_DATA_BITMASK = (1 << NDataBits) - 1;
00094
00095 template <int NAddressBits, int NDataBits>
00096 const int L1GctLut<NAddressBits, NDataBits>::printWidth = 16;
00097
00098 template <int NAddressBits, int NDataBits>
00099 L1GctLut<NAddressBits, NDataBits>::L1GctLut() : m_setupOk(false) {}
00100
00101 template <int NAddressBits, int NDataBits>
00102 L1GctLut<NAddressBits, NDataBits>::~L1GctLut() {}
00103
00104 template <int NAddressBits, int NDataBits>
00105 uint16_t L1GctLut<NAddressBits, NDataBits>::lutValue(const uint16_t lutAddress) const
00106 {
00107 if (!m_setupOk) return (uint16_t) 0;
00108 uint16_t address=(lutAddress & MAX_ADDRESS_BITMASK);
00109 uint16_t data=(value(address) & MAX_DATA_BITMASK);
00110 return data;
00111 }
00112
00113 template <int NAddressBits, int NDataBits>
00114 template <int KAddressBits, int KDataBits>
00115 bool L1GctLut<NAddressBits, NDataBits>::equalityCheck(const L1GctLut<KAddressBits, KDataBits>& rhsLut) const
00116 {
00117 if (KAddressBits==NAddressBits && KDataBits==NDataBits) {
00118 bool match=true;
00119 for (uint16_t address=0; address<=MAX_ADDRESS_BITMASK; address++) {
00120 if (this->lutValue(address)!=rhsLut.lutValue(address)) { match = false; break; }
00121 }
00122 return match;
00123 } else {
00124 return false;
00125 }
00126 }
00127
00128 template <int NAddressBits, int NDataBits>
00129 std::string L1GctLut<NAddressBits, NDataBits>::printHeader() const
00130 {
00131 std::stringstream ss;
00132 ss << std::hex << std::showbase;
00133 ss << std::setw(8) << "|";
00134 for (int a=0; ((a<printWidth) && (a<=MAX_ADDRESS_BITMASK)); ++a) {
00135 ss << std::setw(7) << a;
00136 }
00137 ss << std::endl;
00138 ss << std::setfill('-') << std::setw(8) << "+";
00139 for (int a=0; ((a<printWidth) && (a<=MAX_ADDRESS_BITMASK)); ++a) {
00140 ss << std::setw(7) << "-";
00141 }
00142 ss << std::endl;
00143
00144 return ss.str();
00145 }
00146
00147 template <int NAddressBits, int NDataBits>
00148 std::string L1GctLut<NAddressBits, NDataBits>::printLine(const int add) const
00149 {
00150 std::stringstream ss;
00151 ss << std::hex << std::showbase;
00152 int a=add;
00153 ss << std::setw(7) << a << "|";
00154 for (int c=0; ((c<printWidth) && (a<=MAX_ADDRESS_BITMASK)); ++c) {
00155 uint16_t address = static_cast<uint16_t>(a++);
00156 ss << std::setw(7) << lutValue(address);
00157 }
00158 ss << std::endl;
00159
00160 return ss.str();
00161 }
00162
00163 #endif