I need to check the name of a TClonesArray (TClonesArray::GetName(), i.e., the class name of the contained objects) contained in a branch of a TTree. The problem is that the address of that branch might have already been set in an external routine, so I cannot simply set the branch address to a temporary TClonesArray buffer, read the first entry and call temporary->GetName(). I tried to clone the branch in this way:
The code behaves as desired, but I get this kind of errors on the console:
Warning in <TBranchElement::InitializeOffsets>: Branch 'tempCloneBranch' has no mother!
So I guess that cloning a branch is not a 100% safe operation, and even if the above code fits my purpose the error messages are very annoying. Can anyone please suggest me a smarter way to do this? Thanks.
You can probably also dobranch->GetEntry(0);
char *oldBuffer = branch->GetAddress();
TClonesArray *buffer = (TClonesArray*)oldBuffer;
if (!strcmp(buffer->GetName(),"MyClasss")){...
Note that neither solution works in all cases of TTree layout …
Cheers,
Philippe.
See TTreeFormula.cxx TBranchElement* bc = (TBranchElement*) branch;
if (bc == bc->GetMother()) {
// Top level branch
//clones = *((TClonesArray**) bc->GetAddress());
clones = (TClonesArray*) bc->GetObject();
} else if (!leafcur || !leafcur->IsOnTerminalBranch()) {
TStreamerElement* element = (TStreamerElement*) bc->GetInfo()->GetElems()[bc->GetID()];
if (element->IsaPointer()) {
clones = *((TClonesArray**) bc->GetAddress());
//clones = *((TClonesArray**) bc->GetObject());
} else {
//clones = (TClonesArray*) bc->GetAddress();
clones = (TClonesArray*) bc->GetObject();
}
}
Thanks Philippe, I’ll try with your solution if mine shows some problem (I’m lazy and since my impolementation seems to work I don’t want to touch it )