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()
48 // AliTRDarrayDictionary default contructor
55 //________________________________________________________________________________
56 AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime)
68 // AliTRDarrayDictionary contructor
72 Allocate(nrow,ncol,ntime);
76 //________________________________________________________________________________
77 AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
82 ,fNumberOfChannels(a.fNumberOfChannels)
88 // AliTRDarrayDictionary copy constructor
91 fDictionary = new Int_t[fNDdim];
92 for(Int_t i=0; i<fNDdim; i++)
94 fDictionary[i]=a.fDictionary[i];
99 //________________________________________________________________________________
100 AliTRDarrayDictionary::~AliTRDarrayDictionary()
103 // AliTRDarrayDictionary destructor
108 delete [] fDictionary;
114 //________________________________________________________________________________
115 AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a)
118 // Assignment operator
128 delete [] fDictionary;
134 fNumberOfChannels = a.fNumberOfChannels;
136 fDictionary = new Int_t[fNDdim];
137 for(Int_t i=0; i<fNDdim; i++)
139 fDictionary[i]=a.fDictionary[i];
145 //________________________________________________________________________________
146 void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
149 // Allocates memory for the dictionary array with dimensions
150 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
151 // To be consistent with AliTRDarrayADC
152 // Object initialized to -1
158 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
159 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
160 Int_t numberofmcms = fNcol/padspermcm;
161 fNumberOfChannels = numberofmcms*adcchannelspermcm;
162 fNDdim=nrow*fNumberOfChannels*ntime;
165 delete [] fDictionary;
168 fDictionary = new Int_t[fNDdim];
169 for(Int_t i=0; i<fNDdim; i++)
176 //________________________________________________________________________________
177 void AliTRDarrayDictionary::Compress()
180 // Compress the array
184 // AliDebug(1,"Compressing");
191 Int_t *longArr = new Int_t[fNDdim];
196 memset(longArr,0,sizeof(Int_t)*fNDdim);
198 for(Int_t i=0;i<fNDdim; i++)
201 if(fDictionary[i]==-1)
203 for(k=i;k<fNDdim;k++)
205 if(fDictionary[k]==-1)
220 //Calculate the size of the compressed array
221 for(Int_t i=0; i<fNDdim;i++)
225 counter=counter+longArr[i]-1;
228 newDim=fNDdim-counter; //Size of the compressed array
230 //Fill the buffer of the compressed array
231 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 = new Int_t[newDim];
263 for(Int_t i=0; i<newDim; i++)
265 fDictionary[i] = buffer[i];
280 //________________________________________________________________________________
281 void AliTRDarrayDictionary::Expand()
288 longArr = new Int_t[fNDdim];
291 //Initialize the array
292 memset(longArr,0,sizeof(Int_t)*fNDdim);
295 for(Int_t i=0; i<fNDdim;i++)
297 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
299 longArr[r2]=-fDictionary[i];
304 //Calculate new dimensions
305 for(Int_t i=0; i<fNDdim;i++)
309 dimexp=dimexp+longArr[i]-1;
312 dimexp=dimexp+fNDdim;
314 //Write in the buffer the new array
316 bufferE = new Int_t[dimexp];
319 for(Int_t i=0; i<dimexp; i++)
321 if(fDictionary[contaexp]>=-1)
323 bufferE[i]=fDictionary[contaexp];
325 if(fDictionary[contaexp]<-1)
327 for(Int_t j=0; j<longArr[h];j++)
340 delete [] fDictionary;
344 fDictionary = new Int_t[dimexp];
346 for(Int_t i=0; i<dimexp; i++)
348 fDictionary[i] = bufferE[i];
350 if(bufferE) delete [] bufferE;
351 if(longArr) delete [] longArr;
354 //________________________________________________________________________________
355 void AliTRDarrayDictionary::Reset()
358 // Reset the array, the old contents are deleted
359 // and the data array elements are set to zero.
362 memset(fDictionary,0,sizeof(Int_t)*fNDdim);
365 //________________________________________________________________________________
366 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
369 // Get the data using the pad numbering.
370 // To access data using the mcm scheme use instead
371 // the method GetDataByAdcCol
374 Int_t corrcolumn = fgLutPadNumbering[ncol];
376 return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
379 //________________________________________________________________________________
380 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
383 // Set the data using the pad numbering.
384 // To write data using the mcm scheme use instead
385 // the method SetDataByAdcCol
388 Int_t colnumb = fgLutPadNumbering[ncol];
390 fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
394 //________________________________________________________________________________
395 void AliTRDarrayDictionary::CreateLut()
398 // Initializes the Look Up Table to relate
399 // pad numbering and mcm channel numbering
402 if(fgLutPadNumbering) return;
404 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
405 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
407 for(Int_t mcm=0; mcm<8; mcm++)
409 Int_t lowerlimit=0+mcm*18;
410 Int_t upperlimit=18+mcm*18;
411 Int_t shiftposition = 1+3*mcm;
412 for(Int_t index=lowerlimit;index<upperlimit;index++)
414 fgLutPadNumbering[index]=index+shiftposition;