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];
223 //_____________________________________________________________________________
224 void AliTRDSignalIndex::ResetArrays()
226 memset(fBoolIndex,0x00,sizeof(Bool_t)*fMaxLimit);
227 memset(fSortedIndex,0xFF,sizeof(RowCol)*(fMaxLimit+1));
228 fSortedWasInit = kFALSE;
231 //_____________________________________________________________________________
232 void AliTRDSignalIndex::Reset()
235 // Reset the array but keep the size - realloc
244 Allocate(fNrows, fNcols, fNtbins);
248 //_____________________________________________________________________________
249 void AliTRDSignalIndex::ResetContent()
252 // Reset the array but keep the size - no realloc
267 //_____________________________________________________________________________
268 void AliTRDSignalIndex::ResetContentConditional(const Int_t nrow, const Int_t ncol, const Int_t ntime)
271 // Reset the array but keep the size if no need to enlarge - no realloc
279 if ((nrow > fNrows) ||
282 Allocate(nrow, ncol, ntime);
292 //_____________________________________________________________________________
293 void AliTRDSignalIndex::ClearAll()
296 // Reset the values - clear all!
309 delete [] fBoolIndex;
314 delete [] fSortedIndex;
321 fSortedWasInit = kFALSE;
326 //_____________________________________________________________________________
327 Bool_t AliTRDSignalIndex::NextRCIndex(Int_t &row, Int_t &col)
330 // Returns next used RC combination
333 if(fSortedIndex[fPositionRC].rc>-1){
334 row = fCurrRow = fSortedIndex[fPositionRC].s.row;
335 col = fCurrCol = fSortedIndex[fPositionRC].s.col;
340 if(fSortedWasInit || fCountRC==1)
341 { //we already reached the end of the array
348 { //we have not created the sorted array up to now, let's do so
350 return NextRCIndex(row, col);
356 //_____________________________________________________________________________
357 Bool_t AliTRDSignalIndex::NextRCTbinIndex(Int_t &row, Int_t &col, Int_t &tbin)
360 // Returns the next tbin, or if there is no next time bin, it returns the
361 // next used RC combination.
364 if (NextTbinIndex(tbin)) {
370 if (NextRCIndex(row, col)) {
371 return NextRCTbinIndex(row, col, tbin);
379 //_____________________________________________________________________________
380 Bool_t AliTRDSignalIndex::NextTbinIndex(Int_t &tbin)
383 // Returns the next tbin of the current RC combination
386 if(fCurrTbin<fNtbins)
396 //_____________________________________________________________________________
397 void AliTRDSignalIndex::InitSortedIndex()
400 // Creates the SortedIndex
403 fSortedWasInit = kTRUE;
404 std::sort((UShort_t*)fSortedIndex, ((UShort_t*)fSortedIndex) + fCountRC);
408 //_____________________________________________________________________________
409 void AliTRDSignalIndex::ResetCounters()
412 // Reset the counters/iterators