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 /////////////////////////////////////////////////////////
27 #include "AliTRDarrayDictionary.h"
30 ClassImp(AliTRDarrayDictionary)
32 //________________________________________________________________________________
33 AliTRDarrayDictionary::AliTRDarrayDictionary()
43 // AliTRDarrayDictionary default contructor
48 //________________________________________________________________________________
49 AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime)
60 // AliTRDarrayDictionary contructor
63 Allocate(nrow,ncol,ntime);
67 //________________________________________________________________________________
68 AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
78 // AliTRDarrayDictionary copy constructor
81 fDictionary = new Int_t[fNDdim];
82 for(Int_t i=0; i<fNDdim; i++)
84 fDictionary[i]=a.fDictionary[i];
89 //________________________________________________________________________________
90 AliTRDarrayDictionary::~AliTRDarrayDictionary()
93 // AliTRDarrayDictionary destructor
98 delete [] fDictionary;
104 //________________________________________________________________________________
105 AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a)
108 // Assignment operator
118 delete [] fDictionary;
125 fDictionary = new Int_t[fNDdim];
126 for(Int_t i=0; i<fNDdim; i++)
128 fDictionary[i]=a.fDictionary[i];
134 //________________________________________________________________________________
135 void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
138 // Allocates memory for the dictionary array with dimensions
140 // Object initialized to -1
146 fNDdim=nrow*ncol*ntime;
149 delete [] fDictionary;
152 fDictionary = new Int_t[fNDdim];
153 for(Int_t i=0; i<fNDdim; i++)
160 //________________________________________________________________________________
161 void AliTRDarrayDictionary::Compress()
164 // Compress the array
168 // AliDebug(1,"Compressing");
174 longArr = new Int_t[fNDdim];
176 for(Int_t i=0; i<fNDdim;i++)
180 for(Int_t i=0;i<fNDdim; i++)
183 if(fDictionary[i]==-1)
185 for(k=i;k<fNDdim;k++)
187 if(fDictionary[k]==-1)
201 //Calculate the size of the compressed array
202 for(Int_t i=0; i<fNDdim;i++)
206 counter=counter+longArr[i]-1;
209 newDim=fNDdim-counter; //Size of the compressed array
210 //Fill the buffer of the compressed array
212 buffer = new Int_t[newDim];
215 for(Int_t i=0; i<newDim; i++)
217 if(counterTwo<fNDdim)
219 if(fDictionary[counterTwo]!=-1)
221 buffer[i]=fDictionary[counterTwo];
223 if(fDictionary[counterTwo]==-1)
225 buffer[i]=-(longArr[g]);
226 counterTwo=counterTwo+longArr[g]-1;
236 delete [] fDictionary;
239 fDictionary = new Int_t[newDim];
241 for(Int_t i=0; i<newDim; i++)
243 fDictionary[i] = buffer[i];
258 //________________________________________________________________________________
259 void AliTRDarrayDictionary::Expand()
266 longArr = new Int_t[fNDdim];
268 for(Int_t i=0; i<fNDdim;i++)
273 for(Int_t i=0; i<fNDdim;i++)
275 if((fDictionary[i]<0)&&(fDictionary[i]!=-1))
277 longArr[r2]=-fDictionary[i];
282 //Calculate new dimensions
283 for(Int_t i=0; i<fNDdim;i++)
287 dimexp=dimexp+longArr[i]-1;
290 dimexp=dimexp+fNDdim;
292 //Write in the buffer the new array
294 bufferE = new Int_t[dimexp];
297 for(Int_t i=0; i<dimexp; i++)
299 if(fDictionary[contaexp]>=-1)
301 bufferE[i]=fDictionary[contaexp];
303 if(fDictionary[contaexp]<-1)
305 for(Int_t j=0; j<longArr[h];j++)
318 delete [] fDictionary;
322 fDictionary = new Int_t[dimexp];
324 for(Int_t i=0; i<dimexp; i++)
326 fDictionary[i] = bufferE[i];
328 if(bufferE) delete [] bufferE;
329 if(longArr) delete [] longArr;
332 //________________________________________________________________________________
333 void AliTRDarrayDictionary::Reset()
336 // Reset the array, the old contents are deleted
337 // and the data array elements are set to zero.
340 memset(fDictionary,0,sizeof(Int_t)*fNDdim);