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