# How to extract a data from dna.root file?

**URL:** <https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182>\
**Category:** ROOT\
**Created:** [June 3, 2013, 1:08pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182 "2013-06-03T13:08:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 3, 2013, 2:09pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/2 "2013-06-03T14:09:01Z")

</div>

```auto
//
// 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 *fname = "dna.root",
          const char *nname = "ntuple")
{
  if (!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
  
  // See:
  // http://root.cern.ch/root/html/TTreePlayer.html#TTreePlayer:Scan
  // http://root.cern.ch/root/html/TTree.html#TTree:Scan
  t->SetScanField(0);
  t->Scan("*");
  
  // See:
  // http://root.cern.ch/root/html/TObject.html#TObject:SaveAs
  t->SaveAs("dump.xml");
  // t->SaveAs(TString::Format("%s.xml", nname));
  
  delete f; // no longer needed (automatically deletes "t")
}

```

---

_[View the full topic](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182)._
