Thanks all for pointing out missing namespace reference.
Regards,
Vassili.
Vassili Maroussov wrote:
> Dear ROOTers,
>
> I cannot compile the file in the attachment, although the <iostream> 
> is included:
>
> ----------------------------
> [pcmspur5] ~/TreePlay > g++ -c count_trees.cxx -I`root-config --incdir`
> count_trees.cxx: In function `int count_trees(const char*)':
> count_trees.cxx:20: `cerr' undeclared (first use this function)
> count_trees.cxx:20: (Each undeclared identifier is reported only once 
> for each
>   function it appears in.)
> count_trees.cxx:20: `endl' undeclared (first use this function)
> count_trees.cxx:45: `cout' undeclared (first use this function)
> [pcmspur5] ~/TreePlay >
> ----------------------------
>
> What may be a reason for that? I use ROOT 5.06 and gcc 3.2.3 (Red Hat 
> Linux 3.2.3-53)
>
> Regards,
>
> Vassili.
>
>------------------------------------------------------------------------
>
>#include <iostream>
>
>#include <Ttypes.h>
>#include <TSystem.h>
>#include <TFile.h>
>#include <TTree.h>
>#include <TKey.h>
>
>#include <libgen.h>    //to use basename(char *)
>
>int count_trees(const char *file0)
>{
>//Counts number of object inherited from TTree in file0 and
>//reports number of objects of unknown type
>
>   char *file = gSystem->ExpandPathName(file0);
>   
>	TFile f(file, "READ"); 
>   if (f.IsZombie()) {
>      cerr << "ERROR (count_trees): cannot open " << file << endl;
>      return -1;
>   }
>   
>	TList *li = f.GetListOfKeys();
>	TKey *key;
>	TClass *cl = 0;
>	TIter next(li);
>   
>   Int_t ntrees    = 0;
>   Int_t nunknowns = 0;
>
>	while ((key = (TKey*)next())) {
>		cl = gROOT->GetClass(key->GetClassName());
>
>      // the case of unknown object
>		if (!cl) {
>         nunknowns++;
>         continue;
>		}
>		// the case of tree
>		if (cl->InheritsFrom(TTree::Class())) {
>         ntrees++;
>		}
>	}
>   cout << file      << " : "
>        << ntrees    << " trees, "
>        << nunknowns << " unknown objects." << endl;
>        
>   return 0;
>}
>
>void usage_help(char *pname)
>{
>   cout << "\n\"" << basename(pname) << "\" counts number of TTrees\n";
>   cout << "and unknown objects in the input_file\n\n";
>   cout << "Usage:\n\t" << basename(pname) << " input_file" << endl;
>}
>
>int main(int argc, char *argv[])
>{
>   if (argc != 2) {
>      usage_help(argv[0]);
>      return -1;
>   }
>   
>   count_trees(argv[1]);
>   return 0;
>}
>  
>
Received on Tue Mar 14 2006 - 16:39:42 MET
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET