Is there a general way to find out what class was stored in a TClonesArray , in a branch of a TTtree in a TFile. I can get the leaf names so for example if the array contains a TVector3, then the leaf names can be found, terminating in .px,.py, .pz etc., but I can't find a way to discover that it was created from a TVector3. Can it be done, if so how?
Actually I found the answer elsewhere on this forum, here it is with explanatory comments added:
Assuming branch is a TBranch* …
char *oldBuffer=branch->GetAddress(); // current pointer to branch
Long64_t oldReadEntry=branch->GetReadEntry();// current entry number
TClonesArray *buffer=NULL; // pointer to an empty TClonesArray
branch->SetAddress(&buffer); // tell branch to go here!
branch->GetEntry(0); // read in the 0th entry into buffer
branch->SetAddress(oldBuffer); // return branch to original position
branch->GetEntry(oldReadEntry);//re-read original entry
Now you have an instance of the TClonesArray object stored in “buffer”, you can find out what TClass it is like this: buffer->GetClass();