]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDSignalIndex.cxx
Introducing a new AliNeutralTrackParam class for dealing with the neutral particles...
[u/mrichter/AliRoot.git] / TRD / AliTRDSignalIndex.cxx
CommitLineData
ca21baaa 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// //
c8ab4518 23// Author: //
24// Mateusz Ploskon (ploskon@ikf.uni-frankfurt.de) //
ca21baaa 25// //
26///////////////////////////////////////////////////////////////////////////////
27
064d808d 28#include "TObject.h"
c8ab4518 29
ca21baaa 30#include "AliLog.h"
31
c8ab4518 32#include "AliTRDSignalIndex.h"
33
ca21baaa 34ClassImp(AliTRDSignalIndex)
35
36//_____________________________________________________________________________
37AliTRDSignalIndex::AliTRDSignalIndex()
c8ab4518 38 :TObject()
39 ,fDet(-1)
40 ,fLayer(-1)
41 ,fStack(-1)
42 ,fSM(-1)
064d808d 43 ,fBoolIndex(NULL)
44 ,fSortedIndex(NULL)
45 ,fMaxLimit(0)
46 ,fPositionRC(0)
47 ,fSortedWasInit(kFALSE)
48 ,fCurrRow(0)
49 ,fCurrCol(0)
50 ,fCurrTbin(0)
c8ab4518 51 ,fNrows(0)
52 ,fNcols(0)
53 ,fNtbins(0)
c8ab4518 54 ,fHasEntry(kFALSE)
ca21baaa 55{
56 //
c8ab4518 57 // Default contructor
ca21baaa 58 //
c8ab4518 59
ca21baaa 60 ResetCounters();
c8ab4518 61
ca21baaa 62}
63
64//_____________________________________________________________________________
65AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
c8ab4518 66 :TObject()
67 ,fDet(-1)
68 ,fLayer(-1)
69 ,fStack(-1)
70 ,fSM(-1)
064d808d 71 ,fBoolIndex(NULL)
72 ,fSortedIndex(NULL)
73 ,fMaxLimit(0)
74 ,fPositionRC(0)
75 ,fSortedWasInit(kFALSE)
76 ,fCurrRow(0)
77 ,fCurrCol(0)
78 ,fCurrTbin(0)
c8ab4518 79 ,fNrows(0)
80 ,fNcols(0)
81 ,fNtbins(0)
c8ab4518 82 ,fHasEntry(kFALSE)
ca21baaa 83{
c8ab4518 84 //
85 // Not the default contructor... hmmm...
86 //
87
ca21baaa 88 Allocate(nrow, ncol, ntime);
c8ab4518 89
ca21baaa 90}
91
92//_____________________________________________________________________________
c8ab4518 93AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
94 :TObject(a)
95 ,fDet(a.fDet)
96 ,fLayer(a.fLayer)
97 ,fStack(a.fStack)
98 ,fSM(a.fSM)
064d808d 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)
c8ab4518 107 ,fNrows(a.fNrows)
108 ,fNcols(a.fNcols)
109 ,fNtbins(a.fNtbins)
c8ab4518 110 ,fHasEntry(a.fHasEntry)
ca21baaa 111{
112 //
c8ab4518 113 // Copy constructor
ca21baaa 114 //
115
064d808d 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));
ca21baaa 121}
122
123//_____________________________________________________________________________
c8ab4518 124AliTRDSignalIndex::~AliTRDSignalIndex()
ca21baaa 125{
126 //
c8ab4518 127 // Destructor
ca21baaa 128 //
c8ab4518 129
064d808d 130 if (fBoolIndex) {
131 delete [] fBoolIndex;
132 fBoolIndex = NULL;
133 }
134
135if (fSortedIndex) {
136 delete [] fSortedIndex;
137 fSortedIndex = NULL;
c10bf383 138 }
c8ab4518 139
ca21baaa 140}
141
142//_____________________________________________________________________________
143void AliTRDSignalIndex::Copy(TObject &a) const
144{
145 //
146 // Copy function
147 //
148
c8ab4518 149 ((AliTRDSignalIndex &)a).fDet = fDet;
150 ((AliTRDSignalIndex &)a).fLayer = fLayer;
151 ((AliTRDSignalIndex &)a).fStack = fStack;
152 ((AliTRDSignalIndex &)a).fSM = fSM;
064d808d 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;
c8ab4518 159 ((AliTRDSignalIndex &)a).fNrows = fNrows;
160 ((AliTRDSignalIndex &)a).fNcols = fNcols;
161 ((AliTRDSignalIndex &)a).fNtbins = fNtbins;
c8ab4518 162 ((AliTRDSignalIndex &)a).fHasEntry = fHasEntry;
163
064d808d 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
ca21baaa 178}
179
180//_____________________________________________________________________________
181AliTRDSignalIndex& 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}
c8ab4518 191
ca21baaa 192//_____________________________________________________________________________
064d808d 193void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime)
ca21baaa 194{
195 //
c8ab4518 196 // Create the arrays
ca21baaa 197 //
198
199 fNrows = nrow;
200 fNcols = ncol;
201 fNtbins = ntime;
202
064d808d 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;
c8ab4518 212 }
ca21baaa 213
064d808d 214 fBoolIndex = new Bool_t[fMaxLimit];
215 fSortedIndex = new Short_t[2*fMaxLimit];
c8ab4518 216
064d808d 217 ResetArrays();
218
ca21baaa 219 ResetCounters();
c8ab4518 220
ca21baaa 221 fHasEntry = kFALSE;
c8ab4518 222
ca21baaa 223}
224
064d808d 225//_____________________________________________________________________________
226void AliTRDSignalIndex::ResetArrays()
227{
228 memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
229 memset(fSortedIndex,0xFF,2*sizeof(Short_t)*fMaxLimit);
230}
231
ca21baaa 232//_____________________________________________________________________________
233void AliTRDSignalIndex::Reset()
234{
235 //
236 // Reset the array but keep the size - realloc
237 //
238
c8ab4518 239 fDet = -1;
ca21baaa 240 fLayer = -1;
241 fStack = -1;
c8ab4518 242 fSM = -1;
ca21baaa 243
c8ab4518 244 // All will be lost
ca21baaa 245 Allocate(fNrows, fNcols, fNtbins);
c8ab4518 246
ca21baaa 247}
248
001be664 249//_____________________________________________________________________________
250void AliTRDSignalIndex::ResetContent()
251{
252 //
253 // Reset the array but keep the size - no realloc
254 //
255
064d808d 256 ResetArrays();
001be664 257 ResetCounters();
c8ab4518 258
001be664 259 fHasEntry = kFALSE;
c8ab4518 260
001be664 261}
262
263//_____________________________________________________________________________
064d808d 264void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
001be664 265{
266 //
267 // Reset the array but keep the size if no need to enlarge - no realloc
268 //
269
c8ab4518 270 fDet = -1;
001be664 271 fLayer = -1;
272 fStack = -1;
c8ab4518 273 fSM = -1;
274
275 if ((nrow > fNrows) ||
276 (ncol > fNcols) ||
277 (ntime > fNtbins)) {
278 Allocate(nrow, ncol, ntime);
279 }
280 else {
064d808d 281 ResetArrays();
c8ab4518 282 ResetCounters();
283 fHasEntry = kFALSE;
284 }
001be664 285
001be664 286}
287
ca21baaa 288//_____________________________________________________________________________
289void AliTRDSignalIndex::ClearAll()
290{
291 //
292 // Reset the values - clear all!
293 //
294
c8ab4518 295 fDet = -1;
296 fLayer = -1;
297 fStack = -1;
298 fSM = -1;
ca21baaa 299
c8ab4518 300 fNrows = -1;
301 fNcols = -1;
ca21baaa 302 fNtbins = -1;
303
064d808d 304 if (fBoolIndex) {
305 delete [] fBoolIndex;
306 fBoolIndex = NULL;
307 }
308
309 if (fSortedIndex) {
310 delete [] fSortedIndex;
311 fSortedIndex = NULL;
c8ab4518 312 }
064d808d 313
ca21baaa 314 ResetCounters();
c8ab4518 315
ca21baaa 316 fHasEntry = kFALSE;
c8ab4518 317
ca21baaa 318}
319
320//_____________________________________________________________________________
064d808d 321void AliTRDSignalIndex::AddIndexTBin(Int_t row, Int_t col, Int_t /*tbin*/)
ca21baaa 322{
064d808d 323 //
324 // This function is now obsolate, it will be deleted in future.
c8ab4518 325 //
326 // Store the index row-column-tbin as an interesting one
327 // The RC index is updated to!!!
328 // This is to be used in the TRD clusterizer!
329 //
064d808d 330
331 AddIndexRC(row, col);
c8ab4518 332
064d808d 333}
c8ab4518 334
064d808d 335//_____________________________________________________________________________
336void AliTRDSignalIndex::AddIndexRC(const Int_t row, const Int_t col)
337{
338 //
339 // Store the index row-column as an interesting one
340 // The RC index is updated to!!!
341 // This is to be used in the TRD clusterizer!
342 //
c8ab4518 343
064d808d 344 if (row * col + 1 >= fMaxLimit) {
345 AliError(Form("Out-of-limits row * col %d. Limit is: %d"
346 ,row * col
347 ,fMaxLimit));
348 return;
c8ab4518 349 }
064d808d 350
351 fBoolIndex[row*fNcols+col]=kTRUE;
ca21baaa 352
353 fHasEntry = kTRUE;
c8ab4518 354
ca21baaa 355}
356
357//_____________________________________________________________________________
358Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
359{
c8ab4518 360 //
064d808d 361 // Returns next used RC combination
c8ab4518 362 //
ca21baaa 363
064d808d 364 if(fSortedIndex[fPositionRC]>-1){
365 row = fCurrRow = fSortedIndex[fPositionRC];
366 fPositionRC++;
367 col = fCurrCol = fSortedIndex[fPositionRC];
368 fPositionRC++;
369 return kTRUE;
c8ab4518 370 }
371 else {
064d808d 372 if(fSortedWasInit || !fHasEntry)
373 {
374 ResetCounters();
375 row = fCurrRow;
376 col = fCurrCol;
377 return kFALSE;
378 }
379 else
380 {
381 InitSortedIndex();
382 return NextRCIndex(row, col);
383 }
c8ab4518 384 }
ca21baaa 385
ca21baaa 386}
387
388//_____________________________________________________________________________
c8ab4518 389Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
ca21baaa 390{
c8ab4518 391 //
064d808d 392 // Returns the next tbin, or if there is no next time bin, it returns the
393 // next used RC combination.
394 //
ca21baaa 395
c8ab4518 396 if (NextTbinIndex(tbin)) {
064d808d 397 row = fCurrRow;
398 col = fCurrCol;
c8ab4518 399 return kTRUE;
400 }
401 else {
402 if (NextRCIndex(row, col)) {
403 return NextRCTbinIndex(row, col, tbin);
ca21baaa 404 }
c8ab4518 405 }
ca21baaa 406
407 return kFALSE;
c8ab4518 408
ca21baaa 409}
410
411//_____________________________________________________________________________
c8ab4518 412Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
ca21baaa 413{
c8ab4518 414 //
064d808d 415 // Returns the next tbin of the current RC combination
c8ab4518 416 //
064d808d 417
418 if(fCurrTbin<fNtbins)
419 {
420 tbin = fCurrTbin++;
421 return kTRUE;
422 }
ca21baaa 423
064d808d 424 return kFALSE;
ca21baaa 425
064d808d 426}
ca21baaa 427
064d808d 428//_____________________________________________________________________________
429void AliTRDSignalIndex::InitSortedIndex()
430{
431 //
432 // Creates the SortedIndex
433 //
c8ab4518 434
064d808d 435 fSortedWasInit = kTRUE;
436 int pos=0;
437 for(int row = 0; row < fNrows; row++)
438 for(int col = 0; col < fNcols; col++)
439 if(IsBoolIndex(row, col)){
440 fSortedIndex[pos] = row;
441 pos++;
442 fSortedIndex[pos] = col;
443 pos++;
444 }
ca21baaa 445}
446
c8ab4518 447//_____________________________________________________________________________
448void AliTRDSignalIndex::ResetCounters()
449{
450 //
451 // Reset the counters/iterators
452 //
453
064d808d 454 fCurrRow = -1;
455 fCurrCol = -1;
456 fCurrTbin = -1;
457 fPositionRC = 0;
c8ab4518 458}