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