-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
groot/rtree: problem reading slices with formula? #736
Comments
hum... I've added a test for that: it's working (locally, at least, let's see what the CI pipeline says). how do you create the |
Yes ok, I am not too surprised that it works. I would need to do some more checks but to answer your question, I am using these // Branches and function
Vars := []string{"hits_time_mc"}
Fct := func(xs []float32) []float64 {
res := make([]float64, len(xs))
for i, x := range xs {
res[i] = float64(x)
}
return res
}
// FormulFunc and value getter
formFunc := r.FormulaFunc(Vars, Fct)
getVal := formFunc.Func().(func()[]float64)
// Event loop
err = r.Read(func(ctx rtree.RCtx) error {
fmt.Println(len(getVal()))
return nil
}
) This prints 0 for me. But my code is getting a bit convoluted ... I should start with a small standalone example - unless you see something above which is not correct. Thanks |
ok. so, you pass a |
Yes! I do this: r, err := rtree.NewReader(t, []rtree.ReadVar{}, rtree.WithRange(0, ana.Nevts))
OK ... But this still works for non-sliced types. (sorry I closed it by mistake) |
must be something else. package main
import (
"flag"
"log"
"go-hep.org/x/hep/groot"
"go-hep.org/x/hep/groot/rtree"
)
func main() {
flag.Parse()
fname := flag.Arg(0)
tname := "tree"
f, err := groot.Open(fname)
if err != nil {
panic(err)
}
defer f.Close()
o, err := f.Get(tname)
if err != nil {
panic(err)
}
t := o.(rtree.Tree)
r, err := rtree.NewReader(t, []rtree.ReadVar{})
if err != nil {
panic(err)
}
defer r.Close()
form, err := r.FormulaFunc(
[]string{"SliF32"},
func(xs []float32) []float64 {
o := make([]float64, len(xs))
for i, v := range xs {
o[i] = float64(2 * v)
}
return o
},
)
if err != nil {
panic(err)
}
fct := form.Func().(func() []float64)
err = r.Read(func(ctx rtree.RCtx) error {
log.Printf("evt[%d]: %v", ctx.Entry, fct())
return nil
})
if err != nil {
panic(err)
}
} and then:
|
OK, we can close: it's on my side then. Thanks for checking. |
I am back to this. Actually there might be something odd (maybe with my input file?). I have basically copy-pasted your code, change file/tree/branch names and I get the exact same result. So I have the same problem even if I skip all my machinery, just with a simple & direct The function to run is here: https://github.com/rmadar/tree-gonalyzer/blob/d18c7a38af67a3aaa3d9756a4c43bc83ba6f5a10/ana/example_treefunc_test.go#L189 (but this basically the same as yours). More importantly, I have put my test file here: https://github.com/rmadar/tree-gonalyzer/blob/master/testdata/fileSlices.root |
ok: that's because, in your file, the |
OK, then I am not crazy :)! I used this file in a couple of other ROOT codes ( If that might help, I used the following command lines to create the branch (in a ROOT code): vector<float> time;
tree->Branch("hits_time_mc", &time); |
I think I have a fix. could you reproduce that file (but with only, say, 5 events, so its size is about ~200k ?) |
(and -if possible- only with the |
The file with only 5 events and the two branches Just to clarfiy one point: tree->Branch("hits_n", &n, "hits_n/I");
tree->Branch("hits_time_mc", &hits_time_mc); |
ok, thanks. as soon as I finished my "entretien annuel", I'll commit the fix:
|
thanks for the input file. |
amazing, it works! |
I am trying to read a slice, i.e
a vector<float>
branch with artree.Formula
, using something like:In the event loop,
getSlice()
returns always an empty slice. Given it's quite late, it's not impossible I am doing a mistake ... But I wanted to know if there would be a reason why reading slices can fail withrtree.Formula
.The text was updated successfully, but these errors were encountered: