Project
Loading...
Searching...
No Matches
GPUQAHelper.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef GPUQAHELPER_H
16#define GPUQAHELPER_H
17
18#include <utility>
19#include <vector>
20#include <type_traits>
21
22#ifdef GPUCA_STANDALONE
24#endif
25
28
29namespace o2
30{
31class MCCompLabel;
32namespace gpu
33{
34namespace internal
35{
36
37template <bool WEIGHT, class T, class S, class U = T>
39{
40 public:
41 GPUTPCTrkLbl(const S* v, float maxFake = 0.1f) : mClusterLabels(v), mTrackMCMaxFake(maxFake) { mLabels.reserve(5); };
42 GPUTPCTrkLbl(const GPUTPCTrkLbl&) = default;
43 inline void reset()
44 {
45 mLabels.clear();
46 mNCl = 0;
47 mTotalWeight = 0.f;
48 }
49 inline void addLabel(uint32_t elementId)
50 {
51 if constexpr (std::is_same<T, AliHLTTPCClusterMCWeight>::value) {
52 for (uint32_t i = 0; i < sizeof(mClusterLabels[elementId]) / sizeof(mClusterLabels[elementId].fClusterID[0]); i++) {
53 const auto& element = mClusterLabels[elementId].fClusterID[i];
54 if (element.fMCID >= 0) {
55 if constexpr (WEIGHT) {
56 mTotalWeight += element.fWeight;
57 }
58 bool found = false;
59 for (uint32_t l = 0; l < mLabels.size(); l++) {
60 if (mLabels[l].first.fMCID == element.fMCID) {
61 mLabels[l].second++;
62 if constexpr (WEIGHT) {
63 mLabels[l].first.fWeight += element.fWeight;
64 }
65 found = true;
66 break;
67 }
68 }
69 if (!found) {
70 mLabels.emplace_back(element, 1);
71 }
72 }
73 }
74 } else {
75 for (const auto& element : mClusterLabels->getLabels(elementId)) {
76 bool found = false;
77 for (uint32_t l = 0; l < mLabels.size(); l++) {
78 if (mLabels[l].first == element) {
79 mLabels[l].second++;
80 found = true;
81 break;
82 }
83 }
84 if (!found) {
85 mLabels.emplace_back(element, 1);
86 }
87 }
88 }
89 mNCl++;
90 }
91 inline U computeLabel(float* labelWeight = nullptr, float* totalWeight = nullptr, int32_t* maxCount = nullptr)
92 {
93 if (mLabels.size() == 0) {
94 return U(); //default constructor creates NotSet label
95 } else {
96 uint32_t bestLabelNum = 0, bestLabelCount = 0;
97 for (uint32_t j = 0; j < mLabels.size(); j++) {
98 if (mLabels[j].second > bestLabelCount) {
99 bestLabelNum = j;
100 bestLabelCount = mLabels[j].second;
101 }
102 }
103 auto& bestLabel = mLabels[bestLabelNum].first;
104 if constexpr (std::is_same<T, AliHLTTPCClusterMCWeight>::value && WEIGHT) {
105 *labelWeight = bestLabel.fWeight;
106 *totalWeight = mTotalWeight;
107 *maxCount = bestLabelCount;
108 } else {
109 (void)labelWeight;
110 (void)totalWeight;
111 (void)maxCount;
112 }
113 U retVal = bestLabel;
114 if (bestLabelCount < (1.f - mTrackMCMaxFake) * mNCl) {
115 retVal.setFakeFlag();
116 }
117 return retVal;
118 }
119 }
120
121 private:
122 const S* mClusterLabels;
123 std::vector<std::pair<T, uint32_t>> mLabels;
124 const float mTrackMCMaxFake;
125 uint32_t mNCl = 0;
126 float mTotalWeight = 0.f;
127};
128} // namespace internal
129
131 int64_t id = -1;
132 GPUTPCTrkLbl_ret() = default;
133 template <class T>
135#ifdef GPUCA_TPC_GEOMETRY_O2
136 GPUTPCTrkLbl_ret(const MCCompLabel& a) : id(a.getTrackEventSourceID()){};
137#endif
138#ifdef GPUCA_STANDALONE
140#endif
142 {
143 id = -1;
144 }
145};
146
147template <bool WEIGHT = false, class U = void, class T, template <class> class S, typename... Args>
148static inline auto GPUTPCTrkLbl(const S<T>* x, Args... args)
149{
150 if constexpr (std::is_same<U, void>::value) {
151 return internal::GPUTPCTrkLbl<WEIGHT, T, S<T>>(x, args...);
152 } else {
153 return internal::GPUTPCTrkLbl<WEIGHT, T, S<T>, U>(x, args...);
154 }
155}
156
157template <bool WEIGHT = false, class U = void, typename... Args>
158static inline auto GPUTPCTrkLbl(const AliHLTTPCClusterMCLabel* x, Args... args)
159{
162 if constexpr (std::is_same<U, void>::value) {
163 return internal::GPUTPCTrkLbl<WEIGHT, T, S>(x, args...);
164 } else {
165 return internal::GPUTPCTrkLbl<WEIGHT, T, S, U>(x, args...);
166 }
167}
168
169} // namespace gpu
170} // namespace o2
171
172#endif
int32_t i
int32_t retVal
uint32_t j
Definition RawData.h:0
GPUTPCTrkLbl(const GPUTPCTrkLbl &)=default
void addLabel(uint32_t elementId)
Definition GPUQAHelper.h:49
GPUTPCTrkLbl(const S *v, float maxFake=0.1f)
Definition GPUQAHelper.h:41
U computeLabel(float *labelWeight=nullptr, float *totalWeight=nullptr, int32_t *maxCount=nullptr)
Definition GPUQAHelper.h:91
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...