[quote=“tpochep”][quote=“wiso”]Second question: Is there a general reduce function to apply recursively?
f(f(f(f(x0, x1), x2), x3), ..., xn)
in my case f(a, b) -> a + b[/quote]
Is it somehow a ROOT-related question? May be something like std::accumulate/std::inner_product can help (though they work with sequences)?
C++ is not a functional programming language, so you have to clarify what do you understand as ‘reduce function to apply recursively’. Oh, and accumulate/inner_product both contains iteration under the hood instead of recursion you want.
[/quote]
C++ is not a functional programming language, but you can use functional programming pattern in C++, in fact std::accumulate does what I need, but I would like to have it directly in the TTree, for example:
tree->reduce("my_branch ** 2", function)
where function is what you prefer: TF1, functor, *function, lambda, … for example
float function(float a, float b) {return a + b; }
I can dump the content of a branch in a std::vector and then use std::transform, std::accumulate, but I need to dump everything in memory and it is not necessary.
[quote]
P.S. Ah, and if you were asking about something TTree-related, please ignore my reply, since I understood your question as a general C++ question
(though why not write your own TTreeIterator which works as an input iterator (C++ iterator category))
)) .
And about ‘too much code’ - with ROOT 6 we have new classes in $ROOTSYS/tree/treeplayer - TTreeReader and others who intend to significantly improve/simplify work with trees. I’m not sure if they are documented already in a ROOT user’s guide, but probably, you can have a look[/quote]
thank you. I am curious to see it.