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