Skip to content

Commit b7df4cd

Browse files
MichaelLettrichshahor02
authored andcommitted
[TrackPar] use std::array instead of C arrays
* Use std::array instead of C arrays * Change interfaces of member functions to std::array refs from ptrs * Fallback to member functions using pointers to ensure compatibility with alignment framework for now, will be deprecated in the future.
1 parent cd9835a commit b7df4cd

File tree

4 files changed

+83
-19
lines changed

4 files changed

+83
-19
lines changed

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrization.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class TrackParametrization
139139
GPUdDefault() ~TrackParametrization() = default;
140140

141141
GPUd() void set(value_t x, value_t alpha, const params_t& par, int charge = 1, const PID pid = PID::Pion);
142+
GPUd() void set(value_t x, value_t alpha, const value_t* par, int charge = 1, const PID pid = PID::Pion);
142143
GPUd() const value_t* getParams() const;
143144
GPUd() value_t getParam(int i) const;
144145
GPUd() value_t getX() const;
@@ -219,9 +220,9 @@ class TrackParametrization
219220
std::string asString() const;
220221
#endif
221222

222-
protected:
223223
GPUd() void updateParam(value_t delta, int i);
224-
GPUd() void updateParams(const value_t delta[kNParams]);
224+
GPUd() void updateParams(const params_t& delta);
225+
GPUd() void updateParams(const value_t* delta);
225226

