]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDSignalIndex.cxx
AliESDCentrality replaced by AliCentrality
[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
534529cb 28#include <algorithm>
064d808d 29#include "TObject.h"
ca21baaa 30#include "AliLog.h"
c8ab4518 31#include "AliTRDSignalIndex.h"
32
ca21baaa 33ClassImp(AliTRDSignalIndex)
34
35//_____________________________________________________________________________
36AliTRDSignalIndex::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//_____________________________________________________________________________
64AliTRDSignalIndex::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 92AliTRDSignalIndex::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 123AliTRDSignalIndex::~AliTRDSignalIndex()
ca21baaa 124{
125 //
c8ab4518 126 // Destructor
ca21baaa 127 //
c8ab4518 128
064d808d 129 if (fBoolIndex) {
130 delete [] fBoolIndex;
131 fBoolIndex = NULL;
132 }
133
134if (fSortedIndex) {
135 delete [] fSortedIndex;
136 fSortedIndex = NULL;
c10bf383 137 }
c8ab4518 138
ca21baaa 139}
140
141//_____________________________________________________________________________
142void 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//_____________________________________________________________________________
180AliTRDSignalIndex& 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 192void 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//_____________________________________________________________________________
226void AliTRDSignalIndex::ResetArrays()
227{
228 memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
c8b52e81 229 memset(fSortedIndex,0xFF,sizeof(RowCol)*fCountRC);
ae63fafc 230 fSortedWasInit = kFALSE;
064d808d 231}
232
ca21baaa 233//_____________________________________________________________________________
234void 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//_____________________________________________________________________________
251void AliTRDSignalIndex::ResetContent()
252{
253 //
254 // Reset the array but keep the size - no realloc
255 //
256
534529cb 257 fDet = -1;
258 fLayer = -1;
259 fStack = -1;
260 fSM = -1;
261
064d808d 262 ResetArrays();
001be664 263 ResetCounters();
c8ab4518 264
534529cb 265 fCountRC = 1;
c8ab4518 266
001be664 267}
268
269//_____________________________________________________________________________
064d808d 270void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
001be664 271{
272 //
273 // Reset the array but keep the size if no need to enlarge - no realloc
274 //
275
c8ab4518 276 fDet = -1;
001be664 277 fLayer = -1;
278 fStack = -1;
c8ab4518 279 fSM = -1;
280
281 if ((nrow > fNrows) ||
282 (ncol > fNcols) ||
283 (ntime > fNtbins)) {
284 Allocate(nrow, ncol, ntime);
285 }
286 else {
064d808d 287 ResetArrays();
c8ab4518 288 ResetCounters();
534529cb 289 fCountRC = 1;
c8ab4518 290 }
001be664 291
001be664 292}
293
ca21baaa 294//_____________________________________________________________________________
295void AliTRDSignalIndex::ClearAll()
296{
297 //
298 // Reset the values - clear all!
299 //
300
c8ab4518 301 fDet = -1;
302 fLayer = -1;
303 fStack = -1;
304 fSM = -1;
ca21baaa 305
c8ab4518 306 fNrows = -1;
307 fNcols = -1;
ca21baaa 308 fNtbins = -1;
309
064d808d 310 if (fBoolIndex) {
311 delete [] fBoolIndex;
312 fBoolIndex = NULL;
313 }
314
315 if (fSortedIndex) {
316 delete [] fSortedIndex;
317 fSortedIndex = NULL;
c8ab4518 318 }
064d808d 319
ca21baaa 320 ResetCounters();
c8ab4518 321
534529cb 322 fCountRC = 1;
ae63fafc 323 fSortedWasInit = kFALSE;
324 fMaxLimit = 0;
c8ab4518 325
ca21baaa 326}
327
ca21baaa 328//_____________________________________________________________________________
1ab4da8c 329Bool_t AliTRDSignalIndex::CheckSorting(Int_t &row, Int_t &col)
ca21baaa 330{
c8ab4518 331 //
1ab4da8c 332 // Check whether array was read to end or it was not sorted until now
c8ab4518 333 //
ca21baaa 334
1ab4da8c 335 if(fSortedWasInit || fCountRC==1)
336 { //we already reached the end of the array
337 ResetCounters();
338 row = fCurrRow;
339 col = fCurrCol;
340 return kFALSE;
341 }
342 else
343 { //we have not sorted the array up to now, let's do so
344 InitSortedIndex();
345 return NextRCIndex(row, col);
346 }
ca21baaa 347}
348
349//_____________________________________________________________________________
c8ab4518 350Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
ca21baaa 351{
c8ab4518 352 //
064d808d 353 // Returns the next tbin, or if there is no next time bin, it returns the
354 // next used RC combination.
355 //
ca21baaa 356
c8ab4518 357 if (NextTbinIndex(tbin)) {
064d808d 358 row = fCurrRow;
359 col = fCurrCol;
c8ab4518 360 return kTRUE;
361 }
362 else {
363 if (NextRCIndex(row, col)) {
364 return NextRCTbinIndex(row, col, tbin);
ca21baaa 365 }
c8ab4518 366 }
ca21baaa 367
368 return kFALSE;
c8ab4518 369
ca21baaa 370}
371
372//_____________________________________________________________________________
c8ab4518 373Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
ca21baaa 374{
c8ab4518 375 //
064d808d 376 // Returns the next tbin of the current RC combination
c8ab4518 377 //
064d808d 378
379 if(fCurrTbin<fNtbins)
380 {
381 tbin = fCurrTbin++;
382 return kTRUE;
383 }
ca21baaa 384
064d808d 385 return kFALSE;
ca21baaa 386
064d808d 387}
ca21baaa 388
064d808d 389//_____________________________________________________________________________
390void AliTRDSignalIndex::InitSortedIndex()
391{
392 //
393 // Creates the SortedIndex
394 //
c8ab4518 395
064d808d 396 fSortedWasInit = kTRUE;
534529cb 397 std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC);
398
ca21baaa 399}
400
c8ab4518 401//_____________________________________________________________________________
402void AliTRDSignalIndex::ResetCounters()
403{
404 //
405 // Reset the counters/iterators
406 //
407
064d808d 408 fCurrRow = -1;
409 fCurrCol = -1;
410 fCurrTbin = -1;
411 fPositionRC = 0;
c8ab4518 412}