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