CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
l1t::LUT Class Reference

#include <LUT.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

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 &)
 

Private Attributes

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

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 27 of file LUT.h.

Member Enumeration Documentation

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

Definition at line 29 of file LUT.h.

Constructor & Destructor Documentation

l1t::LUT::LUT ( )
inline

Definition at line 33 of file LUT.h.

33 :data_(){}
std::vector< int > data_
Definition: LUT.h:63
l1t::LUT::LUT ( std::istream &  stream)
inlineexplicit

Definition at line 35 of file LUT.h.

References read().

35  :
36  data_()
37  {
38  read(stream);
39  }
std::vector< int > data_
Definition: LUT.h:63
int read(std::istream &stream)
Definition: LUT.cc:35
l1t::LUT::~LUT ( )
inline

Definition at line 42 of file LUT.h.

42 {}

Member Function Documentation

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

Definition at line 44 of file LUT.h.

References addressMask_, data_, and dataMask_.

Referenced by cuy.FindIssue::__init__().

44 {return (address&addressMask_)<data_.size() ? dataMask_ & data_[addressMask_&address] : 0;}
std::vector< int > data_
Definition: LUT.h:63
unsigned int addressMask_
Definition: LUT.h:60
unsigned int dataMask_
Definition: LUT.h:61
bool l1t::LUT::empty ( ) const
inline

Definition at line 52 of file LUT.h.

References data_.

Referenced by Vispa.Gui.VispaWidget.TextField::setAutosizeFont(), and Vispa.Gui.VispaWidget.TextField::setAutotruncate().

52 {return data_.empty();}
std::vector< int > data_
Definition: LUT.h:63
unsigned int l1t::LUT::maxSize ( ) const
inline

Definition at line 51 of file LUT.h.

References addressMask_, and max().

const T & max(const T &a, const T &b)
unsigned int addressMask_
Definition: LUT.h:60
unsigned int l1t::LUT::nrBitsAddress ( ) const
inline

Definition at line 48 of file LUT.h.

References nrBitsAddress_.

48 {return nrBitsAddress_;}
unsigned int nrBitsAddress_
Definition: LUT.h:58
unsigned int l1t::LUT::nrBitsData ( ) const
inline

Definition at line 49 of file LUT.h.

References nrBitsData_.

49 {return nrBitsData_;}
unsigned int nrBitsData_
Definition: LUT.h:59
int l1t::LUT::read ( std::istream &  stream)

Definition at line 35 of file LUT.cc.

References addressMask_, data_, dataMask_, DUP_ENTRIES, python.tagInventory::entries, spr::find(), geometryCSVtoXML::line, max(), MAX_ADDRESS_OUTOFRANGE, MISS_ENTRIES, NO_ENTRIES, readHeader_(), python.multivaluedict::sort(), AlCaHLTBitMon_QueryRunRegistry::string, SUCCESS, and create_public_lumi_plots::transform.

Referenced by Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::goto(), LUT(), and Vispa.Plugins.EdmBrowser.EdmDataAccessor.EdmDataAccessor::setFilterBranches().

