Skip to content

Commit 7e9c43b

Browse files
committed
Feat: add GPUErrorQA class
1 parent ab5cad3 commit 7e9c43b

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define AliceO2_TPC_QC_GPUERRORQA_H
1919

2020
#include <memory>
21+
#include <unordered_map>
2122
#include <gsl/span>
2223

2324
// root includes
@@ -55,11 +56,14 @@ class GPUErrorQA
5556
/// Reset all histograms
5657
void resetHistograms();
5758

59+
/// return histograms
60+
std::unordered_map<std::string, std::unique_ptr<TH1>>& getMapHist() { return mMapHist; };
61+
5862
/// Dump results to a file
5963
void dumpToFile(std::string filename);
6064

6165
private:
62-
std::unique_ptr<TH1F> mHist;
66+
std::unordered_map<std::string, std::unique_ptr<TH1>> mMapHist;
6367
ClassDefNV(GPUErrorQA, 1)
6468
};
6569
} // namespace qc

Detectors/TPC/qc/src/GPUErrorQA.cxx

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
#include <cmath>
1515
#include <memory>
16+
#include <unordered_map>
1617

1718
// root includes
1819
#include "TFile.h"
1920
#include <TH1.h>
2021

2122
// o2 includes
2223
#include "TPCQC/GPUErrorQA.h"
23-
#include "GPUErrors.h"
24+
#include "GPUDefMacros.h"
2425

2526
ClassImp(o2::tpc::qc::GPUErrorQA);
2627

@@ -30,26 +31,49 @@ using namespace o2::tpc::qc;
3031
void GPUErrorQA::initializeHistograms()
3132
{
3233
TH1::AddDirectory(false);
33-
mHist = std::make_unique<TH1F>("ErrorCounter", "ErrorCounter", o2::gpu::GPUErrors::getMaxErrors(), 0, o2::gpu::GPUErrors::getMaxErrors());
34+
35+
// get gpu error names
36+
// copied from GPUErrors.h
37+
static std::unordered_map<uint32_t, const char*> errorNames = {
38+
#define GPUCA_ERROR_CODE(num, name, ...) {num, GPUCA_M_STR(name)},
39+
#include "GPUErrorCodes.h"
40+
#undef GPUCA_ERROR_CODE
41+
};
42+
43+
// 1D histogram counting all reported errors
44+
mMapHist["ErrorCounter"] = std::make_unique<TH1F>("ErrorCounter", "ErrorCounter", errorNames.size(), 0, errorNames.size());
45+
mMapHist["ErrorCounter"]->GetXaxis()->SetTitle("Error Codes");
46+
mMapHist["ErrorCounter"]->GetYaxis()->SetTitle("Entries");
47+
// for convienence, label each bin with the error name
48+
for (size_t bin = 1; bin < mMapHist["ErrorCounter"]->GetNbinsX(); bin++) {
49+
auto const& it = errorNames.find(bin);
50+
mMapHist["ErrorCounter"]->GetXaxis()->SetBinLabel(bin, it->second);
51+
}
3452
}
3553
//______________________________________________________________________________
3654
void GPUErrorQA::resetHistograms()
3755
{
38-
mHist->Reset();
56+
for (const auto& pair : mMapHist) {
57+
pair.second->Reset();
58+
}
3959
}
4060
//______________________________________________________________________________
4161
void GPUErrorQA::processErrors(gsl::span<const std::array<uint32_t, 4>> errors)
4262
{
4363
for (const auto& error : errors) {
4464
uint32_t errorCode = error[0];
45-
mHist->Fill(static_cast<float>(errorCode));
65+
mMapHist["ErrorCounter"]->Fill(static_cast<float>(errorCode));
4666
}
4767
}
4868

4969
//______________________________________________________________________________
5070
void GPUErrorQA::dumpToFile(const std::string filename)
5171
{
52-
auto f = std::unique_ptr<TFile>(TFile::Open(filename.c_str(), "recreate"));
53-
mHist->Write();
54-
f->Close();
72+
auto f = std::unique_ptr<TFile>(TFile::Open(filename.data(), "recreate"));
73+
for (const auto& [name, hist] : mMapHist) {
74+
TObjArray arr;
75+
arr.SetName(name.data());
76+
arr.Add(hist.get());
77+
arr.Write(arr.GetName(), TObject::kSingleKey);
78+
}
5579
}

0 commit comments

Comments
 (0)