#include "TFile.h" #include "TTree.h" #include "TRef.h" #include "TRefArray.h" class Track : public TObject { public: Int_t id ; TRef ref; Track(){} ~Track(){} ClassDef(Track,1) }; class Vertex : public TObject { public: Int_t id ; TRefArray tks; Vertex(){} ~Vertex(){} ClassDef(Vertex,1) }; ClassImp(Track) ClassImp(Vertex) //-------------------------------------------------------------- void writeref() { printf("------- write ------------\n"); TFile f("reftree.root","RECREATE"); TTree *t = new TTree("reftree","ref tree"); Vertex *vtx = new Vertex(); Track *trk = new Track(); t->Branch("vtx","Vertex", &vtx); //t->BranchRef(); //Int_t ObjectNumber = TProcessID::GetObjectCount(); for(int iv=0; iv<3; iv++) { vtx->id=iv; vtx->tks.Clear(); for(int it=0; it<2; it++) { TObjString *str = new TObjString( Form("ev = %d track = %d",iv,it)); trk->id = iv*1000+it; trk->ref=str; vtx->tks.Add(trk); printf("trk id = %d \t",trk->id); trk->ref.GetObject()->Print(); } int ntr = vtx->tks.GetEntries(); printf("vertex = %d ntr = %d\n\n", iv, ntr ); t->Fill(); } //TProcessID::SetObjectCount(ObjectNumber); t->Write(); f.Close(); } //-------------------------------------------------------------- void readref() { printf("------- read ------------\n"); TFile f("reftree.root"); TTree *t = (TTree*)(f.Get("reftree")); //t->Print(); Track *trk = 0; Vertex *vtx = 0; t->SetBranchAddress("vtx", &vtx); int nentr = t->GetEntries(); printf("tree with %d entries\n", nentr); for(int iv=0; ivGetEntry(iv); int ntr = vtx->tks.GetEntries(); printf("vertex %d ntr = %d\n",vtx->id, ntr); for(int it=0; ittks.At(it)); printf("iv = %d it=%d trk id = %d\t",iv, it, trk->id); trk->ref.GetObject()->Print(); } } f.Close(); } //-------------------------------------------------------------- void testref_tree() { writeref(); readref(); }