CMS 3D CMS Logo

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