From interpreted to compiled Tree reading macro

Dear ROOTers,

I have this working macro, btagging.c, attached here, which reads branches in a TChain successfully, and I would like to compile it to run faster on larger samples.

btagging.c (14.6 KB)

I created the simplest possible Makefile (attached)

Makefile.txt (133 Bytes)

and adjusted a few syntax details (added cmath include, change exit statements to return, add namespace statement at the top, and move to int main() appellation, see attached file btag_comp.c).

btag_comp.c (11.3 KB)

It compiles fine but seg faults when starting to read the branches. I tried many options in a slightly chaotic order, but none prevailed. Can anybody point me to the main transitions needed to have this executable running? Looking at a good old MakeCode output, what I am doing here doesn’t look so different. Also, note that this tree contains more branches than the ones listed in the code, but I only setup those that I need later on.

Many thanks in advance,

Andrée

Try to initialize all pointers:
vector *b_WHATEVER = new vector;

Thanks a lot, that fixed it and it runs beautifully now! I thought the pointers would get their address set by SetBranchAddress, hence the mistake.

Cheers,

Andrée

Hi Andrée,

[quote]I thought the pointers would get their address set by SetBranchAddress, hence the mistake.[/quote]They can, however they also support the user passing an existing object to use and the setting to zero (as opposed to a value) help distinguish between the two cases.

Cheers,
Philippe.