If statement for ClassName checking

Hello,
I’m trying to extract all histograms from the List and draw them. And inside for loop I want to define ClassName of histograms but “if” statements are not checked. If I do it in the console without any “if” and “for” for each histograms, everything works fine. What am I doing wrong? I’m using ROOT v5.34.34.
Thanks.

[code]void loop1(const char* filein=“histograms.root”)
{

TFile* f = new TFile(filein);

if (!f->IsOpen()) {
printf(" Cannot open input file %s\n",filein);
exit(1) ;
}

TList* histESD = (TList*) f->Get(“histESD”);

for(int i = 0; i < histESD->GetSize(); i++)
{
TObject obj = (TObject)histESD->At(i);
cout <<
if(obj->ClassName() == “TH1F”)
{
TH1F h = (TH1F)obj;
name = h->GetName();
h->Draw();
}
else if(obj->ClassName() == “TH2F”)
{
TH2F h = (TH2F)obj;
name = h->GetName();
h->Draw();
}
else if(obj->ClassName() == “TH3F”)
{
TH3F h = (TH3F)obj;
name = h->GetName();
h->Draw();
}
else if(obj->ClassName() == “TH1I”)
{
TH1I h = (TH1I)obj;
name = h->GetName();
h->Draw();
}
}
}[/code]

How about “histograms.root”?

[code]#include “TFile.h”
#include “THashList.h”
#include “TObject.h”
#include “TH1.h”
#include “TH2.h”
#include “TH3.h”
#include “TCanvas.h”

#include
#include

void loop1(const char *filein = “histograms.root”)
{
if ((!filein) || (!(filein[0]))) return; // just a precaution
TFile *f = TFile::Open(filein);
if ((!f) || (f->IsZombie())) {
std::cout << " Cannot open input file " << filein << std::endl;
delete f;
return ;
}

THashList *histESD; f->GetObject(“histESD”, histESD);
if (!histESD) {
std::cout << " Cannot retrieve histESD" << std::endl;
delete f;
return ;
}

for(int i = 0; i < histESD->GetSize(); i++)
{
const char name;
TObject obj = histESD->At(i);
if (!obj) continue; // just a precaution
if(!std::strcmp(obj->ClassName(), “TH1F”))
{
name = obj->GetName();
new TCanvas(name, name);
((TH1F
)obj)->Draw();
}
else if(!std::strcmp(obj->ClassName(), “TH2F”))
{
name = obj->GetName();
new TCanvas(name, name);
((TH2F
)obj)->Draw();
}
else if(!std::strcmp(obj->ClassName(), “TH3F”))
{
name = obj->GetName();
new TCanvas(name, name);
((TH3F*)obj)->Draw();
}
else if(!std::strcmp(obj->ClassName(), “TH1I”))
{
name = obj->GetName();
new TCanvas(name, name);
((TH1I*)obj)->Draw();
}
}
}[/code]

[quote=“Pepe Le Pew”] [/quote]
Thanks very much!