File indexing completed on 2024-04-06 12:20:58
0001 #include "L1Trigger/L1TMuonEndCap/interface/PtLUTWriter.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003
0004 #include <fstream>
0005 #include <iostream>
0006 #include <stdexcept>
0007
0008 #define PTLUT_SIZE (1 << 30)
0009
0010 PtLUTWriter::PtLUTWriter()
0011 : ptlut_(),
0012 version_(7),
0013 ok_(false) {
0014 ptlut_.reserve(PTLUT_SIZE / 64);
0015 }
0016
0017 PtLUTWriter::~PtLUTWriter() {}
0018
0019 void PtLUTWriter::write(const std::string& lut_full_path, const uint16_t num_, const uint16_t denom_) const {
0020
0021 if (not(denom_ == 64))
0022 {
0023 edm::LogError("L1T") << "denom_ = " << denom_;
0024 return;
0025 }
0026
0027 std::cout << "Writing LUT, this might take a while..." << std::endl;
0028
0029 std::ofstream outfile(lut_full_path, std::ios::binary);
0030 if (!outfile.good()) {
0031 char what[256];
0032 snprintf(what, sizeof(what), "Fail to open %s", lut_full_path.c_str());
0033 throw std::invalid_argument(what);
0034 }
0035
0036 if (ptlut_.size() != (PTLUT_SIZE / denom_)) {
0037 char what[256];
0038 snprintf(what, sizeof(what), "ptlut_.size() is %lu != %i", ptlut_.size(), PTLUT_SIZE);
0039 throw std::invalid_argument(what);
0040 }
0041
0042 if (num_ == 1)
0043 ptlut_.at(0) = version_;
0044
0045 typedef uint64_t full_word_t;
0046 full_word_t full_word;
0047 full_word_t sub_word[4] = {0, 0, 0, 0};
0048
0049 table_t::const_iterator ptlut_it = ptlut_.begin();
0050 table_t::const_iterator ptlut_end = ptlut_.end();
0051
0052 while (ptlut_it != ptlut_end) {
0053 sub_word[0] = *ptlut_it++;
0054 sub_word[1] = *ptlut_it++;
0055 sub_word[2] = *ptlut_it++;
0056 sub_word[3] = *ptlut_it++;
0057
0058 full_word = 0;
0059 full_word |= ((sub_word[0] & 0x1FF) << 0);
0060 full_word |= ((sub_word[1] & 0x1FF) << 9);
0061 full_word |= ((sub_word[2] & 0x1FF) << 32);
0062 full_word |= ((sub_word[3] & 0x1FF) << (32 + 9));
0063
0064 outfile.write(reinterpret_cast<char*>(&full_word), sizeof(full_word_t));
0065 }
0066 outfile.close();
0067
0068
0069 return;
0070 }
0071
0072 void PtLUTWriter::push_back(const content_t& pt) { ptlut_.push_back(pt); }