Go-HEP: write support for TH1x, TH2x and TGraphs in go-hep/rootio

as alluded to during the ROOT Users’ workshop:

GoHEP v0.15.0 has now support for (also) writing ROOT files:

  • TObjString, TObject, TNamed,
  • TH1x, TH2x, TGraph, TGraph{,Asymm}Errors

it also ships with a new root-cp command that can extract objects from a ROOT file and save them into a new one.

go-hep/rootio also supports writing compressed ROOT files (zlib, LZ4, LZMA).

Here is the full announcement: https://go-hep.org/news/release-0.15.0/

and here is a simple example:

func main() {
	w, err := rootio.Create("out.root", rootio.WithLZ4(flate.BestCompression))
	if err != nil {
		log.Fatal(err)
	}
	defer w.Close()

	v := rootio.NewObjString("Hello World from Go-HEP!")

	err = w.Put("my-obj-string", v)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("keys: %d\n", len(w.Keys()))

	err = w.Close()
	if err != nil {
		log.Fatalf("could not close file: %v", err)
	}
}

(Go-HEP tests make sure that the file is also correctly read-back from ROOT/C++)

also:

$> root-cp -h
Usage: root-cp [options] file1.root [file2.root [...]] out.root

ex:
 $> root-cp f.root out.root
 $> root-cp f1.root f2.root f3.root out.root
 $> root-cp f1.root:hist.* f2.root:h2 out.root

options:

$> root-cp ./testdata/graphs.root:g.* out.root
$> root-cp root://xrootd.example.org/file.root:hist.* out.root

Next steps are:

  • TTree, TBranch{,Element}, TLeaf{,Element} and TBasket
  • interoperability of TTree with Apache Arrow (both read & write to leverage the whole Apache Arrow ecosystem)
  • profiling (CPU/Memory)

Enjoy :slight_smile:

(and happy to get any kind of feedback)

1 Like

BTW: like for all GoHEP releases, this works on all Go-supported platforms:

  • linux-x86 (32b, 64b)
  • linux-x86 (s390x)
  • linux-arm (32b, 64b)
  • darwin (32b, 64b)
  • windows (32b, 64b)
  • freebsd, openbsd (32b, 64b)
  • dragonfly (64b)
  • plan9 (32b,64b)

and even:

  • WebAssembly (wasm)

so if you are on Windows-64b and want to write ROOT files… then you can use GoHEP (or uproot) :slight_smile:

PS: the complete list is actually:

$> go tool dist list
android/386
android/amd64
android/arm
android/arm64
darwin/386
darwin/amd64
darwin/arm
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
js/wasm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/riscv64
linux/s390x
nacl/386
nacl/amd64p32
nacl/arm
netbsd/386
netbsd/amd64
netbsd/arm
openbsd/386
openbsd/amd64
openbsd/arm
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64