Reusing a TChain

hi,
i have a TChain which includes say two TTrees. after looping over the events, i would like then, to remove the two TTrees from the TChain and add two new TTrees (with the same structure) in the same TChain. I wonder how i can easily implement this. I tried the TChain::Reset method, but it did not really help.
Does someone have some hint on how to easily do that?
TFile* f = TFile::Open(“file1.root”);
TTree* p = f->Get(“physics”);
p->MakeClass(“physics”);
.q
then
root
TChain* c = new TChain(“physics”);
c->Add(“file1.root”);
c->Add(“file2.root”);
physics* p = new phyics©;
for (int i=0; iGetEntries(); i++){
c->GetEntry(i);
// do what i need to do with p->som_variable
}

then i want to do in the same ROOT session
c->Reset();
c->Add(“file3.root”);
c->Add(“file4.root”);
p->Init©;
for (int i=0; i< c->GetEntries(); i++){
c->GetEntry(i); // but here, it returns a size==0
}

What am doing wrong here?
i will be grateful for help.

Hi,

I can not reproduce this problem. Which version of ROOT are you using? Note that recreating the TChain object (rather than ‘Reseting’ the existing one) should be a good work around.

Cheers,
Philippe.

[quote=“pcanal”]Hi,

I can not reproduce this problem. Which version of ROOT are you using? Note that recreating the TChain object (rather than ‘Reseting’ the existing one) should be a good work around.

Cheers,
Philippe.[/quote]
hi Philippe;
indeed i am using 5.26.00e. with a compiled standalone application. i will move to the approach you’re suggesting. thanks