CMS 3D CMS Logo

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

#include <CSCComparatorCodeLUT.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
 
 CSCComparatorCodeLUT (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
 
 ~CSCComparatorCodeLUT ()
 

Private Member Functions

int readHeader (std::istream &)
 

Private Attributes

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

Detailed Description

Definition at line 14 of file CSCComparatorCodeLUT.h.

Member Enumeration Documentation

◆ ReadCodes

Enumerator
SUCCESS 
NO_ENTRIES 
DUP_ENTRIES 
MISS_ENTRIES 
MAX_ADDRESS_OUTOFRANGE 
NO_HEADER 

Definition at line 16 of file CSCComparatorCodeLUT.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

◆ CSCComparatorCodeLUT()

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

Definition at line 5 of file CSCComparatorCodeLUT.cc.

7  if (fname != std::string("")) {
8  load(fname);
9  } else {
10  initialize();
11  }
12 }

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

◆ ~CSCComparatorCodeLUT()

CSCComparatorCodeLUT::~CSCComparatorCodeLUT ( )
inline

Definition at line 28 of file CSCComparatorCodeLUT.h.

28 {}

Member Function Documentation

◆ checkedInput()

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

Definition at line 64 of file CSCComparatorCodeLUT.cc.

64  {
65  unsigned maxIn = (1 << maxWidth) - 1;
66  return (in < maxIn ? in : maxIn);
67 }

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

◆ data()

float CSCComparatorCodeLUT::data ( unsigned int  address) const

Definition at line 17 of file CSCComparatorCodeLUT.cc.

17  {
18  return (address & addressMask_) < data_.size() ? data_[address] : 0;
19 }

References addressMask_, and data_.

Referenced by lookupPacked(), and write().

◆ empty()

bool CSCComparatorCodeLUT::empty ( void  ) const
inline

Definition at line 50 of file CSCComparatorCodeLUT.h.

50 { return data_.empty(); }

References data_.

Referenced by initialize().

◆ initialize()

void CSCComparatorCodeLUT::initialize ( void  )

Definition at line 51 of file CSCComparatorCodeLUT.cc.

51  {
52  if (empty()) {
53  std::stringstream stream;
54  stream << "#<header> V1 " << m_codeInWidth << " " << m_outWidth << " </header> " << std::endl;
55  for (int in = 0; in < (1 << m_codeInWidth); ++in) {
56  int out = lookup(in);
57  stream << in << " " << out << std::endl;
58  }
59  read(stream);
60  }
61  m_initialized = true;
62 }

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

Referenced by CSCComparatorCodeLUT().

◆ load()

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

Definition at line 21 of file CSCComparatorCodeLUT.cc.

21  {
22  std::ifstream fstream;
23  fstream.open(edm::FileInPath(inFileName.c_str()).fullPath());
24  if (!fstream.good()) {
25  fstream.close();
26  throw cms::Exception("FileOpenError") << "Failed to open LUT file: " << inFileName;
27  }
28  int readCode = read(fstream);
29 
30  m_initialized = true;
31  fstream.close();
32 
33  return readCode;
34 }

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

Referenced by CSCComparatorCodeLUT().

◆ lookup()

float CSCComparatorCodeLUT::lookup ( int  code) const

Definition at line 36 of file CSCComparatorCodeLUT.cc.

36  {
37  if (m_initialized) {
38  return lookupPacked(code);
39  }
40  return 0;
41 }

References lookupPacked(), and m_initialized.

Referenced by initialize().

◆ lookupPacked()

float CSCComparatorCodeLUT::lookupPacked ( const int  input) const

Definition at line 43 of file CSCComparatorCodeLUT.cc.

43  {
44  if (m_initialized) {
45  return data((unsigned int)input);
46  }
47  throw cms::Exception("Uninitialized") << "If you're not loading a LUT from file you need to implement lookupPacked.";
48  return 0;
49 }

References data(), Exception, input, and m_initialized.

Referenced by lookup().

