How to empty the previous tree content I have chained?

I have different root file with the same tree name, and now I want to chain them separately with same TChain name , like this:

TChain  *fchain=new TChain("cc","");
for(int i=0;i<2;i++)
{
   if(i==0)
    {
       fchain->Add("one.root");
    }
  if(i==1)
   {
      fchain->Add("two.root");
   }
}

and then, I need to SetBranchAddress and some calculation, and this is the same for the two files. The critical point is that when the i==1 cycle end, I hope that the first file can be cleared. Does ROOT can achive this?

The piece of code you sent is equivalent to:

TChain  *fchain=new TChain("cc","");
fchain->Add("one.root");
fchain->Add("two.root);

No need for a loop. But may be that’s not your real code and in reality you define the filename according to i ? Anyway we would need a bit more code to understand your problem.

Maybe you want fchain->Reset();?

when i=1, I chaine the first file, and do some something to get a result;
when i=2, I chaine the second file, and do the same thing to get another result;
and last, I need to use the two result to get my final result. So I hope that I can clear the previous root. and every time chaine different root file.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.