How to add data to an existing Root-tuple

Hi,
I want to simply add more data to a Rtuple, respecting the Tree
structure already in it.

Say that every day I want to add 24*60 more pairs, one per minute,
(timestamp, temperature) to a monitoring Rtuple.

This seems to be a really basic thing to do, but I haven’t been able
to find a working example yet. Until now I’ve been RECREATING
the Rtuple afresh every time, and running a bit longer,
but it really seems a silly thing to do. Thanks for any idea!

do:

[code] TFile *file = TFile::Open(“myfile.root”,“update”);
TTree T = (TTree)file->Get(“name of my ntuple”);
//set branch addrees for the Tree
T->SetBranchAddress(“branch1”,address of variable1 or pointer to object1)
T->SetBranchAddress(“branch2”,address of variable2 or pointer to object2)

//continue to fill
T->Fill();

//save the header again
T->Write();
delete file;
[/code]

Rene

Hi, and thanks for the prompt reply!
I did what you suggested, along these lines:

Bool_t startFresh = kFALSE;

TFile* f = 0;
TTree monitor = 0;
if ( startFresh ) {
f = new TFile(“rootOut/monitor.root”,“recreate”);
monitor = new TTree(“monitor”,“monitor TTree”);
monitor->Branch(“timeStamp”,&timeStamp,“timeStamp/i”);
monitor->Branch(“monData”,monData,“monData[15]/F”);
} else {
f = new TFile(“rootOut/monitor.root”,“update”);
monitor = (TTree
)f->Get(“monitor”);
monitor->SetBranchAddress(“timeStamp”,&timeStamp);
monitor->SetBranchAddress(“monData”,monData);
}

and run the program twice with startFresh = kTRUE, then kFALSE.

Now the problem is, in the output file I have 2 directories,
one for each run, and they both contain the sum of all data.
This is shown in the TBrowser window, and also doing this:

root [0] TFile _file0 = TFile::Open(“rootOut/monitor.root”)
root [1] .ls
TFile
* rootOut/monitor.root
TFile* rootOut/monitor.root
KEY: TTree monitor;2 monitor TTree
KEY: TTree monitor;1 monitor TTree

If I run the program every day for one year, I’ll end up having
365 directories. How can I avoid it? Thanks again!

These are not directories, only copies of the TTree header (one per Write).
If you do not want to keep all the cycles, instead do

T->Write(); do

T->Write("monitor",TObject::kOverwrite); //or kWriteDelete
see doc of TObject::Write at: root.cern.ch/root/html/TObject.h … ject:Write

Rene

Done! Thanks Rene…