[ROOT] merging directories

From: Michael Gold (gold@higgs.phys.unm.edu)
Date: Fri May 16 2003 - 02:20:56 MEST


Dear rooters:

here is my problem.  I have files which all have a certain
directory ( here called dbDir ).  This directory has a 
number of subdirectories, each subdirectory contains some
TObjects.  I'd like to collect all the subdirectories from
multiple files and put them into a single dbDir, then 
append this to an output file.  below is my attempt
to do this.  the program will seg violate at the end
when I try to write the output file.  If I remove the
line "delete input", then the program does not seg violate,
but then the output file directory dbDir is empty.

suggestions?

here is the basic loop in the main code:

int main( int argc, char *argv[] ) {

....
  // create directory for db files in fout 
  TDirectory *dbDir =  new TDirectory("db"," data base stuff");

  // Recreate output file
  TFile *fout = new TFile(outFileName.c_str(),"recreate");
  
.... 

  //loop over files 
  while(getline(fileList,inFile,'\n')) {
    ++ nFiles;
    // read db files
    readDb(inFile,dbDir);
  }// end loop over files
  dbDir->ls();
  fout->Append(dbDir);
......
  fout->Write();
}

here is the subroutine that attempts to 
read from input file into dbDir:

void readDb(string inFile, TDirectory *dbDir)
{
    TFile *input = new TFile(inFile.c_str());
    TDirectory  *fileDir  = (TDirectory *) input->GetKey("db")->ReadObj();
    assert(fileDir);
    TIter next( fileDir->GetListOfKeys());
    TKey *kdir;
    while (( kdir = (TKey *)next())) {
      if(kdir->ReadObj()->InheritsFrom("TDirectory")) {
        TDirectory *subDir =  (TDirectory *) kdir->ReadObj() ;
        dbDir->Append(subDir);
        subDir->ReadAll();      
      }
    }
    dbDir->ls();
    delete input;
}



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET