Check if an object exists in a root file

Hello co-rooters!

I was wondering if there is a way, to check whether an object, inside a root file, exists.
The idea is that I have a root file with histograms saved in it. To use the histograms I call

The problem is that some of this histograms don’t exist. Therefore if such a histogram is not found the code crashes. I would like to be able to check if a histogram exists, so as to continue working with my program.

Something like this would be ideal (I am doing this while opening multiple files in a loop)

//Load File TFile *f = new TFile(TString::Format("Signals_%d_%d.root",run, seg)); if (f->IsOpen()==kFALSE) continue;

Any help or idea is more than welcome!


if the object is not found, the pointer, in your case hSignal, is a null pointer: you can check that.


You are right…
I used

and it seems to be doing the job!