Hi all,
I have a class storing variables that also have functions defining some derived value vased upon this variable, e.g.:
class MyClass : public TObject {
public:
double MyVar; // a variable
double GetDerivedValue() const
{
// perform some calculation based on MyVar
...
}
};
The problem is, if this is stored in a tree and then one calls the draw command:
tree->Draw("MyClass.GetDerivedClass()");
this can be very slow because the entire object must be pulled in (of course) to properly call the function.
My question is the following: Is it possible to somehow have a Hook called for this class when it’s Filled in a tree (and/or written to a file) that calculates cached variables in protected variables?
For example:
class MyClass : public TObject {
public:
double MyVar; // a variable
double GetDerivedValue() const
{
// perform some calculation based on MyVar
...
}
virtual void SomeHook()
{
MyDerivedValue = GetDerivedValue();
}
protected:
double MyDerivedValue; // cached value
};
MyClass* my = new MyClass();
tree->Branch("MyBranch", my);
my->MyVar = 1.;
tree->Fill(); // Somehow calls MyClass::SomeHook() to fill the protected variables
I’ve had a look in the code to see if there are any hooks called before a Fill for a TObject, but I can’t find any. Does anyone have any ideas of how one might do this? The advantage would be of course to be able to have fast access to this value in a TTree::Draw command.
I of course understand this could be done manually, but ensuring this is done could be relatively error prone.