]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDarrayADC.cxx
Introduce new digits structures by Hermes with ZS in digitzer stage
[u/mrichter/AliRoot.git] / TRD / AliTRDarrayADC.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: AliTRDarrayADC.cxx 25392 2008-04-23 19:40:29Z cblume $ */
17
18 ////////////////////////////////////////////////////////
19 //                                                    //
20 // Container class for ADC values                     //
21 //                                                    //
22 // Author:                                            //
23 // Hermes Leon Vargas  (hleon@ikf.uni-frankfurt.de)   //
24 //                                                    // 
25 ////////////////////////////////////////////////////////
26
27 #include "AliTRDarrayADC.h"
28 #include "Cal/AliTRDCalPadStatus.h" 
29
30 ClassImp(AliTRDarrayADC)
31
32 //____________________________________________________________________________________
33 AliTRDarrayADC::AliTRDarrayADC()
34                :TObject()
35                ,fNdet(0)
36                ,fNrow(0)
37                ,fNcol(0)
38                ,fNtime(0) 
39                ,fNAdim(0)
40                ,fADC(0)
41 {
42   //
43   // AliTRDarrayADC default constructor
44   //
45
46 }
47
48 //____________________________________________________________________________________
49 AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime)
50                :TObject()
51                ,fNdet(0)               
52                ,fNrow(0)
53                ,fNcol(0)
54                ,fNtime(0) 
55                ,fNAdim(0)
56                ,fADC(0)
57 {
58   //
59   // AliTRDarrayADC constructor
60   //
61
62   Allocate(nrow,ncol,ntime);
63
64 }
65
66 //____________________________________________________________________________________
67 AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
68                :TObject()
69                ,fNdet(b.fNdet)
70                ,fNrow(b.fNrow)
71                ,fNcol(b.fNcol)
72                ,fNtime(b.fNtime) 
73                ,fNAdim(b.fNAdim)
74                ,fADC(0)
75 {
76   //
77   // AliTRDarrayADC copy constructor
78   //
79
80   fADC =  new Short_t[fNAdim];
81   for(Int_t i=0; i<fNAdim; i++)
82     {
83       fADC[i]=b.fADC[i];
84     }
85
86 }
87
88 //____________________________________________________________________________________
89 AliTRDarrayADC::~AliTRDarrayADC()
90 {
91   //
92   // AliTRDarrayADC destructor
93   //
94
95   if(fADC)
96     {
97       delete [] fADC;
98       fADC=0;
99     }
100
101 }
102
103 //____________________________________________________________________________________
104 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
105 {
106   //
107   // Assignment operator
108   //
109
110   if(this==&b)
111     {
112       return *this;
113     }
114
115   if(fADC)
116     {
117       delete [] fADC;
118     }
119   fNdet=b.fNdet;
120   fNrow=b.fNrow;
121   fNcol=b.fNcol;
122   fNtime=b.fNtime;
123   fNAdim=b.fNAdim;
124   fADC = new Short_t[fNAdim];
125   for(Int_t i=0;i<fNAdim;i++)
126     {
127       fADC[i]=b.fADC[i];
128     }
129   return *this;
130
131 }
132
133 //____________________________________________________________________________________
134 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
135 {
136   //
137   // Allocate memory for an AliTRDarrayADC array with dimensions
138   // Row*Col*Time
139   //
140   
141   fNrow=nrow;
142   fNcol=ncol;
143   fNtime=ntime;
144   fNAdim=nrow*ncol*ntime;  
145
146   if(fADC)
147     {
148       delete [] fADC;
149     }
150   
151   fADC = new Short_t[fNAdim];
152   for(Int_t a=0; a<fNAdim; a++)
153     {
154       fADC[a]=0;
155     }
156
157 }
158
159 //____________________________________________________________________________________
160 Short_t AliTRDarrayADC::GetDataB(Int_t row, Int_t col, Int_t time) const
161 {
162   //
163   // Get the ADC value for a given position: row, col, time
164   // Taking bit masking into account
165   //
166   // Adapted from code of the class AliTRDdataArrayDigits 
167   //
168
169   Short_t tempval = fADC[(row*fNcol+col)*fNtime+time];
170   // Be aware of manipulations introduced by pad masking in the RawReader
171   // Only output the manipulated Value
172   CLRBIT(tempval, 10);
173   CLRBIT(tempval, 11);
174   CLRBIT(tempval, 12);
175   return tempval;
176
177 }
178
179 //____________________________________________________________________________________
180 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
181 {
182   // 
183   // Returns the pad status stored in the pad signal
184   //
185   // Output is a UChar_t value
186   // Status Codes:
187   //               Noisy Masking:           2
188   //               Bridged Left Masking     8
189   //               Bridged Right Masking    8
190   //               Not Connected Masking Digits
191   //
192   // Adapted from code of the class AliTRDdataArrayDigits
193   //
194
195   UChar_t padstatus = 0;
196   Short_t signal = GetData(row,col,time);
197   if(signal > 0 && TESTBIT(signal, 10)){
198     if(TESTBIT(signal, 11))
199       if(TESTBIT(signal, 12))
200         padstatus = AliTRDCalPadStatus::kPadBridgedRight;
201       else
202         padstatus = AliTRDCalPadStatus::kNotConnected;
203     else
204       if(TESTBIT(signal, 12))
205         padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
206       else
207         padstatus = AliTRDCalPadStatus::kMasked;
208   }
209
210   return padstatus;
211
212 }
213
214 //____________________________________________________________________________________
215 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
216 {
217   //
218   // Setting the pad status into the signal using the Bits 10 to 14 
219   // (currently used: 10 to 12)
220   //
221   // Input codes (Unsigned char):
222   //               Noisy Masking:           2
223   //               Bridged Left Masking     8
224   //               Bridged Right Masking    8
225   //               Not Connected Masking    32
226   //
227   // Status codes: Any masking:             Bit 10(1)
228   //               Noisy masking:           Bit 11(0), Bit 12(0)
229   //               No Connection masking:   Bit 11(1), Bit 12(0)
230   //               Bridged Left masking:    Bit 11(0), Bit 12(1)
231   //               Bridged Right masking:   Bit 11(1), Bit 12(1)
232   // 
233   // Adapted from code of the class AliTRDdataArrayDigits
234   //
235
236   Short_t signal = GetData(row,col,time);
237
238   // Only set the Pad Status if the signal is > 0
239   if(signal > 0)
240     {
241       switch(status)
242         {
243         case AliTRDCalPadStatus::kMasked:
244           SETBIT(signal, 10);
245           CLRBIT(signal, 11);
246           CLRBIT(signal, 12);
247           break;
248         case AliTRDCalPadStatus::kNotConnected:
249           SETBIT(signal, 10);
250           SETBIT(signal, 11);
251           CLRBIT(signal, 12);
252           break;
253         case AliTRDCalPadStatus::kPadBridgedLeft:
254           SETBIT(signal, 10);
255           CLRBIT(signal, 11);
256           SETBIT(signal, 12);
257           break;
258         case AliTRDCalPadStatus::kPadBridgedRight:
259           SETBIT(signal, 10);
260           SETBIT(signal, 11);
261           SETBIT(signal, 12);
262         default:
263           CLRBIT(signal, 10);
264           CLRBIT(signal, 11);
265           CLRBIT(signal, 12);
266         }
267       SetData(row, col, time, signal);
268     }
269
270 }
271
272 //____________________________________________________________________________________
273 Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
274 {
275   // 
276   // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
277   // 
278   // Adapted from code of the class AliTRDdataArrayDigits
279   //
280
281   Short_t signal = GetData(row,col,time);
282   return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
283
284 }
285
286 //____________________________________________________________________________________
287 void AliTRDarrayADC::Compress()
288 {
289   //
290   // Compress the array
291   //
292
293   Int_t counter=0;
294   Int_t newDim=0;
295   Int_t j;                  
296   Int_t l;                  
297   Int_t r=0;                
298   Int_t s=0;                
299   Int_t *longm;            
300   longm = new Int_t[fNAdim];  
301   Int_t *longz;            
302   longz = new Int_t[fNAdim];
303   Int_t k=0;
304   for(Int_t i=0; i<fNAdim;i++)
305     {
306       longz[i]=0;
307       longm[i]=0;
308     }
309
310   for(Int_t i=0;i<fNAdim; i++)
311     {
312       j=0;
313       if(fADC[i]==-1)
314         {
315           for(k=i;k<fNAdim;k++)
316             {
317               if((fADC[k]==-1)&&(j<16000))   
318                 {
319                   j=j+1;
320                   longm[r]=j;                
321                 }
322               else
323                 {
324                   break;
325                 }
326             }
327           r=r+1;            
328         }
329       l=16001;
330       if(fADC[i]==0)
331         {
332           for(k=i;k<fNAdim;k++)
333             {
334               if((fADC[k]==0)&&(l<32767))     
335                 {                             
336                   l=l+1;
337                   longz[s]=l;                
338                 }
339               else
340                 {
341                   break;
342                 }
343             }
344           s=s+1;         
345         }
346       if(fADC[i]>0)
347         {
348           i=i+1;
349         }
350       i=i+j+(l-16001-1); 
351     }
352
353   //Calculate the size of the compressed array
354   for(Int_t i=0; i<fNAdim;i++)
355     {
356       if(longm[i]!=0)   
357         {
358           counter=counter+longm[i]-1;
359         }
360       if(longz[i]!=0)  
361         {
362           counter=counter+(longz[i]-16001)-1;
363         }
364     }
365   newDim = fNAdim-counter;   //Dimension of the compressed array
366   Short_t* buffer;
367   buffer = new Short_t[newDim];
368   Int_t counterTwo=0;
369
370   //Fill the buffer of the compressed array
371   Int_t g=0;
372   Int_t h=0; 
373   for(Int_t i=0; i<newDim; i++)
374     {
375       if(counterTwo<fNAdim)
376         {
377           if(fADC[counterTwo]>0)
378             {
379               buffer[i]=fADC[counterTwo];
380             }
381           if(fADC[counterTwo]==-1)
382             {
383               buffer[i]=-(longm[g]);
384               counterTwo=counterTwo+longm[g]-1;
385               g++;
386             }  
387           if(fADC[counterTwo]==0)
388             {
389               buffer[i]=-(longz[h]); 
390               counterTwo=counterTwo+(longz[h]-16001)-1;
391               h++;
392             }  
393           counterTwo++;
394         }
395     }
396
397   //Copy the buffer
398   if(fADC)
399     {
400       delete [] fADC;
401       fADC=0;
402     }
403   fADC = new Short_t[newDim];
404   fNAdim = newDim;
405   for(Int_t i=0; i<newDim; i++)
406     {
407       fADC[i] = buffer[i]; 
408     }
409
410   //Delete auxiliary arrays
411   if(buffer)
412     {
413       delete [] buffer;
414       buffer=0;
415     } 
416   if(longz) 
417     {
418       delete [] longz;
419       longz=0;
420     }
421   if(longm) 
422     {
423       delete [] longm;
424       longm=0;
425     }
426
427 }
428
429 //____________________________________________________________________________________
430 void AliTRDarrayADC::Expand()
431 {
432   //
433   // Expand the array
434   //
435
436   Int_t *longz;
437   longz = new Int_t[fNAdim];
438   Int_t *longm;
439   longm = new Int_t[fNAdim];
440   Int_t dimexp=0;
441   //Initialize arrays
442   for(Int_t i=0; i<fNAdim;i++)
443     {
444       longz[i]=0;
445       longm[i]=0;
446     }
447   Int_t r2=0; 
448   Int_t r3=0; 
449   for(Int_t i=0; i<fNAdim;i++)
450     {
451       if((fADC[i]<0)&&(fADC[i]>=-16000))      
452         {
453           longm[r2]=-fADC[i];
454           r2++;
455         }
456       if(fADC[i]<-16000)  
457         {
458           longz[r3]=-fADC[i]-16001;  
459           r3++;
460         }
461     }
462   //Calculate the new dimensions of the array
463   for(Int_t i=0; i<fNAdim;i++)
464     {
465       if(longm[i]!=0)       
466         {
467           dimexp=dimexp+longm[i]-1;
468         }
469       if(longz[i]!=0)      
470         {
471           dimexp=dimexp+longz[i]-1;
472         }
473     }
474   dimexp=dimexp+fNAdim;   
475
476   //Write in the buffer the new array
477   Short_t* bufferE;
478   bufferE = new Short_t[dimexp];
479   Int_t contaexp =0;     
480   Int_t h=0;
481   Int_t l=0;  
482   for(Int_t i=0; i<dimexp; i++)
483     {
484       if(fADC[contaexp]>0)  
485         {
486           bufferE[i]=fADC[contaexp];
487         }
488
489       if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))  
490         {
491           for(Int_t j=0; j<longm[h];j++)
492             {
493               bufferE[i+j]=-1;
494             }
495           i=i+longm[h]-1;
496           h++;
497         }
498       if(fADC[contaexp]<-16000)  
499         {
500           for(Int_t j=0; j<longz[l];j++)
501             {
502               bufferE[i+j]=0;  
503             }
504           i=i+longz[l]-1;
505           l++;
506         }
507       contaexp++;
508     }
509   //Copy the buffer
510   if(fADC)
511     {
512       delete [] fADC;
513       fADC=0;
514     }
515
516   fADC = new Short_t[dimexp];
517   fNAdim = dimexp;
518   for(Int_t i=0; i<dimexp; i++)
519     {
520       fADC[i] = bufferE[i]; 
521     }
522
523   //Delete auxiliary arrays
524   if(bufferE) delete [] bufferE;
525   if(longm) delete [] longm;
526   if(longz) delete [] longz;
527
528 }