]>
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 | ||
186 | if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this); | |
187 | return *this; | |
188 | ||
189 | } | |
c8ab4518 | 190 | |
ca21baaa | 191 | //_____________________________________________________________________________ |
064d808d | 192 | void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime) |
ca21baaa | 193 | { |
194 | // | |
c8ab4518 | 195 | // Create the arrays |
ca21baaa | 196 | // |
197 | ||
198 | fNrows = nrow; | |
199 | fNcols = ncol; | |
200 | fNtbins = ntime; | |
201 | ||
064d808d | 202 | fMaxLimit = nrow * ncol + 1; |
203 | ||
204 | if (fBoolIndex) { | |
205 | delete [] fBoolIndex; | |
206 | fBoolIndex = NULL; | |
207 | } | |
208 | if (fSortedIndex) { | |
209 | delete [] fSortedIndex; | |
210 | fSortedIndex = NULL; | |
c8ab4518 | 211 | } |
ca21baaa | 212 | |
064d808d | 213 | fBoolIndex = new Bool_t[fMaxLimit]; |
dc25be4b | 214 | fSortedIndex = new RowCol[fMaxLimit+1]; |
c8ab4518 | 215 | |
c8b52e81 | 216 | fCountRC = fMaxLimit+1; |
217 | ||
064d808d | 218 | ResetArrays(); |
ca21baaa | 219 | ResetCounters(); |
c8ab4518 | 220 | |
534529cb | 221 | fCountRC = 1; |
c8ab4518 | 222 | |
ca21baaa | 223 | } |
224 | ||
064d808d | 225 | //_____________________________________________________________________________ |
226 | void AliTRDSignalIndex::ResetArrays() | |
227 | { | |
c5304fc0 | 228 | if (!IsAllocated()) |
229 | return; | |
064d808d | 230 | memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit); |
c8b52e81 | 231 | memset(fSortedIndex,0xFF,sizeof(RowCol)*fCountRC); |
ae63fafc | 232 | fSortedWasInit = kFALSE; |
064d808d | 233 | } |
234 | ||
ca21baaa | 235 | //_____________________________________________________________________________ |
236 | void AliTRDSignalIndex::Reset() | |
237 | { | |
238 | // | |
239 | // Reset the array but keep the size - realloc | |
240 | // | |
241 | ||
c8ab4518 | 242 | fDet = -1; |
ca21baaa | 243 | fLayer = -1; |
244 | fStack = -1; | |
c8ab4518 | 245 | fSM = -1; |
ca21baaa | 246 | |
c8ab4518 | 247 | // All will be lost |
ca21baaa | 248 | Allocate(fNrows, fNcols, fNtbins); |
c8ab4518 | 249 | |
ca21baaa | 250 | } |
251 | ||
001be664 | 252 | //_____________________________________________________________________________ |
253 | void AliTRDSignalIndex::ResetContent() | |
254 | { | |
255 | // | |
256 | // Reset the array but keep the size - no realloc | |
257 | // | |
258 | ||
534529cb | 259 | fDet = -1; |
260 | fLayer = -1; | |
261 | fStack = -1; | |
262 | fSM = -1; | |
263 | ||
064d808d | 264 | ResetArrays(); |
001be664 | 265 | ResetCounters(); |
c8ab4518 | 266 | |
534529cb | 267 | fCountRC = 1; |
c8ab4518 | 268 | |
001be664 | 269 | } |
270 | ||
271 | //_____________________________________________________________________________ | |
064d808d | 272 | void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime) |
001be664 | 273 | { |
274 | // | |
275 | // Reset the array but keep the size if no need to enlarge - no realloc | |
276 | // | |
277 | ||
c8ab4518 | 278 | fDet = -1; |
001be664 | 279 | fLayer = -1; |
280 | fStack = -1; | |
c8ab4518 | 281 | fSM = -1; |
282 | ||
283 | if ((nrow > fNrows) || | |
284 | (ncol > fNcols) || | |
285 | (ntime > fNtbins)) { | |
286 | Allocate(nrow, ncol, ntime); | |
287 | } | |
288 | else { | |
064d808d | 289 | ResetArrays(); |
c8ab4518 | 290 | ResetCounters(); |
534529cb | 291 | fCountRC = 1; |
c8ab4518 | 292 | } |
001be664 | 293 | |
001be664 | 294 | } |
295 | ||
ca21baaa | 296 | //_____________________________________________________________________________ |
297 | void AliTRDSignalIndex::ClearAll() | |
298 | { | |
299 | // | |
300 | // Reset the values - clear all! | |
301 | // | |
302 | ||
c8ab4518 | 303 | fDet = -1; |
304 | fLayer = -1; | |
305 | fStack = -1; | |
306 | fSM = -1; | |
ca21baaa | 307 | |
c8ab4518 | 308 | fNrows = -1; |
309 | fNcols = -1; | |
ca21baaa | 310 | fNtbins = -1; |
311 | ||
064d808d | 312 | if (fBoolIndex) { |
313 | delete [] fBoolIndex; | |
314 | fBoolIndex = NULL; | |
315 | } | |
316 | ||
317 | if (fSortedIndex) { | |
318 | delete [] fSortedIndex; | |
319 | fSortedIndex = NULL; | |
c8ab4518 | 320 | } |
064d808d | 321 | |
ca21baaa | 322 | ResetCounters(); |
c8ab4518 | 323 | |
534529cb | 324 | fCountRC = 1; |
ae63fafc | 325 | fSortedWasInit = kFALSE; |
326 | fMaxLimit = 0; | |
c8ab4518 | 327 | |
ca21baaa | 328 | } |
329 | ||
ca21baaa | 330 | //_____________________________________________________________________________ |
1ab4da8c | 331 | Bool_t AliTRDSignalIndex::CheckSorting(Int_t &row, Int_t &col) |
ca21baaa | 332 | { |
c8ab4518 | 333 | // |
1ab4da8c | 334 | // Check whether array was read to end or it was not sorted until now |
c8ab4518 | 335 | // |
ca21baaa | 336 | |
1ab4da8c | 337 | if(fSortedWasInit || fCountRC==1) |
338 | { //we already reached the end of the array | |
339 | ResetCounters(); | |
340 | row = fCurrRow; | |
341 | col = fCurrCol; | |
342 | return kFALSE; | |
343 | } | |
344 | else | |
345 | { //we have not sorted the array up to now, let's do so | |
346 | InitSortedIndex(); | |
347 | return NextRCIndex(row, col); | |
348 | } | |
ca21baaa | 349 | } |
350 | ||
351 | //_____________________________________________________________________________ | |
c8ab4518 | 352 | Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin) |
ca21baaa | 353 | { |
c8ab4518 | 354 | // |
064d808d | 355 | // Returns the next tbin, or if there is no next time bin, it returns the |
356 | // next used RC combination. | |
357 | // | |
ca21baaa | 358 | |
c8ab4518 | 359 | if (NextTbinIndex(tbin)) { |
064d808d | 360 | row = fCurrRow; |
361 | col = fCurrCol; | |
c8ab4518 | 362 | return kTRUE; |
363 | } | |
364 | else { | |
365 | if (NextRCIndex(row, col)) { | |
366 | return NextRCTbinIndex(row, col, tbin); | |
ca21baaa | 367 | } |
c8ab4518 | 368 | } |
ca21baaa | 369 | |
370 | return kFALSE; | |
c8ab4518 | 371 | |
ca21baaa | 372 | } |
373 | ||
374 | //_____________________________________________________________________________ | |
c8ab4518 | 375 | Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin) |
ca21baaa | 376 | { |
c8ab4518 | 377 | // |
064d808d | 378 | // Returns the next tbin of the current RC combination |
c8ab4518 | 379 | // |
064d808d | 380 | |
381 | if(fCurrTbin<fNtbins) | |
382 | { | |
383 | tbin = fCurrTbin++; | |
384 | return kTRUE; | |
385 | } | |
ca21baaa | 386 | |
064d808d | 387 | return kFALSE; |
ca21baaa | 388 | |
064d808d | 389 | } |
ca21baaa | 390 | |
064d808d | 391 | //_____________________________________________________________________________ |
392 | void AliTRDSignalIndex::InitSortedIndex() | |
393 | { | |
394 | // | |
395 | // Creates the SortedIndex | |
396 | // | |
c8ab4518 | 397 | |
064d808d | 398 | fSortedWasInit = kTRUE; |
534529cb | 399 | std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC); |
400 | ||
ca21baaa | 401 | } |
402 | ||
c8ab4518 | 403 | //_____________________________________________________________________________ |
404 | void AliTRDSignalIndex::ResetCounters() | |
405 | { | |
406 | // | |
407 | // Reset the counters/iterators | |
408 | // | |
409 | ||
064d808d | 410 | fCurrRow = -1; |
411 | fCurrCol = -1; | |
412 | fCurrTbin = -1; | |
413 | fPositionRC = 0; | |
c8ab4518 | 414 | } |