Looping over TTrees in TFile

Hi I am trying to loop over 4 TTrees that are in one TFile like so:

Int_t loop(){
  TFile * pYieldFile =  new TFile("pYieldFile.root","READ");
  char * treeString[4]={"Raw","RU","VMDUnfolded","Unfolded"};
  Int_t trees=4;
  for ( Int_t it=0; it<trees; it++)
  {
     os << "yieldData" << treeString[it] << ends;
      text=os.str();
      treeName=text.c_str();
      os.seekp(0);

      //Get the trees... and attach the branches..                              
      TTree * pYieldData = pYieldFile->Get(treeName);

  }
}

When I get to the second loop the code throws an error:

Error: illegal pointer to class object pYieldData 0x0 117

Can someone tell me what I am doing wrong here.

Hi,

can you attach the complete version of your script?

Cheers, Axel.

I got it to work by using the TIter and TKey technique I saw in another post.