CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
L1MuGMTLUT Class Reference

#include <L1MuGMTLUT.h>

Inheritance diagram for L1MuGMTLUT:
L1MuGMTLFCOUDeltaEtaLUT L1MuGMTLFDeltaEtaLUT L1MuGMTLFDisableHotLUT L1MuGMTLFEtaConvLUT L1MuGMTLFMatchQualLUT L1MuGMTLFMergeRankCombineLUT L1MuGMTLFMergeRankEtaPhiLUT L1MuGMTLFMergeRankEtaQLUT L1MuGMTLFMergeRankPtQLUT L1MuGMTLFOvlEtaConvLUT L1MuGMTLFPhiProEtaConvLUT L1MuGMTLFPhiProLUT L1MuGMTLFPtMixLUT L1MuGMTLFSortRankCombineLUT L1MuGMTLFSortRankEtaPhiLUT L1MuGMTLFSortRankEtaQLUT L1MuGMTLFSortRankPtQLUT L1MuGMTMIAUEtaConvLUT L1MuGMTMIAUEtaProLUT L1MuGMTMIAUPhiPro1LUT L1MuGMTMIAUPhiPro2LUT

Classes

class  PortDecoder
 

Public Types

typedef std::pair< std::string, unsigned > port
 

Public Member Functions

 L1MuGMTLUT ()
 Init and Destruct. More...
 
 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 More...
 
 L1MuGMTLUT (const char *name, const std::string &instances, const std::string &inputs, const std::string &outputs, unsigned vme_addr_width=0, bool distrRAM=false)
 
void Load (const char *path)
 I/O functions. More...
 
std::vector< unsigned > Lookup (int idx, const std::vector< unsigned > &address) const
 additional lookup function (std::vector -> vector) More...
 
std::vector< unsigned > Lookup (int idx, unsigned address) const
 additional lookup function (unsigned -> std::vector) More...
 
virtual unsigned LookupFunctionPacked (int idx, unsigned address) const
 
unsigned LookupPacked (int idx, unsigned) const
 
unsigned LookupPacked (int idx, const std::vector< unsigned > &address) const
 additional lookup function (std::vector -> unisgned) More...
 
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. More...
 
std::string Name ()
 
int numberOfInstances ()
 get the number of Instances More...
 
void Save (const char *path)
 save to LUT file More...
 
virtual ~L1MuGMTLUT ()
 destructor More...
 

Protected Member Functions

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. More...
 
void Set (int idx, unsigned address, unsigned value)
 set with single address and value More...
 
std::vector< unsigned > u2vec (unsigned value, const std::vector< port > &widths) const
 generate composite address or value from compact unsigned More...
 
unsigned vec2u (const std::vector< unsigned > &vec, const std::vector< port > &widths) const
 generate address or value from composite address or value More...
 

Protected Attributes

std::vector< std::vector< unsigned > > m_Contents
 
bool m_distrRAM
 
unsigned m_GeneralLUTVersion
 
bool m_initialized
 
std::vector< portm_Inputs
 
std::vector< std::string > m_InstNames
 
std::string m_name
 
int m_NLUTS
 
std::vector< portm_Outputs
 
bool m_saveFlag
 
unsigned m_TotalInWidth
 
unsigned m_TotalOutWidth
 
bool m_UseLookupFunction
 
unsigned m_vme_addr_width
 

Friends

class L1MuGMTLUTConverter
 

Detailed Description

Description: A general-purpose Look-Up-Table Class

Base class for all LUTs in the Global Muon Trigger Simulation

INPUTS OUTPUTS


| | | |– Y(1) eta(6) –| | 1 8..13 | | phi(8) –| | 0..7 | |– X(1)

| | 0

std::vector<unsigned> inp; inp [0] = phi inp [1] = eta

std::vector<unsigned> out = MyLUT.Lookup (lutidx, inp); X = out[0]; Y = out[1];

Definition at line 73 of file L1MuGMTLUT.h.

Member Typedef Documentation

◆ port

typedef std::pair<std::string, unsigned> L1MuGMTLUT::port

Definition at line 75 of file L1MuGMTLUT.h.

Constructor & Destructor Documentation

◆ L1MuGMTLUT() [1/3]

L1MuGMTLUT::L1MuGMTLUT ( )
inline

Init and Destruct.

default constructor w/o init

Definition at line 80 of file L1MuGMTLUT.h.

80 : m_initialized(false), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false){};
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211
bool m_initialized
Definition: L1MuGMTLUT.h:209
bool m_saveFlag
Definition: L1MuGMTLUT.h:221

◆ L1MuGMTLUT() [2/3]

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 
)
inline

constructor with init

Definition at line 83 of file L1MuGMTLUT.h.

References Init(), submitPVValidationJobs::instances, and Skims_PA_cff::name.

89  : m_initialized(false), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {
90  Init(name, instances, in_widths, out_widths, vme_addr_width, distrRAM);
91  };
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211
bool m_initialized
Definition: L1MuGMTLUT.h:209
bool m_saveFlag
Definition: L1MuGMTLUT.h:221
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

◆ L1MuGMTLUT() [3/3]

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 
)
inline

Definition at line 93 of file L1MuGMTLUT.h.

