Simple Analysis Using TTree::Draw

In the “Simple Analysis Using TTree::Draw”:
one can find:
root[] TTree *MyTree = T
This is misleading for a newcomer (it will not work when used in a macro).
I’d like to propose to change it into:
root[] TTree *MyTree; f.GetObject(“T”, MyTree)
Alternatively, one could leave the original “code” and add the new one with a note that it works in a macro.

[quote]This is misleading for a newcomer (it will not work when used in a macro).[/quote]Beside the missing ‘;’, it should also work in a macro (but not in compiled code) or am I missing something?


Well, my first idea was that the problem comes from a “named macro” (i.e. when used in a “function” / “subroutine”).
But now I’ve got another explanation.
If CINT already knows “T” as something (e.g. a “function”, “subroutine”, “variable”) then it will happily try to assign that “T” to “MyTree” without checking its type (i.e. without checking that it’s a “TTree *” and without looking into the opened root file for it -> that’s probably what happened to a “newcomer” who tried this “simple example”).
Anyhow, “automatically declared variables” (e.g. the “T” in the original “simple example”) are then valid for “outer parts” of expressions only, so it’s probably better to avoid them (and, of course, they will fail as soon as one tries to precompile ones macro).
So, I believe it makes sense to advertise the “proper way”.

Fair enough ; I expanded the text a little bit. (Still the point of this part of the text is to introduce the ability of CINT to automatically declare variables).