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
2526ClassImp (o2::tpc::qc::GPUErrorQA);
2627
@@ -30,26 +31,49 @@ using namespace o2::tpc::qc;
3031void 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// ______________________________________________________________________________
3654void GPUErrorQA::resetHistograms ()
3755{
38- mHist ->Reset ();
56+ for (const auto & pair : mMapHist ) {
57+ pair.second ->Reset ();
58+ }
3959}
4060// ______________________________________________________________________________
4161void 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// ______________________________________________________________________________
5070void 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