]>
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; | |
ffc57435 | 153 | ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit; |
064d808d | 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 | ||
064d808d | 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 | // | |
c8ab4518 | 331 | |
064d808d | 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; | |
c8ab4518 | 337 | } |
064d808d | 338 | |
339 | fBoolIndex[row*fNcols+col]=kTRUE; | |
ca21baaa | 340 | |
341 | fHasEntry = kTRUE; | |
c8ab4518 | 342 | |
ca21baaa | 343 | } |
344 | ||
345 | //_____________________________________________________________________________ | |
346 | Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col) | |
347 | { | |
c8ab4518 | 348 | // |
064d808d | 349 | // Returns next used RC combination |
c8ab4518 | 350 | // |
ca21baaa | 351 | |
064d808d | 352 | if(fSortedIndex[fPositionRC]>-1){ |
353 | row = fCurrRow = fSortedIndex[fPositionRC]; | |
354 | fPositionRC++; | |
355 | col = fCurrCol = fSortedIndex[fPositionRC]; | |
356 | fPositionRC++; | |
357 | return kTRUE; | |
c8ab4518 | 358 | } |
359 | else { | |
064d808d | 360 | if(fSortedWasInit || !fHasEntry) |
e484a267 | 361 | { //we already reached the end of the array |
064d808d | 362 | ResetCounters(); |
363 | row = fCurrRow; | |
364 | col = fCurrCol; | |
365 | return kFALSE; | |
366 | } | |
367 | else | |
e484a267 | 368 | { //we have not created the sorted array up to now, let's do so |
064d808d | 369 | InitSortedIndex(); |
370 | return NextRCIndex(row, col); | |
371 | } | |
c8ab4518 | 372 | } |
ca21baaa | 373 | |
ca21baaa | 374 | } |
375 | ||
376 | //_____________________________________________________________________________ | |
c8ab4518 | 377 | Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin) |
ca21baaa | 378 | { |
c8ab4518 | 379 | // |
064d808d | 380 | // Returns the next tbin, or if there is no next time bin, it returns the |
381 | // next used RC combination. | |
382 | // | |
ca21baaa | 383 | |
c8ab4518 | 384 | if (NextTbinIndex(tbin)) { |
064d808d | 385 | row = fCurrRow; |
386 | col = fCurrCol; | |
c8ab4518 | 387 | return kTRUE; |
388 | } | |
389 | else { | |
390 | if (NextRCIndex(row, col)) { | |
391 | return NextRCTbinIndex(row, col, tbin); | |
ca21baaa | 392 | } |
c8ab4518 | 393 | } |
ca21baaa | 394 | |
395 | return kFALSE; | |
c8ab4518 | 396 | |
ca21baaa | 397 | } |
398 | ||
399 | //_____________________________________________________________________________ | |
c8ab4518 | 400 | Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin) |
ca21baaa | 401 | { |
c8ab4518 | 402 | // |
064d808d | 403 | // Returns the next tbin of the current RC combination |
c8ab4518 | 404 | // |
064d808d | 405 | |
406 | if(fCurrTbin<fNtbins) | |
407 | { | |
408 | tbin = fCurrTbin++; | |
409 | return kTRUE; | |
410 | } | |
ca21baaa | 411 | |
064d808d | 412 | return kFALSE; |
ca21baaa | 413 | |
064d808d | 414 | } |
ca21baaa | 415 | |
064d808d | 416 | //_____________________________________________________________________________ |
417 | void AliTRDSignalIndex::InitSortedIndex() | |
418 | { | |
419 | // | |
420 | // Creates the SortedIndex | |
421 | // | |
c8ab4518 | 422 | |
064d808d | 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 | } | |
ca21baaa | 433 | } |
434 | ||
c8ab4518 | 435 | //_____________________________________________________________________________ |
436 | void AliTRDSignalIndex::ResetCounters() | |
437 | { | |
438 | // | |
439 | // Reset the counters/iterators | |
440 | // | |
441 | ||
064d808d | 442 | fCurrRow = -1; |
443 | fCurrCol = -1; | |
444 | fCurrTbin = -1; | |
445 | fPositionRC = 0; | |
c8ab4518 | 446 | } |