Check if Object exists in TFile


I have a short question:
Is there a possibility to check if a specific object exists in a root-file (for example I want to check if an object TGraph called “graph” is included in a specific file).
Something like “Bool_t exists(const char* objectname)”:

TFile *f = new TFile("/path_to_file/filename",“READ”);
Bool_t Object_exists;
Object_exists = f->exists(“graph”);

I have to automate a process (so f->GetListOfKeys()->Print() would not help).
Does anybody know if there is a function like the “Bool_t exists”-function??

Kind regards,

Hi Christoph,

isn’t f->GetListOfKeys()->Contains(“graph”) what you are looking for?


Hi Margar,
that’s exactly what I wanted to know. Thanks a lot!!