CMS 3D CMS Logo

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

#include <CSCLUTReader.h>

Public Types

enum  ReadCodes {
  SUCCESS = 0, NO_ENTRIES = 1, DUP_ENTRIES = 2, MISS_ENTRIES = 3,
  MAX_ADDRESS_OUTOFRANGE = 4, NO_HEADER = 5
}
 

Public Member Functions

unsigned checkedInput (unsigned in, unsigned maxWidth) const
 
 CSCLUTReader (const std::string &)
 
float data (unsigned int address) const
 
bool empty () const
 
void initialize ()
 
int load (const std::string &inFileName)
 
float lookup (int code) const
 
float lookupPacked (const int input) const
 
unsigned int maxSize () const
 
unsigned int nrBitsAddress () const
 
unsigned int nrBitsData () const
 
int read (std::istream &stream)
 
void save (std::ofstream &output)
 
void write (std::ostream &stream) const
 
 ~CSCLUTReader ()
 

Private Member Functions

int readHeader (std::istream &)
 

Private Attributes

unsigned int addressMask_
 
std::vector< float > data_
 
unsigned int dataMask_
 
std::string fname_
 
int m_codeInWidth
 
bool m_initialized
 
unsigned m_outWidth
 
unsigned int nrBitsAddress_
 
unsigned int nrBitsData_
 

Detailed Description

Definition at line 14 of file CSCLUTReader.h.

Member Enumeration Documentation

◆ ReadCodes

Enumerator
SUCCESS 
NO_ENTRIES 
DUP_ENTRIES 
MISS_ENTRIES 
MAX_ADDRESS_OUTOFRANGE 
NO_HEADER 

Definition at line 16 of file CSCLUTReader.h.

16  {
17  SUCCESS = 0,
18  NO_ENTRIES = 1,
19  DUP_ENTRIES = 2,
20  MISS_ENTRIES = 3,
22  NO_HEADER = 5
23  };

Constructor & Destructor Documentation

◆ CSCLUTReader()

CSCLUTReader::CSCLUTReader ( const std::string &  fname)
explicit

Definition at line 5 of file CSCLUTReader.cc.

6  : fname_(fname),
8  nrBitsData_(0),
9  addressMask_(0),
10  dataMask_(0),
11  data_(),
12  m_codeInWidth(12),
13  m_outWidth(32) {
14  if (fname != std::string("")) {
15  load(fname);
16  } else {
17  initialize();
18  }
19 }

References alignmentValidation::fname, initialize(), load(), and AlCaHLTBitMon_QueryRunRegistry::string.

◆ ~CSCLUTReader()

CSCLUTReader::~CSCLUTReader ( )
inline

Definition at line 27 of file CSCLUTReader.h.

27 {}

Member Function Documentation

◆ checkedInput()

unsigned CSCLUTReader::checkedInput ( unsigned  in,
unsigned  maxWidth 
) const

Definition at line 74 of file CSCLUTReader.cc.

74  {
75  unsigned maxIn = (1 << maxWidth) - 1;
76  return (in < maxIn ? in : maxIn);
77 }

References recoMuon::in, and SiStripMonitorCluster_cfi::maxWidth.

◆ data()

float CSCLUTReader::data ( unsigned int  address) const

Definition at line 24 of file CSCLUTReader.cc.

24  {
25  return (address & addressMask_) < data_.size() ? data_[address] : 0;
26 }

References addressMask_, and data_.

Referenced by lookupPacked(), and write().

◆ empty()

bool CSCLUTReader::empty ( void  ) const
inline

Definition at line 49 of file CSCLUTReader.h.

49 { return data_.empty(); }

References data_.

Referenced by initialize().

◆ initialize()

void CSCLUTReader::initialize ( void  )

Definition at line 61 of file CSCLUTReader.cc.

61  {
62  if (empty()) {
63  std::stringstream stream;
64  stream << "#<header> V1 " << m_codeInWidth << " " << m_outWidth << " </header> " << std::endl;
65  for (int in = 0; in < (1 << m_codeInWidth); ++in) {
66  int out = lookup(in);
67  stream << in << " " << out << std::endl;
68  }
69  read(stream);
70  }
71  m_initialized = true;
72 }

References empty(), recoMuon::in, lookup(), m_codeInWidth, m_initialized, m_outWidth, MillePedeFileConverter_cfg::out, read(), and cms::cuda::stream.

Referenced by CSCLUTReader().

◆ load()

int CSCLUTReader::load ( const std::string &  inFileName)

Definition at line 28 of file CSCLUTReader.cc.

28  {
29  std::ifstream fstream;
30  fstream.open(edm::FileInPath(inFileName.c_str()).fullPath());
31  if (!fstream.good()) {
32  fstream.close();
33  edm::LogError("CSCLUTReader") << "Failed to open LUT file: " << inFileName;
34  }
35  int readCode = read(fstream);
36 
37  m_initialized = true;
38  fstream.close();
39 
40  return readCode;
41 }

References contentValuesFiles::fullPath, m_initialized, and read().

Referenced by CSCLUTReader().

◆ lookup()

float CSCLUTReader::lookup ( int  code) const

Definition at line 43 of file CSCLUTReader.cc.

43  {
44  if (m_initialized) {
45  return lookupPacked(code);
46  } else {
47  edm::LogError("CSCLUTReader") << "LUT not initialized. " << fname_;
48  return 0;
49  }
50 }

References fname_, lookupPacked(), and m_initialized.

Referenced by initialize().

◆ lookupPacked()

float CSCLUTReader::lookupPacked ( const int  input) const

Definition at line 52 of file CSCLUTReader.cc.

52  {
53  if (m_initialized) {
54  return data((unsigned int)input);
55  } else {
56  edm::LogError("CSCLUTReader") << "If you're not loading a LUT from file you need to implement lookupPacked.";
57  return 0;
58  }
59 }

References data(), input, and m_initialized.

Referenced by lookup().

◆ maxSize()

unsigned int CSCLUTReader::maxSize ( ) const

Definition at line 142 of file CSCLUTReader.cc.

References addressMask_, and SiStripPI::max.

◆ nrBitsAddress()

unsigned int CSCLUTReader::nrBitsAddress ( ) const
inline

Definition at line 45 of file CSCLUTReader.h.

45 { return nrBitsAddress_; }

References nrBitsAddress_.

◆ nrBitsData()

unsigned int CSCLUTReader::nrBitsData ( ) const
inline

Definition at line 46 of file CSCLUTReader.h.

46 { return nrBitsData_; }

References nrBitsData_.

◆ read()

int CSCLUTReader::read ( std::istream &  stream)

Definition at line 79 of file CSCLUTReader.cc.

79  {
80  data_.clear();
81 
82  int readHeaderCode = readHeader(stream);
83  if (readHeaderCode != SUCCESS) {
84  edm::LogError("CSCLUTReader") << "Failed to read header code. " << fname_;
85  return readHeaderCode;
86  }
87 
88  std::vector<std::pair<unsigned int, float> > entries;
89  unsigned int maxAddress = addressMask_;
91 
92  while (std::getline(stream, line)) {
93  line.erase(std::find(line.begin(), line.end(), '#'), line.end()); //ignore comments
94  std::istringstream lineStream(line);
95  std::pair<unsigned int, float> entry;
96  while (lineStream >> entry.first >> entry.second) {
97  entry.first &= addressMask_;
98  // entry.second &= dataMask_;
99  entries.push_back(entry);
100  if (entry.first > maxAddress || maxAddress == addressMask_)
101  maxAddress = entry.first;
102  }
103  }
104  std::sort(entries.begin(), entries.end());
105  if (entries.empty()) {
106  //log the error we read nothing
107  return NO_ENTRIES;
108  }
109  //this check is redundant as dups are also picked up by the next check but might make for easier debugging
110  if (std::adjacent_find(entries.begin(), entries.end(), [](auto const& a, auto const& b) {
111  return a.first == b.first;
112  }) != entries.end()) {
113  //log the error that we have duplicate addresses once masked
114  return DUP_ENTRIES;
115  }
116  if (entries.front().first != 0 ||
117  std::adjacent_find(entries.begin(), entries.end(), [](auto const& a, auto const& b) {
118  return a.first + 1 != b.first;
119  }) != entries.end()) {
120  //log the error that we have a missing entry
121  return MISS_ENTRIES;
122  }
123 
124  if (maxAddress != std::numeric_limits<unsigned int>::max())
125  data_.resize(maxAddress + 1, 0);
126  else {
127  //log the error that we have more addresses than we can deal with (which is 4gb so something probably has gone wrong anyways)
128  return MAX_ADDRESS_OUTOFRANGE;
129  }
130 
131  std::transform(entries.begin(), entries.end(), data_.begin(), [](auto const& x) { return x.second; });
132  return SUCCESS;
133 }

