TTree with Folders

From: Stefano Dusini <stefano.dusini_at_pd.infn.it>
Date: Mon, 19 Oct 2009 22:26:35 +0200


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 Mon Oct 19 2009 - 22:26:58 CEST

This archive was generated by hypermail 2.2.0 : Tue Oct 20 2009 - 11:50:03 CEST