Converting root file to csv using root2csv

ok.
so, first a few clarifying things.

  • root-ls, root2csv, … all the commands from go-hep.org/x/hep are written in Go. Go is a compiled programming language, so one needs a compiler (e.g. one that can be installed from 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:

# 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:

$> 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:

$> 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":

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

hth,
-s