Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:48

0001 
0002 #include "L1Trigger/L1TMuon/interface/MicroGMTLUT.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 
0006 l1t::MicroGMTLUT::MicroGMTLUT(l1t::LUT* lut) : m_totalInWidth(0), m_outWidth(0), m_initialized(true) {
0007   std::stringstream ss;
0008   lut->write(ss);
0009   read(ss);
0010 }
0011 
0012 // I/O functions
0013 void l1t::MicroGMTLUT::save(std::ofstream& output) { write(output); }
0014 
0015 int l1t::MicroGMTLUT::load(const std::string& inFileName) {
0016   std::ifstream fstream;
0017   fstream.open(edm::FileInPath(inFileName.c_str()).fullPath());
0018   if (!fstream.good()) {
0019     fstream.close();
0020     throw cms::Exception("FileOpenError") << "Failed to open LUT file: " << inFileName;
0021   }
0022   int readCode = read(fstream);
0023 
0024   m_initialized = true;
0025   fstream.close();
0026 
0027   return readCode;
0028 }
0029 
0030 int l1t::MicroGMTLUT::lookupPacked(const int input) const {
0031   if (m_initialized) {
0032     return data((unsigned int)input);
0033   }
0034   throw cms::Exception("Uninitialized") << "If you're not loading a LUT from file you need to implement lookupPacked.";
0035   return 0;
0036 }
0037 
0038 void l1t::MicroGMTLUT::initialize() {
0039   if (empty()) {
0040     std::stringstream stream;
0041     stream << "#<header> V1 " << m_totalInWidth << " " << m_outWidth << " </header> " << std::endl;
0042     for (int in = 0; in < (1 << m_totalInWidth); ++in) {
0043       int out = lookupPacked(in);
0044       stream << in << " " << out << std::endl;
0045     }
0046     read(stream);
0047   }
0048   m_initialized = true;
0049 }
0050 
0051 int l1t::MicroGMTLUT::checkedInput(unsigned in, unsigned maxWidth) const {
0052   unsigned maxIn = (1 << maxWidth) - 1;
0053   return (in < maxIn ? in : maxIn);
0054 }