Basic Question About Chaining Root Trees

I am working on a waveform acquisition program that takes data from a Tektronix Oscilloscope and transfers it to individual Root Tree files. My professor would now like me to merge that information such that all of the trees are in one file but can be searched for and individually accessed. I’m still fairly a newbie at ROOT (and am coding it in MSDEV .NET 7.1)., so I know this may have been a question that was covered. I would appreciate any help or examples (or links to the forum topic that already covered this).

A few technical pieces just for clarification:

  • I’m using ROOT Version 4.02
  • I’m Writing C++ Code in .NET 7.1
  • Each individual tree consists of two floating point branches
  • I’d also like to incorporate a time stamp into the signature (header?) of the tree.

I would appreciate any help. Thanks!

Use the TChain class

Rene

Alright I’m using the TChain class to put all of the individual root files I create into a single chain. Then I am merging this chain into a single file. My question is this, how do I access the indiviudal trees within the file (view one at a time and not all at once?)

Here is the code I used to do the described above:

TChain ch(“wfm”);
ch.Add(fileroot); // Bunch of times for each file created

ch.Merge(allroot);

// Allroot and fileroot have the full path information

Thanks!

[quote]Alright I’m using the TChain class to put all of the individual root files I create into a single chain. Then I am merging this chain into a single file. My question is this, how do I access the indiviudal trees within the file (view one at a time and not all at once?)
[/quote]More than just put the individual trees into one file, TChain::Merge creates a single file. I.e. by merging the trees you are losing the notion of individual trees (unless you have a way to tell from the data).

Cheers,
Philippe.

Thanks Philippe. Do you have an idea on how I could put all of the trees into one file without losing theire individuality. (Could I just name them different things and store them to the same file?) I could really use some help on this. The key is all in one but can still be individually accessed. Thanks for help so far and appreciate any help in future.

You will to be use TTree::CloneTree on each individual tree and make sure that you change their name.

Cheers,
Philippe.

After reading over the clone tree class I’m not exactly sure how this is supposed to solve my problem. Am I supposed to use this independetly or in conjunction with TChain? Also since the number of different trees is not fixed, how to I make sure I have different names (this one should be with variable but checking). If I use CloneTree will I be able to put them all in the same file. Example or extended explanation of thought process would be appreciated. Thanks!

[quote]Am I supposed to use this independetly or in conjunction with TChain?[/quote]It is probably easier not to use the TChain in this case.
For example of CloneTree see $ROOTSYS/tutorials and read copytree.C, copytree2.C and copytree3.C.

You simply need to do something like

TFile *newfile = new TFile("gathered.root","recreate"); int count; for each oldifle/oldtree { TFile *oldfile = new TFile(oldfiename); TTree *oldtree; oldfile->GetObject(oldtreename,oldtree); TTree *newtree = oldtree->CloneTree(); newtree->SetName(Form("newtree%d",count); newfile->Write(); delete newtree; ++count; }
Cheers,
Philippe.

Looks like exactly what I need. Let you know how it pans out. Thanks! :smiley: