Skip to content

Commit b83d673

Browse files
ariedel-cerndavidrohr
authored andcommitted
Feat: add GPUErrorQA class
1 parent 0c3f2b5 commit b83d673

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

Detectors/TPC/qc/include/TPCQC/GPUErrorQA.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@
1818
#define AliceO2_TPC_QC_GPUERRORQA_H
1919

2020
#include <memory>
21-
#include <gsl/span>
21+
#include <string>
22+
#include <vector>
23+
#include <unordered_map>
2224

2325
// root includes
24-
#include "TH1.h"
2526

2627
// o2 includes
2728
// #include "DataFormatsTPC/Defs.h"
2829

29-
namespace o2
30-
{
31-
namespace tpc
32-
{
33-
namespace qc
30+
class TH1;
31+
namespace o2::tpc::qc
3432
{
3533

36-
/// @brief TPC QC task for errors from GPU reconstruction
34+
/// @brief TPC QC task for errors from GPU reconstruction
3735
///
3836
/// This class is used to retrieve and visualize GPU errors
3937
/// according to corresponding error code and location.
@@ -47,23 +45,25 @@ class GPUErrorQA
4745
GPUErrorQA() = default;
4846

4947
/// process gpu error reported by the reconstruction workflow
50-
void processErrors(gsl::span<const std::array<uint32_t, 4>> errors);
48+
void processErrors(std::vector<std::array<uint32_t, 4>> errors);
5149

5250
/// Initialize all histograms
5351
void initializeHistograms();
5452

5553
/// Reset all histograms
5654
void resetHistograms();
5755

56+
/// return histograms
57+
const std::unordered_map<std::string, std::unique_ptr<TH1>>& getMapHist() const { return mMapHist; };
58+
5859
/// Dump results to a file
5960
void dumpToFile(std::string filename);
6061

6162
private:
62-
std::unique_ptr<TH1F> mHist;
63-
ClassDefNV(GPUErrorQA, 1)
63+
std::unordered_map<std::string, std::unique_ptr<TH1>> mMapHist;
64+
65+
ClassDefNV(GPUErrorQA, 1);
6466
};
65-
} // namespace qc
66-
} // namespace tpc
67-
} // namespace o2
67+
} // namespace o2::tpc::qc
6868

6969
#endif // AliceO2_TPC_QC_GPUERRORQA_H

Detectors/TPC/qc/src/GPUErrorQA.cxx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@
1111

1212
#define _USE_MATH_DEFINES
1313

14-
#include <cmath>
15-
#include <memory>
16-
1714
// root includes
1815
#include "TFile.h"
19-
#include <TH1.h>
16+
#include "TH1I.h"
2017

2118
// o2 includes
2219
#include "TPCQC/GPUErrorQA.h"
23-
#include "GPUErrors.h"
20+
#include "GPUDefMacros.h"
2421

2522
ClassImp(o2::tpc::qc::GPUErrorQA);
2623

@@ -30,26 +27,49 @@ using namespace o2::tpc::qc;
3027
void GPUErrorQA::initializeHistograms()
3128
{
3229
TH1::AddDirectory(false);
33-
mHist = std::make_unique<TH1F>("ErrorCounter", "ErrorCounter", o2::gpu::GPUErrors::getMaxErrors(), 0, o2::gpu::GPUErrors::getMaxErrors());
30+
31+
// get gpu error names
32+
// copied from GPUErrors.h
33+
static std::unordered_map<uint32_t, const char*> errorNames = {
34+
#define GPUCA_ERROR_CODE(num, name, ...) {num, GPUCA_M_STR(name)},
35+
#include "GPUErrorCodes.h"
36+
#undef GPUCA_ERROR_CODE
37+
};
38+
39+
// 1D histogram counting all reported errors
40+
mMapHist["ErrorCounter"] = std::make_unique<TH1I>("ErrorCounter", "ErrorCounter", errorNames.size(), -0.5, errorNames.size() - 0.5);
41+
mMapHist["ErrorCounter"]->GetXaxis()->SetTitle("Error Codes");
42+
mMapHist["ErrorCounter"]->GetYaxis()->SetTitle("Entries");
43+
// for convienence, label each bin with the error name
44+
for (size_t bin = 1; bin < mMapHist["ErrorCounter"]->GetNbinsX(); bin++) {
45+
auto const& it = errorNames.find(bin);
46+
mMapHist["ErrorCounter"]->GetXaxis()->SetBinLabel(bin, it->second);
47+
}
3448
}
3549
//______________________________________________________________________________
3650
void GPUErrorQA::resetHistograms()
3751
{
38-
mHist->Reset();
52+
for (const auto& pair : mMapHist) {
53+
pair.second->Reset();
54+
}
3955
}
4056
//______________________________________________________________________________
41-
void GPUErrorQA::processErrors(gsl::span<const std::array<uint32_t, 4>> errors)
57+
void GPUErrorQA::processErrors(std::vector<std::array<uint32_t, 4>> errors)
4258
{
4359
for (const auto& error : errors) {
4460
uint32_t errorCode = error[0];
45-
mHist->Fill(static_cast<float>(errorCode));
61+
mMapHist["ErrorCounter"]->AddBinContent(errorCode);
4662
}
4763
}
4864

4965
//______________________________________________________________________________
5066
void GPUErrorQA::dumpToFile(const std::string filename)
5167
{
52-
auto f = std::unique_ptr<TFile>(TFile::Open(filename.c_str(), "recreate"));
53-
mHist->Write();
54-
f->Close();
68+
auto f = std::unique_ptr<TFile>(TFile::Open(filename.data(), "recreate"));
69+
TObjArray arr;
70+
arr.SetName("GPUErrorQA_Hists");
71+
for (const auto& [name, hist] : mMapHist) {
72+
arr.Add(hist.get());
73+
}
74+
arr.Write(arr.GetName(), TObject::kSingleKey);
5575
}

0 commit comments

Comments
 (0)