{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import (\n", " \"io\"\n", " \"os\"\n", " \"path/filepath\"\n", " \n", " \"go-hep.org/x/hep/rootio\"\n", ")\n", "\n", "fname := filepath.Join(os.Getenv(\"GOPATH\"), \"src\", \"go-hep.org/x/hep/rootio/testdata/small-flat-tree.root\")\n", "print(fname)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "f, err := rootio.Open(fname)\n", "if err != nil {\n", " panic(err)\n", "}\n", "defer f.Close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "printf(\"keys: %#v\\n\", f.Keys())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "o, err := f.Get(\"tree\")\n", "if err != nil {\n", " panic(err)\n", "}\n", "t := o.(rootio.Tree)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "printf(\"tree: %q entries=%v\\n\", t.Name(), t.Entries())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "branches := t.Branches()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i,b := range branches {\n", " printf(\"b[%d]: %v\\n\", i, b.Name())\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "type Data struct {\n", " Int32 int32\n", " Str string\n", " SliceFloat64 []float64\n", "}\n", "var data Data\n", "\n", "sc, err := rootio.NewScanner(t, &data)\n", "if err != nil {\n", " panic(err)\n", "}\n", "defer sc.Close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for sc.Next() {\n", " err := sc.Scan()\n", " if err != nil {\n", " panic(err)\n", " }\n", "\n", " printf(\"entry[%d]: %+v\\n\", sc.Entry(), data)\n", " if sc.Entry() == 9 {\n", " break\n", " }\n", "}\n", "\n", "if err := sc.Err(); err != nil && err != io.EOF {\n", " panic(err)\n", "}" ] } ], "metadata": { "kernelspec": { "display_name": "Neugram", "language": "neugram", "name": "neugram" }, "language_info": { "codemirror_mode": "go", "file_extension": ".ng", "mimetype": "", "name": "neugram", "nbconvert_exporter": "", "pygments_lexer": "go", "version": "unreleased" } }, "nbformat": 4, "nbformat_minor": 2 }