How to convert .root to .txt file?

hummm … in ROOT 6, the usage of this script should be:

.> dump.txt
.x dump.cxx
.>

The .x dump.cxx(); > dump.txt part is a retired interface supported only in ROOT 5 and older.

Alternative use the following script:

// Name this file "dump.cxx" and use as:
//
// root [0] .x dump.cxx("dump.txt")
//
// Produces "dump.txt" and "dump.xml" files.
//

void dump(const char *outputname = "dump.txt",
          const char *fname = "dump.root",
          const char *nname = "ntuple")
{
  if (!outputname || !(*outputname) || !fname || !(*fname) || !nname || !(*nname)) return; // just a precaution
  
  TFile *f = TFile::Open(fname, "READ");
  if (!f || f->IsZombie()) { delete f; return; } // just a precaution
  
  TTree *t; f->GetObject(nname, t);
  if (!t) { delete f; return; } // just a precaution
  
  t->SetScanField(0);
  ((TTreePlayer*)t->GetPlayer())->SetScanRedirect(kTRUE);
  ((TTreePlayer*)t->GetPlayer())->SetScanFileName(outputname);
  t->Scan("*");
  t->SaveAs("dump.xml");
  
  delete f; // no longer needed (automatically deletes "t")
}

Cheers,
Philippe.