◆ maxSize()

unsigned int CSCComparatorCodeLUT::maxSize ( ) const

Definition at line 130 of file CSCComparatorCodeLUT.cc.

References addressMask_, and SiStripPI::max.

◆ nrBitsAddress()

unsigned int CSCComparatorCodeLUT::nrBitsAddress ( ) const
inline

Definition at line 46 of file CSCComparatorCodeLUT.h.

46 { return nrBitsAddress_; }

References nrBitsAddress_.

◆ nrBitsData()

unsigned int CSCComparatorCodeLUT::nrBitsData ( ) const
inline

Definition at line 47 of file CSCComparatorCodeLUT.h.

47 { return nrBitsData_; }

References nrBitsData_.

◆ read()

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

Definition at line 69 of file CSCComparatorCodeLUT.cc.

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

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

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

◆ readHeader()

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

Definition at line 134 of file CSCComparatorCodeLUT.cc.

134  {
135  int startPos = stream.tellg(); //we are going to reset to this position before we exit
137  while (std::getline(stream, line)) {
138  if (line.find("#<header>") == 0) { //line
139  std::istringstream lineStream(line);
140 
141  std::string version; //currently not doing anything with this
142  std::string headerField; //currently not doing anything with this
143  if (lineStream >> headerField >> version >> nrBitsAddress_ >> nrBitsData_) {
144  addressMask_ = nrBitsAddress_ != 32 ? (0x1 << nrBitsAddress_) - 1 : ~0x0;
145  dataMask_ = (0x1 << nrBitsData_) - 1;
146  stream.seekg(startPos);
147  return SUCCESS;
148  }
149  }
150  }
151 
152  nrBitsAddress_ = 0;
153  nrBitsData_ = 0;
154  addressMask_ = (0x1 << nrBitsAddress_) - 1;
155  dataMask_ = (0x1 << nrBitsData_) - 1;
156 
157  stream.seekg(startPos);
158  return NO_HEADER;
159 }

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 CSCComparatorCodeLUT::save ( std::ofstream &  output)

Definition at line 15 of file CSCComparatorCodeLUT.cc.

15 { write(output); }

References convertSQLitetoXML_cfg::output, and write().

◆ write()

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

Definition at line 123 of file CSCComparatorCodeLUT.cc.

123  {
124  stream << "#<header> V1 " << nrBitsAddress_ << " " << nrBitsData_ << " </header> " << std::endl;
125  for (unsigned int address = 0; address < data_.size(); address++) {
126  stream << (address & addressMask_) << " " << data(address) << std::endl;
127  }
128 }

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

Referenced by save().

Member Data Documentation

◆ addressMask_

unsigned int CSCComparatorCodeLUT::addressMask_
private

Definition at line 57 of file CSCComparatorCodeLUT.h.

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

◆ data_

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

Definition at line 60 of file CSCComparatorCodeLUT.h.

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

◆ dataMask_

unsigned int CSCComparatorCodeLUT::dataMask_
private

Definition at line 58 of file CSCComparatorCodeLUT.h.

Referenced by readHeader().

◆ m_codeInWidth

int CSCComparatorCodeLUT::m_codeInWidth
private

Definition at line 62 of file CSCComparatorCodeLUT.h.

Referenced by initialize().

◆ m_initialized

bool CSCComparatorCodeLUT::m_initialized
private

Definition at line 64 of file CSCComparatorCodeLUT.h.

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

◆ m_outWidth

unsigned CSCComparatorCodeLUT::m_outWidth
private

Definition at line 63 of file CSCComparatorCodeLUT.h.

Referenced by initialize().

◆ nrBitsAddress_

unsigned int CSCComparatorCodeLUT::nrBitsAddress_
private

Definition at line 55 of file CSCComparatorCodeLUT.h.

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

◆ nrBitsData_

unsigned int CSCComparatorCodeLUT::nrBitsData_
private

Definition at line 56 of file CSCComparatorCodeLUT.h.

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

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