Re: [ROOT] 2 comments on TChain

From: Sebastien Greder (greder@in2p3.fr)
Date: Wed Dec 04 2002 - 18:07:49 MET


Hi Colin,

you can use Add("filename.root",0), it will check if the Tree exists, if
not the file will be skipped in the chain.

seb.


On Wed, 4 Dec 2002, Colin Bernet wrote:

> 
> Hi all,
> 
> 1 - I derived class TChain to add this constructor, which can chain 
> several rootfiles in a single command :
> 
> Chain::Chain(const char* chainname, const char*
> pattern) : TChain(chainname) {
>   string ls("ls ");
>   ls += pattern;
>   
>   cout<<pattern<<endl;
>     
>   FILE *in;
>   in = popen(ls.c_str(), "r");
>   
>   char filename[100];
>   while(fscanf(in,"%s",filename) != EOF) {
>     cout<<filename<<" ... ";
>     TFile tmp(filename);
>     if( tmp.IsZombie() ) {
>       cerr<<"not a root file"<<endl;
>       continue;
>     }
>     if(tmp.ReadKeys() ) {
>       tmp.Close();
>       if(TChain::Add(filename)) cout<<"OK!"<<endl;
>       else cout<<"chainname not found"<<endl;
>     }
>     else 
>       cout<<"No Keys !"<<endl;
>   }
>   pclose(in);
> }
> 
> I think it could be useful to have something like that in the TChain
> class.
> 
> 
> 2- You can notice in this piece of code that I'm opening the TFile to
> check that there are keys inside before adding it to the chain. If one
> tries to add a file with no keys, the chain is usable only for files added
> before (one has to limit number of entries manually).
> TChain::GetEntries() gives the error message :
> 
> Warning in <TFile::Init>: file chunk10001/28000/coral.root has no keys
> Error in <TFile::cd>: Unknown directory CsEfficiency
> Error in <Chain::LoadTree>: cannot find tree with name
> /CsEfficiency/MM02V1___eTree_ in file chunk10001/28000/coral.root
> 
> this check should probably be done in TChain::Add somehow, is it possible
> ? Is there already a way to do this check in a better way ?
> 
> thanks,
> 
> Colin
> 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:22 MET