]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDarrayDictionary.cxx
Coverity ...
[u/mrichter/AliRoot.git] / TRD / AliTRDarrayDictionary.cxx
1 /************************************************************************* 
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. * 
3 *                                                                        * 
4 * Author: The ALICE Off-line Project.                                    * 
5 * Contributors are mentioned in the code where appropriate.              * 
6 *                                                                        * 
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 **************************************************************************/
15
16 /* $Id: AliTRDarrayDictionary.cxx 25392 2008-04-23 19:40:29Z cblume $ */
17
18 /////////////////////////////////////////////////////////
19 //                                                     //
20 // Container Class for Dictionary Info                 //
21 //                                                     //
22 // Author:                                             //
23 //   Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de)   //
24 //                                                     //
25 /////////////////////////////////////////////////////////
26
27 #include <TArray.h>
28
29 #include "AliTRDarrayDictionary.h"
30 #include "AliTRDfeeParam.h"
31
32 ClassImp(AliTRDarrayDictionary)
33
34 Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
35
36 //________________________________________________________________________________
37 AliTRDarrayDictionary::AliTRDarrayDictionary()
38                       :TObject()
39                       ,fNdet(0)
40                       ,fNrow(0)
41                       ,fNcol(0)
42                       ,fNumberOfChannels(0)
43                       ,fNtime(0)
44                       ,fNDdim(0)
45                       ,fDictionary(0)
46 {
47   //
48   // AliTRDarrayDictionary default contructor
49   //
50
51   CreateLut();
52
53 }
54
55 //________________________________________________________________________________
56 AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime)
57                       :TObject()
58                       ,fNdet(0)
59                       ,fNrow(0)
60                       ,fNcol(0)
61                       ,fNumberOfChannels(0)
62                       ,fNtime(0)
63                       ,fNDdim(0)
64                       ,fDictionary(0)
65
66 {
67   //
68   // AliTRDarrayDictionary contructor
69   //
70
71   CreateLut();
72   Allocate(nrow,ncol,ntime);
73
74 }
75
76 //________________________________________________________________________________
77 AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
78                       :TObject()
79                       ,fNdet(a.fNdet)
80                       ,fNrow(a.fNrow)
81                       ,fNcol(a.fNcol)
82                       ,fNumberOfChannels(a.fNumberOfChannels)
83                       ,fNtime(a.fNtime)
84                       ,fNDdim(a.fNDdim)
85                       ,fDictionary(0)
86 {
87   //
88   // AliTRDarrayDictionary copy constructor
89   //
90
91   fDictionary = new Int_t[fNDdim];
92   for(Int_t i=0; i<fNDdim; i++)
93     {
94       fDictionary[i]=a.fDictionary[i];
95     }
96
97 }
98
99 //________________________________________________________________________________
100 AliTRDarrayDictionary::~AliTRDarrayDictionary()
101 {
102   //
103   //   AliTRDarrayDictionary destructor
104   //
105
106   if(fDictionary)
107     {
108       delete [] fDictionary;
109       fDictionary=0;
110     }
111
112 }
113
114 //________________________________________________________________________________
115 AliTRDarrayDictionary &AliTRDarrayDictionary::operator=(const AliTRDarrayDictionary &a)
116 {
117   //
118   // Assignment operator
119   //
120
121   if(this==&a)
122     {
123       return *this;
124     }
125
126   if(fDictionary)
127     {
128       delete [] fDictionary;
129     }
130   fNdet=a.fNdet;
131   fNDdim=a.fNDdim;
132   fNrow=a.fNrow;
133   fNcol=a.fNcol;
134   fNumberOfChannels = a.fNumberOfChannels;
135   fNtime=a.fNtime;
136   fDictionary = new Int_t[fNDdim];
137   for(Int_t i=0; i<fNDdim; i++)
138     {
139       fDictionary[i]=a.fDictionary[i];
140     }
141   return *this;
142
143 }
144
145 //________________________________________________________________________________
146 void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
147 {
148   //
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
153   //
154
155   fNrow=nrow;
156   fNcol=ncol;
157   fNtime=ntime;
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;
163   if(fDictionary)
164     {
165       delete [] fDictionary;
166       fDictionary=0;
167     }
168   fDictionary = new Int_t[fNDdim];
169   for(Int_t i=0; i<fNDdim; i++)
170     {
171       fDictionary[i] = -1; 
172     }
173
174 }
175
176 //________________________________________________________________________________
177 void AliTRDarrayDictionary::Compress()
178 {
179   //
180   // Compress the array
181   //
182
183
184   //  AliDebug(1,"Compressing");
185   Int_t counter=0;
186   Int_t newDim=0;
187   Int_t j;                 
188   Int_t r=0;
189   Int_t k=0;
190
191   Int_t *longArr = new Int_t[fNDdim];  
192
193   if(longArr) 
194     {
195
196       memset(longArr,0,sizeof(Int_t)*fNDdim);
197
198       for(Int_t i=0;i<fNDdim; i++)
199         {
200           j=0;
201           if(fDictionary[i]==-1)
202             {
203               for(k=i;k<fNDdim;k++)
204                 {
205                   if(fDictionary[k]==-1)
206                     {
207                       j=j+1;
208                       longArr[r]=j;
209                     }
210                   else
211                     {
212                       break;
213                     }
214                 } 
215               r=r+1;    
216             }
217           i=i+j;
218         }
219
220       //Calculate the size of the compressed array
221       for(Int_t i=0; i<fNDdim;i++)
222         {
223           if(longArr[i]!=0)  
224             {
225               counter=counter+longArr[i]-1;
226             }
227         }
228       newDim=fNDdim-counter;   //Size of the compressed array
229
230       //Fill the buffer of the compressed array
231       Int_t* buffer = new Int_t[newDim];
232       Int_t counterTwo=0;
233       Int_t g=0;
234       if(buffer)
235         {
236
237           for(Int_t i=0; i<newDim; i++)
238             {
239               if(counterTwo<fNDdim)
240                 {
241                   if(fDictionary[counterTwo]!=-1)
242                     {
243                       buffer[i]=fDictionary[counterTwo];
244                     }
245                   if(fDictionary[counterTwo]==-1)
246                     {
247                       buffer[i]=-(longArr[g]);
248                       counterTwo=counterTwo+longArr[g]-1;
249                       g++;
250                     }  
251                   counterTwo++;
252                 }
253             }
254
255           //Copy the buffer
256           if(fDictionary)
257             {
258               delete [] fDictionary;
259               fDictionary=0;
260             }
261           fDictionary = new Int_t[newDim];
262           fNDdim = newDim;
263           for(Int_t i=0; i<newDim; i++)
264             {
265               fDictionary[i] = buffer[i]; 
266             }
267
268           delete [] buffer;
269           buffer=0;
270
271         }
272     
273       delete [] longArr;
274       longArr=0;
275
276     }
277
278 }
279
280 //________________________________________________________________________________
281 void AliTRDarrayDictionary::Expand()
282 {
283   //  
284   //  Expand the array
285   //  
286
287   Int_t *longArr;
288   longArr = new Int_t[fNDdim];
289   Int_t dimexp=0;
290
291   //Initialize the array
292   memset(longArr,0,sizeof(Int_t)*fNDdim);
293
294   Int_t r2=0;
295   for(Int_t i=0; i<fNDdim;i++)
296     {
297       if((fDictionary[i]<0)&&(fDictionary[i]!=-1))  
298         {
299           longArr[r2]=-fDictionary[i]; 
300           r2++;
301         }
302     }
303
304   //Calculate new dimensions
305   for(Int_t i=0; i<fNDdim;i++)
306     {
307       if(longArr[i]!=0)      
308         {
309           dimexp=dimexp+longArr[i]-1;
310         }
311     }
312   dimexp=dimexp+fNDdim;  
313
314   //Write in the buffer the new array
315   Int_t* bufferE;
316   bufferE = new Int_t[dimexp];
317   Int_t contaexp =0;    
318   Int_t h=0;
319   for(Int_t i=0; i<dimexp; i++)
320     {
321       if(fDictionary[contaexp]>=-1)  
322         {
323           bufferE[i]=fDictionary[contaexp];
324         }
325       if(fDictionary[contaexp]<-1)  
326         {
327           for(Int_t j=0; j<longArr[h];j++)
328             {
329               bufferE[i+j]=-1;
330             }
331           i=i+longArr[h]-1;
332           h++;
333         }
334       contaexp++;
335     }
336
337   //Copy the buffer
338   if(fDictionary)
339     {
340       delete [] fDictionary;
341       fDictionary=0;
342     }
343
344   fDictionary = new Int_t[dimexp];
345   fNDdim = dimexp;
346   for(Int_t i=0; i<dimexp; i++)
347     {
348       fDictionary[i] = bufferE[i]; 
349     }
350   if(bufferE) delete [] bufferE;
351   if(longArr) delete [] longArr;
352
353 }
354 //________________________________________________________________________________
355 void AliTRDarrayDictionary::Reset()
356 {
357   //
358   // Reset the array, the old contents are deleted
359   // and the data array elements are set to zero.
360   //
361
362   memset(fDictionary,0,sizeof(Int_t)*fNDdim);
363
364 }
365 //________________________________________________________________________________
366 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
367 {
368   //
369   // Get the data using the pad numbering.
370   // To access data using the mcm scheme use instead
371   // the method GetDataByAdcCol
372   //
373
374   Int_t corrcolumn = fgLutPadNumbering[ncol];
375
376   return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
377
378 }
379 //________________________________________________________________________________
380 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
381 {
382   //
383   // Set the data using the pad numbering.
384   // To write data using the mcm scheme use instead
385   // the method SetDataByAdcCol
386   //
387
388   Int_t colnumb = fgLutPadNumbering[ncol];
389
390   fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
391
392 }
393
394 //________________________________________________________________________________
395 void AliTRDarrayDictionary::CreateLut()
396 {
397   //
398   // Initializes the Look Up Table to relate
399   // pad numbering and mcm channel numbering
400   //
401
402   if(fgLutPadNumbering)  return;
403   
404    fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
405    memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
406
407   for(Int_t mcm=0; mcm<8; mcm++)
408     {
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++)
413         {
414           fgLutPadNumbering[index]=index+shiftposition;
415         }
416     }
417 }