CMS 3D CMS Logo

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