# 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:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 12, 2019, 1:49pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/21 "2019-03-12T13:49:57Z")

</div>

Fix missing ;  
No dump.cxx is:

```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 *outputname = "dump.txt", 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) 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")
}

```

No no errors, but no output files…

PS dna.root - [https://www.file-up.org/9ofsmxb1dmqn](https://www.file-up.org/9ofsmxb1dmqn)

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 12, 2019, 2:17pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/22 "2019-03-12T14:17:16Z")

</div>

> [@rootroot](#):
>
> PS dna.root - [https://www.file-up.org/9ofsmxb1dmqn](https://www.file-up.org/9ofsmxb1dmqn)

I can not download the file from this link. It ‘just’ bring to what seems like scams/fake-download etc…

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 12, 2019, 2:18pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/23 "2019-03-12T14:18:03Z")

</div>

> [@rootroot](#):
>
> No no errors, but no output files…

The file ‘diump.txt’ is not even created?

---

<div class="post-metadata">

**Author:** ![11112](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/1/d78d45/32.png) [@11112](https://root-forum.cern.ch/u/11112)\
**Post date:** [March 13, 2019, 7:27am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/24 "2019-03-13T07:27:27Z")

</div>

Try to download root.dna from here - [https://yadi.sk/d/8fN-s6zXz1gyKQ](https://yadi.sk/d/8fN-s6zXz1gyKQ)

Yes, dump.txt and dump.xml is not created. Nothing…

---

<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:** [March 13, 2019, 7:44am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/25 "2019-03-13T07:44:14Z")

</div>

Note that there is no “ntuple” TTree in your “dna.root” TFile.

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 13, 2019, 11:33am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/26 "2019-03-13T11:33:56Z")

</div>

Thanks!

```auto
const char *nname = "dna")

```

Solve the problem!

---

<div class="post-metadata">

**Author:** ![rootroot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/rootroot/32/37811_2.png) [@rootroot](https://root-forum.cern.ch/u/rootroot)\
**Post date:** [March 13, 2019, 2:42pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/27 "2019-03-13T14:42:27Z")

</div>

Sorry, works, but gives an error on a long tracks:

```auto
Error in <TBranch::TBranch::WriteBasketImpl>: basket's WriteBuffer failed.

```

What does it means?

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [March 14, 2019, 5:18pm UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/28 "2019-03-14T17:18:14Z")

</div>

Most likely the amount of data in that single entry for that single branch is reaching 1Gb (other less likely possibility included disk error). If this is the case, you will need to ask the branch to be split further. If it is already non-splittable but let us know the class layout and semantic content to see if we can come up with an alternative storage strategy.

---

<div class="post-metadata">

**Author:** ![Khalidhussain1134](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/khalidhussain1134/32/19474_2.png) [@Khalidhussain1134](https://root-forum.cern.ch/u/Khalidhussain1134)\
**Post date:** [June 13, 2020, 5:44am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/29 "2020-06-13T05:44:58Z")

</div>

Dear All, I also want to convert root file into text file, I tried the above code shared by # [Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote) and still getting the below error;

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/4/84f4806fdf726a9aa39016aa4514f17600e32aa6.png),

My root file is attached.[SPECT.root](https://root-forum.cern.ch/uploads/short-url/CssCnSRglsgQ8czqPzbPJ1jnvt.root) (551.2 KB)

Any help is highly appreciated  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Khalidhussain1134](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/khalidhussain1134/32/19474_2.png) [@Khalidhussain1134](https://root-forum.cern.ch/u/Khalidhussain1134)\
**Post date:** [June 13, 2020, 7:56am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/31 "2020-06-13T07:56:54Z")

</div>

Thank you for your quick response;  
I am using root 6 and entered the command in same ordered as you advised, you can see in the screenshot but still error; please see the screenshot below;

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/b/6/b64a078e639b66da763f9c11ff4e355b157eb9f7.png)

Please see where I am wrong;

Thank you

---

<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 13, 2020, 9:58am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/33 "2020-06-13T09:58:45Z")

</div>

> [@How to extract a data from dna.root file?](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/9):
>
> In ROOT 6, you need to: root [0] .\> dump.txt .x dump.cxx .\> root [3] Note also that, in many simple cases, you should be able to use the operating system redirection, e.g.: [...]$ root -l -q dump.cxx \> dump.txt

> [@How to convert .root to .txt file?](https://root-forum.cern.ch/t/how-to-convert-root-to-txt-file/30534/4):
>
> 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…

---

<div class="post-metadata">

**Author:** ![Khalidhussain1134](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/khalidhussain1134/32/19474_2.png) [@Khalidhussain1134](https://root-forum.cern.ch/u/Khalidhussain1134)\
**Post date:** [June 17, 2020, 2:58am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/34 "2020-06-17T02:58:15Z")

</div>

Dear #Wile\_E\_Coyote, I tired almost all the way mentioned in above threads but still unable to convert .root to .txt ,

I tried [ .\> dump.txt  
.x dump.cxx  
.\> ]  
and another way [.x dump.cxx(“dump.txt”)]  
annother way [ .\> dump.txt  
.x dump.cxx  
root -l -q dump.cxx \> dump.txt ]

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/b/f/bfd75a829431c8b1ca467e3f76ba41938271d68c.png)

Thanks for your cooperation.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [June 17, 2020, 5:07am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/35 "2020-06-17T05:07:54Z")

</div>

Have a look inside the dump.cxx file. It needs you to provide 3 arguments (or change the defaults in the macro itself!), according to _your_ files and trees:

```auto
root[] .x dump.cxx("myoutput.txt","myrootfile.root","mytreename")

```

and it creates “myoutput.txt” and “dump.xml” (the latter name is not in the arguments but obviously you can change the code).

---

<div class="post-metadata">

**Author:** ![Khalidhussain1134](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/khalidhussain1134/32/19474_2.png) [@Khalidhussain1134](https://root-forum.cern.ch/u/Khalidhussain1134)\
**Post date:** [June 17, 2020, 5:44am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/36 "2020-06-17T05:44:30Z")

</div>

Dear # Dastudillo thank you for your reply.

I already set the default arguments to my desired file names, moreover same arguments was also given while executing dump.cxx. ![image](https://root-forum.cern.ch/uploads/default/original/3X/e/4/e4a9b6eded8411d1b60e97d3cb22a8dcf021637d.png) I wonder to see that the **.x dump.cxx(“spect.txt”, “SPECT.root”,“mytree”)** does nothing , text file only created after executing .\> dump.txt file created ]

Still there is nothing in output please guide,

---

<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 17, 2020, 7:07am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/37 "2020-06-17T07:07:44Z")

</div>

Note that there is no “mytreename” nor “mytree” TTree in your “[SPECT.root](https://root-forum.cern.ch/uploads/short-url/CssCnSRglsgQ8czqPzbPJ1jnvt.root)” TFile.  
Try:  
`[...]$ rootls -l SPECT.root`

BTW. You can also try [the latest “groot/cmd/root-ls”, “groot/cmd/root-dump” and another “groot/cmd/root2\*”](https://go-hep.org/dist/latest/) standalone utilities from the [Go-HEP](https://go-hep.org/) project.

---

<div class="post-metadata">

**Author:** ![sbinet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sbinet/32/13166_2.png) [@sbinet](https://root-forum.cern.ch/u/sbinet)\
**Post date:** [June 17, 2020, 9:14am UTC](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182/38 "2020-06-17T09:14:14Z")

</div>

BTW, I’ve put (thanks to Wile’s suggestion) a `/dist/latest` link that should always point to the latest release of Go-HEP binaries (_ie:_ including binaries from `groot`, a pure-Go implementation of (a subset of) ROOT)

here:

- [https://go-hep.org/dist/latest](https://go-hep.org/dist/latest)

[Previous page](https://root-forum.cern.ch/t/how-to-extract-a-data-from-dna-root-file/16182.md?page=1)
