CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 75 of file L1MuGMTLUT.h.

Member Typedef Documentation

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

Definition at line 78 of file L1MuGMTLUT.h.

Constructor & Destructor Documentation

L1MuGMTLUT::L1MuGMTLUT ( )
inline

Init and Destruct.

default constructor w/o init

Definition at line 83 of file L1MuGMTLUT.h.

83 : m_initialized(0), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {};
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:198
bool m_initialized
Definition: L1MuGMTLUT.h:196
bool m_saveFlag
Definition: L1MuGMTLUT.h:208
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 86 of file L1MuGMTLUT.h.

References Init().

90  : m_initialized(0), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {
91  Init (name, instances, in_widths, out_widths, vme_addr_width, distrRAM);
92  };
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:198
bool m_initialized
Definition: L1MuGMTLUT.h:196
bool m_saveFlag
Definition: L1MuGMTLUT.h:208
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:47
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 94 of file L1MuGMTLUT.h.

References Init().

98  : m_initialized(0), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {
99  Init (name, L1MuGMTLUTHelpers::Tokenizer(" ",instances), PortDecoder(inputs), PortDecoder(outputs),
100  vme_addr_width, distrRAM);
101  };
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:198
bool m_initialized
Definition: L1MuGMTLUT.h:196
bool m_saveFlag
Definition: L1MuGMTLUT.h:208
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:47
L1MuGMTLUT::~L1MuGMTLUT ( )
virtual

destructor

Definition at line 35 of file L1MuGMTLUT.cc.

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

Member Function Documentation

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 47 of file L1MuGMTLUT.cc.

References L1MuGMTConfig::getVersionLUTs(), i, mergeVDriftHistosByStation::name, and edm::second().

Referenced by L1MuGMTLUT().

50 {
51  m_name = name;
52  m_InstNames = instances;
53  m_NLUTS = instances.size();
54 
55  m_Inputs = in_widths;
56  m_TotalInWidth = 0;
57  for (unsigned i=0; i< in_widths.size(); i++) m_TotalInWidth += in_widths[i].second;
58 
59  m_Outputs = out_widths;
60  m_TotalOutWidth = 0;
61  for (unsigned i=0; i< out_widths.size(); i++) m_TotalOutWidth += out_widths[i].second;
62 
63  m_vme_addr_width = vme_addr_width;
64  m_distrRAM = distrRAM;
65 
66  if (m_distrRAM && (m_TotalInWidth != vme_addr_width) ) {
67  edm::LogWarning("AddressMismatch")
68  << "L1MuGMTLUT::Init(): for distributed RAM the GMT (Input) address width "
69  << "has to match the VME address width. Core Generation will not work.";
70  }
71 
73  m_initialized = true;
74 }
int i
Definition: DBlmapReader.cc:9
U second(std::pair< T, U > const &p)
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:202
static unsigned getVersionLUTs()
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:203
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:201
bool m_initialized
Definition: L1MuGMTLUT.h:196
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:204
std::vector< std::string > m_InstNames
Definition: L1MuGMTLUT.h:199
std::string m_name
Definition: L1MuGMTLUT.h:207
bool m_distrRAM
Definition: L1MuGMTLUT.h:206
unsigned m_GeneralLUTVersion
Definition: L1MuGMTLUT.h:209
unsigned m_vme_addr_width
Definition: L1MuGMTLUT.h:205
void L1MuGMTLUT::Load ( const char *  path)

I/O functions.

load from LUT file

Definition at line 194 of file L1MuGMTLUT.cc.

References spr::find(), i, recoMuon::in, geometryCSVtoXML::line, L1MuGMTLUTHelpers::replace(), results_mgr::tok, and relativeConstraints::value.

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

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

Definition at line 115 of file L1MuGMTLUT.h.

