]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDSignalIndex.cxx
Rawstream classes and digitsManager of AliTRD now changed to use new AliTRDSignalInde...
[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::AddIndexTBin(Int_t row, Int_t col, Int_t /*tbin*/)
325 {
326   //
327   // This function is now obsolate, it will be deleted in future. 
328   //
329   // Store the index row-column-tbin as an interesting one
330   // The RC index is updated to!!!
331   // This is to be used in the TRD clusterizer!
332   //
333  
334   AddIndexRC(row, col);
335
336 }
337
338 //_____________________________________________________________________________
339 void AliTRDSignalIndex::AddIndexRC(const Int_t row, const Int_t col)
340 {
341   //
342   // Store the index row-column as an interesting one
343   // The RC index is updated to!!!
344   // This is to be used in the TRD clusterizer!
345   //
346
347   if (row * col + 1 >= fMaxLimit) {
348     AliError(Form("Out-of-limits row * col %d. Limit is: %d"
349                  ,row * col
350                  ,fMaxLimit));
351     return;
352   }
353  
354   fBoolIndex[row*fNcols+col]=kTRUE;
355
356   fHasEntry = kTRUE;
357
358 }
359
360 //_____________________________________________________________________________
361 Bool_t  AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
362 {
363   //
364   // Returns next used RC combination
365   //
366
367   if(fSortedIndex[fPositionRC]>-1){
368     row = fCurrRow = fSortedIndex[fPositionRC];
369     fPositionRC++;
370     col = fCurrCol = fSortedIndex[fPositionRC];
371     fPositionRC++;
372     return kTRUE;
373   }
374   else {
375     if(fSortedWasInit || !fHasEntry)
376       {
377         ResetCounters();
378         row = fCurrRow;
379         col = fCurrCol;
380         return kFALSE;
381       }
382     else
383       {
384         InitSortedIndex();
385         return NextRCIndex(row, col);
386       }
387   }
388
389 }
390
391 //_____________________________________________________________________________
392 Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
393 {
394   //
395   // Returns the next tbin, or if there is no next time bin, it returns the
396   // next used RC combination.
397   //  
398
399   if (NextTbinIndex(tbin)) {
400     row = fCurrRow;
401     col = fCurrCol;
402     return kTRUE;
403   }
404   else {
405     if (NextRCIndex(row, col)) {
406       return NextRCTbinIndex(row, col, tbin);
407     }
408   }
409
410   return kFALSE;
411
412 }
413
414 //_____________________________________________________________________________
415 Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
416 {
417   //
418   // Returns the next tbin of the current RC combination
419   //
420   
421   if(fCurrTbin<fNtbins)
422     {
423       tbin = fCurrTbin++;
424       return kTRUE;
425     }
426
427   return kFALSE;
428
429 }
430
431 //_____________________________________________________________________________
432 void AliTRDSignalIndex::InitSortedIndex()
433 {
434   //
435   // Creates the SortedIndex
436   //
437
438   fSortedWasInit = kTRUE;
439   int pos=0;
440   for(int row = 0; row < fNrows; row++)
441     for(int col = 0; col < fNcols; col++)
442       if(IsBoolIndex(row, col)){
443         fSortedIndex[pos] = row;
444         pos++;
445         fSortedIndex[pos] = col;
446         pos++;
447       }
448 }
449
450 //_____________________________________________________________________________
451 void AliTRDSignalIndex::ResetCounters()    
452
453   //
454   // Reset the counters/iterators
455   //
456
457   fCurrRow    = -1;
458   fCurrCol    = -1;
459   fCurrTbin   = -1;
460   fPositionRC =  0;
461 }