]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliRectMatrix.cxx
Some of the coding violations corrected
[u/mrichter/AliRoot.git] / STEER / AliRectMatrix.cxx
1 #include "AliRectMatrix.h"
2 #include <TString.h>
3 //
4
5 ClassImp(AliRectMatrix)
6
7
8 //___________________________________________________________
9 AliRectMatrix::AliRectMatrix() 
10 : fNRows(0),fNCols(0),fRows(0)
11 {}
12
13 //___________________________________________________________
14 AliRectMatrix::AliRectMatrix(Int_t nrow,Int_t ncol)
15   : fNRows(nrow),fNCols(ncol),fRows(0)
16 {
17   //
18   fRows = new Double_t*[fNRows];
19   for (int i=fNRows;i--;) {
20     fRows[i] = new Double_t[fNCols];
21     memset(fRows[i],0,fNCols*sizeof(Double_t));
22   }
23   //
24 }
25
26 //___________________________________________________________
27 AliRectMatrix::AliRectMatrix(const AliRectMatrix &src)
28   : TObject(src),fNRows(src.fNRows), fNCols(src.fNCols), fRows(0)
29 {
30   fRows = new Double_t*[fNRows];
31   for (int i=fNRows;i--;) {
32     fRows[i] = new Double_t[fNCols];
33     memcpy(fRows[i], src.fRows[i], fNCols*sizeof(Double_t));
34   }
35 }
36
37 //___________________________________________________________
38 AliRectMatrix::~AliRectMatrix()
39 {
40   if (fNRows) for (int i=fNRows;i--;) delete[] fRows[i];
41   delete[] fRows;
42 }
43
44 //___________________________________________________________
45 AliRectMatrix& AliRectMatrix::operator=(const AliRectMatrix& src)
46 {
47   //
48   if (&src == this) return *this;
49   if (fNRows) for (int i=fNRows;i--;) delete[] fRows[i];
50   delete[] fRows;
51   fNRows = src.fNRows;
52   fNCols = src.fNCols;
53   fRows = new Double_t*[fNRows];
54   for (int i=fNRows;i--;) {
55     fRows[i] = new Double_t[fNCols];
56     memcpy(fRows[i], src.fRows[i], fNCols*sizeof(Double_t));
57   }
58   //
59   return *this;
60 }
61
62 //___________________________________________________________
63 void AliRectMatrix::Print(Option_t* option) const
64 {
65   printf("Rectangular Matrix:  %d rows %d columns\n",fNRows,fNCols);
66   TString opt = option; opt.ToLower();
67   if (opt.IsNull()) return;
68   for (int i=0;i<fNRows;i++) {
69     for (Int_t j=0;j<=fNCols;j++) printf("%+.3e|",Query(i,j));
70     printf("\n");
71   }
72 }
73
74
75 //___________________________________________________________
76 void AliRectMatrix::Reset()
77 {
78   for (int i=fNRows;i--;) {
79     double *row = GetRow(i); 
80     for (int j=fNCols;j--;)  row[j] = 0.;
81   }
82 }