References Init(), PixelMapPlotter::inputs, submitPVValidationJobs::instances, Skims_PA_cff::name, and PatBasicFWLiteJetAnalyzer_Selector_cfg::outputs.

99  : m_initialized(false), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {
100  Init(name,
102  PortDecoder(inputs),
103  PortDecoder(outputs),
104  vme_addr_width,
105  distrRAM);
106  };
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211
bool m_initialized
Definition: L1MuGMTLUT.h:209
bool m_saveFlag
Definition: L1MuGMTLUT.h:221
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

◆ ~L1MuGMTLUT()

L1MuGMTLUT::~L1MuGMTLUT ( )
virtual

destructor

Definition at line 35 of file L1MuGMTLUT.cc.

35  {
36  if (!m_UseLookupFunction) {
37  // de-allocate vectors
38  // no destuction needed for vector< vector <unsigned> >
39 
40  // for (int i=0;i < m_NLUTS; i++)
41  // m_Contents[i].clear();
42  // m_Contents.clear();
43  }
44 }
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211

Member Function Documentation

◆ Init()

void L1MuGMTLUT::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 
)
protected

Initialize the LUT.

Definition at line 46 of file L1MuGMTLUT.cc.

References L1MuGMTConfig::getVersionLUTs(), mps_fire::i, submitPVValidationJobs::instances, Skims_PA_cff::name, and edm::second().

Referenced by L1MuGMTLUT().

51  {
52  m_name = name;
54  m_NLUTS = instances.size();
55 
56  m_Inputs = in_widths;
57  m_TotalInWidth = 0;
58  for (unsigned i = 0; i < in_widths.size(); i++)
59  m_TotalInWidth += in_widths[i].second;
60 
61  m_Outputs = out_widths;
62  m_TotalOutWidth = 0;
63  for (unsigned i = 0; i < out_widths.size(); i++)
64  m_TotalOutWidth += out_widths[i].second;
65 
66  m_vme_addr_width = vme_addr_width;
67  m_distrRAM = distrRAM;
68 
69  if (m_distrRAM && (m_TotalInWidth != vme_addr_width)) {
70  edm::LogWarning("AddressMismatch") << "L1MuGMTLUT::Init(): for distributed RAM the GMT (Input) address width "
71  << "has to match the VME address width. Core Generation will not work.";
72  }
73 
75  m_initialized = true;
76 }
U second(std::pair< T, U > const &p)
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:215
static unsigned getVersionLUTs()
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:216
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214
bool m_initialized
Definition: L1MuGMTLUT.h:209
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:217
std::vector< std::string > m_InstNames
Definition: L1MuGMTLUT.h:212
std::string m_name
Definition: L1MuGMTLUT.h:220
bool m_distrRAM
Definition: L1MuGMTLUT.h:219
unsigned m_GeneralLUTVersion
Definition: L1MuGMTLUT.h:222
Log< level::Warning, false > LogWarning
unsigned m_vme_addr_width
Definition: L1MuGMTLUT.h:218

◆ Load()

void L1MuGMTLUT::Load ( const char *  path)

I/O functions.

load from LUT file

Definition at line 200 of file L1MuGMTLUT.cc.

References visDQMUpload::buf, spr::find(), mps_fire::i, recoMuon::in, mps_splice::line, castor_dqm_sourceclient_file_cfg::path, L1MuGMTLUTHelpers::replace(), and relativeConstraints::value.

