Dear Rooters
I would like to read tables containing (x, y, value) in each line,
as an array ar[][]. However, the number of rows and columns would
always be different.
In an example given by Rene Brun in the mail from Sun Feb 13 2000
(http://root.cern.ch/root/roottalk/roottalk00/0367.html)
he has written “I assume that your array has a constant size in x and y”
and has presented the file “array.C”
Is there an easy way to generalize this example, when the dimensions
are not constant?
As a first attempt I have modified the file “array.C” in a way that
it uses class TMatrix instead of a 2-dim array (see below).
Since I do not need matrix calculations, but only a 2-dim array,
especially
arrays with the size of about 1000 x 1000, my question is, is the use
of class TMatrix the right way or does there exist a better solution?
Thank you in advance
Christian Stratowa
Vienna, Austria
//----------file array.C
#include "TMatrix.h"
#include <iostream.h>
#include <math.h>
void fillarray(Int_t nrow,Int_t ncol)
{
TFile f("test.root","recreate");
TTree T("T","a simple test with an array");
TMatrix *ma = new TMatrix(nrow,ncol);
T.Branch("ma",&ma,64000,0);
for (Int_t i=0;i<nrow;i++) {
for (Int_t j=0;j<ncol;j++) {
ma(i,j) = gRandom->Gaus(i,j);
}
}
T.Fill();
T.Write();
}
void readarray()
{
Int_t nrow;
Int_t ncol;
TMatrix *ma;
TFile *f = new TFile("test.root");
TTree *T = (TTree*)f->Get("T");
T->SetBranchAddress("ma",&ma);
TH1F *hed = new TH1F("hed","ma values",100,-100,100);
T->GetEntry();
nrow = ma->GetNrows();
ncol = ma->GetNcols();
for (Int_t i=0;i<nrow;i++) {
for (Int_t j=0;j<ncol;j++) {
hed->Fill(ma(i,j));
}
}
printf("nrows = %i, ncols = %i \n",nrow,ncol);
hed->Draw();
}
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:40 MET