36 {
37  data_.clear();
38 
39  int readHeaderCode = readHeader_(stream);
40  if(readHeaderCode!=SUCCESS) return readHeaderCode;
41 
42  std::vector<std::pair<unsigned int,int> > entries;
43  unsigned int maxAddress=addressMask_;
45 
46  while(std::getline(stream,line)){
47  line.erase( std::find( line.begin(), line.end(), '#' ), line.end() ); //ignore comments
48  std::istringstream lineStream(line);
49  std::pair<unsigned int,int> entry;
50  while(lineStream >> entry.first >> entry.second ){
51  entry.first&=addressMask_;
52  entry.second&=dataMask_;
53  entries.push_back(entry);
54  if(entry.first>maxAddress || maxAddress==addressMask_) maxAddress=entry.first;
55  }
56  }
57  std::sort(entries.begin(),entries.end(),PairSortBy1st<unsigned int,int>());
58  if(entries.empty()){
59  //log the error we read nothing
60  return NO_ENTRIES;
61  }
62  //this check is redundant as dups are also picked up by the next check but might make for easier debugging
63  if(std::adjacent_find(entries.begin(),entries.end(),PairSortBy1st<unsigned int,int,std::equal_to<unsigned int> >())!=entries.end()){
64  //log the error that we have duplicate addresses once masked
65  return DUP_ENTRIES;
66  }
67  if(entries.front().first!=0 ||
68  std::adjacent_find(entries.begin(),entries.end(),
69  PairSortBy1st<unsigned int,int,std::binary_negate<Adjacent<unsigned int> > >(std::binary_negate<Adjacent<unsigned int> >(Adjacent<unsigned int>())))!=entries.end()){ //not a great way, must be a better one...
70  //log the error that we have a missing entry
71  return MISS_ENTRIES;
72  }
73 
74 
75  if(maxAddress!=std::numeric_limits<unsigned int>::max()) data_.resize(maxAddress+1,0);
76  else{
77  //log the error that we have more addresses than we can deal with (which is 4gb so something probably has gone wrong anyways)
79  }
80 
81  std::transform(entries.begin(),entries.end(),data_.begin(),Pair2nd<unsigned int,int>());
82  return SUCCESS;
83 
84 }
std::vector< int > data_
Definition: LUT.h:63
Definition: LUT.cc:27
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const T & max(const T &a, const T &b)
unsigned int addressMask_
Definition: LUT.h:60
int readHeader_(std::istream &)
Definition: LUT.cc:94
Definition: LUT.cc:18
unsigned int dataMask_
Definition: LUT.h:61
int l1t::LUT::readHeader_ ( std::istream &  stream)
private

Definition at line 94 of file LUT.cc.

References geometryCSVtoXML::line, AlCaHLTBitMon_QueryRunRegistry::string, definitions::SUCCESS, and BeamSplash_cfg::version.

Referenced by read().

95 {
96 
97  int startPos=stream.tellg(); //we are going to reset to this position before we exit
99  while(std::getline(stream,line)){
100  if(line.find("#<header>")==0){ //line
101  std::istringstream lineStream(line);
102 
103  std::string version; //currently not doing anything with this
104  std::string headerField; //currently not doing anything with this
105  if(lineStream >> headerField >> version >> nrBitsAddress_ >> nrBitsData_){
106  addressMask_ = nrBitsAddress_!=32 ? (0x1<<nrBitsAddress_)-1 : ~0x0;
107  dataMask_ = (0x1<<nrBitsData_)-1;
108  stream.seekg(startPos);
109  return SUCCESS;
110  }
111  }
112  }
113 
114  nrBitsAddress_ =0;
115  nrBitsData_ = 0;
116  addressMask_ = (0x1<<nrBitsAddress_)-1;
117  dataMask_ = (0x1<<nrBitsData_)-1;
118 
119  stream.seekg(startPos);
120  return NO_HEADER;
121 }
unsigned int nrBitsData_
Definition: LUT.h:59
unsigned int addressMask_
Definition: LUT.h:60
unsigned int nrBitsAddress_
Definition: LUT.h:58
unsigned int dataMask_
Definition: LUT.h:61
void l1t::LUT::write ( std::ostream &  stream) const

Definition at line 86 of file LUT.cc.

References data.

Referenced by pkg.AbstractPkg::generate().

87 {
88  stream <<"#<header> V1 "<<nrBitsAddress_<<" "<<nrBitsData_<<" </header> "<<std::endl;
89  for(unsigned int address=0;address<data_.size();address++){
90  stream << (address&addressMask_)<<" "<<data(address)<<std::endl;
91  }
92 }
std::vector< int > data_
Definition: LUT.h:63
unsigned int nrBitsData_
Definition: LUT.h:59
unsigned int addressMask_
Definition: LUT.h:60
int data(unsigned int address) const
Definition: LUT.h:44
unsigned int nrBitsAddress_
Definition: LUT.h:58

Member Data Documentation

unsigned int l1t::LUT::addressMask_
private

Definition at line 60 of file LUT.h.

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

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

Definition at line 63 of file LUT.h.

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

unsigned int l1t::LUT::dataMask_
private

Definition at line 61 of file LUT.h.

Referenced by data(), and read().

unsigned int l1t::LUT::nrBitsAddress_
private

Definition at line 58 of file LUT.h.

Referenced by nrBitsAddress().

unsigned int l1t::LUT::nrBitsData_
private

Definition at line 59 of file LUT.h.

Referenced by nrBitsData().