CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
l1t::LUT Class Reference

#include <LUT.h>

Inheritance diagram for l1t::LUT:
l1t::MicroGMTLUT l1t::MicroGMTAbsoluteIsolationCheckLUT l1t::MicroGMTCaloIndexSelectionLUT l1t::MicroGMTExtrapolationLUT l1t::MicroGMTMatchQualLUT l1t::MicroGMTRankPtQualLUT l1t::MicroGMTRelativeIsolationCheckLUT l1t::MicroGMTMatchQualFineLUT l1t::MicroGMTMatchQualSimpleLUT

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

int data (unsigned int address) const
 
bool empty () const
 
 LUT ()
 
 LUT (std::istream &stream)
 
unsigned int maxSize () const
 
unsigned int nrBitsAddress () const
 
unsigned int nrBitsData () const
 
int read (std::istream &stream)
 
void write (std::ostream &stream) const
 
 ~LUT ()
 

Private Member Functions

int readHeader_ (std::istream &)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Attributes

unsigned int addressMask_
 
std::vector< int > data_
 
unsigned int dataMask_
 
unsigned int nrBitsAddress_
 
unsigned int nrBitsData_
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

Detailed Description

Description: A class implimentating a look up table

Implementation: Internally stores data in vector filled with 32 bit ints address and output is masked to specifed number of bits vector only allocates as necessary, eg we may have a 32 bit address but we obviously dont want to allocate a 4gb vector

Error handling: currently waiting guidance on how to deal with this Exceptions are currently forbiden, emulator fails should not impact on the rest of the software chain. As such, everything silently fails gracefully

Author
: Sam Harper - RAL, Jim Brooke - Bristol

Definition at line 29 of file LUT.h.

Member Enumeration Documentation

◆ ReadCodes

enum l1t::LUT::ReadCodes
Enumerator
SUCCESS 
NO_ENTRIES 
DUP_ENTRIES 
MISS_ENTRIES 
MAX_ADDRESS_OUTOFRANGE 
NO_HEADER 

Definition at line 31 of file LUT.h.

31  {
32  SUCCESS = 0,
33  NO_ENTRIES = 1,
34  DUP_ENTRIES = 2,
35  MISS_ENTRIES = 3,
37  NO_HEADER = 5
38  };

Constructor & Destructor Documentation

◆ LUT() [1/2]

l1t::LUT::LUT ( )
inline

Definition at line 40 of file LUT.h.

◆ LUT() [2/2]

l1t::LUT::LUT ( std::istream &  stream)
inlineexplicit

Definition at line 42 of file LUT.h.

42 : data_() { read(stream); }

References read(), and cms::cuda::stream.

◆ ~LUT()

l1t::LUT::~LUT ( )
inline

Definition at line 44 of file LUT.h.

44 {}

Member Function Documentation

◆ data()

int l1t::LUT::data ( unsigned int  address) const
inline

◆ empty()

bool l1t::LUT::empty ( ) const
inline

Definition at line 58 of file LUT.h.

58 { return data_.empty(); }

References data_.

Referenced by L1TMuonGlobalParamsViewer::printLUT().

◆ maxSize()

unsigned int l1t::LUT::maxSize ( ) const
inline

◆ nrBitsAddress()

unsigned int l1t::LUT::nrBitsAddress ( ) const
inline

Definition at line 52 of file LUT.h.

52 { return nrBitsAddress_; }

References nrBitsAddress_.

Referenced by l1t::Stage2Layer2TauAlgorithmFirmwareImp1::loadCalibrationLuts().

◆ nrBitsData()

unsigned int l1t::LUT::nrBitsData ( ) const
inline

Definition at line 53 of file LUT.h.

53 { return nrBitsData_; }

References nrBitsData_.

Referenced by OMTFProcessor::configure(), and l1t::Stage2Layer2TauAlgorithmFirmwareImp1::loadCalibrationLuts().

◆ read()

int l1t::LUT::read ( std::istream &  stream)

Definition at line 11 of file LUT.cc.

11  {
12  data_.clear();
13 
14  int readHeaderCode = readHeader_(stream);
15  if (readHeaderCode != SUCCESS)
16  return readHeaderCode;
17 
18  std::vector<std::pair<unsigned int, int> > entries;
19  unsigned int maxAddress = addressMask_;
21 
22  while (std::getline(stream, line)) {
23  line.erase(std::find(line.begin(), line.end(), '#'), line.end()); //ignore comments
24  std::istringstream lineStream(line);
25  std::pair<unsigned int, int> entry;
26  while (lineStream >> entry.first >> entry.second) {
27  entry.first &= addressMask_;
28  entry.second &= dataMask_;
29  entries.push_back(entry);
30  if (entry.first > maxAddress || maxAddress == addressMask_)
31  maxAddress = entry.first;
32  }
33  }
34  std::sort(entries.begin(), entries.end());
35  if (entries.empty()) {
36  //log the error we read nothing
37  return NO_ENTRIES;
38  }
39  //this check is redundant as dups are also picked up by the next check but might make for easier debugging
40  if (std::adjacent_find(entries.begin(), entries.end(), [](auto const& a, auto const& b) {
41  return a.first == b.first;
42  }) != entries.end()) {
43  //log the error that we have duplicate addresses once masked
44  return DUP_ENTRIES;
45  }
46  if (entries.front().first != 0 ||
47  std::adjacent_find(entries.begin(), entries.end(), [](auto const& a, auto const& b) {
48  return a.first + 1 != b.first;
49  }) != entries.end()) {
50  //log the error that we have a missing entry
51  return MISS_ENTRIES;
52  }
53 
54  if (maxAddress != std::numeric_limits<unsigned int>::max())
55  data_.resize(maxAddress + 1, 0);
56  else {
57  //log the error that we have more addresses than we can deal with (which is 4gb so something probably has gone wrong anyways)
59  }
60 
61  std::transform(entries.begin(), entries.end(), data_.begin(), [](auto const& x) { return x.second; });
62  return SUCCESS;
63 }

