WIP: Allow selection with an expression in tree2array

This is a work in progress but already seems to function very well.

tree2array has a new optional selection argument which is internally used to select which entries are copied to the output array.

I also cleaned up the existing C++ and Cython code a bit.