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
2522ClassImp (o2::tpc::qc::GPUErrorQA);
2623
@@ -30,26 +27,49 @@ using namespace o2::tpc::qc;
3027void 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// ______________________________________________________________________________
3650void 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// ______________________________________________________________________________
5066void 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