CMS 3D CMS Logo

L1MuGMTLUT Class Reference

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

#include <L1Trigger/GlobalMuonTrigger/src/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

List of all members.

Public Types

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

Public Member Functions

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

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

Protected Attributes

std::vector< std::vector
< unsigned > > 
m_Contents
bool m_distrRAM
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

Classes

class  PortDecoder


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 77 of file L1MuGMTLUT.h.


Member Typedef Documentation

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

Definition at line 80 of file L1MuGMTLUT.h.


Constructor & Destructor Documentation

L1MuGMTLUT::L1MuGMTLUT (  )  [inline]

Init and Destruct.

default constructor w/o init

Definition at line 85 of file L1MuGMTLUT.h.

00085 : m_initialized(0), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {};

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 88 of file L1MuGMTLUT.h.

References Init().

00092                                                                : m_initialized(0), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {
00093       Init (name, instances, in_widths, out_widths, vme_addr_width, distrRAM); 
00094       };

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 96 of file L1MuGMTLUT.h.

References Init().

00100                                                                : m_initialized(0), m_NLUTS(0), m_UseLookupFunction(true), m_saveFlag(false) {
00101       Init (name, L1MuGMTLUTHelpers::Tokenizer(" ",instances), PortDecoder(inputs), PortDecoder(outputs), 
00102             vme_addr_width, distrRAM); 
00103       };

L1MuGMTLUT::~L1MuGMTLUT (  )  [virtual]

destructor

Definition at line 35 of file L1MuGMTLUT.cc.

References m_UseLookupFunction.

00035                         {
00036   if (! m_UseLookupFunction ) {
00037     
00038     // de-allocate vectors
00039     // no destuction needed for vector< vector <unsigned> >
00040 
00041     // for (int i=0;i < m_NLUTS; i++) 
00042     //   m_Contents[i].clear();
00043     // m_Contents.clear();
00044   }
00045 }


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.

Referenced by L1MuGMTLUT(), and Load().

void L1MuGMTLUT::Load ( const char *  path  ) 

I/O functions.

load from LUT file

Definition at line 193 of file L1MuGMTLUT.cc.

References find(), i, in, Init(), parsecf::pyparsing::line(), m_Contents, m_distrRAM, m_initialized, m_Inputs, m_InstNames, m_name, m_NLUTS, m_Outputs, m_TotalInWidth, m_UseLookupFunction, m_vme_addr_width, L1MuGMTLUTHelpers::replace(), row, Set(), and value.

00193                                       {
00194   string lf_name("");
00195   int lf_NLUTS=0; 
00196   vector <string> lf_InstNames;
00197   vector <port> lf_Inputs;
00198   vector <port> lf_Outputs;
00199   unsigned lf_vme_addr_width=0;
00200   bool lf_distrRAM=false;
00201   vector<string> lf_comments;
00202 
00203   ifstream in (path);
00204   const int sz=1000; char buf[sz];
00205 
00206 
00207   // read header
00208   
00209   while ( in.getline(buf, sz) ) {
00210     string line(buf);
00211     string::size_type i=0;
00212     if ( (i=line.find("//")) != string::npos) {
00213       lf_comments.push_back( line.substr(i) ); // save comments
00214       line.erase(i); // and strip
00215     }
00216     L1MuGMTLUTHelpers::Tokenizer tok("=", line);
00217     if (tok.size() == 2) {
00218       L1MuGMTLUTHelpers::replace(tok[0], " ","", false); // skip spaces
00219       L1MuGMTLUTHelpers::replace(tok[0], "\t","", false); // skip tabs
00220 
00221       L1MuGMTLUTHelpers::replace(tok[1], "\t", " ", false); // convert tabs to spaces
00222       L1MuGMTLUTHelpers::replace(tok[1], "  ", " ", true); // skip multiple spaces
00223       tok[1].erase(0, tok[1].find_first_not_of(" ")); // skip leading spaces
00224       tok[1].erase(tok[1].find_last_not_of(" ")+1); // skip trailing spaces
00225             
00226       if (tok[0] == "NAME") lf_name = tok[1];
00227       else if (tok[0] == "INSTANCES") { lf_InstNames = L1MuGMTLUTHelpers::Tokenizer(" ",tok[1]); lf_NLUTS = lf_InstNames.size();}
00228       else if (tok[0] == "LUT_INPUTS") lf_Inputs = PortDecoder(tok[1]);
00229       else if (tok[0] == "LUT_OUTPUTS") lf_Outputs = PortDecoder(tok[1]); 
00230       else if (tok[0] == "VME_ADDR_WIDTH") lf_vme_addr_width = atoi(tok[1].c_str()); 
00231       else if (tok[0] == "DISTRIBUTED_RAM") lf_distrRAM = ( atoi(tok[1].c_str()) == 1 ); 
00232     }
00233     if (tok[0].find("CONTENTS") != string::npos) break;
00234   }
00235 
00236   if (!m_initialized) { // then initialize
00237     Init(lf_name.c_str(), lf_InstNames, lf_Inputs, lf_Outputs, lf_vme_addr_width, lf_distrRAM);    
00238   }
00239   else { // verify compatibility
00240     if (m_name != lf_name ||
00241         m_InstNames != lf_InstNames ||
00242         m_Inputs != lf_Inputs ||
00243         m_Outputs != lf_Outputs ||
00244         m_vme_addr_width != lf_vme_addr_width ||
00245         m_distrRAM != lf_distrRAM) {
00246       edm::LogWarning("LUTParmasMismatch") 
00247           << "L1MuGMTLUT::Load: error: parameters in file do not match configuration of LUT. Load failed.";
00248       return;
00249     }
00250   }
00251   
00252   if (m_UseLookupFunction) {
00253     // allocate vectors
00254     m_Contents.resize( m_NLUTS );
00255     for (int i=0;i < m_NLUTS; i++) 
00256       m_Contents[i].resize( 1 << m_TotalInWidth );
00257 
00258       // switch to table mode
00259     m_UseLookupFunction = false;
00260   }  
00261   
00262   // continue to read contents (first line should be in buf)
00263   int maxrows = 1 << m_TotalInWidth;
00264   int row = 0;
00265   int current_index = -1;
00266   do {
00267     string line(buf);
00268     string::size_type i=0;
00269     if ( (i=line.find("//")) != string::npos) line.erase(i); // strip comments
00270     L1MuGMTLUTHelpers::Tokenizer tok("=", line);
00271 
00272     if (tok.size() == 2 && tok[0].find("CONTENTS") != string::npos) {
00273       L1MuGMTLUTHelpers::Tokenizer tok1("_",tok[0]);
00274       if (tok1.size() !=2) {
00275         edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: error parsing contents tag " << tok[0] << ".";
00276         break;
00277       } 
00278 
00279       istringstream is(tok1[1].c_str());
00280       int newindex; 
00281       is >> newindex;
00282       if (newindex != current_index+1)
00283         edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: warning: LUTS in LUT file are not in order.";
00284 
00285       if (newindex > m_NLUTS-1) {
00286         edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: warning: LUT file contains LUT with too high index (" 
00287              << tok[0] 
00288              << "). max = " << m_NLUTS << " skipping.";
00289         newindex = -1;
00290       }
00291       current_index = newindex;
00292 
00293       if (row != 0) {
00294         if ( row < maxrows ) 
00295           edm::LogWarning("LUTParsingProblem") << "L1MuGMTLUT::Load: warning: LUT file only contains part of LUT contents.";
00296         row = 0;
00297       }
00298       istringstream is1(tok[1].c_str());
00299       unsigned value;
00300       if (is1 >> value) {
00301         if (current_index!=-1)
00302           Set (current_index, row++, value);    
00303       }
00304     }
00305     else {
00306       istringstream is1(line.c_str());
00307       unsigned value;
00308       if (is1 >> value) {
00309         if (row < maxrows) {
00310           if (current_index!=-1)
00311             Set (current_index, row++, value);  
00312         }
00313         else
00314           edm::LogWarning("LUTParsingProblem") 
00315                    << "L1MuGMTLUT::Load: warning: LUT file only contains LUT with too many entries. skipping.";
00316       }
00317     }
00318   } while ( in.getline(buf, sz) );
00319 }

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

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

Definition at line 121 of file L1MuGMTLUT.h.

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

00121                                                                         {
00122       return u2vec ( LookupPacked(idx, address), m_Outputs );
00123     };

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

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

Definition at line 117 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(), 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(), L1MuGMTLFMergeRankEtaPhiLUT::SpecificLookup_rank_etaphi(), L1MuGMTLFSortRankEtaPhiLUT::SpecificLookup_rank_etaphi(), L1MuGMTLFMergeRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFSortRankEtaQLUT::SpecificLookup_rank_etaq(), L1MuGMTLFSortRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFMergeRankPtQLUT::SpecificLookup_rank_ptq(), L1MuGMTLFSortRankCombineLUT::SpecificLookup_sort_rank(), and L1MuGMTLFSortRankEtaQLUT::SpecificLookup_vlq().

00117                                                                                           { 
00118       return Lookup (idx, vec2u ( address, m_Inputs ) ); };

virtual unsigned L1MuGMTLUT::LookupFunctionPacked ( int  idx,
unsigned  address 
) const [inline, virtual]

lookup defined as analytic function to be impemented in derived class

Reimplemented in L1MuGMTLFCOUDeltaEtaLUT, L1MuGMTLFDeltaEtaLUT, L1MuGMTLFDisableHotLUT, L1MuGMTLFEtaConvLUT, L1MuGMTLFMatchQualLUT, L1MuGMTLFMergeRankCombineLUT, L1MuGMTLFMergeRankEtaPhiLUT, L1MuGMTLFMergeRankEtaQLUT, L1MuGMTLFMergeRankPtQLUT, L1MuGMTLFOvlEtaConvLUT, L1MuGMTLFPhiProEtaConvLUT, L1MuGMTLFPhiProLUT, L1MuGMTLFPtMixLUT, L1MuGMTLFSortRankCombineLUT, L1MuGMTLFSortRankEtaPhiLUT, L1MuGMTLFSortRankEtaQLUT, L1MuGMTLFSortRankPtQLUT, L1MuGMTMIAUEtaConvLUT, L1MuGMTMIAUEtaProLUT, L1MuGMTMIAUPhiPro1LUT, and L1MuGMTMIAUPhiPro2LUT.

Definition at line 136 of file L1MuGMTLUT.h.

Referenced by LookupPacked().

00136 { return 0; };

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

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

Definition at line 113 of file L1MuGMTLUT.h.

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

00113                                                                                      { 
00114       return LookupPacked (idx, vec2u ( address, m_Inputs ) ); };

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

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

Definition at line 261 of file L1MuGMTLUT.h.

References LookupFunctionPacked(), m_Contents, m_initialized, m_name, m_NLUTS, m_TotalInWidth, m_TotalOutWidth, m_UseLookupFunction, and value.

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

00261                                                                   {
00262   if (! m_initialized) {
00263     edm::LogWarning("LUTMismatch")  << "Error in L1MuGMTLUT::LookupPacked: LUT not initialized. ";
00264     return 0;
00265   }
00266   if ( idx >= m_NLUTS ) {
00267     edm::LogWarning("LUTMismatch")  << "Error in L1MuGMTLUT::LookupPacked: LUT index exceeds range (0 to " << ( m_NLUTS -1 ) << ")." 
00268         ;
00269     return 0;
00270   }
00271   if ( address >= (unsigned) (1 << m_TotalInWidth) ) {
00272     edm::LogWarning("LUTMismatch")  << "Error in L1MuGMTLUT::LookupPacked: LUT input exceeds range (0 to " << ( (1 << m_TotalInWidth) -1 ) << ")." 
00273         ;
00274     return 0;
00275   }
00276 
00277   unsigned value = 0;
00278   if (m_UseLookupFunction) {
00279     value = LookupFunctionPacked (idx, address);
00280   } else {
00281     value = m_Contents[idx][address];
00282   }
00283 
00284   // check range of output
00285   if ( value >= (unsigned) (1 << m_TotalOutWidth) ) {
00286     edm::LogWarning("LUTMismatch")  << "Error in L1MuGMTLUT::LookupPacked(): LUT output value " << value
00287          << " exceeds range (0 to " << ( (1 << m_TotalOutWidth) -1 ) << ")." 
00288         ;
00289     edm::LogWarning("LUTMismatch")  << "  LUT name: " << m_name;
00290     if (m_UseLookupFunction) 
00291       edm::LogWarning("LUTMismatch")  << "  Lookup Function has to be corrected!!!";
00292     else
00293       edm::LogWarning("LUTMismatch")  << "  LUT File has to be corrected!!!";
00294     return (1 << m_TotalOutWidth) - 1;
00295   }
00296   return value;
00297 }

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 lat::endl(), lat::ends(), i, in, j, parsecf::pyparsing::line(), m_distrRAM, m_Inputs, m_InstNames, m_name, m_Outputs, m_vme_addr_width, L1MuGMTLUTHelpers::replace(), tmp, and L1MuGMTLUTHelpers::upperCase().

00327                                                             {
00328 
00329   // prepare parts
00330   string ins_name (m_name);
00331   string ins_name_upper = L1MuGMTLUTHelpers::upperCase (ins_name);
00332   string ins_instance_string;
00333   string ins_instances_enum;
00334   for (unsigned i=0; i<m_InstNames.size(); i++) {
00335     if (i!=0) ins_instance_string += ' ';
00336     ins_instance_string +=  m_InstNames[i];
00337 
00338     if (i!=0) ins_instances_enum += ", ";
00339     ins_instances_enum += m_InstNames[i];
00340   }
00341   char ins_vme[100]; 
00342   sprintf (ins_vme, "%d", m_vme_addr_width);
00343 
00344   char ins_distr_RAM[10];
00345   sprintf (ins_distr_RAM, "%s", m_distrRAM?"true":"false");
00346   
00347   
00348   string ins_input_decl_list, ins_input_list, ins_input_addr_list;
00349   for (unsigned i=0; i<m_Inputs.size(); i++) {
00350     ins_input_decl_list += string(", unsigned ") + m_Inputs[i].first;
00351     ins_input_list += string(", ") + m_Inputs[i].first;
00352     char tmp[100]; sprintf (tmp, " ,addr[%d]", i);
00353     ins_input_addr_list += string(tmp); 
00354   }
00355   
00356   //  string ins_lookup_functions;
00357   ostringstream os;
00358   for (unsigned i=0; i<m_Outputs.size(); i++) {
00359     os << "  /// specific lookup function for " <<  m_Outputs[i].first << endl;
00360     os << "  unsigned SpecificLookup_" << m_Outputs[i].first << " (int idx" << ins_input_decl_list << ") const {" << endl;
00361     os << "    vector<unsigned> addr(" << m_Inputs.size() << ");" << endl;
00362     for (unsigned j=0; j< m_Inputs.size(); j++) {
00363       os << "    addr[" << j << "] = " << m_Inputs[j].first << ";" << endl;
00364     }
00365     os << "    return Lookup(idx, addr) [" << i << "];" << endl;
00366     os << "  };" << endl << endl;
00367   }
00368   os << "  /// specific lookup function for entire output field" << endl;
00369   os << "  unsigned SpecificLookup (int idx" << ins_input_decl_list << ") const {" << endl;
00370   os << "    vector<unsigned> addr(" << m_Inputs.size() << ");" << endl;
00371   for (unsigned j=0; j< m_Inputs.size(); j++) {
00372     os << "    addr[" << j << "] = " << m_Inputs[j].first << ";" << endl;
00373   }
00374   os << "    return LookupPacked(idx, addr);" << endl;
00375   os << "  };" << endl << endl;
00376 
00377   os << ends;
00378   string ins_lookup_functions = os.str();
00379 
00380   // substitute in .h file
00381   string outfn (fname);
00382   if (outfn.size() == 0) outfn = string("../interface/L1MuGMT") +  m_name + string("LUT.h");
00383   ifstream of_check(outfn.c_str());
00384   if (! of_check.good() ) {
00385     ofstream of(outfn.c_str());
00386   
00387 
00388     ifstream in(template_file_h); 
00389     const int sz=1000; char buf[sz];
00390 
00391     while ( in.getline(buf, sz) ) {
00392       string line(buf);
00393 
00394       L1MuGMTLUTHelpers::replace(line, "###insert_name_upper###", ins_name_upper, false);
00395       L1MuGMTLUTHelpers::replace(line, "###insert_name###", ins_name, false); 
00396       L1MuGMTLUTHelpers::replace(line, "###insert_instance_string###", ins_instance_string, false);
00397       L1MuGMTLUTHelpers::replace(line, "###insert_instances_enum###", ins_instances_enum, false);
00398       L1MuGMTLUTHelpers::replace(line, "###insert_inputs_string###", string(PortDecoder(m_Inputs).str()), false);
00399       L1MuGMTLUTHelpers::replace(line, "###insert_outputs_string###", string(PortDecoder(m_Outputs).str()), false);
00400       L1MuGMTLUTHelpers::replace(line, "###insert_vme_input_width###", string(ins_vme), false);
00401       L1MuGMTLUTHelpers::replace(line, "###insert_distrRAM###", string(ins_distr_RAM), false);
00402       L1MuGMTLUTHelpers::replace(line, "###insert_input_decl_list###", ins_input_decl_list, false);
00403       L1MuGMTLUTHelpers::replace(line, "###insert_input_list###", ins_input_list, false);
00404       L1MuGMTLUTHelpers::replace(line, "###insert_input_addr_list###", ins_input_addr_list, false);
00405       L1MuGMTLUTHelpers::replace(line, "###insert_lookup_functions###", ins_lookup_functions, false);
00406       of << line << endl;
00407     }    
00408   }
00409 
00410   // substitute in .cc file
00411   string outfn_cc (fname);
00412   if (outfn_cc.size() == 0) outfn_cc = string("../interface/L1MuGMT") +  m_name + string("LUT.cc");
00413 
00414   ifstream of_cc_check( outfn_cc.c_str() );
00415   if (! of_cc_check.good() ) {
00416     ofstream of_cc(outfn_cc.c_str());
00417   
00418 
00419     ifstream in_cc(template_file_cc); 
00420     const int sz=1000; char buf[sz];
00421 
00422     while ( in_cc.getline(buf, sz) ) {
00423       string line(buf);
00424 
00425       L1MuGMTLUTHelpers::replace(line, "###insert_name_upper###", ins_name_upper, false);
00426       L1MuGMTLUTHelpers::replace(line, "###insert_name###", ins_name, false); 
00427       L1MuGMTLUTHelpers::replace(line, "###insert_instance_string###", ins_instance_string, false);
00428       L1MuGMTLUTHelpers::replace(line, "###insert_instances_enum###", ins_instances_enum, false);
00429       L1MuGMTLUTHelpers::replace(line, "###insert_inputs_string###", string(PortDecoder(m_Inputs).str()), false);
00430       L1MuGMTLUTHelpers::replace(line, "###insert_outputs_string###", string(PortDecoder(m_Outputs).str()), false);
00431       L1MuGMTLUTHelpers::replace(line, "###insert_vme_input_width###", string(ins_vme), false);
00432       L1MuGMTLUTHelpers::replace(line, "###insert_distrRAM###", string(ins_distr_RAM), false);
00433       L1MuGMTLUTHelpers::replace(line, "###insert_input_decl_list###", ins_input_decl_list, false);
00434       L1MuGMTLUTHelpers::replace(line, "###insert_input_list###", ins_input_list, false);
00435       L1MuGMTLUTHelpers::replace(line, "###insert_input_addr_list###", ins_input_addr_list, false);
00436       L1MuGMTLUTHelpers::replace(line, "###insert_lookup_functions###", ins_lookup_functions, false);
00437       of_cc << line << endl;
00438     }    
00439   }
00440 }

std::string L1MuGMTLUT::Name (  )  [inline]

Definition at line 142 of file L1MuGMTLUT.h.

References m_name.

00142 {return m_name;};

int L1MuGMTLUT::numberOfInstances (  )  [inline]

get the number of Instances

Definition at line 147 of file L1MuGMTLUT.h.

References m_NLUTS.

00147 { return m_NLUTS; };

void L1MuGMTLUT::Save ( const char *  path  ) 

save to LUT file

Definition at line 76 of file L1MuGMTLUT.cc.

References addr, lat::endl(), i, LookupPacked(), m_distrRAM, m_initialized, m_Inputs, m_InstNames, m_name, m_NLUTS, m_Outputs, m_saveFlag, m_TotalInWidth, and m_vme_addr_width.

00076                                       {
00077   if (! m_initialized) {
00078     edm::LogWarning("LUTNotInitialized") << "L1MuGMTLUT::Save: LUT not initialized. ";
00079     return;
00080   }
00081 
00082   m_saveFlag = true;
00083 
00084   ofstream of(path);
00085   of << "// This is a CMS L1 Global Muon Trigger .lut file. " << endl;
00086   of << "//  " << endl;
00087   of << "// It defines a set of look-up-tables(LUTs) of the same type (same inputs and outputs) but" << endl;
00088   of << "// with different default contents. For example a certain type of LUT can have different" << endl;
00089   of << "// default values for DT for RPC and for CSC muons. " << endl;
00090   of << "//  " << endl;
00091   of << "// NAME           gives the name of the LUT. It should match the base name (name without '.lut')" << endl;
00092   of << "//                of the LUT file." << endl;
00093   of << "//                When deriving a C++ sub-class the name is used case sensitive." << endl;
00094   of << "//                In generated VHDL code the name is used in lower case." << endl;
00095   of << "//  " << endl;
00096   of << "// INSTANCES      is the list of instances of the LUT with different default values." << endl;
00097   of << "//                the lists consists of identifiers for each of the instances separated by spaces." << endl;
00098   of << "//                the identifiers can be made up of characters that are valid in VHDL lables. " << endl;
00099   of << "//                In the VHDL code they are used to label the different instances." << endl;
00100   of << "//  " << endl;
00101   of << "//                In C++ and VHDL the instance of a LUT is selected by an integer index where 0 " << endl;
00102   of << "//                corresponds to the leftmost identifier. Integer indices are also used in the CONTENTS_XX" << endl;
00103   of << "//                statements in this file." << endl;
00104   of << "//  " << endl;
00105   of << "// LUT_INPUTS     is the (space-separated) list of inputs of the LUT. Each input is specified in the form" << endl;
00106   of << "//                <input_name>(<number_of_bits>) where <input_name> is the name of the input and" << endl;
00107   of << "//                <number_of_bits> is the number of bits of the input. <input_name> has to be a valid" << endl;
00108   of << "//                identifier both in C++ and in VHDL. In C++ it is represented as an unsigned int." << endl;
00109   of << "//  " << endl;
00110   of << "//                All LUT inputs together make up the address of the corresponding memory." << endl;
00111   of << "//                The first input in the list corresponds to the most-significant bits of the address." << endl;
00112   of << "//  " << endl;
00113   of << "// LUT_OUTPUTS    is the (space-separated) list of outputs of the LUT. Each output is specified in the form" << endl;
00114   of << "//                <output_name>(<number_of_bits>) where <output_name> is the name of the output and" << endl;
00115   of << "//                <number_of_bits> is the number of bits of the output. <output_name> has to be a valid" << endl;
00116   of << "//                identifier both in C++ and in VHDL. In C++ it is represented as an unsigned int." << endl;
00117   of << "//  " << endl;
00118   of << "//                All LUT outputs together make up the data of the corresponding memory." << endl;
00119   of << "//                The first output in the list corresponds to the most-significant data bits." << endl;
00120   of << "//  " << endl;
00121   of << "// VME_ADDR_WIDTH is the address width of the LUT memory when accessed via VME. When the LUT " << endl;
00122   of << "//                is implemented as dual-port block RAM, the VME address with can be different " << endl;
00123   of << "//                from the address width given by the sum of the input widths. It can be larger or" << endl;
00124   of << "//                smaller by a factor of 2^n. When the LUT is implemented as dual-port distributed RAM," << endl;
00125   of << "//                the VME address width has to match the input width. " << endl;
00126   of << "//  " << endl;
00127   of << "// DISTRIBUTED_RAM is 1 if the LUT is to be implemented in distributed RAM and 0 for Block RAM " << endl;
00128   of << "//                 Note that for distributed RAM the address width on the GMT side (sum of input widths)" << endl;
00129   of << "//                 has to match the vme_addr_width" << endl;
00130   of << "//  " << endl;
00131   of << "// CONTENTS_XX    specifies the default contents of instance with index XX (see INSTANCES)." << endl;
00132   of << "//                contents are specified as decimal numbers, one number per line." << endl;
00133   of << "//  " << endl;
00134   of << "// Hannes Sakulin / HEPHY Vienna, 2003" << endl;
00135   of << "// "<< endl;
00136   
00137   of << "NAME = " << m_name << endl;
00138   of << "INSTANCES =" ;
00139   for (unsigned i=0; i<m_InstNames.size(); i++) of << " " << m_InstNames[i];
00140   of << endl;
00141   of << "LUT_INPUTS = " << PortDecoder(m_Inputs).str() <<  endl;
00142   of << "LUT_OUTPUTS = " << PortDecoder(m_Outputs).str() << endl;
00143   of << "VME_ADDR_WIDTH = " << m_vme_addr_width << endl;
00144   of << "DISTRIBUTED_RAM = " << (m_distrRAM?"1":"0") << endl;
00145   for (int i=0; i<m_NLUTS; i++) {
00146     of << "// " << m_InstNames[i] << endl;
00147     of << "CONTENTS_" << i << " = ";
00148     for (unsigned addr = 0; addr < (unsigned) (1<<m_TotalInWidth); addr ++) {
00149       of << LookupPacked (i, addr) << endl;
00150     }
00151     of << endl;
00152   }
00153 
00154   m_saveFlag = false;
00155 
00156 }

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

set with single address and value

Definition at line 170 of file L1MuGMTLUT.cc.

References m_Contents, m_initialized, m_NLUTS, m_TotalInWidth, and m_TotalOutWidth.

Referenced by Load().

00170                                                                {
00171   if (! m_initialized) {
00172      edm::LogWarning("LUTNotInitialized") << "L1MuGMTLUT::Set: LUT not initialized. ";
00173     return;
00174   }
00175 
00176   if ( idx >= m_NLUTS ) {
00177     edm::LogWarning("LUTRangeViolation") << "L1MuGMTLUT::Set: LUT index exceeds range (0 to " << ( m_NLUTS -1 ) << ").";
00178     return;
00179   }
00180   if ( address >= (unsigned)(1 << m_TotalInWidth) ) {
00181     edm::LogWarning("LUTRangeViolation") << "Error in L1MuGMTLUT::Set: LUT input exceeds range (0 to " << ( (1 << m_TotalInWidth) -1 ) << ").";
00182     return;
00183   }
00184   if ( value >= (unsigned)(1 << m_TotalOutWidth) ) {
00185     edm::LogWarning("LUTRangeViolation") << "Error in L1MuGMTLUT::Set: LUT output exceeds range (0 to " << ( (1 << m_TotalOutWidth) -1 ) << ")." ;
00186     return;
00187   }
00188   m_Contents[idx][address] = value;
00189 }

std::vector< unsigned > L1MuGMTLUT::u2vec ( unsigned  value,
const std::vector< port > &  widths 
) const [inline, protected]

generate composite address or value from compact unsigned

Definition at line 240 of file L1MuGMTLUT.h.

References i, and output().

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

00240                                                                                            {
00241   std::vector<unsigned> output( widths.size(), 0);
00242  
00243   unsigned start_ofs=0;
00244 
00245   for (int i=widths.size()-1; i>=0; i--) {
00246     int mask = ( (1 << widths[i].second) - 1 ) << start_ofs;
00247     output[i] = ( value & mask ) >> start_ofs;
00248     start_ofs += widths[i].second;
00249   }
00250 
00251   return output;
00252 }

unsigned L1MuGMTLUT::vec2u ( const std::vector< unsigned > &  vec,
const std::vector< port > &  widths 
) const [inline, protected]

generate address or value from composite address or value

Definition at line 215 of file L1MuGMTLUT.h.

References i, and value.

Referenced by Lookup(), and LookupPacked().

00215                                                                                                {
00216   if (vec.size() != widths.size()) {
00217     edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::vec2u: number of LUT inputs/outputs does not match definition";
00218     return (0);
00219   }
00220   
00221   unsigned value = 0;
00222   unsigned start_ofs=0;
00223 
00224   for (int i=vec.size()-1; i>=0; i--) {
00225     if ( vec[i] >= (unsigned) (1 << widths[i].second) ) {
00226       edm::LogWarning("LUTMismatch") << "Error in L1MuGMTLUT::vec2u: LUT input/output number " << i 
00227            << " exceeds range (0 to " << ( (1 << widths[i].second) -1 ) << ")." 
00228           ;
00229     }
00230     else
00231       value |= vec[i] << start_ofs;
00232     start_ofs += widths[i].second;
00233   }
00234   
00235   return (value);
00236 }


Friends And Related Function Documentation

friend class L1MuGMTLUTConverter [friend]

Definition at line 142 of file L1MuGMTLUT.h.


Member Data Documentation

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

Definition at line 202 of file L1MuGMTLUT.h.

Referenced by Load(), LookupPacked(), and Set().

bool L1MuGMTLUT::m_distrRAM [protected]

Definition at line 208 of file L1MuGMTLUT.h.

Referenced by Load(), MakeSubClass(), and Save().

bool L1MuGMTLUT::m_initialized [protected]

Definition at line 198 of file L1MuGMTLUT.h.

Referenced by Load(), LookupPacked(), Save(), and Set().

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

Definition at line 203 of file L1MuGMTLUT.h.

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

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

Definition at line 201 of file L1MuGMTLUT.h.

Referenced by Load(), MakeSubClass(), and Save().

std::string L1MuGMTLUT::m_name [protected]

Definition at line 209 of file L1MuGMTLUT.h.

Referenced by Load(), LookupPacked(), MakeSubClass(), Name(), and Save().

int L1MuGMTLUT::m_NLUTS [protected]

Definition at line 199 of file L1MuGMTLUT.h.

Referenced by Load(), LookupPacked(), numberOfInstances(), Save(), and Set().

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

Definition at line 204 of file L1MuGMTLUT.h.

Referenced by Load(), Lookup(), MakeSubClass(), and Save().

bool L1MuGMTLUT::m_saveFlag [protected]

Definition at line 210 of file L1MuGMTLUT.h.

Referenced by Save(), L1MuGMTLFPhiProEtaConvLUT::TheLookupFunction(), L1MuGMTMIAUEtaConvLUT::TheLookupFunction(), and L1MuGMTMIAUEtaProLUT::TheLookupFunction().

unsigned L1MuGMTLUT::m_TotalInWidth [protected]

Definition at line 205 of file L1MuGMTLUT.h.

Referenced by Load(), LookupPacked(), Save(), and Set().

unsigned L1MuGMTLUT::m_TotalOutWidth [protected]

Definition at line 206 of file L1MuGMTLUT.h.

Referenced by LookupPacked(), and Set().

bool L1MuGMTLUT::m_UseLookupFunction [protected]

Definition at line 200 of file L1MuGMTLUT.h.

Referenced by Load(), LookupPacked(), and ~L1MuGMTLUT().

unsigned L1MuGMTLUT::m_vme_addr_width [protected]

Definition at line 207 of file L1MuGMTLUT.h.

Referenced by Load(), MakeSubClass(), and Save().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:26:55 2009 for CMSSW by  doxygen 1.5.4