1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliTRDarrayADC.cxx 25392 2008-04-23 19:40:29Z cblume $ */
18 ////////////////////////////////////////////////////////
20 // Container class for ADC values //
23 // Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) //
25 ////////////////////////////////////////////////////////
27 #include "AliTRDarrayADC.h"
28 #include "Cal/AliTRDCalPadStatus.h"
29 #include "AliTRDfeeParam.h"
31 ClassImp(AliTRDarrayADC)
33 Short_t *AliTRDarrayADC::fgLutPadNumbering = 0x0;
35 //____________________________________________________________________________________
36 AliTRDarrayADC::AliTRDarrayADC()
48 // AliTRDarrayADC default constructor
55 //____________________________________________________________________________________
56 AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime)
68 // AliTRDarrayADC constructor
72 Allocate(nrow,ncol,ntime);
76 //____________________________________________________________________________________
77 AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
82 ,fNumberOfChannels(b.fNumberOfChannels)
85 ,fBaseline(b.fBaseline)
89 // AliTRDarrayADC copy constructor
92 fADC = new Short_t[fNAdim];
93 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
97 //____________________________________________________________________________________
98 AliTRDarrayADC::~AliTRDarrayADC()
101 // AliTRDarrayADC destructor
112 //____________________________________________________________________________________
113 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
116 // Assignment operator
130 fNumberOfChannels = b.fNumberOfChannels;
133 fADC = new Short_t[fNAdim];
134 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
140 //____________________________________________________________________________________
141 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
144 // Allocate memory for an AliTRDarrayADC array with dimensions
145 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
151 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
152 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
153 Int_t numberofmcms = fNcol/padspermcm;
154 fNumberOfChannels = numberofmcms*adcchannelspermcm;
155 fNAdim=nrow*fNumberOfChannels*ntime;
162 fADC = new Short_t[fNAdim];
163 memset(fADC,0,sizeof(Short_t)*fNAdim);
167 //____________________________________________________________________________________
168 Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
171 // Get the ADC value for a given position: row, col, time
172 // Taking bit masking into account
174 // Adapted from code of the class AliTRDdataArrayDigits
177 Short_t tempval = GetData(row,col,time);
178 // Be aware of manipulations introduced by pad masking in the RawReader
179 // Only output the manipulated Value
187 //____________________________________________________________________________________
188 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
191 // Returns the pad status stored in the pad signal
193 // Output is a UChar_t value
196 // Bridged Left Masking 8
197 // Bridged Right Masking 8
198 // Not Connected Masking Digits
200 // Adapted from code of the class AliTRDdataArrayDigits
203 UChar_t padstatus = 0;
204 Short_t signal = GetData(row,col,time);
205 if(signal > 0 && TESTBIT(signal, 10)){
206 if(TESTBIT(signal, 11))
207 if(TESTBIT(signal, 12))
208 padstatus = AliTRDCalPadStatus::kPadBridgedRight;
210 padstatus = AliTRDCalPadStatus::kNotConnected;
212 if(TESTBIT(signal, 12))
213 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
215 padstatus = AliTRDCalPadStatus::kMasked;
222 //____________________________________________________________________________________
223 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
226 // Setting the pad status into the signal using the Bits 10 to 14
227 // (currently used: 10 to 12)
229 // Input codes (Unsigned char):
231 // Bridged Left Masking 8
232 // Bridged Right Masking 8
233 // Not Connected Masking 32
235 // Status codes: Any masking: Bit 10(1)
236 // Noisy masking: Bit 11(0), Bit 12(0)
237 // No Connection masking: Bit 11(1), Bit 12(0)
238 // Bridged Left masking: Bit 11(0), Bit 12(1)
239 // Bridged Right masking: Bit 11(1), Bit 12(1)
241 // Adapted from code of the class AliTRDdataArrayDigits
244 Short_t signal = GetData(row,col,time);
246 // Only set the Pad Status if the signal is > 0
251 case AliTRDCalPadStatus::kMasked:
256 case AliTRDCalPadStatus::kNotConnected:
261 case AliTRDCalPadStatus::kPadBridgedLeft:
266 case AliTRDCalPadStatus::kPadBridgedRight:
275 SetData(row, col, time, signal);
280 //____________________________________________________________________________________
281 Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
284 // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
286 // Adapted from code of the class AliTRDdataArrayDigits
289 Short_t signal = GetData(row,col,time);
290 return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
294 //____________________________________________________________________________________
295 void AliTRDarrayADC::Compress()
298 // Compress the array
308 longm = new Int_t[fNAdim];
310 longz = new Int_t[fNAdim];
312 memset(longz,0,sizeof(Int_t)*fNAdim);
313 memset(longm,0,sizeof(Int_t)*fNAdim);
315 for(Int_t i=0;i<fNAdim; i++)
320 for(k=i;k<fNAdim;k++)
322 if((fADC[k]==-1)&&(j<16000))
337 for(k=i;k<fNAdim;k++)
339 if((fADC[k]==0)&&(l<32767))
358 //Calculate the size of the compressed array
359 for(Int_t i=0; i<fNAdim;i++)
363 counter=counter+longm[i]-1;
367 counter=counter+(longz[i]-16001)-1;
370 newDim = fNAdim-counter; //Dimension of the compressed array
372 buffer = new Short_t[newDim];
375 //Fill the buffer of the compressed array
378 for(Int_t i=0; i<newDim; i++)
380 if(counterTwo<fNAdim)
382 if(fADC[counterTwo]>0)
384 buffer[i]=fADC[counterTwo];
386 if(fADC[counterTwo]==-1)
388 buffer[i]=-(longm[g]);
389 counterTwo=counterTwo+longm[g]-1;
392 if(fADC[counterTwo]==0)
394 buffer[i]=-(longz[h]);
395 counterTwo=counterTwo+(longz[h]-16001)-1;
408 fADC = new Short_t[newDim];
410 for(Int_t i=0; i<newDim; i++)
415 //Delete auxiliary arrays
434 //____________________________________________________________________________________
435 void AliTRDarrayADC::Expand()
441 //Check if the array has not been already expanded
443 for(Int_t i=0; i<fNAdim; i++)
453 // AliDebug(1,"Nothing to expand");
458 longz = new Int_t[fNAdim];
460 longm = new Int_t[fNAdim];
463 memset(longz,0,sizeof(Int_t)*fNAdim);
464 memset(longm,0,sizeof(Int_t)*fNAdim);
467 for(Int_t i=0; i<fNAdim;i++)
469 if((fADC[i]<0)&&(fADC[i]>=-16000))
476 longz[r3]=-fADC[i]-16001;
480 //Calculate the new dimensions of the array
481 for(Int_t i=0; i<fNAdim;i++)
485 dimexp=dimexp+longm[i]-1;
489 dimexp=dimexp+longz[i]-1;
492 dimexp=dimexp+fNAdim;
494 //Write in the buffer the new array
496 bufferE = new Short_t[dimexp];
500 for(Int_t i=0; i<dimexp; i++)
504 bufferE[i]=fADC[contaexp];
507 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
509 for(Int_t j=0; j<longm[h];j++)
516 if(fADC[contaexp]<-16000)
518 for(Int_t j=0; j<longz[l];j++)
534 fADC = new Short_t[dimexp];
536 for(Int_t i=0; i<dimexp; i++)
538 fADC[i] = bufferE[i];
541 //Delete auxiliary arrays
542 if(bufferE) delete [] bufferE;
543 if(longm) delete [] longm;
544 if(longz) delete [] longz;
547 //____________________________________________________________________________________
548 void AliTRDarrayADC::DeleteNegatives()
552 //This method modifies the digits array, changing the negative values (-1)
553 //Produced during digitization into zero.
556 for(Int_t a=0; a<fNAdim; a++)
564 //________________________________________________________________________________
565 void AliTRDarrayADC::Reset()
568 // Reset the array, the old contents are deleted
569 // The array keeps the same dimensions as before
572 memset(fADC,0,sizeof(Short_t)*fNAdim);
575 //________________________________________________________________________________
576 Short_t AliTRDarrayADC::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
579 // Get the data using the pad numbering.
580 // To access data using the mcm scheme use instead
581 // the method GetDataByAdcCol
584 Int_t corrcolumn = fgLutPadNumbering[ncol];
586 return fADC[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
589 //________________________________________________________________________________
590 void AliTRDarrayADC::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value)
593 // Set the data using the pad numbering.
594 // To write data using the mcm scheme use instead
595 // the method SetDataByAdcCol
598 Int_t colnumb = fgLutPadNumbering[ncol];
600 fADC[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime] = TMath::Max(value-fBaseline
605 //________________________________________________________________________________
606 void AliTRDarrayADC::CreateLut()
609 // Initializes the Look Up Table to relate
610 // pad numbering and mcm channel numbering
613 if(fgLutPadNumbering) return;
615 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
616 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
618 for(Int_t mcm=0; mcm<8; mcm++)
620 Int_t lowerlimit=0+mcm*18;
621 Int_t upperlimit=18+mcm*18;
622 Int_t shiftposition = 1+3*mcm;
623 for(Int_t index=lowerlimit;index<upperlimit;index++)
625 fgLutPadNumbering[index]=index+shiftposition;