rootio: add support for TChain
it should be possible to combine multiple rootio.Tree
s (with the same layout) from multiple ROOT files into one rootio.Tree
.
right, now, to get at a rootio.Tree
, one does:
func main() {
f, err := rootio.Open("testdata/chain.1.root")
if err != nil {
log.Fatal(err)
}
defer f.Close()
obj, err := f.Get("tree")
if err != nil {
log.Fatal(err)
}
tree := obj.(rootio.Tree)
fmt.Printf("entries= %v\n", tree.Entries())
}
the rootio.Tree
interface is:
// Tree is a collection of branches of data.
type Tree interface {
Named
Entries() int64
TotBytes() int64
ZipBytes() int64
Branch(name string) Branch
Branches() []Branch
Leaves() []Leaf
getFile() *File
loadEntry(i int64) error
}
it should be possible to have a type that implements the rootio.Tree
interface but logically concatenates multiple rootio.Tree
s together.
Something like the io.MultiReader
function: https://godoc.org/io#MultiReader
Initially, one could just require the user to pass already created/retrieved rootio.Tree
to a, e.g., Chain
function:
// Chain returns a new Tree that is the logical concatenation of all the input Trees.
func Chain(trees ...Tree) Tree { ... }
one should think about resource ownership:
- who should close the ROOT file containing a Tree when that Tree has been completely read ?
- how to integrate the
chain
type with theScanner
s ? - is it better to have a
Chain
function that takes a tree name and a list of file names ? (so resource ownership is clearer). it's less composable... - perhaps introduce a
ChainScanner
that opens and closes files as needed when eachTree
has been consumed ?