Hi Anton, When you use structs, you must be very careful. You cannot assume that the alignment by the compiler is the sum of the sizeof the constituents. To make branches from a struct, it is better to allocate each member to a different branch and pass the address of each member. In the case of classes, Root obtains the offset information directly from the compiler using the Showmembers function generated by rootcint. Concerning your questions about characters, I have made a small macro using your struct { gROOT->Reset(); typedef struct { Int_t adc1; Int_t adc2; char ticker[10]; } TData; TData tick; TTree *tree = new TTree("tree","testing structs"); tree->Branch("adc1",&tick.adc1,"adc1/I"); tree->Branch("adc2",&tick.adc2,"adc2/I"); tree->Branch("ticker",(void*)&tick.ticker[0],"ticker[10]/C"); for (Int_t i=0;i<20;i++) { tick.adc1 = i; tick.adc2 = 1000-i; sprintf(tick.ticker,"tick_%d",i); tree->Fill(); } tree->Print(); tree->Scan(); } Rene Brun > Anton Fokin wrote: > > Hi rooters, > > I wonder how to fill a tree with a C structure which contains > cnaracter strings. If I have > > typedef struct { > char ticker[10]; > Int_t adc1; > Int_t adc2; > } TData; > and do > > static TData Data; > > TBranch *branch = > tree->Branch("Data",&Data,"ticker/C:adc1/I:adc2/I"); > > it doesn't work (well, as expected although) and to get it working I > have to put my string variable at the bottom of the structure, i.e. > > typedef struct { > Int_t adc1; > Int_t adc2; > char ticker[10]; > } TData; > > > Could you comment this? Also, could you tell me if it is possible to > work with this character string in the TTree::Draw method? something > like "ticker==MUMMY" or ... > > Best, > Anton
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:36 MET