# Converting root file to csv using root2csv

**URL:** <https://root-forum.cern.ch/t/converting-root-file-to-csv-using-root2csv/42583>\
**Category:** Newbie\
**Tags:** root\
**Created:** [December 3, 2020, 7:01pm UTC](https://root-forum.cern.ch/t/converting-root-file-to-csv-using-root2csv/42583 "2020-12-03T19:01:04Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [December 4, 2020, 9:06am UTC](https://root-forum.cern.ch/t/converting-root-file-to-csv-using-root2csv/42583/5 "2020-12-04T09:06:03Z")

</div>

ok.  
so, first a few clarifying things.

- `root-ls`, `root2csv`, … all the commands from [go-hep.org/x/hep](https://go-hep.org/x/hep) are written in [Go](https://golang.org). Go is a compiled programming language, so one needs a compiler (_e.g._ one that can be installed from [golang.org](https://golang.org)) to compile Go source code into an executable for a given operating system + architecture (_e.g.:_ `linux` + 64bits machine).

- `go get go-hep.org/x/hep/cmd/root2csv` will fetch the Go code for `root2csv`, compile it and install the resulting binary under some directory (by default `$(go env GOPATH)/bin`).

- Go has this nice property of being able to produce (by default) statically compiled binaries/executables, so a binary that has been compiled on machine A (a Linux/64b machine) can be easily copied to machine B (another Linux/64b machine) w/o needing to install a bunch of things.

so, with that out of the way, let’s try this step by step, assuming you have not installed Go and that you are on a Linux machine:

```auto
# retrieve the root-ls and root2csv binaries for Linux/64b
$> cd /some/where
$> curl -O -L https://go-hep.org/dist/v0.27.0/root-ls-linux_amd64.exe
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed
100 16.9M 100 16.9M 0 0 2134k 0 0:00:08 0:00:08 --:--:-- 2447k

## rename to something shorter
$> mv root-ls-linux_amd64.exe root-ls

## make it exectubale
$> chmod +x ./root-ls

## test it
$> ./root-ls -h
Usage: root-ls [options] file1.root [file2.root [...]]

ex:
 $> root-ls ./testdata/graphs.root

options:
  -profile string
    	filename of cpuprofile
  -sinfos
    	print StreamerInfos
  -t	print Tree(s) (recursively)

```

at this point, you have a working `root-ls` executable.  
(you can do the same for the `root2csv` executable.)

and you can test it with your favorite ROOT file:

```auto
$> cd /some/where
$> ./root-ls -t /path/to/your/favorite/file.root

```

if you have a Go installation ready and correctly installed, the following would work as well:

```auto
$> go get -v go-hep.org/x/hep/groot/cmd/root-ls
$> go get -v go-hep.org/x/hep/cmd/root2csv

## it should have installed the resulting binaries under $GOPATH/bin.
$> go env GOPATH
/some/path

$> /some/path/bin/root-ls -h
Usage: root-ls [options] file1.root [file2.root [...]]

ex:
 $> root-ls ./testdata/graphs.root

options:
  -profile string
    	filename of cpuprofile
  -sinfos
    	print StreamerInfos
  -t	print Tree(s) (recursively)

```

ditto for `root2csv`.

if you put that `$GOPATH/bin` directory as part of your `$PATH` environment variable, the binaries produced by `go get` will be readily available from your shell w/o having to type the full path.

and here is an example of `root2csv` usage, with your favorite ROOT file, assuming it contains a `TTree` `"mytree"`:

```auto
$> root2csv -f /path/to/your/favorite/file.root -o my-output.csv -t mytree

```

hth,  
-s

---

_[View the full topic](https://root-forum.cern.ch/t/converting-root-file-to-csv-using-root2csv/42583)._
