Checking ntuple formula error

Hi
I am wondering if it is possible to check if a (user-provided) formula for TNtuple::Draw(…) contains errors.
I tried to check it by inspecting ntuple->GetSelectedRows(), which is -1 in case of errors, but shortly after, my application crashes with segfault. What is the right
way? On the machines I need to use it, we have versiion
5.16/00 27 June 2007
Thanks

[quote]I tried to check it by inspecting ntuple->GetSelectedRows(), which is -1 in case of error[/quote]This is a priori a good way to check.

[quote]but shortly after, my application crashes with segfault.[/quote]A priori this should not be related to the failed selection … unless you are access GetV1,2,3 even in case of failure …

Cheers,
Philippe

In this case I don’t access the GetV1 etc arrays…
This is the output, maybe it helps:

Hi,

I can not reproduce this problem (in my example TSelectorDraw::TakeAction is not even called when the selection is invalid). Can you send me the content of your function named “tab::prepare_graph”?

Thanks,
Philippe

Still alive here… is not anymore printed…
Thanks

Hi,

Please note that this linentuple->Draw(draw_cmd,get("Condition").c_str(),"goff");is suspicious. Unless get return the std::string by reference, it possible that the returned (by value) string is deleted before the result of c_str() is being used hence leading TTree::Draw to use a random value. However this does not quite match your symptoms since you are seeing it crash in (I am somewhat guessing):ntuple->Draw(xfield.c_str(),"","goff");

Also I still can not reproduce your problem. Would you be able to provide a complete running example?

Cheers,
Philippe.

Sorry. The reason was, that ‘Condition’ could occasionally be an empty string. Segfault occured in this case in the following line (which was supposed to check weather ‘Condition’ is the faulty string)

This is now checked, it works nicely. However, this case could be handled by TNtuple::Draw, instead of causing a segfault.

Concerning the temporary variables: I remember some statement by Stroustroup, that temporary variables have a lifetime until the whole expression is evaluated, so therefore my solution seems to be safe, but I might be wrong…

[quote]Concerning the temporary variables:[/quote]I am pretty sure you are correct.

[quote]However, this case could be handled by TNtuple::Draw, instead of causing a segfault. [/quote]Interestingly, I am still not able to reproduce this problem :frowning: Hence I don’t know exactly where to fix it. If you had a debug version of ROOT, it would be interesting to see exactly where the crash is happening.

Cheers,
Philippe.

My ‘hacky’ way of checking if a formula compiles correctly

  1. Create a TTreeFormula( “name”, “formula”, tree );

  2. If your TTreeFormula::GetTree() is NULL, then the formula did not compile.

pcanal - any idea if this is a valid thing to do? It’s the only way I could find to do this - I wish there was an easier (more clear) way - sometimes you might not want to actually draw the formula to find out if it’s possible (in the case of big trees for example).

Cheers,

  • Peter

Hi,

Creating a TTreeFormula is indeed the correct way to check whether a formula is correct or not. Rather than GetTree()==0, I recommend tesrting: GetNdim()==0.

Cheers,
Philippe