43 #ifndef L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h 44 #define L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h 60 class L1MuGMTLUTConverter;
75 typedef std::pair<std::string, unsigned>
port;
84 const std::vector<std::string>& instances,
85 const std::vector<port>& in_widths,
86 const std::vector<port>& out_widths,
87 unsigned vme_addr_width = 0,
88 bool distrRAM =
false)
90 Init(name, instances, in_widths, out_widths, vme_addr_width, distrRAM);
97 unsigned vme_addr_width = 0,
98 bool distrRAM =
false)
116 inline unsigned LookupPacked(
int idx,
const std::vector<unsigned>& address)
const {
121 inline std::vector<unsigned>
Lookup(
int idx,
const std::vector<unsigned>& address)
const {
126 inline std::vector<unsigned>
Lookup(
int idx,
unsigned address)
const {
136 void Save(
const char* path);
144 const char* template_file_h =
"../interface/L1MuGMTLUT_SubClass.h_template",
145 const char* template_file_cc =
"../interface/L1MuGMTLUT_SubClass.cc_template");
157 const std::vector<std::string>& instances,
158 const std::vector<port>& in_widths,
159 const std::vector<port>& out_widths,
160 unsigned vme_addr_width = 0,
161 bool distrRAM =
false);
164 inline unsigned vec2u(
const std::vector<unsigned>& vec,
const std::vector<port>& widths)
const;
167 inline std::vector<unsigned>
u2vec(
unsigned value,
const std::vector<port>& widths)
const;
170 void Set(
int idx,
unsigned address,
unsigned value);
173 typedef std::vector<port>
base;
181 for (
unsigned int i = 0;
i < tok.size();
i++) {
182 size_type obrace = tok[
i].find(
"("), cbrace = tok[
i].find(
")");
183 if (obrace != std::string::npos && cbrace != std::string::npos)
185 port(tok[
i].substr(0, obrace), (
unsigned)atoi(tok[
i].substr(obrace + 1, cbrace - obrace - 1).c_str())));
187 edm::LogWarning(
"LUTMismatch") <<
"L1MuGMTLUT::PortDecoder: error decoding port " << tok[
i];
192 for (
unsigned int i = 0;
i <
size();
i++) {
197 sprintf(buf,
"(%d)", (*
this)[
i].
second);
227 unsigned L1MuGMTLUT::vec2u(
const std::vector<unsigned>& vec,
const std::vector<port>& widths)
const {
228 if (vec.size() != widths.size()) {
230 <<
"Error in L1MuGMTLUT::vec2u: number of LUT inputs/outputs does not match definition";
235 unsigned start_ofs = 0;
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) <<
").";
242 value |= vec[
i] << start_ofs;
243 start_ofs += widths[
i].second;
252 std::vector<unsigned>
output(widths.size(), 0);
254 unsigned start_ofs = 0;
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;
274 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT not initialized. ";
278 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT index exceeds range (0 to " 283 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT input exceeds range (0 to " 297 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked(): LUT output value " << value
301 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
std::vector< std::vector< unsigned > > m_Contents
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< 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)