1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // General container for data from TRD detector segments //
21 // Adapted from AliDigits, origin M.Ivanov //
24 // Mateusz Ploskon (ploskon@ikf.uni-frankfurt.de) //
26 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliTRDSignalIndex.h"
33 ClassImp(AliTRDSignalIndex)
35 //_____________________________________________________________________________
36 AliTRDSignalIndex::AliTRDSignalIndex()
47 ,fSortedWasInit(kFALSE)
63 //_____________________________________________________________________________
64 AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
75 ,fSortedWasInit(kFALSE)
84 // Not the default contructor... hmmm...
87 Allocate(nrow, ncol, ntime);
91 //_____________________________________________________________________________
92 AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
100 ,fMaxLimit(a.fMaxLimit)
101 ,fPositionRC(a.fPositionRC)
102 ,fCountRC(a.fCountRC)
103 ,fSortedWasInit(a.fSortedWasInit)
104 ,fCurrRow(a.fCurrRow)
105 ,fCurrCol(a.fCurrCol)
106 ,fCurrTbin(a.fCurrTbin)
115 fBoolIndex = new Bool_t[fMaxLimit];
116 memcpy(fBoolIndex, a.fBoolIndex, fMaxLimit*sizeof(Bool_t));
118 fSortedIndex = new RowCol[fMaxLimit+1];
119 memcpy(fSortedIndex, a.fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
122 //_____________________________________________________________________________
123 AliTRDSignalIndex::~AliTRDSignalIndex()
130 delete [] fBoolIndex;
135 delete [] fSortedIndex;
141 //_____________________________________________________________________________
142 void AliTRDSignalIndex::Copy(TObject &a) const
148 ((AliTRDSignalIndex &)a).fDet = fDet;
149 ((AliTRDSignalIndex &)a).fLayer = fLayer;
150 ((AliTRDSignalIndex &)a).fStack = fStack;
151 ((AliTRDSignalIndex &)a).fSM = fSM;
152 ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit;
153 ((AliTRDSignalIndex &)a).fPositionRC = fPositionRC;
154 ((AliTRDSignalIndex &)a).fCountRC = fCountRC;
155 ((AliTRDSignalIndex &)a).fSortedWasInit = fSortedWasInit;
156 ((AliTRDSignalIndex &)a).fCurrRow = fCurrRow;
157 ((AliTRDSignalIndex &)a).fCurrCol = fCurrCol;
158 ((AliTRDSignalIndex &)a).fCurrTbin = fCurrTbin;
159 ((AliTRDSignalIndex &)a).fNrows = fNrows;
160 ((AliTRDSignalIndex &)a).fNcols = fNcols;
161 ((AliTRDSignalIndex &)a).fNtbins = fNtbins;
163 if(((AliTRDSignalIndex &)a).fBoolIndex)
165 delete [] ((AliTRDSignalIndex &)a).fBoolIndex;
167 ((AliTRDSignalIndex &)a).fBoolIndex = new Bool_t[fMaxLimit];
168 memcpy(((AliTRDSignalIndex &)a).fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
170 if(((AliTRDSignalIndex &)a).fSortedIndex)
172 delete [] ((AliTRDSignalIndex &)a).fSortedIndex;
174 ((AliTRDSignalIndex &)a).fSortedIndex = new RowCol[fMaxLimit+1];
175 memcpy(((AliTRDSignalIndex &)a).fSortedIndex, fSortedIndex, (fMaxLimit+1)*sizeof(RowCol));
179 //_____________________________________________________________________________
180 AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a)
183 // Assignment operator
186 if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this);
191 //_____________________________________________________________________________
192 void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime)
202 fMaxLimit = nrow * ncol + 1;
205 delete [] fBoolIndex;
209 delete [] fSortedIndex;
213 fBoolIndex = new Bool_t[fMaxLimit];
214 fSortedIndex = new RowCol[fMaxLimit+1];
216 fCountRC = fMaxLimit+1;
225 //_____________________________________________________________________________
226 void AliTRDSignalIndex::ResetArrays()
230 memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
231 memset(fSortedIndex,0xFF,sizeof(RowCol)*fCountRC);
232 fSortedWasInit = kFALSE;
235 //_____________________________________________________________________________
236 void AliTRDSignalIndex::Reset()
239 // Reset the array but keep the size - realloc
248 Allocate(fNrows, fNcols, fNtbins);
252 //_____________________________________________________________________________
253 void AliTRDSignalIndex::ResetContent()
256 // Reset the array but keep the size - no realloc
271 //_____________________________________________________________________________
272 void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
275 // Reset the array but keep the size if no need to enlarge - no realloc
283 if ((nrow > fNrows) ||
286 Allocate(nrow, ncol, ntime);
296 //_____________________________________________________________________________
297 void AliTRDSignalIndex::ClearAll()
300 // Reset the values - clear all!
313 delete [] fBoolIndex;
318 delete [] fSortedIndex;
325 fSortedWasInit = kFALSE;
330 //_____________________________________________________________________________
331 Bool_t AliTRDSignalIndex::CheckSorting(Int_t &row, Int_t &col)
334 // Check whether array was read to end or it was not sorted until now
337 if(fSortedWasInit || fCountRC==1)
338 { //we already reached the end of the array
345 { //we have not sorted the array up to now, let's do so
347 return NextRCIndex(row, col);
351 //_____________________________________________________________________________
352 Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
355 // Returns the next tbin, or if there is no next time bin, it returns the
356 // next used RC combination.
359 if (NextTbinIndex(tbin)) {
365 if (NextRCIndex(row, col)) {
366 return NextRCTbinIndex(row, col, tbin);
374 //_____________________________________________________________________________
375 Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
378 // Returns the next tbin of the current RC combination
381 if(fCurrTbin<fNtbins)
391 //_____________________________________________________________________________
392 void AliTRDSignalIndex::InitSortedIndex()
395 // Creates the SortedIndex
398 fSortedWasInit = kTRUE;
399 std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC);
403 //_____________________________________________________________________________
404 void AliTRDSignalIndex::ResetCounters()
407 // Reset the counters/iterators