]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDSignalIndex.cxx
Memory leaks
[u/mrichter/AliRoot.git] / TRD / AliTRDSignalIndex.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  General container for data from TRD detector segments                    //
21 //  Adapted from AliDigits, origin M.Ivanov                                  //
22 //                                                                           //
23 //  Author:                                                                  //
24 //    Mateusz Ploskon (ploskon@ikf.uni-frankfurt.de)                         //
25 //                                                                           //
26 ///////////////////////////////////////////////////////////////////////////////
27
28 #include "TArrayI.h"
29
30 #include "AliLog.h"
31
32 #include "AliTRDSignalIndex.h"
33
34 ClassImp(AliTRDSignalIndex)
35
36 //_____________________________________________________________________________
37 AliTRDSignalIndex::AliTRDSignalIndex()
38   :TObject()
39   ,fDet(-1)
40   ,fLayer(-1)
41   ,fStack(-1)
42   ,fSM(-1)
43   ,fIndex(NULL)
44   ,fPositionRow(0)
45   ,fPositionCol(0)
46   ,fPositionTbin(0)
47   ,fLastRow(0)
48   ,fLastCol(0)
49   ,fLastTbin(0)
50   ,fNrows(0)
51   ,fNcols(0)
52   ,fNtbins(0)
53   ,fMaxLimit(0)
54   ,fResetCounters(kTRUE)
55   ,fHasEntry(kFALSE)
56 {
57   //
58   // Default contructor
59   //
60
61   ResetCounters();
62
63 }
64
65 //_____________________________________________________________________________
66 AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
67   :TObject()
68   ,fDet(-1)
69   ,fLayer(-1)
70   ,fStack(-1)
71   ,fSM(-1)
72   ,fIndex(NULL)
73   ,fPositionRow(0)
74   ,fPositionCol(0)
75   ,fPositionTbin(0)
76   ,fLastRow(0)
77   ,fLastCol(0)
78   ,fLastTbin(0)
79   ,fNrows(0)
80   ,fNcols(0)
81   ,fNtbins(0)
82   ,fMaxLimit(0)
83   ,fResetCounters(kTRUE)
84   ,fHasEntry(kFALSE)
85 {
86   //
87   // Not the default contructor... hmmm...
88   //
89
90   Allocate(nrow, ncol, ntime);  
91
92 }
93
94 //_____________________________________________________________________________
95 AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
96   :TObject(a)
97   ,fDet(a.fDet)
98   ,fLayer(a.fLayer)
99   ,fStack(a.fStack)
100   ,fSM(a.fSM)
101   ,fIndex(a.fIndex)
102   ,fPositionRow(a.fPositionRow)
103   ,fPositionCol(a.fPositionCol)
104   ,fPositionTbin(a.fPositionTbin)
105   ,fLastRow(a.fLastRow)
106   ,fLastCol(a.fLastCol)
107   ,fLastTbin(a.fLastTbin)
108   ,fNrows(a.fNrows)
109   ,fNcols(a.fNcols)
110   ,fNtbins(a.fNtbins)
111   ,fMaxLimit(a.fMaxLimit)
112   ,fResetCounters(a.fResetCounters)
113   ,fHasEntry(a.fHasEntry)
114 {
115   //
116   // Copy constructor
117   //
118
119 }
120
121 //_____________________________________________________________________________
122 AliTRDSignalIndex::~AliTRDSignalIndex()
123 {
124   //
125   // Destructor
126   //
127
128   if (fIndex) {
129     delete fIndex;
130     fIndex = NULL;
131   }
132
133 }
134
135 //_____________________________________________________________________________
136 void AliTRDSignalIndex::Copy(TObject &a) const
137 {
138   //
139   // Copy function
140   //
141
142   ((AliTRDSignalIndex &)a).fDet           = fDet;
143   ((AliTRDSignalIndex &)a).fLayer         = fLayer;
144   ((AliTRDSignalIndex &)a).fStack         = fStack;
145   ((AliTRDSignalIndex &)a).fSM            = fSM;
146   ((AliTRDSignalIndex &)a).fIndex         = fIndex;
147   ((AliTRDSignalIndex &)a).fPositionRow   = fPositionRow;
148   ((AliTRDSignalIndex &)a).fPositionTbin  = fPositionTbin;
149   ((AliTRDSignalIndex &)a).fLastRow       = fLastRow;
150   ((AliTRDSignalIndex &)a).fLastCol       = fLastCol;
151   ((AliTRDSignalIndex &)a).fLastTbin      = fLastTbin;
152   ((AliTRDSignalIndex &)a).fNrows         = fNrows;
153   ((AliTRDSignalIndex &)a).fNcols         = fNcols;
154   ((AliTRDSignalIndex &)a).fNtbins        = fNtbins;
155   ((AliTRDSignalIndex &)a).fMaxLimit      = fMaxLimit;
156   ((AliTRDSignalIndex &)a).fResetCounters = fResetCounters;
157   ((AliTRDSignalIndex &)a).fHasEntry      = fHasEntry;
158
159 }
160
161 //_____________________________________________________________________________
162 AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a)
163 {
164   //
165   // Assignment operator
166   //
167
168   if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this);
169   return *this;
170
171 }
172
173 //_____________________________________________________________________________
174 void AliTRDSignalIndex::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
175 {
176   //
177   // Create the arrays
178   //
179
180   fNrows = nrow;
181   fNcols = ncol;
182   fNtbins = ntime;
183
184   fMaxLimit = nrow * ncol * ntime + nrow * ncol * 2;
185   if (fIndex) {
186     delete fIndex;
187     fIndex = NULL;
188   }
189
190   fIndex = new TArrayI(fMaxLimit);
191   fIndex->Reset(-1);
192
193   ResetCounters();
194
195   fHasEntry = kFALSE;
196
197 }
198
199 //_____________________________________________________________________________
200 void AliTRDSignalIndex::Reset()
201 {
202   //
203   // Reset the array but keep the size - realloc
204   //
205
206   fDet   = -1;
207   fLayer = -1;
208   fStack = -1;
209   fSM    = -1;
210
211   // All will be lost 
212   Allocate(fNrows, fNcols, fNtbins);
213
214 }
215
216 //_____________________________________________________________________________
217 void AliTRDSignalIndex::ResetContent()
218 {
219   //
220   // Reset the array but keep the size - no realloc
221   //
222
223   fIndex->Reset(-1);
224   ResetCounters();
225
226   fHasEntry = kFALSE;
227
228 }
229
230 //_____________________________________________________________________________
231 void AliTRDSignalIndex::ResetContentConditional(Int_t nrow, Int_t ncol,Int_t ntime)
232 {
233   //
234   // Reset the array but keep the size if no need to enlarge - no realloc
235   //
236
237   fDet   = -1;
238   fLayer = -1;
239   fStack = -1;
240   fSM    = -1;
241
242   if ((nrow  > fNrows) || 
243       (ncol  > fNcols) || 
244       (ntime > fNtbins)) {
245     Allocate(nrow, ncol, ntime);
246   }
247   else {
248     fIndex->Reset(-1);
249     ResetCounters();
250     fHasEntry = kFALSE;
251   }
252
253 }
254
255 //_____________________________________________________________________________
256 void AliTRDSignalIndex::ClearAll()
257 {
258   //
259   // Reset the values - clear all!
260   //
261
262   fDet    = -1;
263   fLayer  = -1;
264   fStack  = -1;
265   fSM     = -1;
266
267   fNrows  = -1;
268   fNcols  = -1;
269   fNtbins = -1;
270
271   if (fIndex) {
272     delete fIndex;
273     fIndex = NULL;
274   }
275   fIndex = new TArrayI();
276   ResetCounters();
277
278   fHasEntry = kFALSE;
279
280 }
281
282 //_____________________________________________________________________________
283 void AliTRDSignalIndex::AddIndexTBin(Int_t row, Int_t col, Int_t tbin)
284 {
285   //
286   // Store the index row-column-tbin as an interesting one
287   // The RC index is updated to!!!
288   // This is to be used in the TRD clusterizer!
289   //
290
291   if (row * col * tbin + row * col * 2 >= fMaxLimit) {
292     AliError(Form("Out-of-limits fPositionCol + fNtbins %d. Limit is: %d"
293                  ,fPositionCol + fNtbins
294                  ,fMaxLimit));
295     return;
296   }
297
298   if ((row != fLastRow) || 
299       (col != fLastCol)) {
300
301     // New RC combination
302     if (fResetCounters == kTRUE) {
303       fPositionRow    = 0;
304       fPositionCol   = 1;  
305       fResetCounters = kFALSE;
306     }
307     else {
308       fPositionRow += fNtbins + 2;
309       fPositionCol += fNtbins + 2;
310     }
311
312     fPositionTbin = 1;
313
314     (*fIndex)[fPositionRow] = row;
315     (*fIndex)[fPositionCol] = col;
316     (*fIndex)[fPositionCol + fPositionTbin] = tbin;
317     ++fPositionTbin;
318
319   }
320   else {
321
322     // Same RCT combination ?
323       
324     (*fIndex)[fPositionCol + fPositionTbin] = tbin;
325     ++fPositionTbin;      
326   
327   }
328   
329   fLastRow  = row;
330   fLastCol  = col;
331   fLastTbin = tbin;
332
333   fHasEntry = kTRUE;
334
335 }
336
337 //_____________________________________________________________________________
338 Bool_t  AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
339 {
340   //
341   // Return the position (index in the data array) of the next available pad
342   //
343
344   if (fResetCounters == kTRUE) {
345     fPositionRow   = 0;
346     fPositionCol   = 1;
347     fResetCounters = kFALSE;
348   }
349   else {
350     fPositionRow  += fNtbins + 2;
351     fPositionCol  += fNtbins + 2;
352   }
353
354   if (fPositionRow >= fMaxLimit) {
355     return kFALSE;
356   }
357
358   fPositionTbin = 1;
359
360   row = (*fIndex)[fPositionRow];
361   col = (*fIndex)[fPositionCol];
362
363   if ((row > -1) && 
364       (col > -1)) { 
365     return kTRUE;
366   }
367   
368   return kFALSE;
369
370 }
371
372 //_____________________________________________________________________________
373 Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
374 {
375   //
376   // Return the position (index in the data array) of the next available tbin 
377   // within the current pad
378   //
379
380   if (fPositionRow >= fMaxLimit) {
381     return kFALSE;
382   }
383
384   if (NextTbinIndex(tbin)) {
385     row  = (*fIndex)[fPositionRow];
386     col  = (*fIndex)[fPositionCol];
387     fResetCounters = kFALSE;
388     return kTRUE;
389   }
390   else {
391     if (NextRCIndex(row, col)) {
392       return NextRCTbinIndex(row, col, tbin);
393     }
394   }
395
396   return kFALSE;
397
398 }
399
400 //_____________________________________________________________________________
401 Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
402 {
403   //
404   // Return the position (index in the data array) of the next available tbin 
405   // within the current pad
406   //
407
408   if ((fPositionCol + fPositionTbin >= fMaxLimit) || 
409       (fPositionTbin                >  fNtbins  )) {
410     return kFALSE;
411   }
412
413   tbin = (*fIndex)[fPositionCol + fPositionTbin];
414
415   if (tbin > -1) {
416     ++fPositionTbin;
417     return kTRUE;
418   }
419
420   return kFALSE;
421
422 }
423
424 //_____________________________________________________________________________
425 void AliTRDSignalIndex::ResetCounters()    
426
427   //
428   // Reset the counters/iterators
429   //
430
431   fPositionRow   =  0;
432   fPositionCol   =  fPositionRow + 1;
433   fPositionTbin  =  1;
434   fLastRow       = -1;
435   fLastCol       = -1;
436   fLastTbin      = -1;
437   fResetCounters = kTRUE; 
438
439 }