References a, addressMask_, b, data_, dataMask_, 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, and HcalDetIdTransform::transform().

Referenced by l1t::convertToLUT(), edmIntegrityCheck.PublishToFileSystem::get(), LUT(), l1t::MicroGMTLUT::MicroGMTLUT(), and XMLConfigReader::readLUTs().

◆ readHeader_()

int l1t::LUT::readHeader_ ( std::istream &  stream)
private

Definition at line 72 of file LUT.cc.

72  {
73  int startPos = stream.tellg(); //we are going to reset to this position before we exit
75  while (std::getline(stream, line)) {
76  if (line.find("#<header>") == 0) { //line
77  std::istringstream lineStream(line);
78 
79  std::string version; //currently not doing anything with this
80  std::string headerField; //currently not doing anything with this
81  if (lineStream >> headerField >> version >> nrBitsAddress_ >> nrBitsData_) {
82  addressMask_ = nrBitsAddress_ != 32 ? (0x1 << nrBitsAddress_) - 1 : ~0x0;
83  dataMask_ = (0x1 << nrBitsData_) - 1;
84  stream.seekg(startPos);
85  return SUCCESS;
86  }
87  }
88  }
89 
90  nrBitsAddress_ = 0;
91  nrBitsData_ = 0;
92  addressMask_ = (0x1 << nrBitsAddress_) - 1;
93  dataMask_ = (0x1 << nrBitsData_) - 1;
94 
95  stream.seekg(startPos);
96  return NO_HEADER;
97 }

References mps_splice::line, cms::cuda::stream, AlCaHLTBitMon_QueryRunRegistry::string, and BeamSplash_cfg::version.

Referenced by read().

◆ serialize()

template<class Archive >
void l1t::LUT::serialize ( Archive &  ar,
const unsigned int  version 
)
private

◆ write()

void l1t::LUT::write ( std::ostream &  stream) const

Definition at line 65 of file LUT.cc.

65  {
66  stream << "#<header> V1 " << nrBitsAddress_ << " " << nrBitsData_ << " </header> " << std::endl;
67  for (unsigned int address = 0; address < data_.size(); address++) {
68  stream << (address & addressMask_) << " " << data(address) << std::endl;
69  }
70 }

References data, and cms::cuda::stream.

Referenced by pkg.AbstractPkg::generate(), and l1t::MicroGMTLUT::MicroGMTLUT().

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 69 of file LUT.h.

◆ cond::serialization::access

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 69 of file LUT.h.

Member Data Documentation

◆ addressMask_

unsigned int l1t::LUT::addressMask_
private

Definition at line 65 of file LUT.h.

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

◆ data_

std::vector<int> l1t::LUT::data_
private

Definition at line 68 of file LUT.h.

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

◆ dataMask_

unsigned int l1t::LUT::dataMask_
private

Definition at line 66 of file LUT.h.

Referenced by data(), and read().

◆ nrBitsAddress_

unsigned int l1t::LUT::nrBitsAddress_
private

Definition at line 63 of file LUT.h.

Referenced by nrBitsAddress().

◆ nrBitsData_

unsigned int l1t::LUT::nrBitsData_
private

Definition at line 64 of file LUT.h.

Referenced by nrBitsData().

l1t::LUT::data_
std::vector< int > data_
Definition: LUT.h:68
l1t::LUT::nrBitsData_
unsigned int nrBitsData_
Definition: LUT.h:64
mps_splice.entry
entry
Definition: mps_splice.py:68
cms::cuda::stream
cudaStream_t stream
Definition: HistoContainer.h:57
l1t::LUT::NO_HEADER
Definition: LUT.h:37
DDAxes::x
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
l1t::LUT::addressMask_
unsigned int addressMask_
Definition: LUT.h:65
l1t::LUT::read
int read(std::istream &stream)
Definition: LUT.cc:11
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
l1t::LUT::DUP_ENTRIES
Definition: LUT.h:34
a
double a
Definition: hdecay.h:119
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
l1t::LUT::nrBitsAddress_
unsigned int nrBitsAddress_
Definition: LUT.h:63
l1t::LUT::data
int data(unsigned int address) const
Definition: LUT.h:46
l1t::LUT::dataMask_
unsigned int dataMask_
Definition: LUT.h:66
l1t::LUT::MAX_ADDRESS_OUTOFRANGE
Definition: LUT.h:36
l1t::LUT::readHeader_
int readHeader_(std::istream &)
Definition: LUT.cc:72
l1t::LUT::SUCCESS
Definition: LUT.h:32
l1t::LUT::NO_ENTRIES
Definition: LUT.h:33
l1t::LUT::MISS_ENTRIES
Definition: LUT.h:35
mps_splice.line
line
Definition: mps_splice.py:76
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45