Re: easy histogram disabling

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Mon, 27 Jun 2011 16:03:22 +0200


Hi Thiemo,

Sorry, absolutely out of question. Even the call to a virtual function requires the this pointer to point to a valid object.

I could instead recommend you to do something like this:

MyDebug::Hist(1, "name", x, -1., 1., 100); MyDebug::Hist2d(6, "name2", x, y, -10., 10., 10, 0., 1., 10);

...

MyDebug::DrawAll();

where the implementation for DebugHist could look like this:

namespace MyDebug {
  in gDebugLevel = 0;
  THashList gHists;
  void Fill(int debuglevel, const char* name, double x, double xmin, double xmax, int nbins) {

    if (gDebug < debuglevel) return;
    TH1* hist = (TH1*) gHists->FindObject(name);     if (!hist) {

       hist = new TH1F(name, name, xmin, xmax, nbins);
       hist->SetDirectory(0);
       gHists->Add(hist);

    }
    hist->Fill(x);
  }
  void DrawAll() {
     TIter iHist(&gHists);
     TH1* hist = 0;
     while ((hist = (TH1*)iHist()))) {
       new TCanvas();
       hist->Draw();
     }

  }
}

That's a very basic version of what you are probably looking for, but it should get you started.

Cheers, Axel.

Thiemo Nagel wrote on 06/27/2011 02:54 PM:
> Dear ROOTers,
>
> when debugging software, I often come across the issue, that I'd like to
> make extensive use of histograms to understand some problem in detail,
> however I'd like to be able to turn off these histograms (because of
> memory and speed issues) when the same code is used in production.
>
> The obvious solution is to write code along the lines of:
>
> TH3D *h1;
> if (debug)
> h1 = new TH3D(...);
> else
> h1 = NULL;
>
> ...
>
> if (debug1)
> h1->Fill(...);
> if (debug2)
> h2->Fill(...);
> if (debug3)
> h3->Fill(...);
>
> ...
>
> However, this impairs the readability of the code, especially when large
> numbers of histograms and different levels of debugging are used.
>
> To my mind, there would be a simple way to improve this. Adding to the
> top of the THxx::Fill() methods
>
> if (!this) return;
>
> would allow much cleaner code:
>
> h1->Fill(...);
> h2->Fill(...);
> h3->Fill(...);
>
> What do you think? Would you accept a patch?
>
> Cheers,
> Thiemo
>
Received on Mon Jun 27 2011 - 16:03:29 CEST

This archive was generated by hypermail 2.2.0 : Fri Jul 01 2011 - 17:50:01 CEST