References 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(), L1MuGMTMIAUEtaConvLUT::SpecificLookup_eta_out(), L1MuGMTLFPhiProEtaConvLUT::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(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFMergeRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFSortRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFSortRankCombineLUT::SpecificLookup_sort_rank(), and L1MuGMTLFSortRankEtaQLUT::SpecificLookup_vlq().

115  {
116  return Lookup (idx, vec2u ( address, m_Inputs ) ); };
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:214
std::vector< unsigned > Lookup(int idx, const std::vector< unsigned > &address) const
additional lookup function (std::vector -&gt; vector)
Definition: L1MuGMTLUT.h:115
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:201
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
std::vector<unsigned> L1MuGMTLUT::Lookup ( int  idx,
unsigned  address 
) const
inline

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

Definition at line 119 of file L1MuGMTLUT.h.

References LookupPacked(), m_Outputs, and u2vec().

119  {
120  return u2vec ( LookupPacked(idx, address), m_Outputs );
121  };
std::vector< port > m_Outputs
Definition: L1MuGMTLUT.h:202
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
std::vector< unsigned > u2vec(unsigned value, const std::vector< port > &widths) const
generate composite address or value from compact unsigned
Definition: L1MuGMTLUT.h:239
unsigned LookupPacked(int idx, unsigned) const
Definition: L1MuGMTLUT.h:260
virtual unsigned L1MuGMTLUT::LookupFunctionPacked ( int  idx,
unsigned  address 
) const
inlinevirtual
unsigned L1MuGMTLUT::LookupPacked ( int  idx,
unsigned  address 
) const
inline

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

Definition at line 260 of file L1MuGMTLUT.h.

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

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

260  {
261  if (! m_initialized) {
262  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked: LUT not initialized. ";
263  return 0;
264  }
265  if ( idx >= m_NLUTS ) {
266  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked: LUT index exceeds range (0 to " << ( m_NLUTS -1 ) << ")."
267  ;
268  return 0;
269  }
270  if ( address >= (unsigned) (1 << m_TotalInWidth) ) {
271  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked: LUT input exceeds range (0 to " << ( (1 << m_TotalInWidth) -1 ) << ")."
272  ;
273  return 0;
274  }
275 
276  unsigned value = 0;
277  if (m_UseLookupFunction) {
278  value = LookupFunctionPacked (idx, address);
279  } else {
280  value = m_Contents[idx][address];
281  }
282 
283  // check range of output
284  if ( value >= (unsigned) (1 << m_TotalOutWidth) ) {
285  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::LookupPacked(): LUT output value " << value
286  << " exceeds range (0 to " << ( (1 << m_TotalOutWidth) -1 ) << ")."
287  ;
288  edm::LogWarning("LUTMismatch") << " LUT name: " << m_name;
289  if (m_UseLookupFunction)
290  edm::LogWarning("LUTMismatch") << " Lookup Function has to be corrected!!!";
291  else
292  edm::LogWarning("LUTMismatch") << " LUT File has to be corrected!!!";
293  return (1 << m_TotalOutWidth) - 1;
294  }
295  return value;
296 }
std::vector< std::vector< unsigned > > m_Contents
Definition: L1MuGMTLUT.h:200
virtual unsigned LookupFunctionPacked(int idx, unsigned address) const
Definition: L1MuGMTLUT.h:134
bool m_UseLookupFunction
Definition: L1MuGMTLUT.h:198
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:203
bool m_initialized
Definition: L1MuGMTLUT.h:196
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:204
std::string m_name
Definition: L1MuGMTLUT.h:207
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
unsigned L1MuGMTLUT::LookupPacked ( int  idx,
const std::vector< unsigned > &  address 
) const
inline

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

Definition at line 111 of file L1MuGMTLUT.h.

References LookupPacked(), m_Inputs, and vec2u().

111  {
112  return LookupPacked (idx, vec2u ( address, m_Inputs ) ); };
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:214
std::vector< port > m_Inputs
Definition: L1MuGMTLUT.h:201
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
unsigned LookupPacked(int idx, unsigned) const
Definition: L1MuGMTLUT.h:260
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 326 of file L1MuGMTLUT.cc.

References i, recoMuon::in, j, geometryCSVtoXML::line, L1MuGMTLUTHelpers::replace(), AlCaHLTBitMon_QueryRunRegistry::string, and tmp.

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

Definition at line 140 of file L1MuGMTLUT.h.

References m_name.

140 {return m_name;};
std::string m_name
Definition: L1MuGMTLUT.h:207
int L1MuGMTLUT::numberOfInstances ( )
inline

get the number of Instances

Definition at line 145 of file L1MuGMTLUT.h.

References m_NLUTS.

145 { return m_NLUTS; };
void L1MuGMTLUT::Save ( const char *  path)

save to LUT file

Definition at line 77 of file L1MuGMTLUT.cc.

References i, and L1MuGMTLUT::PortDecoder::str().

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

set with single address and value

Definition at line 171 of file L1MuGMTLUT.cc.

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

171  {
172  if (! m_initialized) {
173  edm::LogWarning("LUTNotInitialized") << "L1MuGMTLUT::Set: LUT not initialized. ";
174  return;
175  }
176 
177  if ( idx >= m_NLUTS ) {
178  edm::LogWarning("LUTRangeViolation") << "L1MuGMTLUT::Set: LUT index exceeds range (0 to " << ( m_NLUTS -1 ) << ").";
179  return;
180  }
181  if ( address >= (unsigned)(1 << m_TotalInWidth) ) {
182  edm::LogWarning("LUTRangeViolation") << "Error in L1MuGMTLUT::Set: LUT input exceeds range (0 to " << ( (1 << m_TotalInWidth) -1 ) << ").";
183  return;
184  }
185  if ( value >= (unsigned)(1 << m_TotalOutWidth) ) {
186  edm::LogWarning("LUTRangeViolation") << "Error in L1MuGMTLUT::Set: LUT output exceeds range (0 to " << ( (1 << m_TotalOutWidth) -1 ) << ")." ;
187  return;
188  }
189  m_Contents[idx][address] = value;
190 }
std::vector< std::vector< unsigned > > m_Contents
Definition: L1MuGMTLUT.h:200
unsigned m_TotalInWidth
Definition: L1MuGMTLUT.h:203
bool m_initialized
Definition: L1MuGMTLUT.h:196
unsigned m_TotalOutWidth
Definition: L1MuGMTLUT.h:204
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
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 239 of file L1MuGMTLUT.h.

References i, and convertSQLitetoXML_cfg::output.

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

239  {
240  std::vector<unsigned> output( widths.size(), 0);
241 
242  unsigned start_ofs=0;
243 
244  for (int i=widths.size()-1; i>=0; i--) {
245  int mask = ( (1 << widths[i].second) - 1 ) << start_ofs;
246  output[i] = ( value & mask ) >> start_ofs;
247  start_ofs += widths[i].second;
248  }
249 
250  return output;
251 }
int i
Definition: DBlmapReader.cc:9
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 214 of file L1MuGMTLUT.h.

References i, and relativeConstraints::value.

Referenced by Lookup(), and LookupPacked().

214  {
215  if (vec.size() != widths.size()) {
216  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::vec2u: number of LUT inputs/outputs does not match definition";
217  return (0);
218  }
219 
220  unsigned value = 0;
221  unsigned start_ofs=0;
222 
223  for (int i=vec.size()-1; i>=0; i--) {
224  if ( vec[i] >= (unsigned) (1 << widths[i].second) ) {
225  edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::vec2u: LUT input/output number " << i
226  << " exceeds range (0 to " << ( (1 << widths[i].second) -1 ) << ")."
227  ;
228  }
229  else
230  value |= vec[i] << start_ofs;
231  start_ofs += widths[i].second;
232  }
233 
234  return (value);
235 }
int i
Definition: DBlmapReader.cc:9

Friends And Related Function Documentation

friend class L1MuGMTLUTConverter
friend

Definition at line 140 of file L1MuGMTLUT.h.

Member Data Documentation

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

Definition at line 200 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

bool L1MuGMTLUT::m_distrRAM
protected

Definition at line 206 of file L1MuGMTLUT.h.

unsigned L1MuGMTLUT::m_GeneralLUTVersion
protected

Definition at line 209 of file L1MuGMTLUT.h.

Referenced by L1MuGMTLFMergeRankEtaQLUT::TheLookupFunction().

bool L1MuGMTLUT::m_initialized
protected

Definition at line 196 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

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

Definition at line 199 of file L1MuGMTLUT.h.

std::string L1MuGMTLUT::m_name
protected

Definition at line 207 of file L1MuGMTLUT.h.

Referenced by LookupPacked(), and Name().

int L1MuGMTLUT::m_NLUTS
protected

Definition at line 197 of file L1MuGMTLUT.h.

Referenced by LookupPacked(), and numberOfInstances().

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

Definition at line 202 of file L1MuGMTLUT.h.

Referenced by Lookup().

bool L1MuGMTLUT::m_saveFlag
protected
unsigned L1MuGMTLUT::m_TotalInWidth
protected

Definition at line 203 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

unsigned L1MuGMTLUT::m_TotalOutWidth
protected

Definition at line 204 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

bool L1MuGMTLUT::m_UseLookupFunction
protected

Definition at line 198 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

unsigned L1MuGMTLUT::m_vme_addr_width
protected

Definition at line 205 of file L1MuGMTLUT.h.