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
109 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];
146 //________________________________________________________________________________
147 void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
150 // Allocates memory for the dictionary array with dimensions
151 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
152 // To be consistent with AliTRDarrayADC
153 // Object initialized to -1
159 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
160 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
161 Int_t numberofmcms = fNcol/padspermcm;
162 fNumberOfChannels = numberofmcms*adcchannelspermcm;
163 fNDdim=nrow*fNumberOfChannels*ntime;
166 delete [] fDictionary;
169 fDictionary = new Int_t[fNDdim];
170 memset(fDictionary,-1,sizeof(Int_t)*fNDdim);
174 //________________________________________________________________________________
175 void AliTRDarrayDictionary::Compress()
178 // Compress the array
182 // AliDebug(1,"Compressing");
189 Int_t *longArr = new Int_t[fNDdim];
194 memset(longArr,0,sizeof(Int_t)*fNDdim);
196 for(Int_t i=0;i<fNDdim; i++)
199 if(fDictionary[i]==-1)
201 for(k=i;k<fNDdim;k++)
203 if(fDictionary[k]==-1)
218 //Calculate the size of the compressed array
219 for(Int_t i=0; i<fNDdim;i++)
223 counter=counter+longArr[i]-1;
226 newDim=fNDdim-counter; //Size of the compressed array
228 //Fill the buffer of the compressed array
229 Int_t* buffer = new Int_t[newDim];
234 for(Int_t i=0; i<newDim; i++)
236 if(counterTwo<fNDdim)
238 if(fDictionary[counterTwo]!=-1)
240 buffer[i]=fDictionary[counterTwo];
242 if(fDictionary[counterTwo]==-1)
244 buffer[i]=-(longArr[g]);
245 counterTwo=counterTwo+longArr[g]-1;
255 delete [] fDictionary;
258 fDictionary = buffer;
265 fFlag=kFALSE; // This way it can be expanded afterwards
268 //________________________________________________________________________________
269 void AliTRDarrayDictionary::Expand()
277 AliError("Called expand with dimension zero");
284 // if(WasExpandCalled())
287 if(fNDdim==fNrow*fNumberOfChannels*fNtime)
290 if(fDictionary&&fNDdim==1)
292 dimexp = -fDictionary[0];
293 delete [] fDictionary;
295 fDictionary = new Int_t[dimexp];
297 // Re-initialize the array
298 memset(fDictionary,-1,sizeof(Int_t)*dimexp);
299 fFlag=kTRUE; // Not expand again
303 Int_t *longArr = new Int_t[fNDdim];
304 if(longArr && fDictionary)
306 //Initialize the array
307 memset(longArr,0,sizeof(Int_t)*fNDdim);
310 for(Int_t i=0; i<fNDdim;i++)
312 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
314 longArr[r2]=-fDictionary[i];
319 //Calculate new dimensions
320 for(Int_t i=0; i<fNDdim;i++)
323 dimexp=dimexp+longArr[i]-1;
327 dimexp=dimexp+fNDdim;
329 //Write in the buffer the new array
332 Int_t* bufferE = new Int_t[dimexp];
336 memset(bufferE,-1,sizeof(Int_t)*dimexp);
337 for(Int_t i=0; i<dimexp; i++)
339 if(fDictionary[contaexp]>=-1)
341 bufferE[i]=fDictionary[contaexp];
343 if(fDictionary[contaexp]<-1)
352 delete [] fDictionary;
361 fFlag=kTRUE; // Not expand again
364 //________________________________________________________________________________
365 void AliTRDarrayDictionary::Reset()
368 // Reset the array, the old contents are deleted
369 // and the data array elements are set to zero.
372 memset(fDictionary,0,sizeof(Int_t)*fNDdim);
375 //________________________________________________________________________________
376 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
379 // Get the data using the pad numbering.
380 // To access data using the mcm scheme use instead
381 // the method GetDataByAdcCol
384 Int_t corrcolumn = fgLutPadNumbering[ncol];
386 return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
389 //________________________________________________________________________________
390 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
393 // Set the data using the pad numbering.
394 // To write data using the mcm scheme use instead
395 // the method SetDataByAdcCol
398 Int_t colnumb = fgLutPadNumbering[ncol];
400 fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
404 //________________________________________________________________________________
405 void AliTRDarrayDictionary::CreateLut()
408 // Initializes the Look Up Table to relate
409 // pad numbering and mcm channel numbering
412 if(fgLutPadNumbering) return;
414 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
415 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
417 for(Int_t mcm=0; mcm<8; mcm++)
419 Int_t lowerlimit=0+mcm*18;
420 Int_t upperlimit=18+mcm*18;
421 Int_t shiftposition = 1+3*mcm;
422 for(Int_t index=lowerlimit;index<upperlimit;index++)
424 fgLutPadNumbering[index]= index+shiftposition;