CMS 3D CMS Logo

Array2D.h
Go to the documentation of this file.
1 #ifndef L1Trigger_TrackFindingTMTT_Array2D_h
2 #define L1Trigger_TrackFindingTMTT_Array2D_h
3 
5 
6 #include <vector>
7 #include <utility>
8 
9 //=== Generic 2D array class.
10 
11 // (Replaced boost::numeric::ublas::matrix when boost library
12 // became too big).
13 
14 // Author: Lucas Camolezi
15 
16 namespace tmtt {
17 
18  template <typename T>
19  class Array2D {
20  public:
21  //for a mxn matrix - row major
22  Array2D(unsigned int m, unsigned int n) : array2D_(m * n), m_{m}, n_{n} {}
23 
24  const T& operator()(unsigned int i, unsigned int j) const {
25  if (i >= m_ || j >= n_)
26  throw cms::Exception("LogicError")
27  << "Array2D: indices out of range " << i << " " << j << " " << m_ << " " << n_;
28  return array2D_[i * n_ + j];
29  }
30 
31  T& operator()(unsigned int i, unsigned int j) {
32  // Non-const version of operator, without needing to duplicate code.
33  // (Scott Meyers trick).
34  return const_cast<T&>(std::as_const(*this)(i, j));
35  }
36 
37  private:
38  std::vector<T> array2D_;
39  unsigned int m_, n_;
40  };
41 } // namespace tmtt
42 
43 #endif
Array2D(unsigned int m, unsigned int n)
Definition: Array2D.h:22
T & operator()(unsigned int i, unsigned int j)
Definition: Array2D.h:31
unsigned int n_
Definition: Array2D.h:39
unsigned int m_
Definition: Array2D.h:39
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
std::vector< T > array2D_
Definition: Array2D.h:38
long double T
const T & operator()(unsigned int i, unsigned int j) const
Definition: Array2D.h:24