Root files and TTrees

Hi all,
Im having trouble understanding what is goin on in how my data is saved and how it is appears on the treeviewer.

In concept my program does the following:

TFile *root_file = new TFile(“all_data.root”, “RECREATE”);
TTree *root_tree = new TTree(“root_tree”, “tree1”);

root_tree->Branch(“data1”, &data1, “data1/F”);
root_tree->Branch(“data2”, &data2, “data2/F”);
root_tree->Branch(“data3”, &data3, “data3/F”);
root_tree->Branch(“data4”, &data4, “data4/F”);
root_tree->Branch(“data5”, &data5, “data5/F”);
for(int i; i<1000>fill();

root_tree->Draw(“data1:data2”,…);// draw a few graphs
root_tree->Draw(…);
}
root_file->Write();

when this is done and i look in the TBrowser, i can see 1 root_file.root file, when i click on it i see a number of root_tree folders as well as histograms. In each root_tree folder are the 5 leaves, although im not if there is a difference between branchs and leaves here.
The longer i let the loop run the greater the number of tree folders and histograms. The data in each of the folders are the exactly the same.
I dont know why this occurs.
Why is this happening and how can i make it so that i only get one root_tree folder?

thanks.
sorry for the long posting.

john

What you see are not folder but different ‘revision’ of the TTree object (and the histogram). Another name for those ‘revision’ is ‘cycle’. See the User’s guide or the documentation for TDirectory::Write for some explanation on how to minimize the number of cycle kept on file.
Also to prevent the (assumingly temporary) histogram on the file do
TH1::SetDirectory(0);
Cheers,
Philippe

Thanks for the reply.

This is interesting because one of the problems that i am having is that as my program runs and collects data it slows down dramatically. In my loop i get data, fill the tree and graph them versus time using the Draw() from TTree ( so there are 6 canvas with separate graphs in my gui mainframe). i can see that it is taking large amounts of memory at every loop with Windows task manager.
Speed is important in my application so i am wondering if this slow down is due to the Draw function saving a copy of every graph until the program ends or is this just the speed of graphing when I am tryin to update constantly so many graphs.

Could you send the shortest possible script(s) reproducing this problem.
The time to fill a Tree should be independent of the number of entries.

Rene

There are more efficient way of drawing the graph/histogram than what you have (which recreate histogram each time). For histogram, I would recommend:

TFile *root_file = new TFile("all_data.root", "RECREATE");
TTree *root_tree = new TTree("root_tree", "tree1");
gROOT->cd(); // if the histo are not suppose to go in the file
TH2F* myhisto = new TH2F("histname","title",... etc.... );
....
  myhisto->Reset();
  root_tree->Draw("data1:data2>>histname");
.....

Cheers,
Philippe.

Hi Rene,
Below is the short version of how my program is set up. i have a stop button that will stop the while(true) loop if pressed. The idea is that as i am reading the data from various channels and updating graphs and histograms at the same time. data1 and data2 both have a short term display of 20 points and a long term display and a histogram so that the display is as close to real time as possible.

int MyMainFrame::get_rdgs()
{
root_file = new TFile(comm, “RECREATE”);
root_tree = new TTree(“root_tree”, “tree1”, 0);
root_tree->SetBit(kCanDelete);

         root_tree->Branch("data1", &data1, "data1/F"); 
         root_tree->Branch("data2", &data2, "data2/F");  
         root_tree->Branch("data3", &data3, "data3/F"); 
         root_tree->Branch("data4", &data4, "data4/F"); 
         root_tree->Branch("data5", &data5, "data5/F");
         root_tree->Branch("data6", &data6, "data6/F");
  
         while(true)
         {
                gSystem->ProcessEvents();
             //start getting data from DAQ, filling appropriate branches.  
               //Data from DAQ is recieved in as an array(recieved_data[])
              int j=0;
             for (i=0; i<total_rdgs; i=i+3) 

{
switch (j)
{
case 0:
data1= recieved_data[i];
break;
case 1:
data2=recieved_data[i];
break;
//… etc etc for the rest of the variables.
}
j++; // next channel
}
root_tree->Fill();
graph_all();
}
}

void MyMainFrame::graph_all() // graph, update all canvas
{
fCanvas->cd(); root_tree->SetLineColor(1);
root_tree->Draw(“data1:time_b”,"", “CP”, 20,mintime);
fCanvas->Update();
fCanvas->Clear();

fCanvas1->cd();
root_tree->Draw("data2:time_b","", "CP", 20,mintime);	fCanvas1->Update();
fCanvas1->Clear();

            fCanvas2->cd();
root_tree->Draw("data1:time_b","", "CP");
fCanvas2->Update();
fCanvas2->Clear();
	
fCanvas3->cd();
root_tree->Draw("data2:time_b","", "CP");
fCanvas3->Update();
fCanvas3->Clear();

fCanvas6->cd();
root_tree->Draw("data1>>hmamon");
ma_hist = (TH1F*)gDirectory->Get("hmamon");
ma_hist->SetStats(kFALSE);
fCanvas6->Update();
fCanvas6->Clear();

fCanvas7->cd();
root_tree->Draw("data2>>hkvmon");
kv_hist = (TH1F*)gDirectory->Get("hkvmon");
kv_hist->SetStats(kFALSE);
fCanvas7->Update();
fCanvas7->Clear();

            fCanvas5->cd();   //multi plot
root_tree->SetLineColor(4); //color code 4= blue
root_tree->SetTitle(kFALSE);
            root_tree->Draw("data3:time_b","", "CP", 20,mintime); 	
            root_tree->SetLineColor(2); // 2= red
root_tree->Draw("data4:time_b","", "CP same", 20,mintime);// second plot 
fCanvas5->Update();
fCanvas5->Clear();

fCanvas4->cd();//multi plot
root_tree->SetLineColor(4); //color code 4= blue
root_tree->Draw("data5:time_b","", "CP", 20,mintime); //first plot 
root_tree->SetLineColor(2); // 2= red
root_tree->Draw("data6:time_b","", "CP same", 20,mintime);// second plot 
fCanvas4->Update();
fCanvas4->Clear();

}

ps. and as far as the histograms goin to file, i only need a final copy of the histogram to be saved, after all readings are finished. so i dont believe i need the gRoot->cd();

also lm not sure why using:

myhisto->Reset();
root_tree->Draw(“data1:data2>>histname”);

is not redrawing the histogram everytime. if i use this in my graph_all function i would have assumed that the hist would reset and redraw everything whenever the graph_all function is called.

[quote] is not redrawing the histogram everytime. [/quote]You probably also need a mycanvas->Modified(); mycanvas->Update();

Cheers,
Philippe