Chain, Friend, Howto?

Dear Rooters,

how can one use treesfriends that might have more than one file? To clear up the question. Here is what I got:
During my analyzis I am creating 3 trees. Each one is stored in a different file. I am filling them at the same time. So in each tree there is the same amount of events stored in. Unfortunatly one of the trees becomes very large, so that root will open a new file for this tree. After the analyzis I end up with several files:


Now I want to do a further analyzis of the entries in these trees. In some cases I need the information from all of the trees. So I tried to create chains and friends. Using the follwing procedure:

TChain ChainOne("TreeOne");
TChain ChainTwo("TreeTwo");
TChain ChainThree("TreeThree");
int nOneFiles = ChainOne.Add("TreeOne*.root");
int nTwoFiles = ChainTwo.Add("TreeTwo*.root");
int nThreeFiles = ChainThree.Add("TreeThree*.root");


here the branches are set with
ChainThree.SetBranchAddress("BranchName", &pointerToClass);

the nXFiles gives me the right result (ie. 1 for two and three and 3 for one).

Now if I want to analyze the entries, I use ChainThree.GetEntry(fEntryIterator++);
to get them and analyze them. This works only fine if there is only 1 file for each tree. But the above scenario, this does not work. I will not get the entry of TreeOne. (I can check how many things are inside TreeOne, and it tells me that there are 0). But I see that it loads it to memory, because the memory quickly fills up.

What Do I do wrong here? I have checked, that when using int nOneFiles = ChainOne.Add("TreeOne.root");
(so leaving the star out) It will read the entries correctly as long as it is working on file TreeOne.root but at the point where it has to switch to the next file (TreeOne_1.root) it will only read zeros.

Can you tell me the right procedure, how to procede in my case?

Thank you,


You need to add the chain as friend by pointer rather than by name. With ChainThree.AddFriend("TreeOne"); you end up adding the TTree instead of the TChain. So you need to do:ChainTree.AddFriend(&ChainOne); ChainTree.AddFriend(&ChainTwo);