200  {
201  string lf_name("");
202  vector<string> lf_InstNames;
203  vector<port> lf_Inputs;
204  vector<port> lf_Outputs;
205  unsigned lf_vme_addr_width = 0;
206  bool lf_distrRAM = false;
207  vector<string> lf_comments;
208 
209  ifstream in(path);
210  const int sz = 1000;
211  char buf[sz];
212 
213  // read header
214 
215  while (in.getline(buf, sz)) {
216  string line(buf);
217  string::size_type i = 0;
218  if ((i = line.find("//")) != string::npos) {
219  lf_comments.push_back(line.substr(i)); // save comments
220  line.erase(i); // and strip
221  }
223  if (tok.size() == 2) {
224  L1MuGMTLUTHelpers::replace(tok[0], " ", "", false); // skip spaces
225  L1MuGMTLUTHelpers::replace(tok[0], "\t", "", false); // skip tabs
226 
227  L1MuGMTLUTHelpers::replace(tok[1], "\t", " ", false); // convert tabs to spaces
228  L1MuGMTLUTHelpers::replace(tok[1], " ", " ", true); // skip multiple spaces
229  tok[1].erase(0, tok[1].find_first_not_of(' ')); // skip leading spaces
230  tok[1].erase(tok[1].find_last_not_of(' ') + 1); // skip trailing spaces
231 
232  if (tok[0] == "NAME")
233  lf_name = tok[1];
234  else if (tok[0] == "INSTANCES") {
235  lf_InstNames = L1MuGMTLUTHelpers::Tokenizer(" ", tok[1]);
236  } else if (tok[0] == "LUT_INPUTS")
237  lf_Inputs = PortDecoder(tok[1]);
238  else if (tok[0] == "LUT_OUTPUTS")
239  lf_Outputs = PortDecoder(tok[1]);
240  else if (tok[0] == "VME_ADDR_WIDTH")
241  lf_vme_addr_width = atoi(tok[1].c_str());
242  else if (tok[0] == "DISTRIBUTED_RAM")
243  lf_distrRAM = (atoi(tok[1].c_str()) == 1);
244  }
245  if (tok[0].find("CONTENTS") != string::npos)
246  break;
247  }
248 
249  if (!m_initialized) { // then initialize
250  Init(lf_name.c_str(), lf_InstNames, lf_Inputs, lf_Outputs, lf_vme_addr_width, lf_distrRAM);
251  } else { // verify compatibility
252  if (m_name != lf_name || m_InstNames != lf_InstNames || m_Inputs != lf_Inputs || m_Outputs != lf_Outputs ||
253  m_vme_addr_width != lf_vme_addr_width || m_distrRAM != lf_distrRAM) {
254  edm::LogWarning("LUTParmasMismatch")
255  << "L1MuGMTLUT::Load: error: parameters in file do not match configuration of LUT. Load failed.";
256  return;
257  }
258  }
259 
260  if (m_UseLookupFunction) {
261  // allocate vectors
262  m_Contents.resize(m_NLUTS);
263  for (int i = 0; i < m_NLUTS; i++)
264  m_Contents[i].resize(1 << m_TotalInWidth);
265 
266  // switch to table mode
267  m_UseLookupFunction = false;
268  }
269 
270  // continue to read contents (first line should be in buf)
271  int maxrows = 1 << m_TotalInWidth;
272  int row = 0;
273  int current_index = -1;
274  do {
275  string line(buf);
276  string::size_type i = 0;
277  if ((i = line.find("//")) != string::npos)
278  line.erase(i); // strip comments
280 
281  if (tok.size() == 2 && tok[0].find("CONTENTS") != string::npos) {
282  L1MuGMTLUTHelpers::Tokenizer tok1("_", tok[0]);
283  if (tok1.size() != 2) {
284  edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: error parsing contents tag " << tok[0] << ".";
285  break;
286  }
287 
288  istringstream is(tok1[1]);
289  int newindex;
290  is >> newindex;
291  if (newindex != current_index + 1)
292  edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: warning: LUTS in LUT file are not in order.";
293 
294  if (newindex > m_NLUTS - 1) {
295  edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: warning: LUT file contains LUT with too high index ("
296  << tok[0] << "). max = " << m_NLUTS << " skipping.";
297  newindex = -1;
298  }
299  current_index = newindex;
300 
301  if (row != 0) {
302  if (row < maxrows)
303  edm::LogWarning("LUTParsingProblem")
304  << "L1MuGMTLUT::Load: warning: LUT file only contains part of LUT contents.";
305  row = 0;
306  }
307  istringstream is1(tok[1]);
308  unsigned value;
309  if (is1 >> value) {
310  if (current_index != -1)
311  Set(current_index, row++, value);
312  }
313  } else {
314  istringstream is1(line);
315  unsigned value;
316  if (is1 >> value) {
317  if (row < maxrows) {
318  if (current_index != -1)
319  Set(current_index, row++, value);
320  } else
321  edm::LogWarning("LUTParsingProblem")
322  << "L1MuGMTLUT::Load: warning: LUT file only contains LUT with too many entries. skipping.";
323  }
324  }
325  } while (in.getline(buf, sz));
326 }
void Set(int idx, unsigned address, unsigned value)
set with single address and value
Definition: L1MuGMTLUT.cc:177
std::vector< std::vector< unsigned > > m_Contents
Definition: L1MuGMTLUT.h:213
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
uint16_t size_type
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:215
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:216
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214
bool m_initialized
Definition: L1MuGMTLUT.h:209
Definition: value.py:1
std::vector< std::string > m_InstNames
Definition: L1MuGMTLUT.h:212
std::string m_name
Definition: L1MuGMTLUT.h:220
bool m_distrRAM
Definition: L1MuGMTLUT.h:219
static int replace(std::string &input, const std::string &gone, const std::string &it, bool multiple)
Log< level::Warning, false > LogWarning
unsigned m_vme_addr_width
Definition: L1MuGMTLUT.h:218
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

◆ Lookup() [1/2]

std::vector<unsigned> L1MuGMTLUT::Lookup ( int  idx,
const std::vector< unsigned > &  address 
) const
inline

additional lookup function (std::vector -> vector)

Definition at line 121 of file L1MuGMTLUT.h.

References heavyIonCSV_trainingSettings::idx, m_Inputs, and vec2u().

Referenced by L1MuGMTMIAUPhiPro1LUT::SpecificLookup_cphi_fine(), L1MuGMTMIAUPhiPro1LUT::SpecificLookup_cphi_ofs(), L1MuGMTLFCOUDeltaEtaLUT::SpecificLookup_delta_eta(), L1MuGMTLFDeltaEtaLUT::SpecificLookup_delta_eta(), L1MuGMTLFDisableHotLUT::SpecificLookup_disable_hot(), L1MuGMTLFPhiProLUT::SpecificLookup_dphi(), L1MuGMTLFEtaConvLUT::SpecificLookup_eta_gmt(), L1MuGMTLFPhiProEtaConvLUT::SpecificLookup_eta_out(), L1MuGMTMIAUEtaConvLUT::SpecificLookup_eta_out(), L1MuGMTLFOvlEtaConvLUT::SpecificLookup_eta_ovl(), L1MuGMTMIAUEtaProLUT::SpecificLookup_eta_sel(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup_flag(), L1MuGMTLFMergeRankCombineLUT::SpecificLookup_merge_rank(), L1MuGMTLFMatchQualLUT::SpecificLookup_mq(), L1MuGMTMIAUPhiPro2LUT::SpecificLookup_phi_sel(), L1MuGMTLFPtMixLUT::SpecificLookup_pt_mixed(), L1MuGMTLFSortRankEtaPhiLUT::SpecificLookup_rank_etaphi(), L1MuGMTLFMergeRankEtaPhiLUT::SpecificLookup_rank_etaphi(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFMergeRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFSortRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFSortRankCombineLUT::SpecificLookup_sort_rank(), and L1MuGMTLFSortRankEtaQLUT::SpecificLookup_vlq().

121  {
122  return Lookup(idx, vec2u(address, m_Inputs));
123  };
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
std::vector< unsigned > Lookup(int idx, const std::vector< unsigned > &address) const
additional lookup function (std::vector -> vector)
Definition: L1MuGMTLUT.h:121
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214

◆ Lookup() [2/2]

std::vector<unsigned> L1MuGMTLUT::Lookup ( int  idx,
unsigned  address 
) const
inline

additional lookup function (unsigned -> std::vector)

Definition at line 126 of file L1MuGMTLUT.h.

References heavyIonCSV_trainingSettings::idx, LookupPacked(), m_Outputs, and u2vec().

126  {
127  return u2vec(LookupPacked(idx, address), m_Outputs);
128  };
unsigned LookupPacked(int idx, unsigned) const
Definition: L1MuGMTLUT.h:272
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:215
std::vector< unsigned > u2vec(unsigned value, const std::vector< port > &widths) const
generate composite address or value from compact unsigned
Definition: L1MuGMTLUT.h:251

◆ LookupFunctionPacked()

virtual unsigned L1MuGMTLUT::LookupFunctionPacked ( int  idx,
unsigned  address 
) const
inlinevirtual

◆ LookupPacked() [1/2]

unsigned L1MuGMTLUT::LookupPacked ( int  idx,
unsigned  address 
) const
inline

main lookup function (unsigned -> unsigned) all lookup functions go through this one

Definition at line 272 of file L1MuGMTLUT.h.

References heavyIonCSV_trainingSettings::idx, LookupFunctionPacked(), m_Contents, m_initialized, m_name, m_NLUTS, m_TotalInWidth, m_TotalOutWidth, m_UseLookupFunction, and relativeConstraints::value.

Referenced by Lookup(), LookupPacked(), L1MuGMTLFEtaConvLUT::SpecificLookup(), L1MuGMTLFPhiProEtaConvLUT::SpecificLookup(), L1MuGMTLFSortRankPtQLUT::SpecificLookup(), L1MuGMTLFMergeRankPtQLUT::SpecificLookup(), L1MuGMTLFDisableHotLUT::SpecificLookup(), L1MuGMTLFOvlEtaConvLUT::SpecificLookup(), L1MuGMTLFPtMixLUT::SpecificLookup(), L1MuGMTLFSortRankEtaPhiLUT::SpecificLookup(), L1MuGMTLFDeltaEtaLUT::SpecificLookup(), L1MuGMTLFCOUDeltaEtaLUT::SpecificLookup(), L1MuGMTLFPhiProLUT::SpecificLookup(), L1MuGMTLFMergeRankEtaPhiLUT::SpecificLookup(), L1MuGMTLFMatchQualLUT::SpecificLookup(), L1MuGMTMIAUEtaConvLUT::SpecificLookup(), L1MuGMTMIAUEtaProLUT::SpecificLookup(), L1MuGMTLFSortRankCombineLUT::SpecificLookup(), L1MuGMTLFMergeRankCombineLUT::SpecificLookup(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup(), L1MuGMTMIAUPhiPro2LUT::SpecificLookup(), and L1MuGMTMIAUPhiPro1LUT::SpecificLookup().

272  {
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 }
std::vector< std::vector< unsigned > > m_Contents
Definition: L1MuGMTLUT.h:213
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:211
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:216
bool m_initialized
Definition: L1MuGMTLUT.h:209
Definition: value.py:1
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:217
std::string m_name
Definition: L1MuGMTLUT.h:220
virtual unsigned LookupFunctionPacked(int idx, unsigned address) const
Definition: L1MuGMTLUT.h:140
Log< level::Warning, false > LogWarning

◆ LookupPacked() [2/2]

unsigned L1MuGMTLUT::LookupPacked ( int  idx,
const std::vector< unsigned > &  address 
) const
inline

additional lookup function (std::vector -> unisgned)

Definition at line 116 of file L1MuGMTLUT.h.

References heavyIonCSV_trainingSettings::idx, LookupPacked(), m_Inputs, and vec2u().

116  {
117  return LookupPacked(idx, vec2u(address, m_Inputs));
118  };
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
unsigned LookupPacked(int idx, unsigned) const
Definition: L1MuGMTLUT.h:272
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214

◆ MakeSubClass()

void L1MuGMTLUT::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 at line 333 of file L1MuGMTLUT.cc.

References visDQMUpload::buf, alignmentValidation::fname, mps_fire::i, recoMuon::in, dqmiolumiharvest::j, mps_splice::line, haddnano::of, L1MuGMTLUTHelpers::replace(), str, AlCaHLTBitMon_QueryRunRegistry::string, and createJobs::tmp.

333  {
334  // prepare parts
335  string ins_name(m_name);
336  string ins_name_upper = boost::to_upper_copy(ins_name);
337  string ins_instance_string;
338  string ins_instances_enum;
339  for (unsigned i = 0; i < m_InstNames.size(); i++) {
340  if (i != 0)
341  ins_instance_string += ' ';
342  ins_instance_string += m_InstNames[i];
343 
344  if (i != 0)
345  ins_instances_enum += ", ";
346  ins_instances_enum += m_InstNames[i];
347  }
348  char ins_vme[100];
349  sprintf(ins_vme, "%d", m_vme_addr_width);
350 
351  char ins_distr_RAM[10];
352  sprintf(ins_distr_RAM, "%s", m_distrRAM ? "true" : "false");
353 
354  string ins_input_decl_list, ins_input_list, ins_input_addr_list;
355  for (unsigned i = 0; i < m_Inputs.size(); i++) {
356  ins_input_decl_list += string(", unsigned ") + m_Inputs[i].first;
357  ins_input_list += string(", ") + m_Inputs[i].first;
358  char tmp[100];
359  sprintf(tmp, " ,addr[%d]", i);
360  ins_input_addr_list += string(tmp);
361  }
362 
363  // string ins_lookup_functions;
364  ostringstream os;
365  for (unsigned i = 0; i < m_Outputs.size(); i++) {
366  os << " /// specific lookup function for " << m_Outputs[i].first << endl;
367  os << " unsigned SpecificLookup_" << m_Outputs[i].first << " (int idx" << ins_input_decl_list << ") const {"
368  << endl;
369  os << " vector<unsigned> addr(" << m_Inputs.size() << ");" << endl;
370  for (unsigned j = 0; j < m_Inputs.size(); j++) {
371  os << " addr[" << j << "] = " << m_Inputs[j].first << ";" << endl;
372  }
373  os << " return Lookup(idx, addr) [" << i << "];" << endl;
374  os << " };" << endl << endl;
375  }
376  os << " /// specific lookup function for entire output field" << endl;
377  os << " unsigned SpecificLookup (int idx" << ins_input_decl_list << ") const {" << endl;
378  os << " vector<unsigned> addr(" << m_Inputs.size() << ");" << endl;
379  for (unsigned j = 0; j < m_Inputs.size(); j++) {
380  os << " addr[" << j << "] = " << m_Inputs[j].first << ";" << endl;
381  }
382  os << " return LookupPacked(idx, addr);" << endl;
383  os << " };" << endl << endl;
384 
385  os << ends;
386  string ins_lookup_functions = os.str();
387 
388  // substitute in .h file
389  string outfn(fname);
390  if (outfn.empty())
391  outfn = string("../interface/L1MuGMT") + m_name + string("LUT.h");
392  ifstream of_check(outfn.c_str());
393  if (!of_check.good()) {
394  ofstream of(outfn.c_str());
395 
396  ifstream in(template_file_h);
397  const int sz = 1000;
398  char buf[sz];
399 
400  while (in.getline(buf, sz)) {
401  string line(buf);
402 
403  L1MuGMTLUTHelpers::replace(line, "###insert_name_upper###", ins_name_upper, false);
404  L1MuGMTLUTHelpers::replace(line, "###insert_name###", ins_name, false);
405  L1MuGMTLUTHelpers::replace(line, "###insert_instance_string###", ins_instance_string, false);
406  L1MuGMTLUTHelpers::replace(line, "###insert_instances_enum###", ins_instances_enum, false);
407  L1MuGMTLUTHelpers::replace(line, "###insert_inputs_string###", string(PortDecoder(m_Inputs).str()), false);
408  L1MuGMTLUTHelpers::replace(line, "###insert_outputs_string###", string(PortDecoder(m_Outputs).str()), false);
409  L1MuGMTLUTHelpers::replace(line, "###insert_vme_input_width###", string(ins_vme), false);
410  L1MuGMTLUTHelpers::replace(line, "###insert_distrRAM###", string(ins_distr_RAM), false);
411  L1MuGMTLUTHelpers::replace(line, "###insert_input_decl_list###", ins_input_decl_list, false);
412  L1MuGMTLUTHelpers::replace(line, "###insert_input_list###", ins_input_list, false);
413  L1MuGMTLUTHelpers::replace(line, "###insert_input_addr_list###", ins_input_addr_list, false);
414  L1MuGMTLUTHelpers::replace(line, "###insert_lookup_functions###", ins_lookup_functions, false);
415  of << line << endl;
416  }
417  }
418 
419  // substitute in .cc file
420  string outfn_cc(fname);
421  if (outfn_cc.empty())
422  outfn_cc = string("../interface/L1MuGMT") + m_name + string("LUT.cc");
423 
424  ifstream of_cc_check(outfn_cc.c_str());
425  if (!of_cc_check.good()) {
426  ofstream of_cc(outfn_cc.c_str());
427 
428  ifstream in_cc(template_file_cc);
429  const int sz = 1000;
430  char buf[sz];
431 
432  while (in_cc.getline(buf, sz)) {
433  string line(buf);
434 
435  L1MuGMTLUTHelpers::replace(line, "###insert_name_upper###", ins_name_upper, false);
436  L1MuGMTLUTHelpers::replace(line, "###insert_name###", ins_name, false);
437  L1MuGMTLUTHelpers::replace(line, "###insert_instance_string###", ins_instance_string, false);
438  L1MuGMTLUTHelpers::replace(line, "###insert_instances_enum###", ins_instances_enum, false);
439  L1MuGMTLUTHelpers::replace(line, "###insert_inputs_string###", string(PortDecoder(m_Inputs).str()), false);
440  L1MuGMTLUTHelpers::replace(line, "###insert_outputs_string###", string(PortDecoder(m_Outputs).str()), false);
441  L1MuGMTLUTHelpers::replace(line, "###insert_vme_input_width###", string(ins_vme), false);
442  L1MuGMTLUTHelpers::replace(line, "###insert_distrRAM###", string(ins_distr_RAM), false);
443  L1MuGMTLUTHelpers::replace(line, "###insert_input_decl_list###", ins_input_decl_list, false);
444  L1MuGMTLUTHelpers::replace(line, "###insert_input_list###", ins_input_list, false);
445  L1MuGMTLUTHelpers::replace(line, "###insert_input_addr_list###", ins_input_addr_list, false);
446  L1MuGMTLUTHelpers::replace(line, "###insert_lookup_functions###", ins_lookup_functions, false);
447  of_cc << line << endl;
448  }
449  }
450 }
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:215
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214
std::vector< std::string > m_InstNames
Definition: L1MuGMTLUT.h:212
std::string m_name
Definition: L1MuGMTLUT.h:220
bool m_distrRAM
Definition: L1MuGMTLUT.h:219
string fname
main script
static int replace(std::string &input, const std::string &gone, const std::string &it, bool multiple)
#define str(s)
tmp
align.sh
Definition: createJobs.py:716
unsigned m_vme_addr_width
Definition: L1MuGMTLUT.h:218

◆ Name()

std::string L1MuGMTLUT::Name ( )
inline

Definition at line 147 of file L1MuGMTLUT.h.

References m_name.

147 { return m_name; };
std::string m_name
Definition: L1MuGMTLUT.h:220

◆ numberOfInstances()

int L1MuGMTLUT::numberOfInstances ( )
inline

get the number of Instances

Definition at line 152 of file L1MuGMTLUT.h.

References m_NLUTS.

152 { return m_NLUTS; };

◆ Save()

void L1MuGMTLUT::Save ( const char *  path)

save to LUT file

Definition at line 78 of file L1MuGMTLUT.cc.

References generateTowerEtThresholdLUT::addr, mps_fire::i, haddnano::of, castor_dqm_sourceclient_file_cfg::path, and L1MuGMTLUT::PortDecoder::str().

78  {
79  if (!m_initialized) {
80  edm::LogWarning("LUTNotInitialized") << "L1MuGMTLUT::Save: LUT not initialized. ";
81  return;
82  }
83 
84  m_saveFlag = true;
85 
86  ofstream of(path);
87  of << "// This is a CMS L1 Global Muon Trigger .lut file. " << endl;
88  of << "// " << endl;
89  of << "// It defines a set of look-up-tables(LUTs) of the same type (same inputs and outputs) but" << endl;
90  of << "// with different default contents. For example a certain type of LUT can have different" << endl;
91  of << "// default values for DT for RPC and for CSC muons. " << endl;
92  of << "// " << endl;
93  of << "// NAME gives the name of the LUT. It should match the base name (name without '.lut')" << endl;
94  of << "// of the LUT file." << endl;
95  of << "// When deriving a C++ sub-class the name is used case sensitive." << endl;
96  of << "// In generated VHDL code the name is used in lower case." << endl;
97  of << "// " << endl;
98  of << "// INSTANCES is the list of instances of the LUT with different default values." << endl;
99  of << "// the lists consists of identifiers for each of the instances separated by spaces." << endl;
100  of << "// the identifiers can be made up of characters that are valid in VHDL lables. " << endl;
101  of << "// In the VHDL code they are used to label the different instances." << endl;
102  of << "// " << endl;
103  of << "// In C++ and VHDL the instance of a LUT is selected by an integer index where 0 " << endl;
104  of << "// corresponds to the leftmost identifier. Integer indices are also used in the CONTENTS_XX"
105  << endl;
106  of << "// statements in this file." << endl;
107  of << "// " << endl;
108  of << "// LUT_INPUTS is the (space-separated) list of inputs of the LUT. Each input is specified in the form"
109  << endl;
110  of << "// <input_name>(<number_of_bits>) where <input_name> is the name of the input and" << endl;
111  of << "// <number_of_bits> is the number of bits of the input. <input_name> has to be a valid" << endl;
112  of << "// identifier both in C++ and in VHDL. In C++ it is represented as an unsigned int." << endl;
113  of << "// " << endl;
114  of << "// All LUT inputs together make up the address of the corresponding memory." << endl;
115  of << "// The first input in the list corresponds to the most-significant bits of the address."
116  << endl;
117  of << "// " << endl;
118  of << "// LUT_OUTPUTS is the (space-separated) list of outputs of the LUT. Each output is specified in the form"
119  << endl;
120  of << "// <output_name>(<number_of_bits>) where <output_name> is the name of the output and" << endl;
121  of << "// <number_of_bits> is the number of bits of the output. <output_name> has to be a valid"
122  << endl;
123  of << "// identifier both in C++ and in VHDL. In C++ it is represented as an unsigned int." << endl;
124  of << "// " << endl;
125  of << "// All LUT outputs together make up the data of the corresponding memory." << endl;
126  of << "// The first output in the list corresponds to the most-significant data bits." << endl;
127  of << "// " << endl;
128  of << "// VME_ADDR_WIDTH is the address width of the LUT memory when accessed via VME. When the LUT " << endl;
129  of << "// is implemented as dual-port block RAM, the VME address with can be different " << endl;
130  of << "// from the address width given by the sum of the input widths. It can be larger or" << endl;
131  of << "// smaller by a factor of 2^n. When the LUT is implemented as dual-port distributed RAM,"
132  << endl;
133  of << "// the VME address width has to match the input width. " << endl;
134  of << "// " << endl;
135  of << "// DISTRIBUTED_RAM is 1 if the LUT is to be implemented in distributed RAM and 0 for Block RAM " << endl;
136  of << "// Note that for distributed RAM the address width on the GMT side (sum of input widths)"
137  << endl;
138  of << "// has to match the vme_addr_width" << endl;
139  of << "// " << endl;
140  of << "// CONTENTS_XX specifies the default contents of instance with index XX (see INSTANCES)." << endl;
141  of << "// contents are specified as decimal numbers, one number per line." << endl;
142  of << "// " << endl;
143  of << "// Hannes Sakulin / HEPHY Vienna, 2003" << endl;
144  of << "// " << endl;
145 
146  of << "NAME = " << m_name << endl;
147  of << "INSTANCES =";
148  for (unsigned i = 0; i < m_InstNames.size(); i++)
149  of << " " << m_InstNames[i];
150  of << endl;
151  of << "LUT_INPUTS = " << PortDecoder(m_Inputs).str() << endl;
152  of << "LUT_OUTPUTS = " << PortDecoder(m_Outputs).str() << endl;
153  of << "VME_ADDR_WIDTH = " << m_vme_addr_width << endl;
154  of << "DISTRIBUTED_RAM = " << (m_distrRAM ? "1" : "0") << endl;
155  for (int i = 0; i < m_NLUTS; i++) {
156  of << "// " << m_InstNames[i] << endl;
157  of << "CONTENTS_" << i << " = ";
158  for (unsigned addr = 0; addr < (unsigned)(1 << m_TotalInWidth); addr++) {
159  of << LookupPacked(i, addr) << endl;
160  }
161  of << endl;
162  }
163 
164  m_saveFlag = false;
165 }
unsigned LookupPacked(int idx, unsigned) const
Definition: L1MuGMTLUT.h:272
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:215
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:216
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:214
bool m_initialized
Definition: L1MuGMTLUT.h:209
std::vector< std::string > m_InstNames
Definition: L1MuGMTLUT.h:212
std::string m_name
Definition: L1MuGMTLUT.h:220
bool m_distrRAM
Definition: L1MuGMTLUT.h:219
bool m_saveFlag
Definition: L1MuGMTLUT.h:221
Log< level::Warning, false > LogWarning
unsigned m_vme_addr_width
Definition: L1MuGMTLUT.h:218

◆ Set()

void L1MuGMTLUT::Set ( int  idx,
unsigned  address,
unsigned  value 
)
protected

set with single address and value

Definition at line 177 of file L1MuGMTLUT.cc.

References heavyIonCSV_trainingSettings::idx, and relativeConstraints::value.

177  {
178  if (!m_initialized) {
179  edm::LogWarning("LUTNotInitialized") << "L1MuGMTLUT::Set: LUT not initialized. ";
180  return;
181  }
182 
183  if (idx >= m_NLUTS) {
184  edm::LogWarning("LUTRangeViolation") << "L1MuGMTLUT::Set: LUT index exceeds range (0 to " << (m_NLUTS - 1) << ").";
185  return;
186  }
187  if (address >= (unsigned)(1 << m_TotalInWidth)) {
188  edm::LogWarning("LUTRangeViolation") << "Error in L1MuGMTLUT::Set: LUT input exceeds range (0 to "
189  << ((1 << m_TotalInWidth) - 1) << ").";
190  return;
191  }
192  if (value >= (unsigned)(1 << m_TotalOutWidth)) {
193  edm::LogWarning("LUTRangeViolation") << "Error in L1MuGMTLUT::Set: LUT output exceeds range (0 to "
194  << ((1 << m_TotalOutWidth) - 1) << ").";
195  return;
196  }
197  m_Contents[idx][address] = value;
198 }
std::vector< std::vector< unsigned > > m_Contents
Definition: L1MuGMTLUT.h:213
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:216
bool m_initialized
Definition: L1MuGMTLUT.h:209
Definition: value.py:1
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:217
Log< level::Warning, false > LogWarning

◆ u2vec()

std::vector< unsigned > L1MuGMTLUT::u2vec ( unsigned  value,
const std::vector< port > &  widths 
) const
inlineprotected

generate composite address or value from compact unsigned

Definition at line 251 of file L1MuGMTLUT.h.

References mps_fire::i, gpuClustering::pixelStatus::mask, and convertSQLitetoXML_cfg::output.

Referenced by Lookup(), L1MuGMTLFEtaConvLUT::LookupFunctionPacked(), L1MuGMTLFPhiProEtaConvLUT::LookupFunctionPacked(), L1MuGMTLFOvlEtaConvLUT::LookupFunctionPacked(), L1MuGMTLFSortRankPtQLUT::LookupFunctionPacked(), L1MuGMTLFMergeRankPtQLUT::LookupFunctionPacked(), L1MuGMTLFDisableHotLUT::LookupFunctionPacked(), L1MuGMTLFPtMixLUT::LookupFunctionPacked(), L1MuGMTLFSortRankEtaPhiLUT::LookupFunctionPacked(), L1MuGMTLFDeltaEtaLUT::LookupFunctionPacked(), L1MuGMTLFCOUDeltaEtaLUT::LookupFunctionPacked(), L1MuGMTLFMergeRankEtaPhiLUT::LookupFunctionPacked(), L1MuGMTLFMatchQualLUT::LookupFunctionPacked(), L1MuGMTLFPhiProLUT::LookupFunctionPacked(), L1MuGMTMIAUEtaConvLUT::LookupFunctionPacked(), L1MuGMTLFSortRankCombineLUT::LookupFunctionPacked(), L1MuGMTMIAUEtaProLUT::LookupFunctionPacked(), L1MuGMTLFMergeRankCombineLUT::LookupFunctionPacked(), L1MuGMTLFMergeRankEtaQLUT::LookupFunctionPacked(), L1MuGMTLFSortRankEtaQLUT::LookupFunctionPacked(), L1MuGMTMIAUPhiPro2LUT::LookupFunctionPacked(), and L1MuGMTMIAUPhiPro1LUT::LookupFunctionPacked().

251  {
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 }
constexpr uint32_t mask
Definition: gpuClustering.h:26
Definition: value.py:1

◆ vec2u()

unsigned L1MuGMTLUT::vec2u ( const std::vector< unsigned > &  vec,
const std::vector< port > &  widths 
) const
inlineprotected

generate address or value from composite address or value

Definition at line 227 of file L1MuGMTLUT.h.

References mps_fire::i.

Referenced by Lookup(), and LookupPacked().

227  {
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 }
Definition: value.py:1
Log< level::Warning, false > LogWarning

Friends And Related Function Documentation

◆ L1MuGMTLUTConverter

friend class L1MuGMTLUTConverter
friend

Definition at line 147 of file L1MuGMTLUT.h.

Member Data Documentation

◆ m_Contents

std::vector<std::vector<unsigned> > L1MuGMTLUT::m_Contents
protected

Definition at line 213 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

◆ m_distrRAM

bool L1MuGMTLUT::m_distrRAM
protected

Definition at line 219 of file L1MuGMTLUT.h.

◆ m_GeneralLUTVersion

unsigned L1MuGMTLUT::m_GeneralLUTVersion
protected

Definition at line 222 of file L1MuGMTLUT.h.

Referenced by L1MuGMTLFMergeRankEtaQLUT::TheLookupFunction().

◆ m_initialized

bool L1MuGMTLUT::m_initialized
protected

Definition at line 209 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

◆ m_Inputs

std::vector<port> L1MuGMTLUT::m_Inputs
protected

◆ m_InstNames

std::vector<std::string> L1MuGMTLUT::m_InstNames
protected

Definition at line 212 of file L1MuGMTLUT.h.

◆ m_name

std::string L1MuGMTLUT::m_name
protected

Definition at line 220 of file L1MuGMTLUT.h.

Referenced by LookupPacked(), and Name().

◆ m_NLUTS

int L1MuGMTLUT::m_NLUTS
protected

Definition at line 210 of file L1MuGMTLUT.h.

Referenced by LookupPacked(), and numberOfInstances().

◆ m_Outputs

std::vector<port> L1MuGMTLUT::m_Outputs
protected

Definition at line 215 of file L1MuGMTLUT.h.

Referenced by Lookup().

◆ m_saveFlag

bool L1MuGMTLUT::m_saveFlag
protected

◆ m_TotalInWidth

unsigned L1MuGMTLUT::m_TotalInWidth
protected

Definition at line 216 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

◆ m_TotalOutWidth

unsigned L1MuGMTLUT::m_TotalOutWidth
protected

Definition at line 217 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

◆ m_UseLookupFunction

bool L1MuGMTLUT::m_UseLookupFunction
protected

Definition at line 211 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

◆ m_vme_addr_width

unsigned L1MuGMTLUT::m_vme_addr_width
protected

Definition at line 218 of file L1MuGMTLUT.h.