Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:21

0001 ///
0002 /// \class l1t::LUT
0003 ///
0004 /// Description: A class implimentating a look up table
0005 ///
0006 /// Implementation:
0007 ///    Internally stores data in vector filled with 32 bit ints
0008 ///    address and output is masked to specifed number of bits
0009 ///    vector only allocates as necessary, eg we may have a 32 bit address but we obviously dont want to allocate a 4gb vector
0010 ///
0011 /// Error handling: currently waiting guidance on how to deal with this
0012 /// Exceptions are currently forbiden, emulator fails should not impact on the rest of the software chain. As such, everything silently fails gracefully
0013 /// \author: Sam Harper - RAL, Jim Brooke - Bristol
0014 ///
0015 
0016 //
0017 
0018 #ifndef CondFormats_L1TObjects_LUT_h
0019 #define CondFormats_L1TObjects_LUT_h
0020 
0021 #include <iostream>
0022 #include <vector>
0023 #include <limits>
0024 
0025 #include "CondFormats/Serialization/interface/Serializable.h"
0026 
0027 namespace l1t {
0028 
0029   class LUT {
0030   public:
0031     enum ReadCodes {
0032       SUCCESS = 0,
0033       NO_ENTRIES = 1,
0034       DUP_ENTRIES = 2,
0035       MISS_ENTRIES = 3,
0036       MAX_ADDRESS_OUTOFRANGE = 4,
0037       NO_HEADER = 5
0038     };
0039 
0040     LUT() : nrBitsAddress_(0), nrBitsData_(0), addressMask_(0), dataMask_(0), data_() {}
0041 
0042     explicit LUT(std::istream& stream) : data_() { read(stream); }
0043 
0044     ~LUT() {}
0045 
0046     int data(unsigned int address) const {
0047       return (address & addressMask_) < data_.size() ? dataMask_ & data_[addressMask_ & address] : 0;
0048     }
0049     int read(std::istream& stream);
0050     void write(std::ostream& stream) const;
0051 
0052     unsigned int nrBitsAddress() const { return nrBitsAddress_; }
0053     unsigned int nrBitsData() const { return nrBitsData_; }
0054     //following the convention of vector::size()
0055     unsigned int maxSize() const {
0056       return addressMask_ == std::numeric_limits<unsigned int>::max() ? addressMask_ : addressMask_ + 1;
0057     }
0058     bool empty() const { return data_.empty(); }
0059 
0060   private:
0061     int readHeader_(std::istream&);
0062 
0063     unsigned int nrBitsAddress_;  //technically redundant with addressMask
0064     unsigned int nrBitsData_;     //technically redundant with dataMask
0065     unsigned int addressMask_;
0066     unsigned int dataMask_;
0067 
0068     std::vector<int> data_;
0069     COND_SERIALIZABLE;
0070   };
0071 
0072 }  // namespace l1t
0073 
0074 #endif