first the prelimaries:
Int_t split = 1; // by default, split Event in sub branches
TOscarEvent *event=0; // Event class
TOscarFileHeader *fheader; // File header class, to be stored only once
TParticle particle; // aka Track in Event example
TFile *hfile = new TFile("Event.root","RECREATE","TTree ROOT file");
TTree *tree = new TTree("T","ROOT tree");
// now create (super)branch for file header
TBranch *FileHeaderBranch =
tree->Branch("fHeaderBranch","TOscarFileHeader", &fheader, bufsize,split);
// ... construct fheader object
fheader = new TOscarFileHeader();
// ... fill fheader object
nb += tree->Fill(); //fill the tree
delete fheader;
// now create (super)branch for events
TBranch *EventBranch =
tree->Branch("EventBranch", "TOscarEvent",&event, bufsize,split);
// now in loop over events...
event = new TOscarEvent();
// ... construct and fill event object
nb += tree->Fill(); //fill the tree
delete event;
// and at the end
hfile->Write();
OK, now comes the problem:
Invoking tree->Fill() of course loops over all branches, i.e. the
fheader object gets written to file as often as the event object
instead of once (deleting it only causes the empty object to be written
to file). I then tried to replace the tree->Fill() statements by
nb += FileHeaderBranch->Fill();
and
nb += EventBranch->Fill();
respectively, hoping that now only the branches of the indicated
(super)branch are filled and that I could thus write fheader only once to
the tree file.
The code compiled without error messages and generated the the outputfile;
however, it contained no readable data.
I'd be grateful for any advice you could give,
thanks a lot,
Steffen
--------------------------------------------------------------------------
Steffen A. Bass phone : [01] 919 660 2570
Duke University, Dept. of Physics fax : [01] 919 660 2464
Box 90305, Durham N.C. 27708-0305, USA e-mail: bass@phy.duke.edu
--------------------------------------------------------------------------