45 #ifndef L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h
46 #define L1TriggerGlobalMuonTrigger_L1MuGMTLUT_h
62 class L1MuGMTLUTConverter;
80 typedef std::pair<std::string, unsigned>
port;
89 const std::vector<std::string>& instances,
90 const std::vector<port>& in_widths,
91 const std::vector<port>& out_widths,
93 Init (name, instances, in_widths, out_widths, vme_addr_width, distrRAM);
102 vme_addr_width, distrRAM);
117 inline std::vector<unsigned>
Lookup (
int idx,
const std::vector<unsigned>&
address)
const {
139 void MakeSubClass (
const char*
fname =
"",
const char* template_file_h =
"../interface/L1MuGMTLUT_SubClass.h_template",
140 const char* template_file_cc =
"../interface/L1MuGMTLUT_SubClass.cc_template");
152 void Init(
const char*
name,
const std::vector<std::string>& instances,
153 const std::vector<port>& in_widths,
const std::vector<port>& out_widths,
154 unsigned vme_addr_width=0,
bool distrRAM=
false);
157 inline unsigned vec2u (
const std::vector <unsigned>& vec,
const std::vector<port>& widths)
const;
160 inline std::vector<unsigned>
u2vec (
unsigned value,
const std::vector<port>& widths)
const;
166 typedef std::vector<port>
base;
173 for (
unsigned int i=0;
i<tok.size();
i++) {
174 size_type obrace=tok[
i].find(
"("), cbrace=tok[
i].find(
")");
175 if (obrace != std::string::npos && cbrace != std::string::npos)
176 push_back(
port ( tok[
i].substr(0,obrace), (
unsigned) atoi (tok[
i].substr(obrace+1,cbrace-obrace-1).c_str() ) ) );
178 edm::LogWarning(
"LUTMismatch") <<
"L1MuGMTLUT::PortDecoder: error decoding port " << tok[
i];
183 for (
unsigned int i=0;
i<
size();
i++) {
187 char buf[100]; sprintf(buf,
"(%d)",(*
this)[
i].
second);
190 if (
i!=
size()-1) temp +=
" ";
216 unsigned L1MuGMTLUT::vec2u (
const std::vector <unsigned>& vec,
const std::vector<port>& widths)
const{
217 if (vec.size() != widths.size()) {
218 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::vec2u: number of LUT inputs/outputs does not match definition";
223 unsigned start_ofs=0;
225 for (
int i=vec.size()-1;
i>=0;
i--) {
226 if ( vec[
i] >= (
unsigned) (1 << widths[
i].second) ) {
227 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::vec2u: LUT input/output number " <<
i
228 <<
" exceeds range (0 to " << ( (1 << widths[
i].second) -1 ) <<
")."
232 value |= vec[
i] << start_ofs;
233 start_ofs += widths[
i].second;
242 std::vector<unsigned>
output( widths.size(), 0);
244 unsigned start_ofs=0;
246 for (
int i=widths.size()-1;
i>=0;
i--) {
247 int mask = ( (1 << widths[
i].second) - 1 ) << start_ofs;
248 output[
i] = ( value & mask ) >> start_ofs;
249 start_ofs += widths[
i].second;
264 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT not initialized. ";
268 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT index exceeds range (0 to " << (
m_NLUTS -1 ) <<
")."
273 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked: LUT input exceeds range (0 to " << ( (1 <<
m_TotalInWidth) -1 ) <<
")."
287 edm::LogWarning(
"LUTMismatch") <<
"Error in L1MuGMTLUT::LookupPacked(): LUT output value " << value
292 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
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
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
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)
tuple size
Write out results.