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 memset(fDictionary,-1,sizeof(Int_t)*fNDdim);
177 //________________________________________________________________________________
178 void AliTRDarrayDictionary::Compress()
181 // Compress the array
185 // AliDebug(1,"Compressing");
192 Int_t *longArr = new Int_t[fNDdim];
197 memset(longArr,0,sizeof(Int_t)*fNDdim);
199 for(Int_t i=0;i<fNDdim; i++)
202 if(fDictionary[i]==-1)
204 for(k=i;k<fNDdim;k++)
206 if(fDictionary[k]==-1)
221 //Calculate the size of the compressed array
222 for(Int_t i=0; i<fNDdim;i++)
226 counter=counter+longArr[i]-1;
229 newDim=fNDdim-counter; //Size of the compressed array
231 //Set the flag if the array has no data
235 //Fill the buffer of the compressed array
236 Int_t* buffer = new Int_t[newDim];
241 for(Int_t i=0; i<newDim; i++)
243 if(counterTwo<fNDdim)
245 if(fDictionary[counterTwo]!=-1)
247 buffer[i]=fDictionary[counterTwo];
249 if(fDictionary[counterTwo]==-1)
251 buffer[i]=-(longArr[g]);
252 counterTwo=counterTwo+longArr[g]-1;
262 delete [] fDictionary;
265 fDictionary = buffer;
276 //________________________________________________________________________________
277 void AliTRDarrayDictionary::Expand()
285 if(!HasData()) //if the array has no data (only -1's)
287 if(fDictionary&&fNDdim==1)
289 dimexp = -fDictionary[0];
290 delete [] fDictionary;
292 fDictionary = new Int_t[dimexp];
294 // Re-initialize the array
295 memset(fDictionary,-1,sizeof(Int_t)*dimexp);
300 UShort_t *longArr = new UShort_t[fNDdim];
301 if(longArr && fDictionary)
303 //Initialize the array
304 memset(longArr,0,sizeof(UShort_t)*fNDdim);
307 for(Int_t i=0; i<fNDdim;i++)
309 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
311 longArr[r2]=-fDictionary[i];
316 //Calculate new dimensions
317 for(Int_t i=0; i<fNDdim;i++)
320 dimexp=dimexp+longArr[i]-1;
324 dimexp=dimexp+fNDdim;
326 //Write in the buffer the new array
329 Int_t* bufferE = new Int_t[dimexp];
330 memset(bufferE,-1,sizeof(Int_t)*dimexp);
335 for(Int_t i=0; i<dimexp; i++)
337 if(fDictionary[contaexp]>=-1)
339 bufferE[i]=fDictionary[contaexp];
341 if(fDictionary[contaexp]<-1)
350 delete [] fDictionary;
361 //________________________________________________________________________________
362 void AliTRDarrayDictionary::Reset()
365 // Reset the array, the old contents are deleted
366 // and the data array elements are set to zero.
369 memset(fDictionary,0,sizeof(Int_t)*fNDdim);
372 //________________________________________________________________________________
373 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
376 // Get the data using the pad numbering.
377 // To access data using the mcm scheme use instead
378 // the method GetDataByAdcCol
381 Int_t corrcolumn = fgLutPadNumbering[ncol];
383 return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
386 //________________________________________________________________________________
387 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
390 // Set the data using the pad numbering.
391 // To write data using the mcm scheme use instead
392 // the method SetDataByAdcCol
395 Int_t colnumb = fgLutPadNumbering[ncol];
397 fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
401 //________________________________________________________________________________
402 void AliTRDarrayDictionary::CreateLut()
405 // Initializes the Look Up Table to relate
406 // pad numbering and mcm channel numbering
409 if(fgLutPadNumbering) return;
411 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
412 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
414 for(Int_t mcm=0; mcm<8; mcm++)
416 Int_t lowerlimit=0+mcm*18;
417 Int_t upperlimit=18+mcm*18;
418 Int_t shiftposition = 1+3*mcm;
419 for(Int_t index=lowerlimit;index<upperlimit;index++)
421 fgLutPadNumbering[index]= index+shiftposition;