1 /*************************************************************************
\r
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
\r
4 * Author: The ALICE Off-line Project. *
\r
5 * Contributors are mentioned in the code where appropriate. *
\r
7 * Permission to use, copy, modify and distribute this software and its *
\r
8 * documentation strictly for non-commercial purposes is hereby granted *
\r
9 * without fee, provided that the above copyright notice appears in all *
\r
10 * copies and that both the copyright notice and this permission notice *
\r
11 * appear in the supporting documentation. The authors make no claims *
\r
12 * about the suitability of this software for any purpose. It is *
\r
13 * provided "as is" without express or implied warranty. *
\r
14 **************************************************************************/
\r
16 /* $Id: AliTRDarrayADC.cxx 25392 2008-04-23 19:40:29Z cblume $ */
\r
18 ////////////////////////////////////////////////////////
\r
20 // Container class for ADC values //
\r
23 // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) //
\r
25 ////////////////////////////////////////////////////////
\r
27 #include "AliTRDarrayADC.h"
\r
28 #include "Cal/AliTRDCalPadStatus.h"
\r
29 #include "AliTRDfeeParam.h"
\r
31 ClassImp(AliTRDarrayADC)
\r
33 Short_t *AliTRDarrayADC::fLutPadNumbering = 0x0;
\r
35 //____________________________________________________________________________________
\r
36 AliTRDarrayADC::AliTRDarrayADC()
\r
41 ,fNumberOfChannels(0)
\r
47 // AliTRDarrayADC default constructor
\r
54 //____________________________________________________________________________________
\r
55 AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime)
\r
60 ,fNumberOfChannels(0)
\r
66 // AliTRDarrayADC constructor
\r
70 Allocate(nrow,ncol,ntime);
\r
74 //____________________________________________________________________________________
\r
75 AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
\r
80 ,fNumberOfChannels(b.fNumberOfChannels)
\r
86 // AliTRDarrayADC copy constructor
\r
89 fADC = new Short_t[fNAdim];
\r
90 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
\r
94 //____________________________________________________________________________________
\r
95 AliTRDarrayADC::~AliTRDarrayADC()
\r
98 // AliTRDarrayADC destructor
\r
109 //____________________________________________________________________________________
\r
110 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
\r
113 // Assignment operator
\r
127 fNumberOfChannels = b.fNumberOfChannels;
\r
130 fADC = new Short_t[fNAdim];
\r
131 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
\r
137 //____________________________________________________________________________________
\r
138 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
\r
141 // Allocate memory for an AliTRDarrayADC array with dimensions
\r
142 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
\r
148 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
\r
149 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
\r
150 Int_t numberofmcms = fNcol/padspermcm;
\r
151 fNumberOfChannels = numberofmcms*adcchannelspermcm;
\r
152 fNAdim=nrow*fNumberOfChannels*ntime;
\r
159 fADC = new Short_t[fNAdim];
\r
160 memset(fADC,0,sizeof(Short_t)*fNAdim);
\r
164 //____________________________________________________________________________________
\r
165 Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
\r
168 // Get the ADC value for a given position: row, col, time
\r
169 // Taking bit masking into account
\r
171 // Adapted from code of the class AliTRDdataArrayDigits
\r
174 Short_t tempval = GetData(row,col,time);
\r
175 // Be aware of manipulations introduced by pad masking in the RawReader
\r
176 // Only output the manipulated Value
\r
177 CLRBIT(tempval, 10);
\r
178 CLRBIT(tempval, 11);
\r
179 CLRBIT(tempval, 12);
\r
184 //____________________________________________________________________________________
\r
185 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
\r
188 // Returns the pad status stored in the pad signal
\r
190 // Output is a UChar_t value
\r
192 // Noisy Masking: 2
\r
193 // Bridged Left Masking 8
\r
194 // Bridged Right Masking 8
\r
195 // Not Connected Masking Digits
\r
197 // Adapted from code of the class AliTRDdataArrayDigits
\r
200 UChar_t padstatus = 0;
\r
201 Short_t signal = GetData(row,col,time);
\r
202 if(signal > 0 && TESTBIT(signal, 10)){
\r
203 if(TESTBIT(signal, 11))
\r
204 if(TESTBIT(signal, 12))
\r
205 padstatus = AliTRDCalPadStatus::kPadBridgedRight;
\r
207 padstatus = AliTRDCalPadStatus::kNotConnected;
\r
209 if(TESTBIT(signal, 12))
\r
210 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
\r
212 padstatus = AliTRDCalPadStatus::kMasked;
\r
219 //____________________________________________________________________________________
\r
220 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
\r
223 // Setting the pad status into the signal using the Bits 10 to 14
\r
224 // (currently used: 10 to 12)
\r
226 // Input codes (Unsigned char):
\r
227 // Noisy Masking: 2
\r
228 // Bridged Left Masking 8
\r
229 // Bridged Right Masking 8
\r
230 // Not Connected Masking 32
\r
232 // Status codes: Any masking: Bit 10(1)
\r
233 // Noisy masking: Bit 11(0), Bit 12(0)
\r
234 // No Connection masking: Bit 11(1), Bit 12(0)
\r
235 // Bridged Left masking: Bit 11(0), Bit 12(1)
\r
236 // Bridged Right masking: Bit 11(1), Bit 12(1)
\r
238 // Adapted from code of the class AliTRDdataArrayDigits
\r
241 Short_t signal = GetData(row,col,time);
\r
243 // Only set the Pad Status if the signal is > 0
\r
248 case AliTRDCalPadStatus::kMasked:
\r
249 SETBIT(signal, 10);
\r
250 CLRBIT(signal, 11);
\r
251 CLRBIT(signal, 12);
\r
253 case AliTRDCalPadStatus::kNotConnected:
\r
254 SETBIT(signal, 10);
\r
255 SETBIT(signal, 11);
\r
256 CLRBIT(signal, 12);
\r
258 case AliTRDCalPadStatus::kPadBridgedLeft:
\r
259 SETBIT(signal, 10);
\r
260 CLRBIT(signal, 11);
\r
261 SETBIT(signal, 12);
\r
263 case AliTRDCalPadStatus::kPadBridgedRight:
\r
264 SETBIT(signal, 10);
\r
265 SETBIT(signal, 11);
\r
266 SETBIT(signal, 12);
\r
268 CLRBIT(signal, 10);
\r
269 CLRBIT(signal, 11);
\r
270 CLRBIT(signal, 12);
\r
272 SetData(row, col, time, signal);
\r
277 //____________________________________________________________________________________
\r
278 Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
\r
281 // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
\r
283 // Adapted from code of the class AliTRDdataArrayDigits
\r
286 Short_t signal = GetData(row,col,time);
\r
287 return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
\r
291 //____________________________________________________________________________________
\r
292 void AliTRDarrayADC::Compress()
\r
295 // Compress the array
\r
305 longm = new Int_t[fNAdim];
\r
307 longz = new Int_t[fNAdim];
\r
309 memset(longz,0,sizeof(Int_t)*fNAdim);
\r
310 memset(longm,0,sizeof(Int_t)*fNAdim);
\r
312 for(Int_t i=0;i<fNAdim; i++)
\r
317 for(k=i;k<fNAdim;k++)
\r
319 if((fADC[k]==-1)&&(j<16000))
\r
334 for(k=i;k<fNAdim;k++)
\r
336 if((fADC[k]==0)&&(l<32767))
\r
352 i=i+j+(l-16001-1);
\r
355 //Calculate the size of the compressed array
\r
356 for(Int_t i=0; i<fNAdim;i++)
\r
360 counter=counter+longm[i]-1;
\r
364 counter=counter+(longz[i]-16001)-1;
\r
367 newDim = fNAdim-counter; //Dimension of the compressed array
\r
369 buffer = new Short_t[newDim];
\r
370 Int_t counterTwo=0;
\r
372 //Fill the buffer of the compressed array
\r
375 for(Int_t i=0; i<newDim; i++)
\r
377 if(counterTwo<fNAdim)
\r
379 if(fADC[counterTwo]>0)
\r
381 buffer[i]=fADC[counterTwo];
\r
383 if(fADC[counterTwo]==-1)
\r
385 buffer[i]=-(longm[g]);
\r
386 counterTwo=counterTwo+longm[g]-1;
\r
389 if(fADC[counterTwo]==0)
\r
391 buffer[i]=-(longz[h]);
\r
392 counterTwo=counterTwo+(longz[h]-16001)-1;
\r
405 fADC = new Short_t[newDim];
\r
407 for(Int_t i=0; i<newDim; i++)
\r
409 fADC[i] = buffer[i];
\r
412 //Delete auxiliary arrays
\r
431 //____________________________________________________________________________________
\r
432 void AliTRDarrayADC::Expand()
\r
435 // Expand the array
\r
438 //Check if the array has not been already expanded
\r
440 for(Int_t i=0; i<fNAdim; i++)
\r
450 // AliDebug(1,"Nothing to expand");
\r
455 longz = new Int_t[fNAdim];
\r
457 longm = new Int_t[fNAdim];
\r
459 //Initialize arrays
\r
460 memset(longz,0,sizeof(Int_t)*fNAdim);
\r
461 memset(longm,0,sizeof(Int_t)*fNAdim);
\r
464 for(Int_t i=0; i<fNAdim;i++)
\r
466 if((fADC[i]<0)&&(fADC[i]>=-16000))
\r
468 longm[r2]=-fADC[i];
\r
471 if(fADC[i]<-16000)
\r
473 longz[r3]=-fADC[i]-16001;
\r
477 //Calculate the new dimensions of the array
\r
478 for(Int_t i=0; i<fNAdim;i++)
\r
482 dimexp=dimexp+longm[i]-1;
\r
486 dimexp=dimexp+longz[i]-1;
\r
489 dimexp=dimexp+fNAdim;
\r
491 //Write in the buffer the new array
\r
493 bufferE = new Short_t[dimexp];
\r
494 Int_t contaexp =0;
\r
497 for(Int_t i=0; i<dimexp; i++)
\r
499 if(fADC[contaexp]>0)
\r
501 bufferE[i]=fADC[contaexp];
\r
504 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
\r
506 for(Int_t j=0; j<longm[h];j++)
\r
513 if(fADC[contaexp]<-16000)
\r
515 for(Int_t j=0; j<longz[l];j++)
\r
531 fADC = new Short_t[dimexp];
\r
533 for(Int_t i=0; i<dimexp; i++)
\r
535 fADC[i] = bufferE[i];
\r
538 //Delete auxiliary arrays
\r
539 if(bufferE) delete [] bufferE;
\r
540 if(longm) delete [] longm;
\r
541 if(longz) delete [] longz;
\r
544 //____________________________________________________________________________________
\r
545 void AliTRDarrayADC::DeleteNegatives()
\r
549 //This method modifies the digits array, changing the negative values (-1)
\r
550 //Produced during digitization into zero.
\r
553 for(Int_t a=0; a<fNAdim; a++)
\r
561 //________________________________________________________________________________
\r
562 void AliTRDarrayADC::Reset()
\r
565 // Reset the array, the old contents are deleted
\r
566 // The array keeps the same dimensions as before
\r
569 memset(fADC,0,sizeof(Short_t)*fNAdim);
\r
572 //________________________________________________________________________________
\r
573 Short_t AliTRDarrayADC::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
\r
576 // Get the data using the pad numbering.
\r
577 // To access data using the mcm scheme use instead
\r
578 // the method GetDataByAdcCol
\r
581 Int_t corrcolumn = fLutPadNumbering[ncol];
\r
583 return fADC[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
\r
586 //________________________________________________________________________________
\r
587 void AliTRDarrayADC::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value)
\r
590 // Set the data using the pad numbering.
\r
591 // To write data using the mcm scheme use instead
\r
592 // the method SetDataByAdcCol
\r
595 Int_t colnumb = fLutPadNumbering[ncol];
\r
597 fADC[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
\r
601 //________________________________________________________________________________
\r
602 void AliTRDarrayADC::CreateLut()
\r
605 // Initializes the Look Up Table to relate
\r
606 // pad numbering and mcm channel numbering
\r
609 if(fLutPadNumbering) return;
\r
611 fLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
\r
612 memset(fLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
\r
614 for(Int_t mcm=0; mcm<8; mcm++)
\r
616 Int_t lowerlimit=0+mcm*18;
\r
617 Int_t upperlimit=18+mcm*18;
\r
618 Int_t shiftposition = 1+3*mcm;
\r
619 for(Int_t index=lowerlimit;index<upperlimit;index++)
\r
621 fLutPadNumbering[index]=index+shiftposition;
\r