# Dump TTree in a txt file?

**URL:** <https://root-forum.cern.ch/t/dump-ttree-in-a-txt-file/29069>\
**Category:** ROOT\
**Tags:** tree\
**Created:** [May 18, 2018, 10:29pm UTC](https://root-forum.cern.ch/t/dump-ttree-in-a-txt-file/29069 "2018-05-18T22:29:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristella](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/cristella/32/16288_2.png) [@cristella](https://root-forum.cern.ch/u/cristella)\
**Post date:** [May 18, 2018, 10:29pm UTC](https://root-forum.cern.ch/t/dump-ttree-in-a-txt-file/29069/1 "2018-05-18T22:29:07Z")

</div>

Please provide the following information:

* * *

ROOT Version (e.g. 6.12/02): 6.06/07  
Platform, compiler (e.g. CentOS 7.3, gcc6.2): SLC 6.7, gcc4.9.3

* * *

In ROOT 6.06/07 the redirection of the Three::Scan() method does not work as suggested here:

> [@Write TTree to TXT?](https://root-forum.cern.ch/t/write-ttree-to-txt/11651/2):
>
> Hi, T-\>Scan("\*"); \>T.txt should work (with ROOT 5). Cheers, Axel.

I get:

```auto
root [1] mva_variables_sig->Scan("*"); >ttree.txt
ROOT_prompt_1:1:31: error: expected expression
mva_variables_sig->Scan("*"); >ttree.txt
                              ^
ROOT_prompt_1:1:32: error: use of undeclared identifier 'ttree'
mva_variables_sig->Scan("*"); >ttree.txt

```

Thank you for your help,  
Leonardo

---

<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:** [May 18, 2018, 11:09pm UTC](https://root-forum.cern.ch/t/dump-ttree-in-a-txt-file/29069/2 "2018-05-18T23:09:08Z")

</div>

In v6 you can do either

```auto
root [] .> ttree.txt
root [] mva_variables_sig->Scan("*");
root [] .>

```

or

```auto
TTreePlayer *player = ((TTreePlayer*)(tree->GetPlayer()));
player->SetScanRedirect(true); 
player->SetScanFileName("ttree.txt"); 
mva_variables_sig->Scan("*");

```

---

<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 19, 2018, 10:53am UTC](https://root-forum.cern.ch/t/dump-ttree-in-a-txt-file/29069/3 "2018-05-19T10:53:17Z")

</div>

alternatively, you could also use this little Go program that creates CSV files out of TTrees:

- [go-hep.org/x/hep/cmd/root2csv](https://go-hep.org/x/hep/cmd/root2csv)

I’ve put binaries here if you want to try it out:

- [https://cern.ch/binet/go-hep/rootio/root2csv-darwin-amd64.exe](https://cern.ch/binet/go-hep/rootio/root2csv-darwin-amd64.exe)
- [https://cern.ch/binet/go-hep/rootio/root2csv-linux-amd64.exe](https://cern.ch/binet/go-hep/rootio/root2csv-linux-amd64.exe)
- [https://cern.ch/binet/go-hep/rootio/root2csv-windows-386.exe](https://cern.ch/binet/go-hep/rootio/root2csv-windows-386.exe)

hth,  
-s

---

<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:** [June 2, 2018, 10:53am UTC](https://root-forum.cern.ch/t/dump-ttree-in-a-txt-file/29069/4 "2018-06-02T10:53:19Z")

</div>

Closed on June 2, 2018, 10:53am UTC

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