Re: Writing array in tree again

From: Pasha Murat (murat@cdfsga.fnal.gov)
Date: Sun Mar 22 1998 - 19:24:19 MET


	Hello, 

I modified your macro so it works properly now :
----------------------------------------------
{
  gROOT->Reset();
  Float_t  adc[16];
  TFile *file=new TFile("adc.root","RECREATE");
  TTree *tree=new TTree("tree","Testing still");
  tree->Branch("adc",&adc,"adc[16]/F");
  for(Int_t j=0;j<100;j++) {
    for(Int_t i=0;i<16;i++) adc[i]=i;
    tree->Fill();
  }
  tree->Write();
  tree->Print();
  file->Close();
}
---------------------------------------------
Note that tree->Draw("adc") is equivalent to tree->Draw("adc[0]")


						Regards, Pasha.
--------------------------------------------------------------------------------
Tadeusz Pytlos writes:
 > Hello Rooters,
 > I cannot understand what wrong with arrays written in the tree.
 > According to an article "Re: Newbie question..." I used simple macro arr.C
 > to generate adc.root.
 > {
 >   gROOT->Reset();
 >   Float_t adc[16];
 >   TFile *file=new TFile("adc.root","RECREATE");
 >   TTree *tree=new TTree("tree","Testing still");
 >   tree->Branch("adc",adc,"adc[nadc]/F");
 >   for(Int_t j=0;j<100;j++) {
 >     for(Int_t i=0;i<16;i++) adc[i]=5.0;
 >     tree->Fill();
 >   }
 >   tree->Print();
 >   tree->Write();
 >   file->Close();
 > }
 > Now while I'm trying to read the array
 > f=new TFile("adc.root")
 > f.ls()
 > tree.Print()
 > tree.Draw("adc")
 >      I see 100 events of value 5.0 but I ecpected 100*16=1600 events!!
 > tree.Draw("adc[0])
 >      I see 100 events of 5.0. It's OK.
 > tree.Draw("adc[1])
 >      I see 100 events of 0.0 !!
 > Next are similar. Sometimes even stranger
 > tree.Draw("adc[15])
 >      I see 100 events of 3.3 !!
 > What is also
 > tree.Draw("adc[16]) and next?
 > It seems that the array is write only into adc[0]. Why? The same with
 > the standalone program.
 > Would you tell me what I'm going wrong? I found a similar description in
 > the Thomas Hadig's article "Problem writing arrays", but I couldn't find
 > any answer.
 > Best wishes
 >           Tadeusz Pytlos
 > 
 > --
 > Tadeusz Pytlos        
 > mailto:pytlos@fizwe5.fic.uni.lodz.pl 
 > Lodz, Poland                                                 



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