References a, addressMask_, b, data_, DUP_ENTRIES, mps_splice::entry, spr::find(), fname_, mps_splice::line, SiStripPI::max, MAX_ADDRESS_OUTOFRANGE, MISS_ENTRIES, NO_ENTRIES, readHeader(), jetUpdater_cfi::sort, cms::cuda::stream, AlCaHLTBitMon_QueryRunRegistry::string, SUCCESS, HcalDetIdTransform::transform(), and x.

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), initialize(), and load().

◆ readHeader()

int CSCLUTReader::readHeader ( std::istream &  stream)
private

Definition at line 146 of file CSCLUTReader.cc.

146  {
147  int startPos = stream.tellg(); //we are going to reset to this position before we exit
149  while (std::getline(stream, line)) {
150  if (line.find("#<header>") == 0) { //line
151  std::istringstream lineStream(line);
152 
153  std::string version; //currently not doing anything with this
154  std::string headerField; //currently not doing anything with this
155  if (lineStream >> headerField >> version >> nrBitsAddress_ >> nrBitsData_) {
156  addressMask_ = nrBitsAddress_ != 32 ? (0x1 << nrBitsAddress_) - 1 : ~0x0;
157  dataMask_ = (0x1 << nrBitsData_) - 1;
158  stream.seekg(startPos);
159  return SUCCESS;
160  }
161  }
162  }
163 
164  nrBitsAddress_ = 0;
165  nrBitsData_ = 0;
166  addressMask_ = (0x1 << nrBitsAddress_) - 1;
167  dataMask_ = (0x1 << nrBitsData_) - 1;
168 
169  stream.seekg(startPos);
170  return NO_HEADER;
171 }

References addressMask_, dataMask_, mps_splice::line, NO_HEADER, nrBitsAddress_, nrBitsData_, cms::cuda::stream, AlCaHLTBitMon_QueryRunRegistry::string, SUCCESS, and BeamSplash_cfg::version.

Referenced by read().

◆ save()

void CSCLUTReader::save ( std::ofstream &  output)

Definition at line 22 of file CSCLUTReader.cc.

22 { write(output); }

References convertSQLitetoXML_cfg::output, and write().

◆ write()

void CSCLUTReader::write ( std::ostream &  stream) const

Definition at line 135 of file CSCLUTReader.cc.

135  {
136  stream << "#<header> V1 " << nrBitsAddress_ << " " << nrBitsData_ << " </header> " << std::endl;
137  for (unsigned int address = 0; address < data_.size(); address++) {
138  stream << (address & addressMask_) << " " << data(address) << std::endl;
139  }
140 }

References addressMask_, data(), data_, nrBitsAddress_, nrBitsData_, and cms::cuda::stream.

Referenced by save().

Member Data Documentation

◆ addressMask_

unsigned int CSCLUTReader::addressMask_
private

Definition at line 57 of file CSCLUTReader.h.

Referenced by data(), maxSize(), read(), readHeader(), and write().

◆ data_

std::vector<float> CSCLUTReader::data_
private

Definition at line 60 of file CSCLUTReader.h.

Referenced by data(), empty(), read(), and write().

◆ dataMask_

unsigned int CSCLUTReader::dataMask_
private

Definition at line 58 of file CSCLUTReader.h.

Referenced by readHeader().

◆ fname_

std::string CSCLUTReader::fname_
private

Definition at line 52 of file CSCLUTReader.h.

Referenced by lookup(), and read().

◆ m_codeInWidth

int CSCLUTReader::m_codeInWidth
private

Definition at line 62 of file CSCLUTReader.h.

