Re: [ROOT] C structure as a branch?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Nov 21 2002 - 16:25:40 MET


Hi,

Create classes instead of struct as shown below

Rene Brun


#include "TTree.h"
#include "TFile.h"
#include "TRandom.h"
   
class SmdPeak {

public:
  Float_t peakPos;
  Float_t peakEnerg;
  Float_t sigmaPeak;
  Int_t   corSimuPeak;
  bool    used;
  
  SmdPeak() {}
  
  ClassDef (SmdPeak,1)
};

class FitEvent {

public:
        UInt_t  runnumber;
        Int_t   event;
        Int_t   numbXPeaks;
        Int_t   numbYPeaks;
        Float_t tower[4][3];
        Float_t smdX[61];
        Float_t smdY[101];
        SmdPeak xPeak[4];
        
        ClassDef(FitEvent,1)
};

void struct2()
{
   TFile f("struct.root","recreate");
   TTree T("T","test struct");
   FitEvent *event = new FitEvent;

   T.Branch("first","FitEvent",&event);
   for (Int_t i=0;i<1000;i++) {
      event->event = i;
      event->runnumber = (UInt_t)(100*gRandom->Rndm());
      //for (Int_t j=0;j<event.count;j++) event.meas[j] = i+j;
      T.Fill();
   }
   T.Print();
   T.Show(45);
   T.Write();
}


On Wed, 20 Nov 2002, Yiqun Wang wrote:

> Hi,
> 
> Is there a way to create a branch that is an array of C structure? The
> online reference on
> 
> TBranch(const char *name, void *address, const char *leaflist, Int_t
> basketsize, Int_t compress) :TNamed(name,leaflist)
> 
> only talked about a C structure branch.
> 
> My header file is like this:
> 
> 
> typedef struct{
>   Float_t peakPos;
>   Float_t peakEnerg;
>   Float_t sigmaPeak;
>   Int_t   corSimuPeak;
>   bool    used;
> } SmdPeak;
> 
> typedef struct{
> 
> 	UInt_t  runnumber;
> 	Int_t   event;
> 	Int_t   numbXPeaks;
> 	Int_t   numbYPeaks;
> 	Float_t tower[4][3];
> 	Float_t smdX[61];
> 	Float_t smdY[101];
> 	SmdPeak xPeak[4];
> SmdPeak xPeak[4];
> } FitEvent;
> 
> 
> 



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:20 MET