]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDSignalIndex.cxx
Bug fix in multiplicity limits.
[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
ca21baaa 28#include "TArrayI.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)
43 ,fIndex(NULL)
44 ,fPositionRow(0)
45 ,fPositionCol(0)
46 ,fPositionTbin(0)
47 ,fLastRow(0)
48 ,fLastCol(0)
49 ,fLastTbin(0)
50 ,fNrows(0)
51 ,fNcols(0)
52 ,fNtbins(0)
53 ,fMaxLimit(0)
54 ,fResetCounters(kTRUE)
55 ,fHasEntry(kFALSE)
ca21baaa 56{
57 //
c8ab4518 58 // Default contructor
ca21baaa 59 //
c8ab4518 60
ca21baaa 61 ResetCounters();
c8ab4518 62
ca21baaa 63}
64
65//_____________________________________________________________________________
66AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
c8ab4518 67 :TObject()
68 ,fDet(-1)
69 ,fLayer(-1)
70 ,fStack(-1)
71 ,fSM(-1)
72 ,fIndex(NULL)
73 ,fPositionRow(0)
74 ,fPositionCol(0)
75 ,fPositionTbin(0)
76 ,fLastRow(0)
77 ,fLastCol(0)
78 ,fLastTbin(0)
79 ,fNrows(0)
80 ,fNcols(0)
81 ,fNtbins(0)
82 ,fMaxLimit(0)
83 ,fResetCounters(kTRUE)
84 ,fHasEntry(kFALSE)
ca21baaa 85{
c8ab4518 86 //
87 // Not the default contructor... hmmm...
88 //
89
ca21baaa 90 Allocate(nrow, ncol, ntime);
c8ab4518 91
ca21baaa 92}
93
94//_____________________________________________________________________________
c8ab4518 95AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
96 :TObject(a)
97 ,fDet(a.fDet)
98 ,fLayer(a.fLayer)
99 ,fStack(a.fStack)
100 ,fSM(a.fSM)
101 ,fIndex(a.fIndex)
102 ,fPositionRow(a.fPositionRow)
103 ,fPositionCol(a.fPositionCol)
104 ,fPositionTbin(a.fPositionTbin)
105 ,fLastRow(a.fLastRow)
106 ,fLastCol(a.fLastCol)
107 ,fLastTbin(a.fLastTbin)
108 ,fNrows(a.fNrows)
109 ,fNcols(a.fNcols)
110 ,fNtbins(a.fNtbins)
111 ,fMaxLimit(a.fMaxLimit)
112 ,fResetCounters(a.fResetCounters)
113 ,fHasEntry(a.fHasEntry)
ca21baaa 114{
115 //
c8ab4518 116 // Copy constructor
ca21baaa 117 //
118
ca21baaa 119}
120
121//_____________________________________________________________________________
c8ab4518 122AliTRDSignalIndex::~AliTRDSignalIndex()
ca21baaa 123{
124 //
c8ab4518 125 // Destructor
ca21baaa 126 //
c8ab4518 127
c10bf383 128 if (fIndex) {
129 delete fIndex;
130 fIndex = NULL;
131 }
c8ab4518 132
ca21baaa 133}
134
135//_____________________________________________________________________________
136void AliTRDSignalIndex::Copy(TObject &a) const
137{
138 //
139 // Copy function
140 //
141
c8ab4518 142 ((AliTRDSignalIndex &)a).fDet = fDet;
143 ((AliTRDSignalIndex &)a).fLayer = fLayer;
144 ((AliTRDSignalIndex &)a).fStack = fStack;
145 ((AliTRDSignalIndex &)a).fSM = fSM;
146 ((AliTRDSignalIndex &)a).fIndex = fIndex;
147 ((AliTRDSignalIndex &)a).fPositionRow = fPositionRow;
148 ((AliTRDSignalIndex &)a).fPositionTbin = fPositionTbin;
149 ((AliTRDSignalIndex &)a).fLastRow = fLastRow;
150 ((AliTRDSignalIndex &)a).fLastCol = fLastCol;
151 ((AliTRDSignalIndex &)a).fLastTbin = fLastTbin;
152 ((AliTRDSignalIndex &)a).fNrows = fNrows;
153 ((AliTRDSignalIndex &)a).fNcols = fNcols;
154 ((AliTRDSignalIndex &)a).fNtbins = fNtbins;
155 ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit;
ca21baaa 156 ((AliTRDSignalIndex &)a).fResetCounters = fResetCounters;
c8ab4518 157 ((AliTRDSignalIndex &)a).fHasEntry = fHasEntry;
158
ca21baaa 159}
160
161//_____________________________________________________________________________
162AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a)
163{
164 //
165 // Assignment operator
166 //
167
168 if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this);
169 return *this;
170
171}
c8ab4518 172
ca21baaa 173//_____________________________________________________________________________
174void AliTRDSignalIndex::Allocate(Int_t nrow, Int_t ncol,Int_t ntime)
175{
176 //
c8ab4518 177 // Create the arrays
ca21baaa 178 //
179
180 fNrows = nrow;
181 fNcols = ncol;
182 fNtbins = ntime;
183
184 fMaxLimit = nrow * ncol * ntime + nrow * ncol * 2;
c8ab4518 185 if (fIndex) {
186 delete fIndex;
187 fIndex = NULL;
188 }
ca21baaa 189
190 fIndex = new TArrayI(fMaxLimit);
ca21baaa 191 fIndex->Reset(-1);
c8ab4518 192
ca21baaa 193 ResetCounters();
c8ab4518 194
ca21baaa 195 fHasEntry = kFALSE;
c8ab4518 196
ca21baaa 197}
198
199//_____________________________________________________________________________
200void AliTRDSignalIndex::Reset()
201{
202 //
203 // Reset the array but keep the size - realloc
204 //
205
c8ab4518 206 fDet = -1;
ca21baaa 207 fLayer = -1;
208 fStack = -1;
c8ab4518 209 fSM = -1;
ca21baaa 210
c8ab4518 211 // All will be lost
ca21baaa 212 Allocate(fNrows, fNcols, fNtbins);
c8ab4518 213
ca21baaa 214}
215
001be664 216//_____________________________________________________________________________
217void AliTRDSignalIndex::ResetContent()
218{
219 //
220 // Reset the array but keep the size - no realloc
221 //
222
223 fIndex->Reset(-1);
224 ResetCounters();
c8ab4518 225
001be664 226 fHasEntry = kFALSE;
c8ab4518 227
001be664 228}
229
230//_____________________________________________________________________________
231void AliTRDSignalIndex::ResetContentConditional(Int_t nrow, Int_t ncol,Int_t ntime)
232{
233 //
234 // Reset the array but keep the size if no need to enlarge - no realloc
235 //
236
c8ab4518 237 fDet = -1;
001be664 238 fLayer = -1;
239 fStack = -1;
c8ab4518 240 fSM = -1;
241
242 if ((nrow > fNrows) ||
243 (ncol > fNcols) ||
244 (ntime > fNtbins)) {
245 Allocate(nrow, ncol, ntime);
246 }
247 else {
248 fIndex->Reset(-1);
249 ResetCounters();
250 fHasEntry = kFALSE;
251 }
001be664 252
001be664 253}
254
ca21baaa 255//_____________________________________________________________________________
256void AliTRDSignalIndex::ClearAll()
257{
258 //
259 // Reset the values - clear all!
260 //
261
c8ab4518 262 fDet = -1;
263 fLayer = -1;
264 fStack = -1;
265 fSM = -1;
ca21baaa 266
c8ab4518 267 fNrows = -1;
268 fNcols = -1;
ca21baaa 269 fNtbins = -1;
270
c8ab4518 271 if (fIndex) {
272 delete fIndex;
273 fIndex = NULL;
274 }
ca21baaa 275 fIndex = new TArrayI();
276 ResetCounters();
c8ab4518 277
ca21baaa 278 fHasEntry = kFALSE;
c8ab4518 279
ca21baaa 280}
281
282//_____________________________________________________________________________
283void AliTRDSignalIndex::AddIndexTBin(Int_t row, Int_t col, Int_t tbin)
284{
c8ab4518 285 //
286 // Store the index row-column-tbin as an interesting one
287 // The RC index is updated to!!!
288 // This is to be used in the TRD clusterizer!
289 //
290
291 if (row * col * tbin + row * col * 2 >= fMaxLimit) {
292 AliError(Form("Out-of-limits fPositionCol + fNtbins %d. Limit is: %d"
293 ,fPositionCol + fNtbins
294 ,fMaxLimit));
295 return;
296 }
297
298 if ((row != fLastRow) ||
299 (col != fLastCol)) {
ca21baaa 300
c8ab4518 301 // New RC combination
302 if (fResetCounters == kTRUE) {
303 fPositionRow = 0;
304 fPositionCol = 1;
305 fResetCounters = kFALSE;
ca21baaa 306 }
c8ab4518 307 else {
308 fPositionRow += fNtbins + 2;
309 fPositionCol += fNtbins + 2;
ca21baaa 310 }
c8ab4518 311
312 fPositionTbin = 1;
313
314 (*fIndex)[fPositionRow] = row;
315 (*fIndex)[fPositionCol] = col;
316 (*fIndex)[fPositionCol + fPositionTbin] = tbin;
317 ++fPositionTbin;
318
319 }
320 else {
321
322 // Same RCT combination ?
323
324 (*fIndex)[fPositionCol + fPositionTbin] = tbin;
325 ++fPositionTbin;
326
327 }
ca21baaa 328
329 fLastRow = row;
330 fLastCol = col;
331 fLastTbin = tbin;
332
333 fHasEntry = kTRUE;
c8ab4518 334
ca21baaa 335}
336
337//_____________________________________________________________________________
338Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
339{
c8ab4518 340 //
341 // Return the position (index in the data array) of the next available pad
342 //
ca21baaa 343
c8ab4518 344 if (fResetCounters == kTRUE) {
345 fPositionRow = 0;
346 fPositionCol = 1;
347 fResetCounters = kFALSE;
348 }
349 else {
350 fPositionRow += fNtbins + 2;
351 fPositionCol += fNtbins + 2;
352 }
ecf39416 353
c8ab4518 354 if (fPositionRow >= fMaxLimit) {
355 return kFALSE;
356 }
ca21baaa 357
358 fPositionTbin = 1;
359
360 row = (*fIndex)[fPositionRow];
361 col = (*fIndex)[fPositionCol];
362
c8ab4518 363 if ((row > -1) &&
364 (col > -1)) {
ca21baaa 365 return kTRUE;
c8ab4518 366 }
ca21baaa 367
368 return kFALSE;
c8ab4518 369
ca21baaa 370}
371
372//_____________________________________________________________________________
c8ab4518 373Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
ca21baaa 374{
c8ab4518 375 //
376 // Return the position (index in the data array) of the next available tbin
ca21baaa 377 // within the current pad
c8ab4518 378 //
ca21baaa 379
c8ab4518 380 if (fPositionRow >= fMaxLimit) {
381 return kFALSE;
382 }
ca21baaa 383
c8ab4518 384 if (NextTbinIndex(tbin)) {
385 row = (*fIndex)[fPositionRow];
386 col = (*fIndex)[fPositionCol];
387 fResetCounters = kFALSE;
388 return kTRUE;
389 }
390 else {
391 if (NextRCIndex(row, col)) {
392 return NextRCTbinIndex(row, col, tbin);
ca21baaa 393 }
c8ab4518 394 }
ca21baaa 395
396 return kFALSE;
c8ab4518 397
ca21baaa 398}
399
400//_____________________________________________________________________________
c8ab4518 401Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
ca21baaa 402{
c8ab4518 403 //
404 // Return the position (index in the data array) of the next available tbin
ca21baaa 405 // within the current pad
c8ab4518 406 //
ca21baaa 407
c8ab4518 408 if ((fPositionCol + fPositionTbin >= fMaxLimit) ||
409 (fPositionTbin > fNtbins )) {
410 return kFALSE;
411 }
ca21baaa 412
413 tbin = (*fIndex)[fPositionCol + fPositionTbin];
414
c8ab4518 415 if (tbin > -1) {
416 ++fPositionTbin;
417 return kTRUE;
418 }
ca21baaa 419
420 return kFALSE;
c8ab4518 421
ca21baaa 422}
423
c8ab4518 424//_____________________________________________________________________________
425void AliTRDSignalIndex::ResetCounters()
426{
427 //
428 // Reset the counters/iterators
429 //
430
431 fPositionRow = 0;
432 fPositionCol = fPositionRow + 1;
433 fPositionTbin = 1;
434 fLastRow = -1;
435 fLastCol = -1;
436 fLastTbin = -1;
437 fResetCounters = kTRUE;
438
439}