# convert root file to txt file

**URL:** <https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926>\
**Category:** ROOT\
**Tags:** tree, hist, root\
**Created:** [May 10, 2022, 2:55pm UTC](https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926 "2022-05-10T14:55:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nora](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ed655f/32.png) [@nora](https://root-forum.cern.ch/u/nora)\
**Post date:** [May 10, 2022, 2:55pm UTC](https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926/1 "2022-05-10T14:55:02Z")

</div>

Hi,  
How can I convert root file to txt file, please?  
That what I did.

ofstream file;  
file.open(“here.txt”);

file\<\<energy\<\<endl;

but it stored only the value of the last event.

Thanks

---

<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:** [May 10, 2022, 3:13pm UTC](https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926/2 "2022-05-10T15:13:15Z")

</div>

Try [searching the forum](https://root-forum.cern.ch/search?q=root%20file%20to%20text%20file).

---

<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:** [May 11, 2022, 8:26am UTC](https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926/3 "2022-05-11T08:26:14Z")

</div>

it depends on what you want to extract from the ROOT file (ie: histograms or tree).

but the [root-dump](https://go-hep.org/x/hep/groot/cmd/root-dump) command (from the [Go-HEP/groot](https://go-hep.org) project), may be of interest.

```auto
$> root-dump ./testdata/small-flat-tree.root
>>> file[./testdata/small-flat-tree.root]
key[000]: tree;1 "my tree title" (TTree)
[000][Int32]: 0
[000][Int64]: 0
[000][UInt32]: 0
[000][UInt64]: 0
[000][Float32]: 0
[000][Float64]: 0
[000][Str]: evt-000
[000][ArrayInt32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt64]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayInt64]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayFloat32]: [0 0 0 0 0 0 0 0 0 0]
[000][ArrayFloat64]: [0 0 0 0 0 0 0 0 0 0]
[000][N]: 0
[000][SliceInt32]: []
[000][SliceInt64]: []
[...]

```

```auto
$> root-dump ./testdata/hh2d.root 
>>> file[./testdata/hh2d.root]
key[000]: h2;1 "h2" (TH2D)
BEGIN YODA_HISTO2D_V2 /h2
Path: /h2
Title: h2
Type: Histo2D
---
# Mean: (2.250000e+00, 1.250000e+00)
# Volume: 4.000000e+00
# ID	ID	sumw	sumw2	sumwx	sumwx2	sumwy	sumwy2	sumwxy	numEntries
Total Total 4.000000e+00	4.000000e+00	9.000000e+00	2.300000e+01	5.000000e+00	1.300000e+01	9.000000e+00	8.000000e+00
# 2D outflow persistency not currently supported until API is stable
# xlow	xhigh	ylow	yhigh	sumw	sumw2	sumwx	sumwx2	sumwy	sumwy2	sumwxy	numEntries
-4.000000e+00	-3.200000e+00	-5.000000e+00	-4.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
-4.000000e+00	-3.200000e+00	-4.000000e+00	-3.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
-4.000000e+00	-3.200000e+00	-3.000000e+00	-2.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
[...]

```

hth,  
-s

---

<div class="post-metadata">

**Author:** ![nora](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/ed655f/32.png) [@nora](https://root-forum.cern.ch/u/nora)\
**Post date:** [May 12, 2022, 2:10pm UTC](https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926/4 "2022-05-12T14:10:30Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 26, 2022, 2:10pm UTC](https://root-forum.cern.ch/t/convert-root-file-to-txt-file/49926/5 "2022-05-26T14:10:42Z")

</div>

Closed on May 26, 2022, 2:10pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
