~sbinet/go-hep

1

Re: Question about groot

Sebastien Binet <work@sbinet.org>
Details
Message ID
<0ATZKEPpupZ_GylMHN6xFqMbeEZjyVumXRbosOS7Cf8UFwAEFDURWBGqVY1Ng2NLQnZczEM9v896wDLdOWivmsKmv3WKtasG1KoQmlxmriM=@sbinet.org>
DKIM signature
missing
Download raw message
fun fact: groot (it was called rootio at the time) started from Guy's code (the stuff that's in Geant4).
it was much more straightforward to look at than the T-stuff.

and uproot (v2) was based off groot.

that said, there's a rust library that also handles reading ROOT files:
- https://github.com/cbourjau/alice-rs/tree/master/root-io

I believe using rust code from C/C++ is somewhat easier than Go or Python.

-s

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Thursday, February 18th, 2021 at 7:44 PM, Boudreau, Joseph Francis <boudreau@pitt.edu> wrote:

> Thanks Sebastian.
>
> The only similar package I know of for "reading root without root" but in C++ is buried in Geant4 code.
> There is uproot, but that is python. Do you know of any other C++ package that does this?
>
> --Joe
>
> -------------------------------------------------------------
>
> Don't matter where you are
>
> Everybody's gonna need a ventilator--From Ventilator Blues, by the Rolling Stones
>
> From: Sebastien Binet <work@sbinet.org>
>
> Sent: Thursday, February 18, 2021 13:27
>
> To: Boudreau, Joseph Francis <boudreau@pitt.edu>; ~sbinet/go-hep@lists.sr.ht <~sbinet/go-hep@lists.sr.ht>
>
> Cc: sebastien.binet@cern.ch <sebastien.binet@cern.ch>
>
> Subject: Re: Question about groot
>
> hi Joe,
>
> linking Go code against C/C++ is doable[1,2] but still a bit of work:
> - one needs to write Go code that will be exposed to C/C++
> - not all Go types can be easily exported to C/C++
>
> it's a bit of mechanical work that should, eventually, be automatized (there's some support for that from SWIG, I think.)
>
> here is an example of what I did for a friend at the lab:
> - https://github.com/rmadar/go-topquark-reco/tree/main/capi (the "glue" code)
> - https://github.com/rmadar/go-topquark-reco/blob/main/tbuilder/tbuilder.go#L64 (the wrapped code)
> - https://github.com/rmadar/go-topquark-reco/blob/main/capi/test-root.C (calling it from a ROOT macro)
>
> there's probably room for a "little" tool that generates some of this boilerplate code...
>
> (like I've started a few years ago, for Python[3])
>
> long story short: I think it's doable for small code bases, and for ROOT files that groot can grok (the Athena EDM is probably not going to work, the persistent one, perhaps.)
>
> hth,
> -s
>
> [1]: https://golang.org/pkg/cmd/cgo/
> [2]: https://talks.godoc.org/github.com/sbinet/margo/part-3/talk.slide#9
> [3]: https://github.com/go-python/gopy
>
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Thursday, February 18th, 2021 at 7:05 PM, Boudreau, Joseph Francis <boudreau@pitt.edu> wrote:
>
> > Sebastian, I was wondering whether groot can be linked with c++ code
> > and whether that would be easy enough to even be worth doing?
> >
> > Thanks, Joe.
> >
> > -------------------------------------------------------------
> >
> > Don't matter where you are
> >
> > Everybody's gonna need a ventilator--From Ventilator Blues, by the Rolling Stones

Re: Question about groot

Sebastien Binet <work@sbinet.org>
Details
Message ID
<WJJimU7IMsW-4hgi2Jh0HuDGfhsqLsTZELeqCe0ndMb3NAzndKWS5z87-WW9PQNeU4-KFFaSLdxKCafNCTDXpbZLqKc0XxOVprN_kss9uFU=@sbinet.org>
In-Reply-To
<0ATZKEPpupZ_GylMHN6xFqMbeEZjyVumXRbosOS7Cf8UFwAEFDURWBGqVY1Ng2NLQnZczEM9v896wDLdOWivmsKmv3WKtasG1KoQmlxmriM=@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
thinking about this a tad more (during my holidays), I could imagine exposing a C interface to a subset of groot/riofs.File and groot/rtree.Tree.

it could/would be more or less the croot interface[1,2] I had initially devised but instead of forwarding to ROOT/C++, it would forward to go-hep/groot.

and that would only deal (initially?) with C builtins not requiring a ROOT streamer (so, only flat trees).

e.g.:

#include "croot.h"

croot_ctx_t ctx;
rc = croot_ctx_init(&ctx);
if (rc != 0) {
    abort("could not initialize croot context");
}

// read

croot_file_t f;
rc = croot_file_open(&ctx, &f, "file.root");
if (rc != 0) {
    perror("error: %s", croot_error(&ctx));
}

croot_tree_t tree;
rc = croot_tree_open(&ctx, &f, &tree, "mytree");
int64_t nentries = croot_tree_entries(&ctx, &tree);

// write

croot_file_t newfile;
rc = croot_file_create(&ctx, &newfile, "newfile.root");

croot_tree_t newtree;
rc = croot_tree_create(&ctx, &newfile, &newtree, "newtree");

int32_t i32;
rc = croot_tree_set_branch_i32(&ctx, &newtree, "i32", &i32);
for (int64_t i = 0; i < N; i++) {
    i32 = 2*i + 42;
    rc = croot_tree_write(&ctx, &newtree);
    if (rc != 0) { ... }
}

rc = croot_tree_close(&ctx, &newtree);
rc = croot_file_close(&ctx, &newfile);

(just thinking out loud)

not sure that, with all these limitations, it could still be really useful though.

-s

[1]: https://github.com/go-hep/croot
[2]: https://github.com/go-hep/croot/blob/master/bindings

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐

On Thursday, February 18th, 2021 at 8:36 PM, Sebastien Binet <work@sbinet.org> wrote:

> fun fact: groot (it was called rootio at the time) started from Guy's code (the stuff that's in Geant4).
>
> it was much more straightforward to look at than the T-stuff.
>
> and uproot (v2) was based off groot.
>
> that said, there's a rust library that also handles reading ROOT files:
>
> -   https://github.com/cbourjau/alice-rs/tree/master/root-io
>
>     I believe using rust code from C/C++ is somewhat easier than Go or Python.
>
>     -s
>
>     ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>
>     On Thursday, February 18th, 2021 at 7:44 PM, Boudreau, Joseph Francis boudreau@pitt.edu wrote:
>
> > Thanks Sebastian.
> >
> > The only similar package I know of for "reading root without root" but in C++ is buried in Geant4 code.
> >
> > There is uproot, but that is python. Do you know of any other C++ package that does this?
> >
> > --Joe
> >
> > Don't matter where you are
> >
> > Everybody's gonna need a ventilator--From Ventilator Blues, by the Rolling Stones
> >
> > From: Sebastien Binet work@sbinet.org
> >
> > Sent: Thursday, February 18, 2021 13:27
> >
> > To: Boudreau, Joseph Francis boudreau@pitt.edu; ~sbinet/go-hep@lists.sr.ht ~sbinet/go-hep@lists.sr.ht
> >
> > Cc: sebastien.binet@cern.ch sebastien.binet@cern.ch
> >
> > Subject: Re: Question about groot
> >
> > hi Joe,
> >
> > linking Go code against C/C++ is doable[1,2] but still a bit of work:
> >
> > -   one needs to write Go code that will be exposed to C/C++
> > -   not all Go types can be easily exported to C/C++
> >
> > it's a bit of mechanical work that should, eventually, be automatized (there's some support for that from SWIG, I think.)
> >
> > here is an example of what I did for a friend at the lab:
> >
> > - https://github.com/rmadar/go-topquark-reco/tree/main/capi (the "glue" code)
> >
> > - https://github.com/rmadar/go-topquark-reco/blob/main/tbuilder/tbuilder.go#L64 (the wrapped code)
> >
> > - https://github.com/rmadar/go-topquark-reco/blob/main/capi/test-root.C (calling it from a ROOT macro)
> >
> > there's probably room for a "little" tool that generates some of this boilerplate code...
> >
> > (like I've started a few years ago, for Python3)
> >
> > long story short: I think it's doable for small code bases, and for ROOT files that groot can grok (the Athena EDM is probably not going to work, the persistent one, perhaps.)
> >
> > hth,
> >
> > -s
> >
> > ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> >
> > On Thursday, February 18th, 2021 at 7:05 PM, Boudreau, Joseph Francis boudreau@pitt.edu wrote:
> >
> > > Sebastian, I was wondering whether groot can be linked with c++ code
> > >
> > > and whether that would be easy enough to even be worth doing?
> > >
> > > Thanks, Joe.
> > >
> > > Don't matter where you are
> > >
> > > Everybody's gonna need a ventilator--From Ventilator Blues, by the Rolling Stones
Reply to thread Export thread (mbox)