CMS 3D CMS Logo

L1MuGMTLUT.h
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
34 //
35 //
36 // Author :
37 // H. Sakulin HEPHY Vienna
38 //
39 // Migrated to CMSSW:
40 // I. Mikulec
41 //
42 //--------------------------------------------------
43 #ifndef L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h
44 #define L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h
45 
46 //---------------
47 // C++ Headers --
48 //---------------
49 
50 #include <vector>
51 #include <iostream>
52 //#include <sstream>
53 #include <string>
54 #include <cstdlib>
55 #include <cstdio>
56 
57 //----------------------
58 // Base Class Headers --
59 //----------------------
60 class L1MuGMTLUTConverter;
61 
62 //------------------------------------
63 // Collaborating Class Declarations --
64 //------------------------------------
66 
68 
69 // ---------------------
70 // -- Class Interface --
71 // ---------------------
72 
73 class L1MuGMTLUT {
74 public:
75  typedef std::pair<std::string, unsigned> port;
76 
78 
81 
83  L1MuGMTLUT(const char* name,
84  const std::vector<std::string>& instances,
85  const std::vector<port>& in_widths,
86  const std::vector<port>& out_widths,
87  unsigned vme_addr_width = 0,
88  bool distrRAM = false)
90  Init(name, instances, in_widths, out_widths, vme_addr_width, distrRAM);
91  };
92 
93  L1MuGMTLUT(const char* name,
94  const std::string& instances,
95  const std::string& inputs,
96  const std::string& outputs,
97  unsigned vme_addr_width = 0,
98  bool distrRAM = false)
100  Init(name,
101  L1MuGMTLUTHelpers::Tokenizer(" ", instances),
104  vme_addr_width,
105  distrRAM);
106  };
107 
109  virtual ~L1MuGMTLUT();
110 
113  inline unsigned LookupPacked(int idx, unsigned) const;
114 
116  inline unsigned LookupPacked(int idx, const std::vector<unsigned>& address) const {
117  return LookupPacked(idx, vec2u(address, m_Inputs));
118  };
119 
121  inline std::vector<unsigned> Lookup(int idx, const std::vector<unsigned>& address) const {
122  return Lookup(idx, vec2u(address, m_Inputs));
123  };
124 
126  inline std::vector<unsigned> Lookup(int idx, unsigned address) const {
127  return u2vec(LookupPacked(idx, address), m_Outputs);
128  };
129 
131 
133  void Load(const char* path);
134 
136  void Save(const char* path);
137 
140  virtual unsigned LookupFunctionPacked(int idx, unsigned address) const { return 0; };
141 
143  void MakeSubClass(const char* fname = "",
144  const char* template_file_h = "../interface/L1MuGMTLUT_SubClass.h_template",
145  const char* template_file_cc = "../interface/L1MuGMTLUT_SubClass.cc_template");
146 
147  std::string Name() { return m_name; };
148 
149  friend class L1MuGMTLUTConverter;
150 
152  int numberOfInstances() { return m_NLUTS; };
153 
154 protected:
156  void Init(const char* name,
157  const std::vector<std::string>& instances,
158  const std::vector<port>& in_widths,
159  const std::vector<port>& out_widths,
160  unsigned vme_addr_width = 0,
161  bool distrRAM = false);
162 
164  inline unsigned vec2u(const std::vector<unsigned>& vec, const std::vector<port>& widths) const;
165 
167  inline std::vector<unsigned> u2vec(unsigned value, const std::vector<port>& widths) const;
168 
170  void Set(int idx, unsigned address, unsigned value);
171 
172  class PortDecoder : public std::vector<port> {
173  typedef std::vector<port> base;
174 
175  public:
176  PortDecoder(const std::vector<port>& pt) : base(pt){};
177 
179  // decode std::string of style "phi(2) eta(4)"
181  for (unsigned int i = 0; i < tok.size(); i++) {
182  size_type obrace = tok[i].find("("), cbrace = tok[i].find(")");
183  if (obrace != std::string::npos && cbrace != std::string::npos)
184  push_back(
185  port(tok[i].substr(0, obrace), (unsigned)atoi(tok[i].substr(obrace + 1, cbrace - obrace - 1).c_str())));
186  else
187  edm::LogWarning("LUTMismatch") << "L1MuGMTLUT::PortDecoder: error decoding port " << tok[i];
188  }
189  };
192  for (unsigned int i = 0; i < size(); i++) {
193  // ostd::stringstream os; os << (*this)[i].second << ends;
194  // temp += (*this)[i].first + "(" + std::string( os.str() ) + ")";
195 
196  char buf[100];
197  sprintf(buf, "(%d)", (*this)[i].second);
198  temp += (*this)[i].first + std::string(buf);
199 
200  if (i != size() - 1)
201  temp += " ";
202  }
203  return temp;
204  };
205 
206  private:
207  };
208 
210  int m_NLUTS;
212  std::vector<std::string> m_InstNames;
213  std::vector<std::vector<unsigned> > m_Contents;
214  std::vector<port> m_Inputs; // first port in vector is most significant bits
215  std::vector<port> m_Outputs;
216  unsigned m_TotalInWidth;
217  unsigned m_TotalOutWidth;
223 };
224 
225 //--------------------------------------------------------------------------------
226 
227 unsigned L1MuGMTLUT::vec2u(const std::vector<unsigned>& vec, const std::vector<port>& widths) const {
228  if (vec.size() != widths.size()) {
229  edm::LogWarning("LUTMismatch")
230  << "Error in L1MuGMTLUT::vec2u: number of LUT inputs/outputs does not match definition";
231  return (0);
232  }
233 
234  unsigned value = 0;
235  unsigned start_ofs = 0;
236 
237  for (int i = vec.size() - 1; i >= 0; i--) {
238  if (vec[i] >= (unsigned)(1 << widths[i].second)) {
239  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::vec2u: LUT input/output number " << i
240  << " exceeds range (0 to " << ((1 << widths[i].second) - 1) << ").";
241  } else
242  value |= vec[i] << start_ofs;
243  start_ofs += widths[i].second;
244  }
245 
246  return (value);
247 }
248 
249 //--------------------------------------------------------------------------------
250 
251 std::vector<unsigned> L1MuGMTLUT::u2vec(unsigned value, const std::vector<port>& widths) const {
252  std::vector<unsigned> output(widths.size(), 0);
253 
254  unsigned start_ofs = 0;
255 
256  for (int i = widths.size() - 1; i >= 0; i--) {
257  int mask = ((1 << widths[i].second) - 1) << start_ofs;
258  output[i] = (value & mask) >> start_ofs;
259  start_ofs += widths[i].second;
260  }
261 
262  return output;
263 }
264 
265 //--------------------------------------------------------------------------------
266 
267 //
268 // the main lookup function
269 // looks up either from the function or the table
270 // checks the input and result ranges
271 //
272 unsigned L1MuGMTLUT::LookupPacked(int idx, unsigned address) const {
273  if (!m_initialized) {
274  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked: LUT not initialized. ";
275  return 0;
276  }
277  if (idx >= m_NLUTS) {
278  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked: LUT index exceeds range (0 to "
279  << (m_NLUTS - 1) << ").";
280  return 0;
281  }
282  if (address >= (unsigned)(1 << m_TotalInWidth)) {
283  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked: LUT input exceeds range (0 to "
284  << ((1 << m_TotalInWidth) - 1) << ").";
285  return 0;
286  }
287 
288  unsigned value = 0;
289  if (m_UseLookupFunction) {
290  value = LookupFunctionPacked(idx, address);
291  } else {
292  value = m_Contents[idx][address];
293  }
294 
295  // check range of output
296  if (value >= (unsigned)(1 << m_TotalOutWidth)) {
297  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked(): LUT output value " << value
298  << " exceeds range (0 to " << ((1 << m_TotalOutWidth) - 1) << ").";
299  edm::LogWarning("LUTMismatch") << " LUT name: " << m_name;
301  edm::LogWarning("LUTMismatch") << " Lookup Function has to be corrected!!!";
302  else
303  edm::LogWarning("LUTMismatch") << " LUT File has to be corrected!!!";
304  return (1 << m_TotalOutWidth) - 1;
305  }
306  return value;
307 }
308 
309 #endif
L1MuGMTLUT::PortDecoder::str
std::string str()
Definition: L1MuGMTLUT.h:190
L1MuGMTLUT::PortDecoder::PortDecoder
PortDecoder(const std::string &input)
Definition: L1MuGMTLUT.h:178
mps_fire.i
i
Definition: mps_fire.py:355
L1MuGMTLUT::numberOfInstances
int numberOfInstances()
get the number of Instances
Definition: L1MuGMTLUT.h:152
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
L1MuGMTLUT::m_name
std::string m_name
Definition: L1MuGMTLUT.h:220
funct::false
false
Definition: Factorize.h:34
L1MuGMTLUT::PortDecoder::base
std::vector< port > base
Definition: L1MuGMTLUT.h:173
L1MuGMTLUT::m_distrRAM
bool m_distrRAM
Definition: L1MuGMTLUT.h:219
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
L1MuGMTLUT::m_InstNames
std::vector< std::string > m_InstNames
Definition: L1MuGMTLUT.h:212
L1MuGMTLUT::L1MuGMTLUT
L1MuGMTLUT(const char *name, const std::vector< std::string > &instances, const std::vector< port > &in_widths, const std::vector< port > &out_widths, unsigned vme_addr_width=0, bool distrRAM=false)
constructor with init
Definition: L1MuGMTLUT.h:83
L1MuGMTLUT::m_Inputs
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214
L1MuGMTLUT::m_initialized
bool m_initialized
Definition: L1MuGMTLUT.h:209
PatBasicFWLiteJetAnalyzer_Selector_cfg.outputs
outputs
Definition: PatBasicFWLiteJetAnalyzer_Selector_cfg.py:48
L1MuGMTLUT::m_GeneralLUTVersion
unsigned m_GeneralLUTVersion
Definition: L1MuGMTLUT.h:222
charmTagsComputerCvsB_cfi.idx
idx
Definition: charmTagsComputerCvsB_cfi.py:108
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
L1MuGMTLUT::m_TotalOutWidth
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:217
L1MuGMTLUT::Load
void Load(const char *path)
I/O functions.
Definition: L1MuGMTLUT.cc:200
L1MuGMTLUT::m_saveFlag
bool m_saveFlag
Definition: L1MuGMTLUT.h:221
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
L1MuGMTLUT::PortDecoder::PortDecoder
PortDecoder(const std::vector< port > &pt)
Definition: L1MuGMTLUT.h:176
L1MuGMTLUT::LookupFunctionPacked
virtual unsigned LookupFunctionPacked(int idx, unsigned address) const
Definition: L1MuGMTLUT.h:140
L1MuGMTLUTHelpers::Tokenizer
Lookup Functions.
Definition: L1MuGMTLUTHelpers.h:47
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
L1MuGMTLUT::m_vme_addr_width
unsigned m_vme_addr_width
Definition: L1MuGMTLUT.h:218
L1MuGMTLUT::LookupPacked
unsigned LookupPacked(int idx, const std::vector< unsigned > &address) const
additional lookup function (std::vector -> unisgned)
Definition: L1MuGMTLUT.h:116
L1MuGMTLUT::~L1MuGMTLUT
virtual ~L1MuGMTLUT()
destructor
Definition: L1MuGMTLUT.cc:35
L1MuGMTLUT::Init
void Init(const char *name, const std::vector< std::string > &instances, const std::vector< port > &in_widths, const std::vector< port > &out_widths, unsigned vme_addr_width=0, bool distrRAM=false)
Initialize the LUT.
Definition: L1MuGMTLUT.cc:46
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
funct::true
true
Definition: Factorize.h:173
L1MuGMTLUT::MakeSubClass
void MakeSubClass(const char *fname="", const char *template_file_h="../interface/L1MuGMTLUT_SubClass.h_template", const char *template_file_cc="../interface/L1MuGMTLUT_SubClass.cc_template")
Add Generate SubClass method.
Definition: L1MuGMTLUT.cc:333
L1MuGMTLUT
Definition: L1MuGMTLUT.h:73
L1MuGMTLUT::LookupPacked
unsigned LookupPacked(int idx, unsigned) const
Definition: L1MuGMTLUT.h:272
value
Definition: value.py:1
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
L1MuGMTLUT::Set
void Set(int idx, unsigned address, unsigned value)
set with single address and value
Definition: L1MuGMTLUT.cc:177
L1MuGMTLUT::L1MuGMTLUT
L1MuGMTLUT(const char *name, const std::string &instances, const std::string &inputs, const std::string &outputs, unsigned vme_addr_width=0, bool distrRAM=false)
Definition: L1MuGMTLUT.h:93
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
L1MuGMTLUT::m_Contents
std::vector< std::vector< unsigned > > m_Contents
Definition: L1MuGMTLUT.h:213
L1MuGMTLUT::vec2u
unsigned vec2u(const std::vector< unsigned > &vec, const std::vector< port > &widths) const
generate address or value from composite address or value
Definition: L1MuGMTLUT.h:227
L1MuGMTLUT::port
std::pair< std::string, unsigned > port
Definition: L1MuGMTLUT.h:75
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
L1MuGMTLUT::m_Outputs
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:215
L1MuGMTLUTHelpers.h
relativeConstraints.value
value
Definition: relativeConstraints.py:53
L1MuGMTLUT::u2vec
std::vector< unsigned > u2vec(unsigned value, const std::vector< port > &widths) const
generate composite address or value from compact unsigned
Definition: L1MuGMTLUT.h:251
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
L1MuGMTLUT::Name
std::string Name()
Definition: L1MuGMTLUT.h:147
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
L1MuGMTLUT::m_UseLookupFunction
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211
L1MuGMTLUT::Lookup
std::vector< unsigned > Lookup(int idx, unsigned address) const
additional lookup function (unsigned -> std::vector)
Definition: L1MuGMTLUT.h:126
L1MuGMTLUT::L1MuGMTLUT
L1MuGMTLUT()
Init and Destruct.
Definition: L1MuGMTLUT.h:80
L1MuGMTLUT::Lookup
std::vector< unsigned > Lookup(int idx, const std::vector< unsigned > &address) const
additional lookup function (std::vector -> vector)
Definition: L1MuGMTLUT.h:121
L1MuGMTLUT::Save
void Save(const char *path)
save to LUT file
Definition: L1MuGMTLUT.cc:78
L1MuGMTLUT::m_NLUTS
int m_NLUTS
Definition: L1MuGMTLUT.h:210
L1MuGMTLUT::m_TotalInWidth
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:216
L1MuGMTLUT::PortDecoder
Definition: L1MuGMTLUT.h:172
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
L1MuGMTLUT::L1MuGMTLUTConverter
friend class L1MuGMTLUTConverter
Definition: L1MuGMTLUT.h:147