Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef L1Trigger_TrackFindingTMTT_Array2D_h
0002 #define L1Trigger_TrackFindingTMTT_Array2D_h
0003 
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 
0006 #include <vector>
0007 #include <utility>
0008 
0009 //=== Generic 2D array class.
0010 
0011 // (Replaced boost::numeric::ublas::matrix when boost library
0012 //  became too big).
0013 
0014 // Author: Lucas Camolezi
0015 
0016 namespace tmtt {
0017 
0018   template <typename T>
0019   class Array2D {
0020   public:
0021     //for a mxn matrix - row major
0022     Array2D(unsigned int m, unsigned int n) : array2D_(m * n), m_{m}, n_{n} {}
0023 
0024     const T& operator()(unsigned int i, unsigned int j) const {
0025       if (i >= m_ || j >= n_)
0026         throw cms::Exception("LogicError")
0027             << "Array2D: indices out of range " << i << " " << j << " " << m_ << " " << n_;
0028       return array2D_[i * n_ + j];
0029     }
0030 
0031     T& operator()(unsigned int i, unsigned int j) {
0032       // Non-const version of operator, without needing to duplicate code.
0033       // (Scott Meyers trick).
0034       return const_cast<T&>(std::as_const(*this)(i, j));
0035     }
0036 
0037   private:
0038     std::vector<T> array2D_;
0039     unsigned int m_, n_;
0040   };
0041 }  // namespace tmtt
0042 
0043 #endif