CMS 3D CMS Logo

PtLUTWriter.cc
Go to the documentation of this file.
3 
4 #include <fstream>
5 #include <iostream>
6 #include <stdexcept>
7 #include <cassert>
8 
9 #define PTLUT_SIZE (1<<30)
10 
12  ptlut_(),
13  version_(7), // Initial version, but not hard-coded: gets set by "set_version"
14  ok_(false)
15 {
16  ptlut_.reserve(PTLUT_SIZE / 64); // Hack! Hard-code / manually set denom_ for now - AWB 24.05.17
17 }
18 
20 
21 }
22 
23 void PtLUTWriter::write(const std::string& lut_full_path, const uint16_t num_, const uint16_t denom_) const {
24  //if (ok_) return;
25  if (not(denom_ == 64)) // Check consistency for temporary hack - AWB 24.05.17
26  { edm::LogError("L1T") << "denom_ = " << denom_; return; }
27 
28  std::cout << "Writing LUT, this might take a while..." << std::endl;
29 
30  std::ofstream outfile(lut_full_path, std::ios::binary);
31  if (!outfile.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  if (ptlut_.size() != (PTLUT_SIZE / denom_)) {
38  char what[256];
39  snprintf(what, sizeof(what), "ptlut_.size() is %lu != %i", ptlut_.size(), PTLUT_SIZE);
40  throw std::invalid_argument(what);
41  }
42 
43  if (num_ == 1)
44  ptlut_.at(0) = version_; // address 0 is the pT LUT version number
45 
46  typedef uint64_t full_word_t;
47  full_word_t full_word;
48  full_word_t sub_word[4] = {0, 0, 0, 0};
49 
50  table_t::const_iterator ptlut_it = ptlut_.begin();
51  table_t::const_iterator ptlut_end = ptlut_.end();
52 
53  while (ptlut_it != ptlut_end) {
54  sub_word[0] = *ptlut_it++;
55  sub_word[1] = *ptlut_it++;
56  sub_word[2] = *ptlut_it++;
57  sub_word[3] = *ptlut_it++;
58 
59  full_word = 0;
60  full_word |= ((sub_word[0] & 0x1FF) << 0);
61  full_word |= ((sub_word[1] & 0x1FF) << 9);
62  full_word |= ((sub_word[2] & 0x1FF) << 32);
63  full_word |= ((sub_word[3] & 0x1FF) << (32+9));
64 
65  outfile.write(reinterpret_cast<char*>(&full_word), sizeof(full_word_t));
66  }
67  outfile.close();
68 
69  //ok_ = true;
70  return;
71 }
72 
74  ptlut_.push_back(pt);
75 }
#define PTLUT_SIZE
Definition: PtLUTWriter.cc:9
void write(const std::string &lut_full_path, const uint16_t num_, const uint16_t denom_) const
Definition: PtLUTWriter.cc:23
content_t version_
Definition: PtLUTWriter.h:28
uint16_t content_t
Definition: PtLUTWriter.h:14
unsigned long long uint64_t
Definition: Time.h:15
table_t ptlut_
Definition: PtLUTWriter.h:27
void push_back(const content_t &pt)
Definition: PtLUTWriter.cc:73