Stefano Dusini wrote:
> It is not enough to set the pointer to the object in the folder equal
> to the new created object pointer?
NO. When TTree::Branch(cont char* folder) is called, the branchse are
automatically created with ewhat you have in the folder at this point in
time.
Note also that what you do is not good. You assign vertex=v1, making a
memory leak!
Rene Brun
>
> >> 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
>>>
>
>
Received on Tue Oct 20 2009 - 08:31:49 CEST
This archive was generated by hypermail 2.2.0 : Tue Oct 20 2009 - 17:50:03 CEST