hi Asier,
(CC-ing the Go-HEP mailing list, hope you don't mind)
On Thu Sep 22, 2022 at 12:21 CET, Asier Pereiro Castro wrote:
> Dear Sebastien,
>
> I have recently seen your package go-hep, and I'm studying the viability
> of porting our analysis code to Go, or at least part of it
>
> I already tested some of the go-hep features and translated a couple of
> routines and everything seems to work well. The reading speed is quite
> amazing!
>
> However I looked in the examples and I'm still missing a way to skip
> events. For example, in C++ we do something like this:
>
> for (std::size_t i = 0; i < n; i++) {
> tree->GetEntry(i);
>
> Event event(...);
>
> if ( Selection(event) == false )
> continue;
>
> events.push_back(event):
> }
>
> But here there's no explicit loop so I cannot use this trick.
naively, I would do this:
```
var evt Event
rvars := rtree.ReadVarsFromStruct(&evt)
r, err := rtree.NewReader(t, rvars)
if err != nil {
log.Fatalf("could not create tree reader: %+v", err)
}
defer r.Close()
var evts []Event
err = r.Read(func(ctx rtree.RCtx) error {
if accept(evt) {
evts = append(evts, evt)
}
return nil
})
if err != nil {
log.Fatalf("could not process tree: %+v", err)
}
```
wouldn't that work ?
when "designing" rtree.Reader I was also thinking about being able to
build a "reading list" (ie: collecting all the rtree.RCtx.Entry values
that one wants to read), and "replaying" this list with another
rtree.Reader (so the scheduling of reading a Tree items is further
optimized).
I haven't come to that (yet?).
hth,
-s