Re: ttree ntuple with UShort_t

From: Rene Brun (Rene.Brun@cern.ch)
Date: Mon Nov 15 1999 - 18:16:34 MET


Hi Selim,
This is an alignment problem and it is machine dependent.
When you use a class instead of a struct, rootcint can generate the
appropriate code (class::ShowMembers) to compute the relative offsets of
data members with respect to the pointer to the object.
With struct, the only thing that we can do is to assume that the
compiler
will store in memory the struct items serialy like in the struct
definition.
However, most compilers, for performance reasons, will do the alignment
to a 4 or even 8 bytes boundary (the longest element in the struct).
You SHOULD NOT use a struct as input for a branch if the struct contains
members of different sizes.
Use a class instead. This has the additional advantage that the element
names and types are known and the branch definition will be simpler.

Rene Brun

Selim Issever wrote:
> 
> Hi,..
> 
> either I am doing something stupid, or its real,..
> 
> I am creating Trees via the method A:
> 
>   TTree *tree = new TTree("t", "a tree");
>   tree->Branch("data", &data, formatstring);
> 
> for:
> formatstring = "a/F:b/F";
> struct { Float_t a; Float_t b; } data;
> it works,..
> 
> for
> formatstring = "a/s:b/F";
> struct { UShort_t a; Float_t b; } data;
> I get garbage diplayed, when rereading in the tree and plotting b (or whatever
> follows b),.. a itself is ok,..
> 
> error on my side?
> maybe it matters: I create from within a compiled function,.. and
> *   Version   2.21/05  10 February 1999   *
> 
> Thanks a lot
> Selim
> 
> --
> Selim Issever | Tel: 040 8998-2843    +- "Unser Oertchen ist viel ----
> DESY-F15      | Fax: 040 8998-4033    +- aelter als euer Scheiss-Marl.
> Notkestr. 85  | selim.issever@desy.de +-------  Diplomand ------------
> 22603 Hamburg/Germany   |  http://www.physik.uni-dortmund.de/~issevers



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:42 MET