1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Handling of a matrix structure of objects.
21 // All objects which are derived from TObject may be entered into the matrix
22 // structure. This means that also TObjArray objects can be entered,
23 // which implies an increase of the dimension of the resulting structure.
28 // AliObjMatrix* matrix=new AliObjMatrix();
29 // matrix->SetOwner();
30 // matrix->SetSwapMode();
41 // s->SetPosition(pos,"car");
42 // m->EnterObject(6,21,s);
45 // s->SetSignal(25.84);
49 // s->SetPosition(pos,"car");
50 // m->EnterObject(8,13,s);
53 // s->SetSignal(87.25);
57 // s->SetPosition(pos,"car");
58 // m->EnterObject(64,3,s);
60 // Int_t nrows=matrix->GetMaxRow();
61 // Int_t ncols=matrix->GetMaxColumn();
63 // cout << " Maxrow : " << nrows << " Maxcol : " << ncols
64 // << " Nobjects : " << matrix->GetNobjects() << endl;
66 // for (Int_t i=1; i<=nrows; i++)
68 // for (Int_t j=1; j<=ncols; j++)
70 // s=(AliSignal*)matrix->GetObject(i,j);
71 // if (s) cout << " At (" << i << "," << j << ") Signal : " << s->GetSignal() << endl;
75 //--- Author: Nick van Eijndhoven 23-jan-2003 Utrecht University
76 //- Modified: NvE $Date$ Utrecht University
77 ///////////////////////////////////////////////////////////////////////////
79 #include "AliObjMatrix.h"
81 ClassImp(AliObjMatrix) // Class implementation to enable ROOT I/O
83 AliObjMatrix::AliObjMatrix()
85 // Default constructor.
86 // Note : The owner and swap mode flags will be initialised to 0.
87 // See the memberfunctions SetOwner() and SetSwapMode() for further
96 ///////////////////////////////////////////////////////////////////////////
97 AliObjMatrix::~AliObjMatrix()
99 // Default destructor.
106 ///////////////////////////////////////////////////////////////////////////
107 void AliObjMatrix::Reset()
109 // Reset the whole matrix structure.
110 // Note : The values of the owner and swap mode flags will not be modified.
111 // To modify the ownership, use the memberfunction SetOwner().
112 // To modify the swap mode, use the memberfunction SetSwapMode().
123 ///////////////////////////////////////////////////////////////////////////
124 void AliObjMatrix::SetOwner(Int_t own)
126 // Set the owner flag (0/1) for the stored objects.
127 // When the owner flag is set to 1, all entered objects are owned by the
129 // At invokation of this memberfunction the default argument is own=1.
135 for (Int_t irow=0; irow<fRows->GetSize(); irow++)
137 TObjArray* mrow=(TObjArray*)fRows->At(irow);
142 mrow->SetOwner(kTRUE);
146 mrow->SetOwner(kFALSE);
151 ///////////////////////////////////////////////////////////////////////////
152 Int_t AliObjMatrix::GetOwner()
154 // Provide the owner flag for the stored objects.
157 ///////////////////////////////////////////////////////////////////////////
158 void AliObjMatrix::SetSwapMode(Int_t swap)
160 // Set the swap mode flag (0/1) for the internal matrix storage.
161 // In case the number of rows differs considerably from the number of columns,
162 // it might be more efficient (w.r.t. memory usage and/or output file size)
163 // to internally store the matrix with the rows and colums swapped.
164 // This swapping is only related with the internal storage and as such
165 // is completely hidden for the user.
166 // At invokation of this memberfunction the default argument is swap=1.
168 // Note : The swap mode can only be set as long as no objects have
169 // been stored in the matrix structure (i.e. a new instance
170 // of AliObjMatrix or after invokation of the Reset() function).
178 cout << " *AliObjMatrix::SetSwapMode* Matrix not empty ==> No action." << endl;
181 ///////////////////////////////////////////////////////////////////////////
182 Int_t AliObjMatrix::GetSwapMode()
184 // Provide the swap mode flag for this matrix.
187 ///////////////////////////////////////////////////////////////////////////
188 void AliObjMatrix::EnterObject(Int_t row,Int_t col,TObject* obj)
190 // Enter an object to the matrix structure at location (row,col).
191 // In case the location already contained an object, the existing object
192 // will first be removed before the new object is stored.
193 // According to the status of the copy flag (see the SetCopy() function)
194 // the existing object will also be deleted.
195 // Note : The first location in the matrix is indicated as (1,1).
198 cout << " *AliObjMatrix::AddObject* Invalid argument(s) (row,col) : ("
199 << row << "," << col << ")" << endl;
203 if (row>fMaxrow) fMaxrow=row;
204 if (col>fMaxcol) fMaxcol=col;
213 fRows=new TObjArray(rowx);
218 if (rowx > fRows->GetSize()) fRows->Expand(rowx);
221 TObjArray* mrow=(TObjArray*)fRows->At(rowx-1);
225 TObjArray* columns=new TObjArray(colx);
226 if (fOwn) columns->SetOwner();
227 fRows->AddAt(columns,rowx-1);
232 if (colx > mrow->GetSize()) mrow->Expand(colx);
235 TObject* old=(TObject*)mrow->At(colx-1);
236 if (!old) fNobjects++;
237 if (old && fOwn) delete old;
239 mrow->AddAt(obj,colx-1);
241 ///////////////////////////////////////////////////////////////////////////
242 TObject* AliObjMatrix::GetObject(Int_t row,Int_t col)
244 // Provide a pointer to the object stored at the matrix location (row,col).
245 // In case no object was stored at the indicated location or the location
246 // would reside outside the matrix boundaries, a value 0 will be returned.
247 // Note : The first location in the matrix is indicated as (1,1).
251 if (!fRows || row<1 || col<1) return obj;
260 if (rowx <= fRows->GetSize()) mrow=(TObjArray*)fRows->At(rowx-1);
262 if (!mrow) return obj;
264 if (colx <= mrow->GetSize()) obj=(TObject*)mrow->At(colx-1);
268 ///////////////////////////////////////////////////////////////////////////
269 Int_t AliObjMatrix::GetMaxRow()
271 // Provide the maximum row number index.
274 ///////////////////////////////////////////////////////////////////////////
275 Int_t AliObjMatrix::GetMaxColumn()
277 // Provide the maximum column number index.
280 ///////////////////////////////////////////////////////////////////////////
281 Int_t AliObjMatrix::GetNobjects()
283 // Provide the number of stored objects.
286 ///////////////////////////////////////////////////////////////////////////