Re: problem writing TTree

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Thu, 31 Jan 2008 20:06:37 +0100


Dan,

Simply replace your 38 lines calling tree->Branch by ONE single call

     tree->Branch("t","rootTree",this);

This call will automatically create as many branches as you have data members in your class rootTree.
As, of course, you do not want to put some members like tree,file,debug, modify your rootTree.h file
add a "!" as the first character if the comment field, ie

   TTree* tree; //!
   TFile* file; //!
   bool debug; //!

For more details, read the chapter about creating a Tree from a class in the Users Guide.

Rene Brun

Dan Holmes wrote:
> thanks rene, spot on, that has solved the problem in one go.
>
> ..of course i am interested in turning my 38 Branch calls into one if
> possible! (or if you have any other suggestions! :) )
>
> cheers,
>
> Dan.
>
>
>
> Rene Brun wrote:
>> Dan,
>>
>> I cannot test your problem without your input data set. However, I
>> strongly suggest to change
>> tree = new TTree("data","SPData");
>> file = new TFile("temp/SPDAQTree.root","recreate");
>> for
>> file = new TFile("temp/SPDAQTree.root","recreate");
>> tree = new TTree("data","SPData");
>>
>> I have a comment on your class rootTree. Your 38 calls to
>> tree->Branch can be replaced by one single call ::)
>>
>> Rene Brun
>>
>> Dan Holmes wrote:
>>> Hi ROOT support,
>>>
>>> ..sorry if i missed this in some faqs somewhere..
>>>
>>> I have problems with some code that fills and writes a tree. It was
>>> working ok on slc3/root 5.04, (linked afs version) for many years
>>> but now i have upgraded to slc4, downloaded binaries (and am trying
>>> 5.16, 5.18).
>>>
>>> I have attached my set of .cpp files (makeTree wraps readData which
>>> uses the rootTree object). I suspect you don't want to look at any
>>> of them apart from rootTree.cc.
>>>
>>> The whole thing compiles ok.::
>>> g++ -o makeTree.exe makeTree.cpp `root-config --cflags --libs`
>>> The problem comes when the destructor to readData is called and
>>> rootTree class tries to do TTree*->Write(). I get the horrible
>>> error string attached.
>>>
>>> Anyone know what i'm doing wrong or have any pointers??
>>>
>>> cheers,
>>>
>>> Dan.
>>
>
Received on Thu Jan 31 2008 - 20:06:49 CET

This archive was generated by hypermail 2.2.0 : Fri Feb 01 2008 - 17:50:01 CET