Conditional operator in TTreeFormula, (ie "X > 5?

Hi.

It would be very nice if TTreeFormula and TTree::Draw could support the standard c++ ternary conditional operator.

Although it is easy enough to translate ( X > 5 ? y : z ) into ( ( X > 5 ) * y ) + ( ! ( X > 5 ) * z ) that doesn’t work so well when y and z are strings.

Or perhaps this could be a pair of function in TMath. ie
const char* TMath::IfElseString( Bool_t cond, const char* valTrue, const char* valFalse ).
double TMath::IfElse( Bool_t cond, Double_t valTrue, Double_t valFalse)

Thanks.

Hi,

Support for the ternary conditional operator has been added to TFormula and TTreeFormula in revision 30157 of the svn trunk. (30158 for strings).

Cheers,
Philippe.

Quite impressive. Espcially since ‘:’ was already used given a meaning in draw and cut expressions.

I assume this will be widely available in the next production ROOT release.

Hi,

Yes, it will be part of the next ROOT release (v5.25/02).

Cheers,
Philippe.