Looping over all trees

Hello All,

I would like to write a simple code to open a root file and print the total no of entries in each tree. How do I loop over the trees. I tried the following but it does not seem to work:

  [code] ...
   const char	*keyname;
   file = TFile::Open(ROOTfilename);
   ...
TIter	next(file->GetListOfKeys());
TKey *key;
while ((key=(TKey*)next())) {
	keyname=key->GetName();
	totalEvents 	= keyname->GetEntries(); 
	printf("%50s\t%i\n",keyname,totalEvents);
}
   ...[/code]

Thanks in advance,
Karthik.

should be quite simple

... file = TFile::Open(ROOTfilename); ... TIter next(file->GetListOfKeys()); TKey *key; TTree *T; while ((key=(TKey*)next())) { if (strcmp(key->GetClassName(),"TTree")) continue; //do not use keys that are not trees T = (TTree*)file->Get(key->GetName()); //fetch the Tree header in memory totalEvents = T->GetEntries(); printf("%50s\t%i\n",keyname,totalEvents); delete T; } ...

Rene