TClonesArrays and Trees

Hey everyone. This may be answered somewhere already, but I couldn’t find it. I’m trying to write a TClonesArray of a user-defined class to a tree that has several other branches. The tree seems to be written properly (the array size is normal in the writing code, and I can look at it in the browser and it’s there and seems fine) but when I try to read out the array in a loop, it always has size zero. Here’s the relevant code:

TClonesArray* DOMArray_ = new TClonesArray(“DOMInfo”, 100);

eventTree_->Branch(“EventID”, &EventID_, “EventID/I”);
eventTree_->Branch(“RunID”, &RunID_, “RunID/I”);
eventTree_->Branch(“DOMArray”, “TClonesArray”, &DOMArray_, 32000, 99);

DOMInfo* thisDOM = new((*DOMArray_)[DOMInfoCount_++]) DOMInfo();


Just before the fill statement, the size of the array is as it should be. I now try to do the following to read the array back in from my tree:

TChain* events = new TChain(“Events”);

TClonesArray* nugenDOMArray = new TClonesArray(“DOMInfo”, 100);

events->SetBranchStatus(“DOMArray”, 1);
events->SetBranchAddress(“DOMArray”, nugenDOMArray);

for(Long64_t i=0; i<nugenEntries; i++){
cout << nugenDOMArray->GetLast() << endl;

Now the size of the array always comes out as zero. This seems like it should work. Am I doing something obviously wrong? Thanks!


P.S. I forgot to mention that I load the relevant libraries that have my class definitions in them…


The call:events->SetMakeClass(1);explictly request the TTree to no longer use the ‘object model’. Consequently the information need to be retrieve in small pieces (See the result of MakeSelector on you TTree).

Also (once you removed the SetMakeClass), the code


PS. Also note that since you did put a trailing dot in the name of the branch (when creating) them, the SetBranchStatus is somewhat unhelpfull since it does NOT set the status of the subbranches