Re: reading an array from a tree

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 03 Oct 2006 19:37:43 +0200


Instead of

 tree->SetBranchAddress("a",&a);
do
 tree->SetBranchAddress("a",a);
or
 tree->SetBranchAddress("a",&a[0]);

Rene Brun

Chiara.Zampolli_at_bo.infn.it wrote:
> Dear rooters,
>
> after having created a TTree with a 2-dimentional array, I am not able to
> retrieve the data I have stored... In the attached file you can find the macro
> I use to write the array in the tree, and then the tree in the file. Then, in
> order to retrieve it, I tried in a way similar to the ione used in the case of
> simple "elements":
>
> root [1] TFile *file = new TFile("outArrayS.root","READ")
> root [2] TTree *tree = (TTree*)file->Get("T")
> root [3] Short_t a[1500]
> root [4] tree->SetBranchAddress("a",&a)
> root [5] tree->GetEntry(0)
>
> but then, the objects I read are different from those I expected. For example,
> the 366th entry of array a should be (I think...) equal to 8 (the value of
> bincontent[367] in the macro).
>
> Could you help me in understanding what I am doing wrong?
> Thanks a lot.
> Best Regards,
>
> chiara
>
>
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
> ------------------------------------------------------------------------
>
> void testArrayS(){
> TH1F::AddDirectory(0);
> TFile * filein = new TFile("inTH1I.root","READ");
> TH1I *h1 = (TH1I*)filein->Get("hint");
> filein->Delete("hint");
> filein->Close();
>
> Short_t bincont[1500];
> for (Int_t i=0;i<1500;i++){
> bincont[i]=(Short_t)h1->GetBinContent(i+1);
> //cout << " bin = " << i << " = " << bincont[i] << endl;
> }
>
> static const Int_t size=160000;
> static const Int_t nbins=1500;
> Short_t bigarray[size][nbins];
> gBenchmark->Start("t0");
> for (Int_t i=0;i<size;i++){
> if (i%10000==0) cout << " i = " << i << endl;
> for (Int_t j=0;j<nbins;j++){
> bigarray[i][j]=bincont[j];
> }
> }
> gBenchmark->Stop("t0");
> gBenchmark->Print("t0");
>
> TTree T("T","Tree with array");
> Short_t *p;
> T.Branch("a",&p,"a[1500]/S",100000000);
> for (Int_t i=0;i<size;i++){
> p=&bigarray[i][0];
> T.Fill();
> }
> TFile * fileout = new TFile ("outArrayS.root","RECREATE");
> T.Write();
> fileout->Close();
> }
>
Received on Tue Oct 03 2006 - 19:37:53 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:32:01 MET