CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
PtLUTWriter Class Reference

#include <PtLUTWriter.h>

Public Types

typedef uint64_t address_t
 
typedef uint16_t content_t
 
typedef std::vector< content_ttable_t
 

Public Member Functions

content_t get_version () const
 
 PtLUTWriter ()
 
void push_back (const content_t &pt)
 
void set_version (content_t ver)
 
void write (const std::string &lut_full_path, const uint16_t num_, const uint16_t denom_) const
 
 ~PtLUTWriter ()
 

Private Attributes

bool ok_
 
table_t ptlut_
 
content_t version_
 

Detailed Description

Definition at line 8 of file PtLUTWriter.h.

Member Typedef Documentation

◆ address_t

typedef uint64_t PtLUTWriter::address_t

Definition at line 14 of file PtLUTWriter.h.

◆ content_t

typedef uint16_t PtLUTWriter::content_t

Definition at line 13 of file PtLUTWriter.h.

◆ table_t

typedef std::vector<content_t> PtLUTWriter::table_t

Definition at line 15 of file PtLUTWriter.h.

Constructor & Destructor Documentation

◆ PtLUTWriter()

PtLUTWriter::PtLUTWriter ( )
explicit

Definition at line 10 of file PtLUTWriter.cc.

References ptlut_, and PTLUT_SIZE.

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 }
#define PTLUT_SIZE
Definition: PtLUTWriter.cc:8
content_t version_
Definition: PtLUTWriter.h:27
table_t ptlut_
Definition: PtLUTWriter.h:26

◆ ~PtLUTWriter()

PtLUTWriter::~PtLUTWriter ( )

Definition at line 17 of file PtLUTWriter.cc.

17 {}

Member Function Documentation

◆ get_version()

content_t PtLUTWriter::get_version ( ) const
inline

Definition at line 23 of file PtLUTWriter.h.

References version_.

23 { return version_; }
content_t version_
Definition: PtLUTWriter.h:27

◆ push_back()

void PtLUTWriter::push_back ( const content_t pt)

Definition at line 72 of file PtLUTWriter.cc.

References DiDispStaMuonMonitor_cfi::pt, and ptlut_.

◆ set_version()

void PtLUTWriter::set_version ( content_t  ver)
inline

Definition at line 21 of file PtLUTWriter.h.

References version_.

21 { version_ = ver; }
content_t version_
Definition: PtLUTWriter.h:27

◆ write()

void PtLUTWriter::write ( const std::string &  lut_full_path,
const uint16_t  num_,
const uint16_t  denom_ 
) const

Definition at line 19 of file PtLUTWriter.cc.

References gather_cfg::cout, PixelBaryCentreAnalyzer_cfg::outfile, ptlut_, PTLUT_SIZE, and version_.

19  {
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 }
Log< level::Error, false > LogError
#define PTLUT_SIZE
Definition: PtLUTWriter.cc:8
content_t version_
Definition: PtLUTWriter.h:27
unsigned long long uint64_t
Definition: Time.h:13
table_t ptlut_
Definition: PtLUTWriter.h:26

Member Data Documentation

◆ ok_

bool PtLUTWriter::ok_
private

Definition at line 28 of file PtLUTWriter.h.

◆ ptlut_

table_t PtLUTWriter::ptlut_
mutableprivate

Definition at line 26 of file PtLUTWriter.h.

Referenced by PtLUTWriter(), push_back(), and write().

◆ version_

content_t PtLUTWriter::version_
private

Definition at line 27 of file PtLUTWriter.h.

Referenced by get_version(), set_version(), and write().