Re: [ROOT] Problem with TClonesArray as Branch

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Sep 18 2003 - 12:11:19 MEST


H-Gerd,

You descrive very well the points 1,2 and 3. But in your point 4,
you do not say if you set the branch address. This is mandatory if your class
in the TClonesArray contains complex structures

Rene Brun

"H.-Gerd Rosarius" wrote:
> 
> Hello Rooters,
> 
> I have problems with writing a TClonesArray to a root-file
> and my work doesn't look to different from the Event/Track
> examples coming with ROOT.
> 
> However, let me describe the situation in detail first.
> 
> 1. I wrote an own class, called WARequest, which serves as a
>    kind of data container for different variables of type
>    string, map<string,string>, Double_t, etc.
>    It is derived from TObject.
>    That class includes the ClassDef-/ClassImp-Makros and a
>    dictionary-file is generated with rootcint successfully.
> 
> 2. In my main application I have a TClonesArray which is
>    filled with n objects of type WARequest. The objects
>    in TClonesArray are still fine after filling the array, because
> 
>    WARequest* r = (WARequest*) myClonesArray->At(0);
>    cout << r->getValue() << endl;
> 
>    returns a senseful string like "Hello world!" to the console.
> 
> 3. I want to use a TTree that holds a TClonesArray with my
>    WARequest-Objects as branch. Therefore I coded (shortened):
> 
>    TClonesArray* aBuf = new TClonesArray( "WARequest", 100 );
> 
>    dT = new TTree( "myTree", "No description" );
>    dT->Branch( "myArrayBranch", "TClonesArray", &aBuf, 32000, 99 );
> 
>    and I fill the tree with
> 
>    aBuf = myClonesArray;
>    dT->Fill();
> 
>    At this point all objects in TClonesArray are still in
>    a fine condition.
> 
> 4. I write the tree and close the file.
> 
> When I read the file, get the tree, open the branch, get an entry
> and access the TClonesArray, TClonesArray::GetEntries() returns
> the right number of objects inside.
> If I take an object from TClonesArray and want to get data from
> the object, say again for example
> 
>  WARequest* r = (WARequest*) myClonesArray->At(0);
>  cout << r->getValue() << endl;
> 
> the output consists of strange characters.
> 
> It seems the objects in TClonesArray "forget" the values
> in their fields.
> 
> What is happening here? Am I doing something wrong? If so, what?
> 
> Thanks for any help.
> 
>   H.-Gerd Rosarius
> 
> Tech: Using ROOT 3.05/03 made from source with g++ 3.0.4, running
>       on a Debian Linux box.
> 
> 
> 
> 
> 
> 
> 
> 
> 
>



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET