Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/L1TMuonEndCap/interface/PtLUTReader.h"
0002 
0003 #include <fstream>
0004 #include <iostream>
0005 #include <stdexcept>
0006 
0007 #define PTLUT_SIZE (1 << 30)
0008 
0009 PtLUTReader::PtLUTReader() : ptlut_(), version_(4), ok_(false) {}
0010 
0011 PtLUTReader::~PtLUTReader() {}
0012 
0013 void PtLUTReader::read(const std::string& lut_full_path) {
0014   if (ok_)
0015     return;
0016 
0017   std::cout << "EMTF emulator: attempting to read pT LUT binary file from local area" << std::endl;
0018   std::cout << lut_full_path << std::endl;
0019   std::cout << "Non-standard operation; if it fails, now you know why" << std::endl;
0020   std::cout << "Be sure to check that the 'scale_pt' function still matches this LUT" << std::endl;
0021   std::cout << "Loading LUT, this might take a while..." << std::endl;
0022 
0023   std::ifstream infile(lut_full_path, std::ios::binary);
0024   if (!infile.good()) {
0025     char what[256];
0026     snprintf(what, sizeof(what), "Fail to open %s", lut_full_path.c_str());
0027     throw std::invalid_argument(what);
0028   }
0029 
0030   ptlut_.reserve(PTLUT_SIZE);
0031 
0032   typedef uint64_t full_word_t;
0033   full_word_t full_word;
0034   full_word_t sub_word[4] = {0, 0, 0, 0};
0035 
0036   while (infile.read(reinterpret_cast<char*>(&full_word), sizeof(full_word_t))) {
0037     sub_word[0] = (full_word >> 0) & 0x1FF;  // 9-bit
0038     sub_word[1] = (full_word >> 9) & 0x1FF;
0039     sub_word[2] = (full_word >> 32) & 0x1FF;
0040     sub_word[3] = (full_word >> (32 + 9)) & 0x1FF;
0041 
0042     ptlut_.push_back(sub_word[0]);
0043     ptlut_.push_back(sub_word[1]);
0044     ptlut_.push_back(sub_word[2]);
0045     ptlut_.push_back(sub_word[3]);
0046   }
0047   infile.close();
0048 
0049   if (ptlut_.size() != PTLUT_SIZE) {
0050     char what[256];
0051     snprintf(what, sizeof(what), "ptlut_.size() is %lu != %i", ptlut_.size(), PTLUT_SIZE);
0052     throw std::invalid_argument(what);
0053   }
0054 
0055   version_ = ptlut_.at(0);  // address 0 is the pT LUT version number
0056   ok_ = true;
0057   return;
0058 }
0059 
0060 PtLUTReader::content_t PtLUTReader::lookup(const address_t& address) const { return ptlut_.at(address); }