]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDSignalIndex.cxx
changes AliTRDSignalIndex
[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 "TObject.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   ,fBoolIndex(NULL)
44   ,fSortedIndex(NULL)
45   ,fMaxLimit(0)
46   ,fPositionRC(0)
47   ,fSortedWasInit(kFALSE)
48   ,fCurrRow(0)
49   ,fCurrCol(0)
50   ,fCurrTbin(0)
51   ,fNrows(0)
52   ,fNcols(0)
53   ,fNtbins(0)
54   ,fHasEntry(kFALSE)
55 {
56   //
57   // Default contructor
58   //
59
60   ResetCounters();
61
62 }
63
64 //_____________________________________________________________________________
65 AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
66   :TObject()
67   ,fDet(-1)
68   ,fLayer(-1)
69   ,fStack(-1)
70   ,fSM(-1)
71   ,fBoolIndex(NULL)
72   ,fSortedIndex(NULL)
73   ,fMaxLimit(0)
74   ,fPositionRC(0)
75   ,fSortedWasInit(kFALSE)
76   ,fCurrRow(0)
77   ,fCurrCol(0)
78   ,fCurrTbin(0)
79   ,fNrows(0)
80   ,fNcols(0)
81   ,fNtbins(0)
82   ,fHasEntry(kFALSE)
83 {
84   //
85   // Not the default contructor... hmmm...
86   //
87
88   Allocate(nrow, ncol, ntime);  
89
90 }
91
92 //_____________________________________________________________________________
93 AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
94   :TObject(a)
95   ,fDet(a.fDet)
96   ,fLayer(a.fLayer)
97   ,fStack(a.fStack)
98   ,fSM(a.fSM)
99   ,fBoolIndex(NULL)
100   ,fSortedIndex(NULL)
101   ,fMaxLimit(a.fMaxLimit)
102   ,fPositionRC(a.fPositionRC)
103   ,fSortedWasInit(a.fSortedWasInit)
104   ,fCurrRow(a.fCurrRow)
105   ,fCurrCol(a.fCurrCol)
106   ,fCurrTbin(a.fCurrTbin)
107   ,fNrows(a.fNrows)
108   ,fNcols(a.fNcols)
109   ,fNtbins(a.fNtbins)
110   ,fHasEntry(a.fHasEntry)
111 {
112   //
113   // Copy constructor
114   //
115
116   fBoolIndex = new Bool_t[fMaxLimit];
117   memcpy(fBoolIndex, a.fBoolIndex, fMaxLimit*sizeof(Bool_t));
118
119   fSortedIndex = new Short_t[2*fMaxLimit];
120   memcpy(fSortedIndex, a.fSortedIndex, 2*fMaxLimit*sizeof(Short_t));
121 }
122
123 //_____________________________________________________________________________
124 AliTRDSignalIndex::~AliTRDSignalIndex()
125 {
126   //
127   // Destructor
128   //
129
130   if (fBoolIndex) {
131     delete [] fBoolIndex;
132     fBoolIndex = NULL;
133   }
134
135 if (fSortedIndex) {
136     delete [] fSortedIndex;
137     fSortedIndex = NULL;
138   }
139
140 }
141
142 //_____________________________________________________________________________
143 void AliTRDSignalIndex::Copy(TObject &a) const
144 {
145   //
146   // Copy function
147   //
148
149   ((AliTRDSignalIndex &)a).fDet           = fDet;
150   ((AliTRDSignalIndex &)a).fLayer         = fLayer;
151   ((AliTRDSignalIndex &)a).fStack         = fStack;
152   ((AliTRDSignalIndex &)a).fSM            = fSM;
153   ((AliTRDSignalIndex &)a).fMaxLimit    = fMaxLimit;
154   ((AliTRDSignalIndex &)a).fPositionRC    = fPositionRC;
155   ((AliTRDSignalIndex &)a).fSortedWasInit = fSortedWasInit;
156   ((AliTRDSignalIndex &)a).fCurrRow       = fCurrRow;
157   ((AliTRDSignalIndex &)a).fCurrCol       = fCurrCol;
158   ((AliTRDSignalIndex &)a).fCurrTbin      = fCurrTbin;
159   ((AliTRDSignalIndex &)a).fNrows         = fNrows;
160   ((AliTRDSignalIndex &)a).fNcols         = fNcols;
161   ((AliTRDSignalIndex &)a).fNtbins        = fNtbins;
162   ((AliTRDSignalIndex &)a).fHasEntry      = fHasEntry;
163
164   if(((AliTRDSignalIndex &)a).fBoolIndex)
165     {
166       delete [] ((AliTRDSignalIndex &)a).fBoolIndex;
167     }
168   ((AliTRDSignalIndex &)a).fBoolIndex = new Bool_t[fMaxLimit];
169   memcpy(((AliTRDSignalIndex &)a).fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
170
171   if(((AliTRDSignalIndex &)a).fSortedIndex)
172     {
173       delete [] ((AliTRDSignalIndex &)a).fSortedIndex;
174     }
175   ((AliTRDSignalIndex &)a).fSortedIndex = new Short_t[2*fMaxLimit];
176   memcpy(((AliTRDSignalIndex &)a).fSortedIndex, fSortedIndex, 2*fMaxLimit*sizeof(Short_t));
177
178 }
179
180 //_____________________________________________________________________________
181 AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a)
182 {
183   //
184   // Assignment operator
185   //
186
187   if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this);
188   return *this;
189
190 }
191
192 //_____________________________________________________________________________
193 void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime)
194 {
195   //
196   // Create the arrays
197   //
198
199   fNrows = nrow;
200   fNcols = ncol;
201   fNtbins = ntime;
202
203   fMaxLimit = nrow * ncol + 1;
204
205   if (fBoolIndex) {
206     delete [] fBoolIndex;
207     fBoolIndex = NULL;
208   }
209   if (fSortedIndex) {
210     delete [] fSortedIndex;
211     fSortedIndex = NULL;
212   }
213
214   fBoolIndex = new Bool_t[fMaxLimit];
215   fSortedIndex = new Short_t[2*fMaxLimit];
216
217   ResetArrays();
218  
219   ResetCounters();
220
221   fHasEntry = kFALSE;
222
223 }
224
225 //_____________________________________________________________________________
226 void AliTRDSignalIndex::ResetArrays()
227 {
228   memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
229   memset(fSortedIndex,0xFF,2*sizeof(Short_t)*fMaxLimit);
230   fSortedWasInit = kFALSE;
231 }
232
233 //_____________________________________________________________________________
234 void AliTRDSignalIndex::Reset()
235 {
236   //
237   // Reset the array but keep the size - realloc
238   //
239
240   fDet   = -1;
241   fLayer = -1;
242   fStack = -1;
243   fSM    = -1;
244
245   // All will be lost 
246   Allocate(fNrows, fNcols, fNtbins);
247
248 }
249
250 //_____________________________________________________________________________
251 void AliTRDSignalIndex::ResetContent()
252 {
253   //
254   // Reset the array but keep the size - no realloc
255   //
256
257   ResetArrays();
258   ResetCounters();
259
260   fHasEntry = kFALSE;
261
262 }
263
264 //_____________________________________________________________________________
265 void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
266 {
267   //
268   // Reset the array but keep the size if no need to enlarge - no realloc
269   //
270
271   fDet   = -1;
272   fLayer = -1;
273   fStack = -1;
274   fSM    = -1;
275
276   if ((nrow  > fNrows) || 
277       (ncol  > fNcols) || 
278       (ntime > fNtbins)) {
279     Allocate(nrow, ncol, ntime);
280   }
281   else {
282     ResetArrays();
283     ResetCounters();
284     fHasEntry = kFALSE;
285   }
286
287 }
288
289 //_____________________________________________________________________________
290 void AliTRDSignalIndex::ClearAll()
291 {
292   //
293   // Reset the values - clear all!
294   //
295
296   fDet    = -1;
297   fLayer  = -1;
298   fStack  = -1;
299   fSM     = -1;
300
301   fNrows  = -1;
302   fNcols  = -1;
303   fNtbins = -1;
304
305   if (fBoolIndex) {
306     delete [] fBoolIndex;
307     fBoolIndex = NULL;
308   }
309
310   if (fSortedIndex) {
311     delete [] fSortedIndex;
312     fSortedIndex = NULL;
313   }
314   
315   ResetCounters();
316
317   fHasEntry = kFALSE;
318   fSortedWasInit = kFALSE;
319   fMaxLimit = 0;
320
321 }
322
323 //_____________________________________________________________________________
324 void AliTRDSignalIndex::AddIndexRC(const Int_t row, const Int_t col)
325 {
326   //
327   // Store the index row-column as an interesting one
328   // The RC index is updated to!!!
329   // This is to be used in the TRD clusterizer!
330   //
331
332   if (row * col + 1 >= fMaxLimit) {
333     AliError(Form("Out-of-limits row * col %d. Limit is: %d"
334                  ,row * col
335                  ,fMaxLimit));
336     return;
337   }
338  
339   fBoolIndex[row*fNcols+col]=kTRUE;
340
341   fHasEntry = kTRUE;
342
343 }
344
345 //_____________________________________________________________________________
346 Bool_t  AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
347 {
348   //
349   // Returns next used RC combination
350   //
351
352   if(fSortedIndex[fPositionRC]>-1){
353     row = fCurrRow = fSortedIndex[fPositionRC];
354     fPositionRC++;
355     col = fCurrCol = fSortedIndex[fPositionRC];
356     fPositionRC++;
357     return kTRUE;
358   }
359   else {
360     if(fSortedWasInit || !fHasEntry)
361       { //we already reached the end of the array
362         ResetCounters();
363         row = fCurrRow;
364         col = fCurrCol;
365         return kFALSE;
366       }
367     else
368       { //we have not created the sorted array up to now, let's do so
369         InitSortedIndex();
370         return NextRCIndex(row, col);
371       }
372   }
373
374 }
375
376 //_____________________________________________________________________________
377 Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
378 {
379   //
380   // Returns the next tbin, or if there is no next time bin, it returns the
381   // next used RC combination.
382   //  
383
384   if (NextTbinIndex(tbin)) {
385     row = fCurrRow;
386     col = fCurrCol;
387     return kTRUE;
388   }
389   else {
390     if (NextRCIndex(row, col)) {
391       return NextRCTbinIndex(row, col, tbin);
392     }
393   }
394
395   return kFALSE;
396
397 }
398
399 //_____________________________________________________________________________
400 Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
401 {
402   //
403   // Returns the next tbin of the current RC combination
404   //
405   
406   if(fCurrTbin<fNtbins)
407     {
408       tbin = fCurrTbin++;
409       return kTRUE;
410     }
411
412   return kFALSE;
413
414 }
415
416 //_____________________________________________________________________________
417 void AliTRDSignalIndex::InitSortedIndex()
418 {
419   //
420   // Creates the SortedIndex
421   //
422
423   fSortedWasInit = kTRUE;
424   int pos=0;
425   for(int row = 0; row < fNrows; row++)
426     for(int col = 0; col < fNcols; col++)
427       if(IsBoolIndex(row, col)){
428         fSortedIndex[pos] = row;
429         pos++;
430         fSortedIndex[pos] = col;
431         pos++;
432       }
433 }
434
435 //_____________________________________________________________________________
436 void AliTRDSignalIndex::ResetCounters()    
437
438   //
439   // Reset the counters/iterators
440   //
441
442   fCurrRow    = -1;
443   fCurrCol    = -1;
444   fCurrTbin   = -1;
445   fPositionRC =  0;
446 }