226227
private:
227228
//
@@ -250,6 +251,13 @@ GPUdi() TrackParametrization<value_T>::TrackParametrization(value_t x, value_t a
250251
//____________________________________________________________
251252
template <typename value_T>
252253
GPUdi() void TrackParametrization<value_T>::set(value_t x, value_t alpha, const params_t& par, int charge, const PID pid)
254+
{
255+
set(x, alpha, par.data(), charge, pid);
256+
}
257+
258+
//____________________________________________________________
259+
template <typename value_T>
260+
GPUdi() void TrackParametrization<value_T>::set(value_t x, value_t alpha, const value_t* par, int charge, const PID pid)
253261
{
254262
mX = x;
255263
mAlpha = alpha;
@@ -666,7 +674,14 @@ GPUdi() void TrackParametrization<value_T>::updateParam(value_t delta, int i)
666674

667675
//____________________________________________________________
668676
template <typename value_T>
669-
GPUdi() void TrackParametrization<value_T>::updateParams(const value_t delta[kNParams])
677+
GPUdi() void TrackParametrization<value_T>::updateParams(const params_t& delta)
678+
{
679+
updateParams(delta.data());
680+
}
681+
682+
//____________________________________________________________
683+
template <typename value_T>
684+
GPUdi() void TrackParametrization<value_T>::updateParams(const value_t* delta)
670685
{
671686
for (int i = kNParams; i--;) {
672687
mP[i] += delta[i];

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ template <typename value_T = float>
2727
class TrackParametrizationWithError : public TrackParametrization<value_T>
2828
{ // track+error parameterization
2929
public:
30-
3130
using typename TrackParametrization<value_T>::value_t;
3231
using typename TrackParametrization<value_T>::dim3_t;
3332
using typename TrackParametrization<value_T>::dim2_t;
@@ -53,9 +52,11 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
5352
GPUdDefault() ~TrackParametrizationWithError() = default;
5453
using TrackParametrization<value_T>::TrackParametrization;
5554

55+
using TrackParametrization<value_T>::set;
5656
GPUd() void set(value_t x, value_t alpha, const params_t& par, const covMat_t& cov, int charge = 1, const PID pid = PID::Pion);
57+
GPUd() void set(value_t x, value_t alpha, const value_t* par, const value_t* cov, int charge = 1, const PID pid = PID::Pion);
5758
GPUd() void set(const dim3_t& xyz, const dim3_t& pxpypz, const gpu::gpustd::array<value_t, kLabCovMatSize>& cv, int sign, bool sectorAlpha = true, const PID pid = PID::Pion);
58-
GPUd() const value_t* getCov() const;
59+
GPUd() const covMat_t& getCov() const;
5960
GPUd() value_t getSigmaY2() const;
6061
GPUd() value_t getSigmaZY() const;
6162
GPUd() value_t getSigmaZ2() const;
@@ -89,6 +90,7 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
8990
GPUd() void invert();
9091

9192
GPUd() value_t getPredictedChi2(const dim2_t& p, const dim3_t& cov) const;
93+
GPUd() value_t getPredictedChi2(const value_t* p, const value_t* cov) const;
9294

9395
template <typename T>
9496
GPUd() value_t getPredictedChi2(const BaseCluster<T>& p) const;
@@ -100,6 +102,7 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
100102
bool update(const TrackParametrizationWithError& rhs);
101103

102104
GPUd() bool update(const dim2_t& p, const dim3_t& cov);
105+
GPUd() bool update(const value_t* p, const value_t* cov);
103106

104107
template <typename T>
105108
GPUd() bool update(const BaseCluster<T>& p);
@@ -108,13 +111,16 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
108111

109112
GPUd() void resetCovariance(value_t s2 = 0);
110113
GPUd() void checkCovariance();
114+
GPUd() void setCov(value_t v, size_t i, size_t j);
111115
GPUd() void setCov(value_t v, int i);
116+
GPUd() void setCov(const covMat_t& mat);
112117

113-
GPUd() void updateCov(const value_t delta[kCovMatSize]);
114-
GPUd() void updateCov(value_t delta, int i);
118+
GPUd() void updateCov(const covMat_t& delta);
119+
GPUd() void updateCov(value_t delta, size_t i, size_t j);
120+
GPUd() void updateCov(value_t delta, size_t i);
115121

116122
protected:
117-
value_t mC[kCovMatSize] = {0.f}; // 15 covariance matrix elements
123+
covMat_t mC{0.f}; // 15 covariance matrix elements
118124

119125
ClassDefNV(TrackParametrizationWithError, 2);
120126
};
@@ -140,6 +146,13 @@ GPUdi() TrackParametrizationWithError<value_T>::TrackParametrizationWithError(va
140146
//__________________________________________________________________________
141147
template <typename value_T>
142148
GPUdi() void TrackParametrizationWithError<value_T>::set(value_t x, value_t alpha, const params_t& par, const covMat_t& cov, int charge, const PID pid)
149+
{
150+
set(x, alpha, par.data(), cov.data(), charge, pid);
151+
}
152+
153+
//__________________________________________________________________________
154+
template <typename value_T>
155+
GPUdi() void TrackParametrizationWithError<value_T>::set(value_t x, value_t alpha, const value_t* par, const value_t* cov, int charge, const PID pid)
143156
{
144157
TrackParametrization<value_T>::set(x, alpha, par, charge, pid);
145158
for (int i = 0; i < kCovMatSize; i++) {
@@ -149,7 +162,7 @@ GPUdi() void TrackParametrizationWithError<value_T>::set(value_t x, value_t alph
149162

150163
//__________________________________________________________________________
151164
template <typename value_T>
152-
GPUdi() auto TrackParametrizationWithError<value_T>::getCov() const -> const value_t*
165+
GPUdi() auto TrackParametrizationWithError<value_T>::getCov() const -> const covMat_t&
153166
{
154167
return mC;
155168
}
@@ -283,6 +296,20 @@ GPUdi() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const Base
283296
return getPredictedChi2(pyz, cov);
284297
}
285298

299+
//______________________________________________
300+
template <typename value_T>
301+
GPUdi() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const dim2_t& p, const dim3_t& cov) const -> value_t
302+
{
303+
return getPredictedChi2(p.data(), cov.data());
304+
}
305+
306+
//______________________________________________
307+
template <typename value_T>
308+
GPUdi() bool TrackParametrizationWithError<value_T>::update(const dim2_t& p, const dim3_t& cov)
309+
{
310+
return update(p.data(), cov.data());
311+
}
312+
286313
//__________________________________________________________________________
287314
template <typename value_T>
288315
template <typename T>
@@ -302,16 +329,36 @@ GPUdi() void TrackParametrizationWithError<value_T>::setCov(value_t v, int i)
302329

303330
//__________________________________________________________________________
304331
template <typename value_T>
305-
GPUdi() void TrackParametrizationWithError<value_T>::updateCov(value_t delta, int i)
332+
GPUdi() void TrackParametrizationWithError<value_T>::setCov(value_t v, size_t i, size_t j)
333+
{
334+
mC[CovarMap[i][j]] = v;
335+
}
336+
337+
template <typename value_T>
338+
GPUdi() void TrackParametrizationWithError<value_T>::setCov(const covMat_t& cov)
339+
{
340+
mC = cov;
341+
}
342+
343+
//__________________________________________________________________________
344+
template <typename value_T>
345+
GPUdi() void TrackParametrizationWithError<value_T>::updateCov(value_t delta, size_t i, size_t j)
346+
{
347+
mC[CovarMap[i][j]] += delta;
348+
}
349+
350+
//__________________________________________________________________________
351+
template <typename value_T>
352+
GPUdi() void TrackParametrizationWithError<value_T>::updateCov(value_t delta, size_t i)
306353
{
307354
mC[i] += delta;
308355
}
309356

310357
//__________________________________________________________________________
311358
template <typename value_T>
312-
GPUdi() void TrackParametrizationWithError<value_T>::updateCov(const value_t delta[kCovMatSize])
359+
GPUdi() void TrackParametrizationWithError<value_T>::updateCov(const covMat_t& delta)
313360
{
314-
for (int i = kCovMatSize; i--;) {
361+
for (size_t i = 0; i < kCovMatSize; ++i) {
315362
mC[i] += delta[i];
316363
}
317364
}

DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ GPUd() bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, valu
8484
}
8585
this->setX(xk);
8686
double dy2dx = (f1 + f2) / (r1 + r2);
87-
value_t dP[kNParams] = {0.f};
87+
params_t dP{0.f};
8888
dP[kY] = dx * dy2dx;
8989
dP[kSnp] = x2r;
9090
if (gpu::CAMath::Abs(x2r) < 0.05f) {
@@ -691,7 +691,7 @@ GPUd() void TrackParametrizationWithError<value_T>::resetCovariance(value_t s2)
691691

692692
//______________________________________________
693693
template <typename value_T>
694-
GPUd() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const dim2_t& p, const dim3_t& cov) const -> value_t
694+
GPUd() auto TrackParametrizationWithError<value_T>::getPredictedChi2(const value_t* p, const value_t* cov) const -> value_t
695695
{
696696
// Estimate the chi2 of the space point "p" with the cov. matrix "cov"
697697
auto sdd = static_cast<double>(getSigmaY2()) + static_cast<double>(cov[0]);
@@ -860,7 +860,7 @@ bool TrackParametrizationWithError<value_T>::update(const TrackParametrizationWi
860860

861861
//______________________________________________
862862
template <typename value_T>
863-
GPUd() bool TrackParametrizationWithError<value_T>::update(const dim2_t& p, const dim3_t& cov)
863+
GPUd() bool TrackParametrizationWithError<value_T>::update(const value_t* p, const value_t* cov)
864864
{
865865
// Update the track parameters with the space point "p" having
866866
// the covariance matrix "cov"
@@ -897,8 +897,8 @@ GPUd() bool TrackParametrizationWithError<value_T>::update(const dim2_t& p, cons
897897
return false;
898898
}
899899

900-
value_t dP[kNParams] = {value_t(k00 * dy + k01 * dz), value_t(k10 * dy + k11 * dz), dsnp, value_t(k30 * dy + k31 * dz),
901-
value_t(k40 * dy + k41 * dz)};
900+
const params_t dP{value_t(k00 * dy + k01 * dz), value_t(k10 * dy + k11 * dz), dsnp, value_t(k30 * dy + k31 * dz),
901+
value_t(k40 * dy + k41 * dz)};
902902
this->updateParams(dP);
903903

904904
double c01 = cm10, c02 = cm20, c03 = cm30, c04 = cm40;

GPU/Common/GPUCommonArray.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ namespace o2::gpu::gpustd
2424
#ifdef GPUCA_GPUCODE_DEVICE
2525
template <typename T, size_t N>
2626
struct array {
27-
GPUd() T& operator[](size_t i) { return m_internal_V__[i]; }
28-
GPUd() const T& operator[](size_t i) const { return m_internal_V__[i]; }
27+
GPUd() T& operator[](size_t i) { return m_internal_V__[i]; };
28+
GPUd() const T& operator[](size_t i) const { return m_internal_V__[i]; };
29+
GPUd() T* data() { return m_internal_V__; };
30+
GPUd() const T* data() const { return m_internal_V__; };
2931
T m_internal_V__[N];
3032
};
3133
template <class T, class... E>

0 commit comments

Comments
 (0)