Hi Nicolas, You cannot assume that elements in a C struct are aligned. Use a class instead of a C-struct if the length of the struct members are different. In case of a class the dictionary is used to return the right offset of each member inside the class. Your example will work if you change the position of the element "t" typedef struct { Float_t x,y,z; Float_t t; Char_t c[4]; } POINT; .. tree->Branch("tree",&point,"x/F:y/F:z/F:t/F:c/C4"); Rene Brun On Thu, 27 Mar 2003, Nicolas Produit wrote: > Hi, > > I try to have a tree with some string members. > According to the doc the "/C" is used for that. > But it is not clear to me how exactly to use it. > I have tried many variations around following code all without success: > > #include "TFile.h" > #include "TTree.h" > > main(int argc, char **argv){ > TFile hfile("htree.root","RECREATE","Test for char"); > > typedef struct { > Float_t x,y,z; > Char_t c[4]; > Float_t t; > } POINT; > static POINT point; > > TTree *tree = new TTree("T","Bla"); > tree->Branch("tree",&point,"x/F:y/F:z/F:c/C4:t/F"); > > for ( Int_t i=1; i<10; i++) { > point.x = i; > point.y = 5*i; > point.z = 20*i; > point.t = 100*i; > sprintf(point.c,"bl%d",i); > tree->Fill(); > } > tree->Print(); > hfile.Write(); > hfile.Close(); > > return 0; > } > > Compiling it then > Running it gives: > isdcpc7:~/investigate 213> ./a.out > > ****************************************************************************** > *Tree :T : Bla > * > *Entries : 9 : Total = 13113 bytes File Size = > 0 * > * : : Tree compression factor = 1.00 > * > ****************************************************************************** > *Br 0 :tree : x/F:y/F:z/F:c/C4:t/F > * > *Entries : 9 : Total Size= 12883 bytes File Size = > 0 * > *Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 > * > *............................................................................* > > But then: > isdcpc7:~/investigate 214> root > > ******************************************* > * * > * W E L C O M E to R O O T * > * * > * Version 3.04/02 5 March 2003 * > * * > * You are welcome to visit our Web site * > * http://root.cern.ch * > * * > ******************************************* > > Compiled for linux with thread support. > > CINT/ROOT C/C++ Interpreter version 5.15.68, Dec 12 2002 > Type ? for help. Commands must be C++ statements. > Enclose multiple statements between { }. > root [0] a = new TFile("htree.root") > (class TFile*)0x875a220 > root [1] T->Scan() > ************************************************************************ > * Row * x * y * z * c * t * > ************************************************************************ > * 0 * 1 * 5 * 20 * bl1 * 1.772e-41 * > * 1 * 2 * 10 * 40 * bl2 * 1.808e-41 * > * 2 * 3 * 15 * 60 * bl3 * 1.84e-41 * > * 3 * 4 * 20 * 80 * bl4 * 1.880e-41 * > * 4 * 5 * 25 * 100 * bl5 * 1.916e-41 * > * 5 * 6 * 30 * 120 * bl6 * 1.952e-41 * > * 6 * 7 * 35 * 140 * bl7 * 1.988e-41 * > * 7 * 8 * 40 * 160 * bl8 * 2.02e-41 * > * 8 * 9 * 45 * 180 * bl9 * 2.059e-41 * > ************************************************************************ > (Int_t)9 > > > >
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:10 MET