43 #ifndef L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h 44 #define L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h 60 class L1MuGMTLUTConverter;
78 typedef std::pair<std::string, unsigned>
port;
87 const std::vector<std::string>& instances,
88 const std::vector<port>& in_widths,
89 const std::vector<port>& out_widths,
91 Init (name, instances, in_widths, out_widths, vme_addr_width, distrRAM);
100 vme_addr_width, distrRAM);
111 inline unsigned LookupPacked (
int idx,
const std::vector<unsigned>& address)
const {
115 inline std::vector<unsigned>
Lookup (
int idx,
const std::vector<unsigned>& address)
const {
119 inline std::vector<unsigned>
Lookup (
int idx,
unsigned address)
const {
130 void Save (
const char* path);
137 void MakeSubClass (
const char*
fname =
"",
const char* template_file_h =
"../interface/L1MuGMTLUT_SubClass.h_template",
138 const char* template_file_cc =
"../interface/L1MuGMTLUT_SubClass.cc_template");
150 void Init(
const char*
name,
const std::vector<std::string>& instances,
151 const std::vector<port>& in_widths,
const std::vector<port>& out_widths,
152 unsigned vme_addr_width=0,
bool distrRAM=
false);
155 inline unsigned vec2u (
const std::vector <unsigned>& vec,
const std::vector<port>& widths)
const;
158 inline std::vector<unsigned>
u2vec (
unsigned value,
const std::vector<port>& widths)
const;
161 void Set (
int idx,
unsigned address,
unsigned value);
164 typedef std::vector<port>
base;
171 for (
unsigned int i=0;
i<tok.size();
i++) {
172 size_type obrace=tok[
i].find(
"("), cbrace=tok[
i].find(
")");
173 if (obrace != std::string::npos && cbrace != std::string::npos)
174 push_back( port ( tok[
i].substr(0,obrace), (
unsigned) atoi (tok[
i].substr(obrace+1,cbrace-obrace-1).c_str() ) ) );
176 edm::LogWarning(
"LUTMismatch") <<
"L1MuGMTLUT::PortDecoder: error decoding port " << tok[
i];
181 for (
unsigned int i=0;
i<
size();
i++) {
185 char buf[100]; sprintf(buf,
"(%d)",(*
this)[
i].
second);
188 if (
i!=
size()-1) temp +=
" ";
214 unsigned L1MuGMTLUT::vec2u (
const std::vector <unsigned>& vec,
const std::vector<port>& widths)
const{
215 if (vec.size() != widths.size()) {
216 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::vec2u: number of LUT inputs/outputs does not match definition";
221 unsigned start_ofs=0;
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 ) <<
")." 230 value |= vec[
i] << start_ofs;
231 start_ofs += widths[
i].second;
240 std::vector<unsigned>
output( widths.size(), 0);
242 unsigned start_ofs=0;
244 for (
int i=widths.size()-1;
i>=0;
i--) {
245 int mask = ( (1 << widths[
i].second) - 1 ) << start_ofs;
247 start_ofs += widths[
i].second;
262 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT not initialized. ";
266 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT index exceeds range (0 to " << (
m_NLUTS -1 ) <<
")." 271 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT input exceeds range (0 to " << ( (1 <<
m_TotalInWidth) -1 ) <<
")." 285 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked(): LUT output value " << value
290 edm::LogWarning(
"LUTMismatch") <<
" Lookup Function has to be corrected!!!";
L1MuGMTLUT(const char *name, const std::string &instances, const std::string &inputs, const std::string &outputs, unsigned vme_addr_width=0, bool distrRAM=false)
virtual ~L1MuGMTLUT()
destructor
void Set(int idx, unsigned address, unsigned value)
set with single address and value
unsigned vec2u(const std::vector< unsigned > &vec, const std::vector< port > &widths) const
generate address or value from composite address or value
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::vector< std::vector< unsigned > > m_Contents
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
static std::string const input
friend class L1MuGMTLUTConverter
PortDecoder(const std::string &input)
std::pair< std::string, unsigned > port
U second(std::pair< T, U > const &p)
std::vector< port > m_Outputs
void Save(const char *path)
save to LUT file
L1MuGMTLUT()
Init and Destruct.
std::vector< port > m_Inputs
std::vector< std::string > m_InstNames
void Load(const char *path)
I/O functions.
int numberOfInstances()
get the number of Instances
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
std::vector< unsigned > Lookup(int idx, unsigned address) const
additional lookup function (unsigned -> std::vector)
std::vector< unsigned > u2vec(unsigned value, const std::vector< port > &widths) const
generate composite address or value from compact unsigned
unsigned m_GeneralLUTVersion
PortDecoder(const std::vector< port > &pt)
unsigned LookupPacked(int idx, unsigned) const
unsigned m_vme_addr_width
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.
unsigned LookupPacked(int idx, const std::vector< unsigned > &address) const
additional lookup function (std::vector -> unisgned)