Re: Pb in reading Trees...

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Oct 13 1999 - 11:32:03 MEST


Olivier,
Please read the limitations of split mode at URL:
   http://root.cern.ch/root/HowtoWriteTree.html
Loom at section "Making a Tree with many branches"
You will read:

*In split mode, a data member cannot be a pointer to an array of basic
types. A   variable size array must be encapsulated inside another
object derived from      TObject. 

The problem is that in split mode, we have no way to know that the
length
of the array is one of your data members.
One could imagine an extension like (just to take your example)

   Int_t  fTps_avt_stockage; //Nb canaux entre l'origne et le 1er
   FlashSpectrum *fSpectrum;  //[fTps_avt_stockage]Amplitude=f(tps des
coups par

where the string between [] gives the name of the branch containing the
count.

Rene Brun

Olivier Meplan wrote:
> 
> Hi Rooters!
> 
> I have a pb in reading (and perhaps in filling) a tree.
> The tree declaration I used is:
>         TTree *ptree_flash   = new TTree("FLASH",argv[1]);
>         event_flash = new EventFlash();
>         TBranch *b_flash
> =ptree_flash->Branch("EventFlash","EventFlash",
> &event_flash,bufsize,split);
> Then I fill the tree with:
>         event_flash=new EventFlash(dim_bloc,nb_burst,&buf[i]);
>         ptree_flash->Fill();
> where buf is UShort_t *buf=new UShort_t[lgb], (lgb being a given
> dimension).
> When I fill the tree, I used the method
>         event_flash->GetFlashSpectrum()->Show();
> in order to check what I am reading (and so what I hope to put in the
> tree).
> But when I try to read again the tree, the GetFlashSpectrum()->Show()
> method give me numbers which are completly different from the one I
> (hope to) fill in the tree.
> Is there some one who can tell me what I am doing wrong?
> Thanks very much,
> Olivier Meplan.
> -----------------------------------------------------------------------------
> 
> The definition of the class EventFlash is given in the file
> flash_flash.h, flash_spectrum.h (and the corresponding .C files):
> 
> // ========== flash_flash.h ===========
> class EventFlash : public TObject
> {
>  private:
>  Int_t  fNo_burst;  //Numero de burst
>  UShort_t fNo_voie_flash;  //Numero de la voie du flash touche
>         Int_t  fTps_avt_stockage; //Nb canaux entre l'origne et le 1er
> canal stocke
>         FlashSpectrum *fSpectrum;  //Amplitude=f(tps des coups par
> rapport au burst) pour chaque voie flash
> 
>  public:
> 
> EventFlash():fNo_burst(0),fNo_voie_flash(0),fTps_avt_stockage(0){fSpectrum=new
> FlashSpectrum();}
>         EventFlash(Int_t dim,Int_t burst,UShort_t *event);
>         ~EventFlash(){delete fSpectrum;}
> 
>         Int_t  GetNbBurt() const { return fNo_burst; }
>  UShort_t GetNumVoie() const {return fNo_voie_flash; }
>  Int_t  GetTemps_Avant_Stokage() const {return fTps_avt_stockage; }
>         FlashSpectrum *GetFlashSpectrum()  {return fSpectrum; }
> 
>  ClassDef(EventFlash,1)
> 
> };
> // ========== flash_flash.C ===========
> #include "flash_flash.h"
> 
> ClassImp(EventFlash)
> EventFlash::EventFlash(Int_t dim,Int_t burst,UShort_t *event) :
> TObject()
> {
>         fNo_burst=burst;
>         fSpectrum=new FlashSpectrum(dim);
> 
>         fNo_voie_flash=(*event & 0x00FF);
>         fTps_avt_stockage=*(event+1);
>         for(Int_t i=0 ; i<dim ; i++)
>         {
>                 GetFlashSpectrum()->FillSpectrum(i,(event[i+2] &
> 0x0FFF));
> 
>         }
> }
> // ========== flash_spectrum.h ===========
> class FlashSpectrum : public TObject
> {
>  private:
>         UShort_t *fFlashSpectrum;
>         Int_t  fSize;
> 
>  public:
>  FlashSpectrum(): fSize(10)
>         {
>                 fFlashSpectrum = new UShort_t[fSize];
>        }
>         FlashSpectrum( Int_t size)
>         {
>                 fSize=size;
>                 fFlashSpectrum = new UShort_t[fSize];
>         }
> 
>  ~FlashSpectrum(){delete [] fFlashSpectrum;}
>         void  FillSpectrum(UShort_t *spectrum)
>           {
>                                 for(Int_t i=0; i<fSize ; i++)
> fFlashSpectrum[i]=spectrum[i];
>           }
>         void  FillSpectrum(Int_t i,UShort_t val)
>           {
>            fFlashSpectrum[i]=val;
>           }
>         UShort_t *GetSpectrum(){return fFlashSpectrum;}
>         Int_t  GetSize(){return fSize;}
>         void  Show()
>           {
>                          for(Int_t i=0; i<GetSize(); i++)
>                                  cout<<"AMP:"<<fFlashSpectrum[i]<<endl;
>            }
>    ClassDef(FlashSpectrum,1)
> };
> //===============================
> 
> --
> =========================================================
> |Olivier Meplan             |E-mail:meplan@isn.in2p3.fr
> |                           |
> |ISN, 53 avenue des Martyrs |  Tel +33(0)4 76-28-41-90
> |F-38026 GRENOBLE cedex     |  Fax +33(0)4 76-28-40-04
> =========================================================



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