1 /*************************************************************************
2 * Copyright(c) 1998-2008, 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 **************************************************************************/
16 /* $Id: AliTRDarrayDictionary.cxx 25392 2008-04-23 19:40:29Z cblume $ */
18 /////////////////////////////////////////////////////////
20 // Container Class for Dictionary Info //
23 // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) //
25 /////////////////////////////////////////////////////////
29 #include "AliTRDarrayDictionary.h"
30 #include "AliTRDfeeParam.h"
32 ClassImp(AliTRDarrayDictionary)
34 Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
36 //________________________________________________________________________________
37 AliTRDarrayDictionary::AliTRDarrayDictionary()
49 // AliTRDarrayDictionary default contructor
56 //________________________________________________________________________________
57 AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime)
70 // AliTRDarrayDictionary contructor
74 Allocate(nrow,ncol,ntime);
78 //________________________________________________________________________________
79 AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
84 ,fNumberOfChannels(a.fNumberOfChannels)
91 // AliTRDarrayDictionary copy constructor
94 fDictionary = new Int_t[fNDdim];
95 for(Int_t i=0; i<fNDdim; i++)
97 fDictionary[i]=a.fDictionary[i];
102 //________________________________________________________________________________
103 AliTRDarrayDictionary::~AliTRDarrayDictionary()
106 // AliTRDarrayDictionary destructor
111 delete [] fDictionary;
117 //________________________________________________________________________________
118 AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a)
121 // Assignment operator
131 delete [] fDictionary;
137 fNumberOfChannels = a.fNumberOfChannels;
139 fDictionary = new Int_t[fNDdim];
140 for(Int_t i=0; i<fNDdim; i++)
142 fDictionary[i]=a.fDictionary[i];
149 //________________________________________________________________________________
150 void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
153 // Allocates memory for the dictionary array with dimensions
154 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
155 // To be consistent with AliTRDarrayADC
156 // Object initialized to -1
162 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
163 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
164 Int_t numberofmcms = fNcol/padspermcm;
165 fNumberOfChannels = numberofmcms*adcchannelspermcm;
166 fNDdim=nrow*fNumberOfChannels*ntime;
169 delete [] fDictionary;
172 fDictionary = new Int_t[fNDdim];
173 for(Int_t i=0; i<fNDdim; i++)
180 //________________________________________________________________________________
181 void AliTRDarrayDictionary::Compress()
184 // Compress the array
188 // AliDebug(1,"Compressing");
195 Int_t *longArr = new Int_t[fNDdim];
200 memset(longArr,0,sizeof(Int_t)*fNDdim);
202 for(Int_t i=0;i<fNDdim; i++)
205 if(fDictionary[i]==-1)
207 for(k=i;k<fNDdim;k++)
209 if(fDictionary[k]==-1)
224 //Calculate the size of the compressed array
225 for(Int_t i=0; i<fNDdim;i++)
229 counter=counter+longArr[i]-1;
232 newDim=fNDdim-counter; //Size of the compressed array
234 //Set the flag if the array has no data
238 //Fill the buffer of the compressed array
239 Int_t* buffer = new Int_t[newDim];
244 for(Int_t i=0; i<newDim; i++)
246 if(counterTwo<fNDdim)
248 if(fDictionary[counterTwo]!=-1)
250 buffer[i]=fDictionary[counterTwo];
252 if(fDictionary[counterTwo]==-1)
254 buffer[i]=-(longArr[g]);
255 counterTwo=counterTwo+longArr[g]-1;
265 delete [] fDictionary;
268 fDictionary = new Int_t[newDim];
270 for(Int_t i=0; i<newDim; i++)
272 fDictionary[i] = buffer[i];
287 //________________________________________________________________________________
288 void AliTRDarrayDictionary::Expand()
296 if(!HasData()) //if the array has no data
300 dimexp = -fDictionary[0];
301 delete [] fDictionary;
303 fDictionary = new Int_t[dimexp];
305 // Re-initialize the array
306 for(Int_t i=0; i<dimexp; i++)
312 Int_t *longArr = new Int_t[fNDdim];
313 if(longArr && fDictionary)
316 //Initialize the array
317 memset(longArr,0,sizeof(Int_t)*fNDdim);
320 for(Int_t i=0; i<fNDdim;i++)
322 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
324 longArr[r2]=-fDictionary[i];
329 //Calculate new dimensions
330 for(Int_t i=0; i<fNDdim;i++)
334 dimexp=dimexp+longArr[i]-1;
337 dimexp=dimexp+fNDdim;
339 //Write in the buffer the new array
342 Int_t* bufferE = new Int_t[dimexp];
347 for(Int_t i=0; i<dimexp; i++)
349 if(fDictionary[contaexp]>=-1)
351 bufferE[i]=fDictionary[contaexp];
353 if(fDictionary[contaexp]<-1)
355 for(Int_t j=0; j<longArr[h];j++)
366 delete [] fDictionary;
368 fDictionary = new Int_t[dimexp];
370 for(Int_t i=0; i<dimexp; i++)
372 fDictionary[i] = bufferE[i];
383 //________________________________________________________________________________
384 void AliTRDarrayDictionary::Reset()
387 // Reset the array, the old contents are deleted
388 // and the data array elements are set to zero.
391 memset(fDictionary,0,sizeof(Int_t)*fNDdim);
394 //________________________________________________________________________________
395 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
398 // Get the data using the pad numbering.
399 // To access data using the mcm scheme use instead
400 // the method GetDataByAdcCol
403 Int_t corrcolumn = fgLutPadNumbering[ncol];
405 return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
408 //________________________________________________________________________________
409 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
412 // Set the data using the pad numbering.
413 // To write data using the mcm scheme use instead
414 // the method SetDataByAdcCol
417 Int_t colnumb = fgLutPadNumbering[ncol];
419 fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
423 //________________________________________________________________________________
424 void AliTRDarrayDictionary::CreateLut()
427 // Initializes the Look Up Table to relate
428 // pad numbering and mcm channel numbering
431 if(fgLutPadNumbering) return;
433 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
434 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
436 for(Int_t mcm=0; mcm<8; mcm++)
438 Int_t lowerlimit=0+mcm*18;
439 Int_t upperlimit=18+mcm*18;
440 Int_t shiftposition = 1+3*mcm;
441 for(Int_t index=lowerlimit;index<upperlimit;index++)
443 fgLutPadNumbering[index]=index+shiftposition;