It is not enough to set the pointer to the object in the folder equal to
the new created object pointer?
>> vertex = v1;
or do I have also to call for each entry in the tree
m_vxFold->Add(v1);
Thanks a lot
Stefano
Rene Brun wrote:
> You get in the Tree what you put in the folder!
> You create a RVertex with your default constructor and add it to the
> folder, then you create another RVertex with the argument 100
> but DO NOT PUT it in the folder!
>
> Rene Brun
>
> Stefano Dusini wrote:
>> Hello,
>>
>> I am creating a Tree with a Branch from a Folder according to the
>> following scheme:
>>
>> TFile *fOut = TFile::Open("testVertex.root","recreate");
>> TTree *outTree = new TTree("TreeVX","Vertex output");
>>
>> //create the folders
>> TFolder *m_topFoldVX = gROOT->GetRootFolder ()->AddFolder ("topFoldVX",
>> "Top Level Folders");
>> gROOT->GetListOfBrowsables()->Add (m_topFoldVX, "topFoldVX");
>> TFolder *m_vxFold = m_topFoldVX->AddFolder("Raw","raw data");
>>
>> //create the objects. Both are public TNamed
>> RVertex *vertex = new RVertex();
>> vertex->SetName("Vertex");
>> RTrack *track = new RTrack();
>>
>> //Add the object to the folder
>> m_vxFold->Add(vertex);
>>
>> //create the branch from the folder
>> outTree->Branch(m_topFoldVX->FindFullPathName(m_vxFold->GetName())+1)
>>
>> //Fill the objects
>> RVertex *v1 = new RVertex(100);
>> RTrack *t1 = new RTrack(11);
>>
>> // The track t1 is added to a TObjArray which is a private member of
>> // the RVertex class
>> v1->AddTrack(t1);
>> REMULTrack *t2 = new RTrack(12);
>> v1->AddTrack(t2);
>>
>> // Fill the tree
>> vertex = v1;
>> outTree->Fill();
>>
>> //new vertex
>> RVertex *v2 = new RVertex(101);
>> RTrack *t3 = new RTrack(21);
>> v2->AddTrack(t3);
>>
>> vertex = v2;
>> outTree->Fill();
>>
>> fOut->Write();
>> fOut->Close();
>>
>> This code create a tree with two entries but with the RVertex class
>> which has the values given by the default constructor and not the
>> values given in the code (100,101) and in particular the TObjArray
>> containing the tracks is always empty.
>>
>> But if instead of creating the Branch from the folder I do it explicitly
>>
>> TFile *fOut = TFile::Open("testVertex.root","recreate");
>> TTree *outTree = new TTree("TreeVX","Vertex output");
>>
>> //create the objects
>> RVertex *vertex = new RVertex();
>> vertex->SetName("Vertex");
>> RTrack *track = new RTrack();
>>
>> outTree->Branch("vertexBranch", "REMULVertex",&vertex,16000,2);
>>
>> //Fill the objects
>> RVertex *v1 = new RVertex(100);
>> RTrack *t1 = new RTrack(11);
>>
>> // The track t1 is added to a TObjArray which is a private member of
>> // the RVertex class
>> v1->AddTrack(t1);
>> REMULTrack *t2 = new RTrack(12);
>> v1->AddTrack(t2);
>>
>> // Fill the tree
>> vertex = v1;
>> outTree->Fill();
>>
>> //new vertex
>> RVertex *v2 = new RVertex(101);
>> RTrack *t3 = new RTrack(21);
>> v2->AddTrack(t3);
>>
>> vertex = v2;
>> outTree->Fill();
>>
>> fOut->Write();
>> fOut->Close();
>>
>> the tree is correctly filled with the correct objects.
>>
>> Can you please tell me what is wrong with the first example.
>>
>> Thanks a lot for your help.
>> Stefano
>>
--
__________________________________________________________________
Stefano Dusini, INFN Padova, Via Marzolo, 8 I-35131 Padova, Italy
Phones: +39-049-827-7312 +39-049-789-7676. Handy +39-348-8137991
Received on Tue Oct 20 2009 - 08:26:21 CEST