]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDarrayDictionary.cxx
New Macro for Taku/Efficiency, updates
[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 #include "AliLog.h"
32
33 ClassImp(AliTRDarrayDictionary)
34
35 Short_t *AliTRDarrayDictionary::fgLutPadNumbering = 0x0;
36
37 //________________________________________________________________________________
38 AliTRDarrayDictionary::AliTRDarrayDictionary()
39                       :TObject()
40                       ,fNdet(0)
41                       ,fNrow(0)
42                       ,fNcol(0)
43                       ,fNumberOfChannels(0)
44                       ,fNtime(0)
45                       ,fNDdim(0)
46                       ,fDictionary(0)
47                       ,fFlag(kFALSE)
48 {
49   //
50   // AliTRDarrayDictionary default contructor
51   //
52
53   CreateLut();
54
55 }
56
57 //________________________________________________________________________________
58 AliTRDarrayDictionary::AliTRDarrayDictionary(Int_t nrow, Int_t ncol, Int_t ntime)
59                       :TObject()
60                       ,fNdet(0)
61                       ,fNrow(0)
62                       ,fNcol(0)
63                       ,fNumberOfChannels(0)
64                       ,fNtime(0)
65                       ,fNDdim(0)
66                       ,fDictionary(0)
67                       ,fFlag(kFALSE)
68 {
69   //
70   // AliTRDarrayDictionary contructor
71   //
72
73   CreateLut();
74   Allocate(nrow,ncol,ntime);
75
76 }
77
78 //________________________________________________________________________________
79 AliTRDarrayDictionary::AliTRDarrayDictionary(const AliTRDarrayDictionary &a)
80                       :TObject()
81                       ,fNdet(a.fNdet)
82                       ,fNrow(a.fNrow)
83                       ,fNcol(a.fNcol)
84                       ,fNumberOfChannels(a.fNumberOfChannels)
85                       ,fNtime(a.fNtime)
86                       ,fNDdim(a.fNDdim)
87                       ,fDictionary(0)
88                       ,fFlag(a.fFlag)
89 {
90   //
91   // AliTRDarrayDictionary copy constructor
92   //
93
94   fDictionary = new Int_t[fNDdim];
95   for(Int_t i=0; i<fNDdim; i++)
96     {
97       fDictionary[i]=a.fDictionary[i];
98     }
99
100 }
101
102 //________________________________________________________________________________
103 AliTRDarrayDictionary::~AliTRDarrayDictionary()
104 {
105   //
106   //   AliTRDarrayDictionary destructor
107   //
108
109   delete [] fDictionary;
110   fDictionary=0;
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   fFlag=a.fFlag;
142   return *this;
143
144 }
145
146 //________________________________________________________________________________
147 void AliTRDarrayDictionary::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
148 {
149   //
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
154   //
155
156   fNrow=nrow;
157   fNcol=ncol;
158   fNtime=ntime;
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;
164   if(fDictionary)
165     {
166       delete [] fDictionary;
167       fDictionary=0;
168     }
169   fDictionary = new Int_t[fNDdim];
170   memset(fDictionary,-1,sizeof(Int_t)*fNDdim);
171
172 }
173
174 //________________________________________________________________________________
175 void AliTRDarrayDictionary::Compress()
176 {
177   //
178   // Compress the array
179   //
180
181
182   //  AliDebug(1,"Compressing");
183   Int_t counter=0;
184   Int_t newDim=0;
185   Int_t j;                 
186   Int_t r=0;
187   Int_t k=0;
188
189   Int_t *longArr = new Int_t[fNDdim];  
190
191   if(longArr) 
192     {
193
194       memset(longArr,0,sizeof(Int_t)*fNDdim);
195
196       for(Int_t i=0;i<fNDdim; i++)
197         {
198           j=0;
199           if(fDictionary[i]==-1)
200             {
201               for(k=i;k<fNDdim;k++)
202                 {
203                   if(fDictionary[k]==-1)
204                     {
205                       j=j+1;
206                       longArr[r]=j;
207                     }
208                   else
209                     {
210                       break;
211                     }
212                 } 
213               r=r+1;    
214             }
215           i=i+j;
216         }
217
218       //Calculate the size of the compressed array
219       for(Int_t i=0; i<fNDdim;i++)
220         {
221           if(longArr[i]!=0)  
222             {
223               counter=counter+longArr[i]-1;
224             }
225         }
226       newDim=fNDdim-counter;   //Size of the compressed array
227
228       //Fill the buffer of the compressed array
229       Int_t* buffer = new Int_t[newDim];
230       Int_t counterTwo=0;
231       Int_t g=0;
232       if(buffer)
233         {
234           for(Int_t i=0; i<newDim; i++)
235             {
236               if(counterTwo<fNDdim)
237                 {
238                   if(fDictionary[counterTwo]!=-1)
239                     {
240                       buffer[i]=fDictionary[counterTwo];
241                     }
242                   if(fDictionary[counterTwo]==-1)
243                     {
244                       buffer[i]=-(longArr[g]);
245                       counterTwo=counterTwo+longArr[g]-1;
246                       g++;
247                     }  
248                   counterTwo++;
249                 }
250             }
251
252           //Copy the buffer
253           if(fDictionary)
254             {
255               delete [] fDictionary;
256               fDictionary=0;
257             }
258           fDictionary = buffer;
259           fNDdim = newDim;
260         }
261     
262       delete [] longArr;
263       longArr=0;
264     }
265   fFlag=kFALSE; // This way it can be expanded afterwards
266 }
267
268 //________________________________________________________________________________
269 void AliTRDarrayDictionary::Expand()
270 {
271   //  
272   //  Expand the array
273   //  
274
275   if(fNDdim==0)
276     {
277       AliError("Called expand with dimension zero");
278       return;    
279     }
280
281
282   Int_t dimexp=0;
283   
284 //   if(WasExpandCalled()) 
285 //     return;
286
287   if(fNDdim==fNrow*fNumberOfChannels*fNtime)
288     return;
289
290   if(fDictionary&&fNDdim==1)
291     { 
292       dimexp = -fDictionary[0]; 
293       delete [] fDictionary;
294       fDictionary=0;
295       fDictionary = new Int_t[dimexp];
296       fNDdim = dimexp;
297       // Re-initialize the array
298       memset(fDictionary,-1,sizeof(Int_t)*dimexp);
299       fFlag=kTRUE; // Not expand again
300       return;
301     }
302
303   Int_t *longArr = new Int_t[fNDdim];
304   if(longArr && fDictionary)
305     {
306       //Initialize the array
307       memset(longArr,0,sizeof(Int_t)*fNDdim);
308
309       Int_t r2=0;
310       for(Int_t i=0; i<fNDdim;i++)
311         {
312           if((fDictionary[i]<0)&&(fDictionary[i]!=-1))  
313             {
314               longArr[r2]=-fDictionary[i]; 
315               r2++;
316             }
317         }
318
319       //Calculate new dimensions
320       for(Int_t i=0; i<fNDdim;i++)
321         {
322           if(longArr[i]!=0)      
323             dimexp=dimexp+longArr[i]-1;
324           if(longArr[i]==0)
325             break;
326         }
327       dimexp=dimexp+fNDdim;  
328
329       //Write in the buffer the new array
330       Int_t contaexp =0;    
331       Int_t h=0;
332       Int_t* bufferE = new Int_t[dimexp];
333
334       if(bufferE)
335         {
336           memset(bufferE,-1,sizeof(Int_t)*dimexp);
337           for(Int_t i=0; i<dimexp; i++)
338             {
339               if(fDictionary[contaexp]>=-1)  
340                 {
341                   bufferE[i]=fDictionary[contaexp];
342                 }
343               if(fDictionary[contaexp]<-1)  
344                 {
345                   i=i+longArr[h]-1;
346                   h++;
347                 }
348               contaexp++;
349             }
350
351           //Copy the buffer
352           delete [] fDictionary;
353           fDictionary=bufferE;
354           fNDdim = dimexp;
355         }
356     }
357   if (longArr)
358     {
359       delete [] longArr; 
360     }
361   fFlag=kTRUE; // Not expand again
362
363 }
364 //________________________________________________________________________________
365 void AliTRDarrayDictionary::Reset()
366 {
367   //
368   // Reset the array, the old contents are deleted
369   // and the data array elements are set to zero.
370   //
371
372   memset(fDictionary,0,sizeof(Int_t)*fNDdim);
373
374 }
375 //________________________________________________________________________________
376 Int_t AliTRDarrayDictionary::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
377 {
378   //
379   // Get the data using the pad numbering.
380   // To access data using the mcm scheme use instead
381   // the method GetDataByAdcCol
382   //
383
384   Int_t corrcolumn = fgLutPadNumbering[ncol];
385
386   return fDictionary[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
387
388 }
389 //________________________________________________________________________________
390 void AliTRDarrayDictionary::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Int_t value)
391 {
392   //
393   // Set the data using the pad numbering.
394   // To write data using the mcm scheme use instead
395   // the method SetDataByAdcCol
396   //
397
398   Int_t colnumb = fgLutPadNumbering[ncol];
399
400   fDictionary[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
401
402 }
403
404 //________________________________________________________________________________
405 void AliTRDarrayDictionary::CreateLut()
406 {
407   //
408   // Initializes the Look Up Table to relate
409   // pad numbering and mcm channel numbering
410   //
411
412   if(fgLutPadNumbering)  return;
413   
414    fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
415    memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
416
417   for(Int_t mcm=0; mcm<8; mcm++)
418     {
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++)
423         {
424           fgLutPadNumbering[index]= index+shiftposition;
425         }
426     }
427 }