TTree of TObjArray of TClonesArray

Hi all,
I would like to implement the storage model in subj, and for that playing with
code:

void Tree()
{
  const char *descrip="branch of TObjArray of 2 TClonesArray of TVector3";
  const char *filename="~/kir.root";
  const char *treename="Tree";
  const char *branchname="Branch";
  
  TFile *pFile=TFile::Open(filename,"RECREATE");
  TTree *pTr=new TTree(treename,descrip);
  
  TObjArray *pLstAll=new TObjArray(2); 
  pLstAll->SetOwner();   
  pTr->Branch(branchname,&pLstAll,32000,0); //here set split to 1

  TClonesArray *pLst[2];  
  for(Int_t i=0;i<2>AddAt(pLst[i]=new TClonesArray("TVector3"),i);  
  
  for(Int_t iEvt=0;iEvt<3;iEvt++){
    
    for(Int_t iHit=0;iHit<iEvt;iHit++) 
      new((*pLst[0])[iHit]) TVector3(iEvt,iHit,111);
    
    for(Int_t iHit=0;iHit<iEvt>Fill();
    pLst[0]->Clear();
    pLst[1]->Clear();
  }
  
  pTr->Write();      
  delete pFile;      
  pLstAll->Delete();
  
  pFile=TFile::Open(filename);
  
  pTr=(TTree*)pFile->Get(treename);
  
  pTr->SetBranchAddress(branchname,&pLstAll); 
  
  for(Int_t i=0;i<pTr>GetEntries();i++){
    pTr->GetEntry(i);
    pLst[0]=(TClonesArray*)pLstAll->At(0);
    pLst[1]=(TClonesArray*)pLstAll->At(1);
    Printf("Event %i first list:",i);pLst[0]->Print();
    Printf("Event %i second list:",i);pLst[1]->Print();
  }  
}

If i fill the tree in spliting mode the message that splitting for TObjArray is not allowed is printed also claiming that split is reset to 0, but in this case
there are problems namely no entries for the first list and only single entry for the second. In case i put no spliting manually everything works as expected.
I can’t figure out what is going on.

I use v5-13-06 selfcompiled on SLC4

Hi,

When copy/paste code, please disable the HTML in your post.

[quote]I would like to implement the storage model: TTree of TObjArray of TClonesArray[/quote]What is your intent? What are your goals.

TObjArray can not be split (and apparently your hit some sort of problems in the code trying to change the request). In consequence, the advantage of TClonesArray (since they are not going to be split) is going to be must less than it could have been.

Cheers,
Philippe.

PS. Please provide a running example, if you need the odd behavior to be fixed.

Hi,

I have N lists of the same objects, say MyHit. Each list holds hits for one out of N identical detectors. I would like to store them in separate lists because they need to be processed separately. Storing them in the single list is not affordable as i need to extract subset of hits for the same detector part few times per event. Other possibility is to assign separate branch to each TClonesArray,
but this means i need to do something like

TClonesArray *pCA[N];
for(int i=0;i<N>SetBranchAddress(Form(Name%i",i),&pCA[i]);

in few different classes.
Working macro in attachment.
Tree.C (1.28 KB)

[quote]but this means i need to do something like …[/quote]This is indeed, in my opinion, the best way to store the object in your cases. You will gain the full advantages of splitting: you’ll be able to read each ‘detectors’ independently, you’ll be able to browse your file in the gui, you’ll be able to use TTree::Draw on your data [none of which would work with a TObjArray of].

Cheers,
Philippe