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 ///////////////////////////////////////////////////////////////////////////////
32 #include "AliTRDSignalIndex.h"
34 ClassImp(AliTRDSignalIndex)
36 //_____________________________________________________________________________
37 AliTRDSignalIndex::AliTRDSignalIndex()
47 ,fSortedWasInit(kFALSE)
64 //_____________________________________________________________________________
65 AliTRDSignalIndex::AliTRDSignalIndex(Int_t nrow, Int_t ncol,Int_t ntime)
75 ,fSortedWasInit(kFALSE)
85 // Not the default contructor... hmmm...
88 Allocate(nrow, ncol, ntime);
92 //_____________________________________________________________________________
93 AliTRDSignalIndex::AliTRDSignalIndex(const AliTRDSignalIndex &a)
101 ,fMaxLimit(a.fMaxLimit)
102 ,fPositionRC(a.fPositionRC)
103 ,fSortedWasInit(a.fSortedWasInit)
104 ,fCurrRow(a.fCurrRow)
105 ,fCurrCol(a.fCurrCol)
106 ,fCurrTbin(a.fCurrTbin)
110 ,fHasEntry(a.fHasEntry)
116 fBoolIndex = new Bool_t[fMaxLimit];
117 memcpy(fBoolIndex, a.fBoolIndex, fMaxLimit*sizeof(Bool_t));
119 fSortedIndex = new Short_t[2*fMaxLimit];
120 memcpy(fSortedIndex, a.fSortedIndex, 2*fMaxLimit*sizeof(Short_t));
123 //_____________________________________________________________________________
124 AliTRDSignalIndex::~AliTRDSignalIndex()
131 delete [] fBoolIndex;
136 delete [] fSortedIndex;
142 //_____________________________________________________________________________
143 void AliTRDSignalIndex::Copy(TObject &a) const
149 ((AliTRDSignalIndex &)a).fDet = fDet;
150 ((AliTRDSignalIndex &)a).fLayer = fLayer;
151 ((AliTRDSignalIndex &)a).fStack = fStack;
152 ((AliTRDSignalIndex &)a).fSM = fSM;
153 ((AliTRDSignalIndex &)a).fMaxLimit = fMaxLimit;
154 ((AliTRDSignalIndex &)a).fPositionRC = fPositionRC;
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;
162 ((AliTRDSignalIndex &)a).fHasEntry = fHasEntry;
164 if(((AliTRDSignalIndex &)a).fBoolIndex)
166 delete [] ((AliTRDSignalIndex &)a).fBoolIndex;
168 ((AliTRDSignalIndex &)a).fBoolIndex = new Bool_t[fMaxLimit];
169 memcpy(((AliTRDSignalIndex &)a).fBoolIndex, fBoolIndex, fMaxLimit*sizeof(Bool_t));
171 if(((AliTRDSignalIndex &)a).fSortedIndex)
173 delete [] ((AliTRDSignalIndex &)a).fSortedIndex;
175 ((AliTRDSignalIndex &)a).fSortedIndex = new Short_t[2*fMaxLimit];
176 memcpy(((AliTRDSignalIndex &)a).fSortedIndex, fSortedIndex, 2*fMaxLimit*sizeof(Short_t));
180 //_____________________________________________________________________________
181 AliTRDSignalIndex& AliTRDSignalIndex::operator = (const AliTRDSignalIndex& a)
184 // Assignment operator
187 if (this != &a) ((AliTRDSignalIndex &) a).Copy(*this);
192 //_____________________________________________________________________________
193 void AliTRDSignalIndex::Allocate(const Int_t nrow, const Int_t ncol, const Int_t ntime)
203 fMaxLimit = nrow * ncol + 1;
206 delete [] fBoolIndex;
210 delete [] fSortedIndex;
214 fBoolIndex = new Bool_t[fMaxLimit];
215 fSortedIndex = new Short_t[2*fMaxLimit];
225 //_____________________________________________________________________________
226 void AliTRDSignalIndex::ResetArrays()
228 memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
229 memset(fSortedIndex,0xFF,2*sizeof(Short_t)*fMaxLimit);
230 fSortedWasInit = kFALSE;
233 //_____________________________________________________________________________
234 void AliTRDSignalIndex::Reset()
237 // Reset the array but keep the size - realloc
246 Allocate(fNrows, fNcols, fNtbins);
250 //_____________________________________________________________________________
251 void AliTRDSignalIndex::ResetContent()
254 // Reset the array but keep the size - no realloc
264 //_____________________________________________________________________________
265 void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
268 // Reset the array but keep the size if no need to enlarge - no realloc
276 if ((nrow > fNrows) ||
279 Allocate(nrow, ncol, ntime);
289 //_____________________________________________________________________________
290 void AliTRDSignalIndex::ClearAll()
293 // Reset the values - clear all!
306 delete [] fBoolIndex;
311 delete [] fSortedIndex;
318 fSortedWasInit = kFALSE;
323 //_____________________________________________________________________________
324 void AliTRDSignalIndex::AddIndexRC(const Int_t row, const Int_t col)
327 // Store the index row-column as an interesting one
328 // The RC index is updated to!!!
329 // This is to be used in the TRD clusterizer!
332 if (row * col + 1 >= fMaxLimit) {
333 AliError(Form("Out-of-limits row * col %d. Limit is: %d"
339 fBoolIndex[row*fNcols+col]=kTRUE;
345 //_____________________________________________________________________________
346 Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
349 // Returns next used RC combination
352 if(fSortedIndex[fPositionRC]>-1){
353 row = fCurrRow = fSortedIndex[fPositionRC];
355 col = fCurrCol = fSortedIndex[fPositionRC];
360 if(fSortedWasInit || !fHasEntry)
361 { //we already reached the end of the array
368 { //we have not created the sorted array up to now, let's do so
370 return NextRCIndex(row, col);
376 //_____________________________________________________________________________
377 Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
380 // Returns the next tbin, or if there is no next time bin, it returns the
381 // next used RC combination.
384 if (NextTbinIndex(tbin)) {
390 if (NextRCIndex(row, col)) {
391 return NextRCTbinIndex(row, col, tbin);
399 //_____________________________________________________________________________
400 Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
403 // Returns the next tbin of the current RC combination
406 if(fCurrTbin<fNtbins)
416 //_____________________________________________________________________________
417 void AliTRDSignalIndex::InitSortedIndex()
420 // Creates the SortedIndex
423 fSortedWasInit = kTRUE;
425 for(int row = 0; row < fNrows; row++)
426 for(int col = 0; col < fNcols; col++)
427 if(IsBoolIndex(row, col)){
428 fSortedIndex[pos] = row;
430 fSortedIndex[pos] = col;
435 //_____________________________________________________________________________
436 void AliTRDSignalIndex::ResetCounters()
439 // Reset the counters/iterators