CMS 3D CMS Logo

PtLUTReader.cc
Go to the documentation of this file.
2 
3 #include <fstream>
4 #include <iostream>
5 #include <stdexcept>
6 
7 #define PTLUT_SIZE (1 << 30)
8 
9 PtLUTReader::PtLUTReader() : ptlut_(), version_(4), ok_(false) {}
10 
12 
13 void PtLUTReader::read(const std::string& lut_full_path) {
14  if (ok_)
15  return;
16 
17  std::cout << "EMTF emulator: attempting to read pT LUT binary file from local area" << std::endl;
18  std::cout << lut_full_path << std::endl;
19  std::cout << "Non-standard operation; if it fails, now you know why" << std::endl;
20  std::cout << "Be sure to check that the 'scale_pt' function still matches this LUT" << std::endl;
21  std::cout << "Loading LUT, this might take a while..." << std::endl;
22 
23  std::ifstream infile(lut_full_path, std::ios::binary);
24  if (!infile.good()) {
25  char what[256];
26  snprintf(what, sizeof(what), "Fail to open %s", lut_full_path.c_str());
27  throw std::invalid_argument(what);
28  }
29 
30  ptlut_.reserve(PTLUT_SIZE);
31 
32  typedef uint64_t full_word_t;
33  full_word_t full_word;
34  full_word_t sub_word[4] = {0, 0, 0, 0};
35 
36  while (infile.read(reinterpret_cast<char*>(&full_word), sizeof(full_word_t))) {
37  sub_word[0] = (full_word >> 0) & 0x1FF; // 9-bit
38  sub_word[1] = (full_word >> 9) & 0x1FF;
39  sub_word[2] = (full_word >> 32) & 0x1FF;
40  sub_word[3] = (full_word >> (32 + 9)) & 0x1FF;
41 
42  ptlut_.push_back(sub_word[0]);
43  ptlut_.push_back(sub_word[1]);
44  ptlut_.push_back(sub_word[2]);
45  ptlut_.push_back(sub_word[3]);
46  }
47  infile.close();
48 
49  if (ptlut_.size() != PTLUT_SIZE) {
50  char what[256];
51  snprintf(what, sizeof(what), "ptlut_.size() is %lu != %i", ptlut_.size(), PTLUT_SIZE);
52  throw std::invalid_argument(what);
53  }
54 
55  version_ = ptlut_.at(0); // address 0 is the pT LUT version number
56  ok_ = true;
57  return;
58 }
59 
60 PtLUTReader::content_t PtLUTReader::lookup(const address_t& address) const { return ptlut_.at(address); }
funct::false
false
Definition: Factorize.h:29
gather_cfg.cout
cout
Definition: gather_cfg.py:144
PtLUTReader::content_t
uint16_t content_t
Definition: PtLUTReader.h:13
PtLUTReader::version_
content_t version_
Definition: PtLUTReader.h:25
PtLUTReader::lookup
content_t lookup(const address_t &address) const
Definition: PtLUTReader.cc:60
PtLUTReader::address_t
uint64_t address_t
Definition: PtLUTReader.h:14
PtLUTReader::ok_
bool ok_
Definition: PtLUTReader.h:26
PTLUT_SIZE
#define PTLUT_SIZE
Definition: PtLUTReader.cc:7
PtLUTReader::ptlut_
table_t ptlut_
Definition: PtLUTReader.h:24
PtLUTReader::~PtLUTReader
~PtLUTReader()
Definition: PtLUTReader.cc:11
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PtLUTReader.h
timingPdfMaker.infile
infile
Definition: timingPdfMaker.py:349
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
PtLUTReader::read
void read(const std::string &lut_full_path)
Definition: PtLUTReader.cc:13
PtLUTReader::PtLUTReader
PtLUTReader()
Definition: PtLUTReader.cc:9