ATLAS Offline Software
FPGATrackSimVectors.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef FPGATrackSimVECTORS_H
6 #define FPGATrackSimVECTORS_H
7 
16 #include <vector>
17 #include <stdexcept>
18 
19 // #define DEBUG_FPGATrackSimVECTORS
20 
21 #ifdef DEBUG_FPGATrackSimVECTORS
22 #include <sstream>
23 #endif
24 
25 
26 template <typename T>
27 class vector2D
28 {
29  private:
30 
31  size_t m_d1,m_d2;
32  std::vector<T> m_data;
33 
34  public:
35 
37  m_d1(0), m_d2(0)
38  {}
39 
40  vector2D(size_t d1, size_t d2, T const & t=T()) :
41  m_d1(d1), m_d2(d2), m_data(d1*d2, t)
42  {}
43 
44  size_t size(int dim) const
45  {
46  if (dim == 0) return m_d1;
47  if (dim == 1) return m_d2;
48  else throw std::range_error("vector2D: Argument to size() must be 0 or 1");
49  }
50 
51  void resize(size_t x1, size_t x2, T const & t=T())
52  {
53  m_d1 = x1;
54  m_d2 = x2;
55  m_data.resize(x1*x2, t);
56  }
57 
58  T & operator()(size_t i, size_t j)
59  {
60 #ifdef DEBUG_FPGATrackSimVECTORS
61  if (i >= m_d1 || j >= m_d2)
62  {
63  std::stringstream s;
64  s << "vector2D out of bounds: request (" << i << "," << j << ") size (" << m_d1 << "," << m_d2 << ")";
65  throw std::range_error(s.str());
66  }
67 #endif
68  return m_data[i*m_d2 + j];
69  }
70 
71  T const & operator()(size_t i, size_t j) const
72  {
73 #ifdef DEBUG_FPGATrackSimVECTORS
74  if (i >= m_d1 || j >= m_d2)
75  {
76  std::stringstream s;
77  s << "vector2D out of bounds: request (" << i << "," << j << ") size (" << m_d1 << "," << m_d2 << ")";
78  throw std::range_error(s.str());
79  }
80 #endif
81  return m_data[i*m_d2 + j];
82  }
83 
84  T* operator[](size_t i)
85  {
86 #ifdef DEBUG_FPGATrackSimVECTORS
87  if (i >= m_d1)
88  {
89  std::stringstream s;
90  s << "vector2D out of bounds: request " << i << " size (" << m_d1 << "," << m_d2 << ")";
91  throw std::range_error(s.str());
92  }
93 #endif
94  return m_data.data() + (i * m_d2);
95  }
96 
97  const T* operator[](size_t i) const
98  {
99 #ifdef DEBUG_FPGATrackSimVECTORS
100  if (i >= m_d1)
101  {
102  std::stringstream s;
103  s << "vector2D out of bounds: request " << i << " size (" << m_d1 << "," << m_d2 << ")";
104  throw std::range_error(s.str());
105  }
106 #endif
107  return m_data.data() + (i * m_d2);
108  }
109 
110  T* data()
111  {
112  return m_data.data();
113  }
114 
115  const T* data() const
116  {
117  return m_data.data();
118  }
119 };
120 
121 
122 template <typename T>
123 class vector3D
124 {
125  private:
126 
127  size_t m_d1,m_d2,m_d3;
128  std::vector<T> m_data;
129 
130  public:
131 
133  m_d1(0), m_d2(0), m_d3(0)
134  {}
135 
136  vector3D(size_t d1, size_t d2, size_t d3, T const & t=T()) :
137  m_d1(d1), m_d2(d2), m_d3(d3), m_data(d1*d2*d3, t)
138  {}
139 
140  T & operator()(size_t i, size_t j, size_t k)
141  {
142 #ifdef DEBUG_FPGATrackSimVECTORS
143  if (i >= m_d1 || j >= m_d2 || k >= m_d3)
144  {
145  std::stringstream s;
146  s << "vector3D out of bounds: request (" << i << "," << j << "," << k << ") size (" << m_d1 << "," << m_d2 << "," << m_d3 << ")";
147  throw std::range_error(s.str());
148  }
149 #endif
150  return m_data[i*m_d2*m_d3 + j*m_d3 + k];
151  }
152 
153  T const & operator()(size_t i, size_t j, size_t k) const
154  {
155 #ifdef DEBUG_FPGATrackSimVECTORS
156  if (i >= m_d1 || j >= m_d2 || k >= m_d3)
157  {
158  std::stringstream s;
159  s << "vector3D out of bounds: request (" << i << "," << j << "," << k << ") size (" << m_d1 << "," << m_d2 << "," << m_d3 << ")";
160  throw std::range_error(s.str());
161  }
162 #endif
163  return m_data[i*m_d2*m_d3 + j*m_d3 + k];
164  }
165 
166  void resize(size_t x1, size_t x2, size_t x3, T const & t=T())
167  {
168  m_d1 = x1;
169  m_d2 = x2;
170  m_d3 = x3;
171  m_data.resize(x1*x2*x3, t);
172  }
173 
174  T* data()
175  {
176  return m_data.data();
177  }
178 };
179 
180 
181 #endif
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
vector3D::m_d2
size_t m_d2
Definition: FPGATrackSimVectors.h:127
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
vector2D::m_data
std::vector< T > m_data
Definition: FPGATrackSimVectors.h:32
vector3D::m_d1
size_t m_d1
Definition: FPGATrackSimVectors.h:127
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
vector2D::operator[]
T * operator[](size_t i)
Definition: FPGATrackSimVectors.h:84
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
vector3D::operator()
T const & operator()(size_t i, size_t j, size_t k) const
Definition: FPGATrackSimVectors.h:153
vector2D::vector2D
vector2D(size_t d1, size_t d2, T const &t=T())
Definition: FPGATrackSimVectors.h:40
vector3D::vector3D
vector3D()
Definition: FPGATrackSimVectors.h:132
vector2D
Definition: FPGATrackSimVectors.h:28
vector3D::resize
void resize(size_t x1, size_t x2, size_t x3, T const &t=T())
Definition: FPGATrackSimVectors.h:166
lumiFormat.i
int i
Definition: lumiFormat.py:85
vector3D::vector3D
vector3D(size_t d1, size_t d2, size_t d3, T const &t=T())
Definition: FPGATrackSimVectors.h:136
vector2D::vector2D
vector2D()
Definition: FPGATrackSimVectors.h:36
vector2D::m_d2
size_t m_d2
Definition: FPGATrackSimVectors.h:31
vector3D::data
T * data()
Definition: FPGATrackSimVectors.h:174
vector3D::operator()
T & operator()(size_t i, size_t j, size_t k)
Definition: FPGATrackSimVectors.h:140
vector2D::data
T * data()
Definition: FPGATrackSimVectors.h:110
vector2D::operator()
T const & operator()(size_t i, size_t j) const
Definition: FPGATrackSimVectors.h:71
vector3D::m_d3
size_t m_d3
Definition: FPGATrackSimVectors.h:127
vector2D::data
const T * data() const
Definition: FPGATrackSimVectors.h:115
vector2D::resize
void resize(size_t x1, size_t x2, T const &t=T())
Definition: FPGATrackSimVectors.h:51
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
vector3D::m_data
std::vector< T > m_data
Definition: FPGATrackSimVectors.h:128
vector3D
Definition: FPGATrackSimVectors.h:124
vector2D::operator()
T & operator()(size_t i, size_t j)
Definition: FPGATrackSimVectors.h:58
vector2D::m_d1
size_t m_d1
Definition: FPGATrackSimVectors.h:31
vector2D::operator[]
const T * operator[](size_t i) const
Definition: FPGATrackSimVectors.h:97
vector2D::size
size_t size(int dim) const
Definition: FPGATrackSimVectors.h:44
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
fitman.k
k
Definition: fitman.py:528