ROOT Version: Not Provided Platform: Not Provided Compiler: Not Provided
Hello All,
I’m having trouble running the root2csv code posted by @sbinet I’d also like to convert a root file into a csv. Assistance would be greatly appreciated.
When I try running the following command:
root-ls -t ./
My terminal says -bash: root-ls: command not found
Ok so I have a root-ls directory in my cmd and I pasted a main.go file that I got from the godoc. Now when running root-ls -t ./small-flat-tree.root from the cmd directory it says the same thing -bash: root-ls: command not found. I’ll keep trying and updating as I go along. Thanks again for the help!
Update: Whenever I run main.go from the root2csv directory it exits with:
Usage of /var/folders/p3/pvlzcs2x4sndnpq1dvh03ldc0000gn/T/go-build053216966/b001/exe/main:
-f string
path to input ROOT file name
-o string
path to output CSV file name (default “output.csv”)
-t string
name of the tree to convert (default “tree”)
root2csv: missing input ROOT filename argument
exit status 1
The issue now would be identifying the source of the error.
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":