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