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"
33 ClassImp(AliTRDarrayDictionary)
35 Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
37 //________________________________________________________________________________
38 AliTRDarrayDictionary::AliTRDarrayDictionary()
50 // AliTRDarrayDictionary default contructor
57 //________________________________________________________________________________
58 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 //Fill the buffer of the compressed array
232 Int_t* buffer = new Int_t[newDim];
237 for(Int_t i=0; i<newDim; i++)
239 if(counterTwo<fNDdim)
241 if(fDictionary[counterTwo]!=-1)
243 buffer[i]=fDictionary[counterTwo];
245 if(fDictionary[counterTwo]==-1)
247 buffer[i]=-(longArr[g]);
248 counterTwo=counterTwo+longArr[g]-1;
258 delete [] fDictionary;
261 fDictionary = buffer;
268 fFlag=kFALSE; // This way it can be expanded afterwards
271 //________________________________________________________________________________
272 void AliTRDarrayDictionary::Expand()
280 AliError("Called expand with dimension zero");
287 // if(WasExpandCalled())
290 if(fNDdim==fNrow*fNumberOfChannels*fNtime)
293 if(fDictionary&&fNDdim==1)
295 dimexp = -fDictionary[0];
296 delete [] fDictionary;
298 fDictionary = new Int_t[dimexp];
300 // Re-initialize the array
301 memset(fDictionary,-1,sizeof(Int_t)*dimexp);
302 fFlag=kTRUE; // Not expand again
306 Int_t *longArr = new Int_t[fNDdim];
307 if(longArr && fDictionary)
309 //Initialize the array
310 memset(longArr,0,sizeof(Int_t)*fNDdim);
313 for(Int_t i=0; i<fNDdim;i++)
315 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
317 longArr[r2]=-fDictionary[i];
322 //Calculate new dimensions
323 for(Int_t i=0; i<fNDdim;i++)
326 dimexp=dimexp+longArr[i]-1;
330 dimexp=dimexp+fNDdim;
332 //Write in the buffer the new array
335 Int_t* bufferE = new Int_t[dimexp];
339 memset(bufferE,-1,sizeof(Int_t)*dimexp);
340 for(Int_t i=0; i<dimexp; i++)
342 if(fDictionary[contaexp]>=-1)
344 bufferE[i]=fDictionary[contaexp];
346 if(fDictionary[contaexp]<-1)
355 delete [] fDictionary;
364 fFlag=kTRUE; // Not expand again
367 //________________________________________________________________________________
368 void AliTRDarrayDictionary::Reset()
371 // Reset the array, the old contents are deleted
372 // and the data array elements are set to zero.
375 memset(fDictionary,0,sizeof(Int_t)*fNDdim);
378 //________________________________________________________________________________
379 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
382 // Get the data using the pad numbering.
383 // To access data using the mcm scheme use instead
384 // the method GetDataByAdcCol
387 Int_t corrcolumn = fgLutPadNumbering[ncol];
389 return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
392 //________________________________________________________________________________
393 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
396 // Set the data using the pad numbering.
397 // To write data using the mcm scheme use instead
398 // the method SetDataByAdcCol
401 Int_t colnumb = fgLutPadNumbering[ncol];
403 fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
407 //________________________________________________________________________________
408 void AliTRDarrayDictionary::CreateLut()
411 // Initializes the Look Up Table to relate
412 // pad numbering and mcm channel numbering
415 if(fgLutPadNumbering) return;
417 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
418 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
420 for(Int_t mcm=0; mcm<8; mcm++)
422 Int_t lowerlimit=0+mcm*18;
423 Int_t upperlimit=18+mcm*18;
424 Int_t shiftposition = 1+3*mcm;
425 for(Int_t index=lowerlimit;index<upperlimit;index++)
427 fgLutPadNumbering[index]= index+shiftposition;