Referenced by initialize().

◆ m_initialized

bool CSCLUTReader::m_initialized
private

Definition at line 64 of file CSCLUTReader.h.

Referenced by initialize(), load(), lookup(), and lookupPacked().

◆ m_outWidth

unsigned CSCLUTReader::m_outWidth
private

Definition at line 63 of file CSCLUTReader.h.

Referenced by initialize().

◆ nrBitsAddress_

unsigned int CSCLUTReader::nrBitsAddress_
private

Definition at line 55 of file CSCLUTReader.h.

Referenced by nrBitsAddress(), readHeader(), and write().

◆ nrBitsData_

unsigned int CSCLUTReader::nrBitsData_
private

Definition at line 56 of file CSCLUTReader.h.

Referenced by nrBitsData(), readHeader(), and write().

input
static const std::string input
Definition: EdmProvDump.cc:48
CSCLUTReader::lookupPacked
float lookupPacked(const int input) const
Definition: CSCLUTReader.cc:52
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
CSCLUTReader::addressMask_
unsigned int addressMask_
Definition: CSCLUTReader.h:57
CSCLUTReader::initialize
void initialize()
Definition: CSCLUTReader.cc:61
contentValuesFiles.fullPath
fullPath
Definition: contentValuesFiles.py:64
CSCLUTReader::write
void write(std::ostream &stream) const
Definition: CSCLUTReader.cc:135
mps_splice.entry
entry
Definition: mps_splice.py:68
cms::cuda::stream
uint32_t const T *__restrict__ const uint32_t *__restrict__ int32_t int Histo::index_type cudaStream_t stream
Definition: HistoContainer.h:51
CSCLUTReader::data_
std::vector< float > data_
Definition: CSCLUTReader.h:60
DDAxes::x
CSCLUTReader::MISS_ENTRIES
Definition: CSCLUTReader.h:20
CSCLUTReader::readHeader
int readHeader(std::istream &)
Definition: CSCLUTReader.cc:146
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
CSCLUTReader::data
float data(unsigned int address) const
Definition: CSCLUTReader.cc:24
edm::FileInPath
Definition: FileInPath.h:61
CSCLUTReader::MAX_ADDRESS_OUTOFRANGE
Definition: CSCLUTReader.h:21
CSCLUTReader::dataMask_
unsigned int dataMask_
Definition: CSCLUTReader.h:58
CSCLUTReader::m_initialized
bool m_initialized
Definition: CSCLUTReader.h:64
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
CSCLUTReader::DUP_ENTRIES
Definition: CSCLUTReader.h:19
b
double b
Definition: hdecay.h:118
CSCLUTReader::lookup
float lookup(int code) const
Definition: CSCLUTReader.cc:43
a
double a
Definition: hdecay.h:119
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
CSCLUTReader::nrBitsAddress_
unsigned int nrBitsAddress_
Definition: CSCLUTReader.h:55
recoMuon::in
Definition: RecoMuonEnumerators.h:6
CSCLUTReader::read
int read(std::istream &stream)
Definition: CSCLUTReader.cc:79
CSCLUTReader::SUCCESS
Definition: CSCLUTReader.h:17
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CSCLUTReader::m_outWidth
unsigned m_outWidth
Definition: CSCLUTReader.h:63
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
CSCLUTReader::NO_ENTRIES
Definition: CSCLUTReader.h:18
CSCLUTReader::fname_
std::string fname_
Definition: CSCLUTReader.h:52
CSCLUTReader::nrBitsData_
unsigned int nrBitsData_
Definition: CSCLUTReader.h:56
SiStripMonitorCluster_cfi.maxWidth
maxWidth
Definition: SiStripMonitorCluster_cfi.py:143
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
CSCLUTReader::m_codeInWidth
int m_codeInWidth
Definition: CSCLUTReader.h:62
CSCLUTReader::NO_HEADER
Definition: CSCLUTReader.h:22
mps_splice.line
line
Definition: mps_splice.py:76
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
CSCLUTReader::load
int load(const std::string &inFileName)
Definition: CSCLUTReader.cc:28
CSCLUTReader::empty
bool empty() const
Definition: CSCLUTReader.h:49