When using TTree::MakeClass, I was always wondering what is the Notify() method good for. In the comment it says
As I do not have the need to make changes and obviously the method is not doing anything but returning “kTrue” (which is currently not used), I would remove this function simply to reduce the amount of source code.
However, now I checked the implementation of TTree::Notify(). I do not really understand what it does, but it is more than just returning kTrue. Now I have two questions on this:
- When/Where is TTree::Notify() typically called?
- Shouldnt MyClass::Notify() call the underlying TTrees Notify() ? (where myclass is the output of MakeClass())
TTree::Notify is usually called to tell the TTree that something that it relies on as changed and vice et versa.
[quote] Shouldnt MyClass::Notify() call the underlying TTrees Notify() ? (where myclass is the output of MakeClass())[/quote]No, the intent is the reverse. The TTree would notify your class that something fundamental has changed (for example in the case of a TChain when its switch from one file to the other) so that you can react. In the case of MakeClass there is usually nothing to do there.
Thanks for the explanation.
I use MakeClass and then I change the code to have the underlying TTree as a private member. Thus (hopefully) my class is in control of any fundamental changes to the TTree and I think for me it is save to just ignore calls to Notify.
Just for curiosity: How does the TTree call my class? Do you mean the calls to Notify in the automatically created code (e.g. after construction and when the current file changes in a TChain)?
Your class (the result of MakeClass) would be called back if/when it is registered with the TTree by calling TTree::SetNotify.