]>
Commit | Line | Data |
---|---|---|
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 | 34 | ClassImp(AliTRDSignalIndex) |
35 | ||
36 | //_____________________________________________________________________________ | |
37 | AliTRDSignalIndex::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 | //_____________________________________________________________________________ | |
65 | AliTRDSignalIndex::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 | 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) | |
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 | 124 | AliTRDSignalIndex::~AliTRDSignalIndex() |
ca21baaa | 125 | { |
126 | // | |
c8ab4518 | 127 | // Destructor |
ca21baaa | 128 | // |
c8ab4518 | 129 | |
064d808d | 130 | if (fBoolIndex) { |
131 | delete [] fBoolIndex; | |
132 | fBoolIndex = NULL; | |
133 | } | |
134 | ||
135 | if (fSortedIndex) { | |
136 | delete [] fSortedIndex; | |
137 | fSortedIndex = NULL; | |
c10bf383 | 138 | } |
c8ab4518 | 139 | |
ca21baaa | 140 | } |
141 | ||
142 | //_____________________________________________________________________________ | |
143 | void 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 | //_____________________________________________________________________________ | |
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 | } | |
c8ab4518 | 191 | |
ca21baaa | 192 | //_____________________________________________________________________________ |
064d808d | 193 | void 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 | //_____________________________________________________________________________ |
226 | void AliTRDSignalIndex::ResetArrays() | |
227 | { | |
228 | memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit); | |
229 | memset(fSortedIndex,0xFF,2*sizeof(Short_t)*fMaxLimit); | |
ae63fafc | 230 | fSortedWasInit = kFALSE; |
064d808d | 231 | } |
232 | ||
ca21baaa | 233 | //_____________________________________________________________________________ |
234 | void AliTRDSignalIndex::Reset() | |
235 | { | |
236 | // | |
237 | // Reset the array but keep the size - realloc | |
238 | // | |
239 | ||
c8ab4518 | 240 | fDet = -1; |
ca21baaa | 241 | fLayer = -1; |
242 | fStack = -1; | |
c8ab4518 | 243 | fSM = -1; |
ca21baaa | 244 | |
c8ab4518 | 245 | // All will be lost |
ca21baaa | 246 | Allocate(fNrows, fNcols, fNtbins); |
c8ab4518 | 247 | |
ca21baaa | 248 | } |
249 | ||
001be664 | 250 | //_____________________________________________________________________________ |
251 | void AliTRDSignalIndex::ResetContent() | |
252 | { | |
253 | // | |
254 | // Reset the array but keep the size - no realloc | |
255 | // | |
256 | ||
064d808d | 257 | ResetArrays(); |
001be664 | 258 | ResetCounters(); |
c8ab4518 | 259 | |
001be664 | 260 | fHasEntry = kFALSE; |
c8ab4518 | 261 | |
001be664 | 262 | } |
263 | ||
264 | //_____________________________________________________________________________ | |
064d808d | 265 | void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime) |
001be664 | 266 | { |
267 | // | |
268 | // Reset the array but keep the size if no need to enlarge - no realloc | |
269 | // | |
270 | ||
c8ab4518 | 271 | fDet = -1; |
001be664 | 272 | fLayer = -1; |
273 | fStack = -1; | |
c8ab4518 | 274 | fSM = -1; |
275 | ||
276 | if ((nrow > fNrows) || | |
277 | (ncol > fNcols) || | |
278 | (ntime > fNtbins)) { | |
279 | Allocate(nrow, ncol, ntime); | |
280 | } | |
281 | else { | |
064d808d | 282 | ResetArrays(); |
c8ab4518 | 283 | ResetCounters(); |
284 | fHasEntry = kFALSE; | |
285 | } | |
001be664 | 286 | |
001be664 | 287 | } |
288 | ||
ca21baaa | 289 | //_____________________________________________________________________________ |
290 | void AliTRDSignalIndex::ClearAll() | |
291 | { | |
292 | // | |
293 | // Reset the values - clear all! | |
294 | // | |
295 | ||
c8ab4518 | 296 | fDet = -1; |
297 | fLayer = -1; | |
298 | fStack = -1; | |
299 | fSM = -1; | |
ca21baaa | 300 | |
c8ab4518 | 301 | fNrows = -1; |
302 | fNcols = -1; | |
ca21baaa | 303 | fNtbins = -1; |
304 | ||
064d808d | 305 | if (fBoolIndex) { |
306 | delete [] fBoolIndex; | |
307 | fBoolIndex = NULL; | |
308 | } | |
309 | ||
310 | if (fSortedIndex) { | |
311 | delete [] fSortedIndex; | |
312 | fSortedIndex = NULL; | |
c8ab4518 | 313 | } |
064d808d | 314 | |
ca21baaa | 315 | ResetCounters(); |
c8ab4518 | 316 | |
ca21baaa | 317 | fHasEntry = kFALSE; |
ae63fafc | 318 | fSortedWasInit = kFALSE; |
319 | fMaxLimit = 0; | |
c8ab4518 | 320 | |
ca21baaa | 321 | } |
322 | ||
323 | //_____________________________________________________________________________ | |
064d808d | 324 | void AliTRDSignalIndex::AddIndexTBin(Int_t row, Int_t col, Int_t /*tbin*/) |
ca21baaa | 325 | { |
064d808d | 326 | // |
327 | // This function is now obsolate, it will be deleted in future. | |
c8ab4518 | 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 | // | |
064d808d | 333 | |
334 | AddIndexRC(row, col); | |
c8ab4518 | 335 | |
064d808d | 336 | } |
c8ab4518 | 337 | |
064d808d | 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 | // | |
c8ab4518 | 346 | |
064d808d | 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; | |
c8ab4518 | 352 | } |
064d808d | 353 | |
354 | fBoolIndex[row*fNcols+col]=kTRUE; | |
ca21baaa | 355 | |
356 | fHasEntry = kTRUE; | |
c8ab4518 | 357 | |
ca21baaa | 358 | } |
359 | ||
360 | //_____________________________________________________________________________ | |
361 | Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col) | |
362 | { | |
c8ab4518 | 363 | // |
064d808d | 364 | // Returns next used RC combination |
c8ab4518 | 365 | // |
ca21baaa | 366 | |
064d808d | 367 | if(fSortedIndex[fPositionRC]>-1){ |
368 | row = fCurrRow = fSortedIndex[fPositionRC]; | |
369 | fPositionRC++; | |
370 | col = fCurrCol = fSortedIndex[fPositionRC]; | |
371 | fPositionRC++; | |
372 | return kTRUE; | |
c8ab4518 | 373 | } |
374 | else { | |
064d808d | 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 | } | |
c8ab4518 | 387 | } |
ca21baaa | 388 | |
ca21baaa | 389 | } |
390 | ||
391 | //_____________________________________________________________________________ | |
c8ab4518 | 392 | Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin) |
ca21baaa | 393 | { |
c8ab4518 | 394 | // |
064d808d | 395 | // Returns the next tbin, or if there is no next time bin, it returns the |
396 | // next used RC combination. | |
397 | // | |
ca21baaa | 398 | |
c8ab4518 | 399 | if (NextTbinIndex(tbin)) { |
064d808d | 400 | row = fCurrRow; |
401 | col = fCurrCol; | |
c8ab4518 | 402 | return kTRUE; |
403 | } | |
404 | else { | |
405 | if (NextRCIndex(row, col)) { | |
406 | return NextRCTbinIndex(row, col, tbin); | |
ca21baaa | 407 | } |
c8ab4518 | 408 | } |
ca21baaa | 409 | |
410 | return kFALSE; | |
c8ab4518 | 411 | |
ca21baaa | 412 | } |
413 | ||
414 | //_____________________________________________________________________________ | |
c8ab4518 | 415 | Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin) |
ca21baaa | 416 | { |
c8ab4518 | 417 | // |
064d808d | 418 | // Returns the next tbin of the current RC combination |
c8ab4518 | 419 | // |
064d808d | 420 | |
421 | if(fCurrTbin<fNtbins) | |
422 | { | |
423 | tbin = fCurrTbin++; | |
424 | return kTRUE; | |
425 | } | |
ca21baaa | 426 | |
064d808d | 427 | return kFALSE; |
ca21baaa | 428 | |
064d808d | 429 | } |
ca21baaa | 430 | |
064d808d | 431 | //_____________________________________________________________________________ |
432 | void AliTRDSignalIndex::InitSortedIndex() | |
433 | { | |
434 | // | |
435 | // Creates the SortedIndex | |
436 | // | |
c8ab4518 | 437 | |
064d808d | 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 | } | |
ca21baaa | 448 | } |
449 | ||
c8ab4518 | 450 | //_____________________________________________________________________________ |
451 | void AliTRDSignalIndex::ResetCounters() | |
452 | { | |
453 | // | |
454 | // Reset the counters/iterators | |
455 | // | |
456 | ||
064d808d | 457 | fCurrRow = -1; |
458 | fCurrCol = -1; | |
459 | fCurrTbin = -1; | |
460 | fPositionRC = 0; | |
c8ab4518 | 461 | } |