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 //____________________________________________________________________________________
34 AliTRDarrayADC::AliTRDarrayADC()
46 // AliTRDarrayADC default constructor
51 //____________________________________________________________________________________
52 AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime)
64 // AliTRDarrayADC constructor
67 Allocate(nrow,ncol,ntime);
71 //____________________________________________________________________________________
72 AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
77 ,fNumberOfChannels(b.fNumberOfChannels)
84 // AliTRDarrayADC copy constructor
87 fADC = new Short_t[fNAdim];
88 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
89 fLutPadNumbering = new Short_t[fNcol];
90 memcpy(fLutPadNumbering,b.fLutPadNumbering, fNcol*sizeof(Short_t));
94 //____________________________________________________________________________________
95 AliTRDarrayADC::~AliTRDarrayADC()
98 // AliTRDarrayADC destructor
108 delete [] fLutPadNumbering;
114 //____________________________________________________________________________________
115 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
118 // Assignment operator
131 delete [] fLutPadNumbering;
136 fNumberOfChannels = b.fNumberOfChannels;
139 fADC = new Short_t[fNAdim];
140 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
141 fLutPadNumbering = new Short_t[fNcol];
142 memcpy(fLutPadNumbering,b.fLutPadNumbering, fNcol*sizeof(Short_t));
148 //____________________________________________________________________________________
149 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
152 // Allocate memory for an AliTRDarrayADC array with dimensions
153 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
159 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
160 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
161 Int_t numberofmcms = fNcol/padspermcm;
162 fNumberOfChannels = numberofmcms*adcchannelspermcm;
163 fNAdim=nrow*fNumberOfChannels*ntime;
171 fADC = new Short_t[fNAdim];
172 memset(fADC,0,sizeof(Short_t)*fNAdim);
176 //____________________________________________________________________________________
177 Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
180 // Get the ADC value for a given position: row, col, time
181 // Taking bit masking into account
183 // Adapted from code of the class AliTRDdataArrayDigits
186 Short_t tempval = GetData(row,col,time);
187 // Be aware of manipulations introduced by pad masking in the RawReader
188 // Only output the manipulated Value
196 //____________________________________________________________________________________
197 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
200 // Returns the pad status stored in the pad signal
202 // Output is a UChar_t value
205 // Bridged Left Masking 8
206 // Bridged Right Masking 8
207 // Not Connected Masking Digits
209 // Adapted from code of the class AliTRDdataArrayDigits
212 UChar_t padstatus = 0;
213 Short_t signal = GetData(row,col,time);
214 if(signal > 0 && TESTBIT(signal, 10)){
215 if(TESTBIT(signal, 11))
216 if(TESTBIT(signal, 12))
217 padstatus = AliTRDCalPadStatus::kPadBridgedRight;
219 padstatus = AliTRDCalPadStatus::kNotConnected;
221 if(TESTBIT(signal, 12))
222 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
224 padstatus = AliTRDCalPadStatus::kMasked;
231 //____________________________________________________________________________________
232 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
235 // Setting the pad status into the signal using the Bits 10 to 14
236 // (currently used: 10 to 12)
238 // Input codes (Unsigned char):
240 // Bridged Left Masking 8
241 // Bridged Right Masking 8
242 // Not Connected Masking 32
244 // Status codes: Any masking: Bit 10(1)
245 // Noisy masking: Bit 11(0), Bit 12(0)
246 // No Connection masking: Bit 11(1), Bit 12(0)
247 // Bridged Left masking: Bit 11(0), Bit 12(1)
248 // Bridged Right masking: Bit 11(1), Bit 12(1)
250 // Adapted from code of the class AliTRDdataArrayDigits
253 Short_t signal = GetData(row,col,time);
255 // Only set the Pad Status if the signal is > 0
260 case AliTRDCalPadStatus::kMasked:
265 case AliTRDCalPadStatus::kNotConnected:
270 case AliTRDCalPadStatus::kPadBridgedLeft:
275 case AliTRDCalPadStatus::kPadBridgedRight:
284 SetData(row, col, time, signal);
289 //____________________________________________________________________________________
290 Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
293 // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
295 // Adapted from code of the class AliTRDdataArrayDigits
298 Short_t signal = GetData(row,col,time);
299 return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
303 //____________________________________________________________________________________
304 void AliTRDarrayADC::Compress()
307 // Compress the array
317 longm = new Int_t[fNAdim];
319 longz = new Int_t[fNAdim];
321 memset(longz,0,sizeof(Int_t)*fNAdim);
322 memset(longm,0,sizeof(Int_t)*fNAdim);
324 for(Int_t i=0;i<fNAdim; i++)
329 for(k=i;k<fNAdim;k++)
331 if((fADC[k]==-1)&&(j<16000))
346 for(k=i;k<fNAdim;k++)
348 if((fADC[k]==0)&&(l<32767))
367 //Calculate the size of the compressed array
368 for(Int_t i=0; i<fNAdim;i++)
372 counter=counter+longm[i]-1;
376 counter=counter+(longz[i]-16001)-1;
379 newDim = fNAdim-counter; //Dimension of the compressed array
381 buffer = new Short_t[newDim];
384 //Fill the buffer of the compressed array
387 for(Int_t i=0; i<newDim; i++)
389 if(counterTwo<fNAdim)
391 if(fADC[counterTwo]>0)
393 buffer[i]=fADC[counterTwo];
395 if(fADC[counterTwo]==-1)
397 buffer[i]=-(longm[g]);
398 counterTwo=counterTwo+longm[g]-1;
401 if(fADC[counterTwo]==0)
403 buffer[i]=-(longz[h]);
404 counterTwo=counterTwo+(longz[h]-16001)-1;
417 fADC = new Short_t[newDim];
419 for(Int_t i=0; i<newDim; i++)
424 //Delete auxiliary arrays
443 //____________________________________________________________________________________
444 void AliTRDarrayADC::Expand()
450 //Check if the array has not been already expanded
452 for(Int_t i=0; i<fNAdim; i++)
462 // AliDebug(1,"Nothing to expand");
467 longz = new Int_t[fNAdim];
469 longm = new Int_t[fNAdim];
472 memset(longz,0,sizeof(Int_t)*fNAdim);
473 memset(longm,0,sizeof(Int_t)*fNAdim);
476 for(Int_t i=0; i<fNAdim;i++)
478 if((fADC[i]<0)&&(fADC[i]>=-16000))
485 longz[r3]=-fADC[i]-16001;
489 //Calculate the new dimensions of the array
490 for(Int_t i=0; i<fNAdim;i++)
494 dimexp=dimexp+longm[i]-1;
498 dimexp=dimexp+longz[i]-1;
501 dimexp=dimexp+fNAdim;
503 //Write in the buffer the new array
505 bufferE = new Short_t[dimexp];
509 for(Int_t i=0; i<dimexp; i++)
513 bufferE[i]=fADC[contaexp];
516 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
518 for(Int_t j=0; j<longm[h];j++)
525 if(fADC[contaexp]<-16000)
527 for(Int_t j=0; j<longz[l];j++)
543 fADC = new Short_t[dimexp];
545 for(Int_t i=0; i<dimexp; i++)
547 fADC[i] = bufferE[i];
550 //Delete auxiliary arrays
551 if(bufferE) delete [] bufferE;
552 if(longm) delete [] longm;
553 if(longz) delete [] longz;
556 //____________________________________________________________________________________
557 void AliTRDarrayADC::DeleteNegatives()
561 //This method modifies the digits array, changing the negative values (-1)
562 //Produced during digitization into zero.
565 for(Int_t a=0; a<fNAdim; a++)
573 //________________________________________________________________________________
574 void AliTRDarrayADC::Reset()
577 // Reset the array, the old contents are deleted
578 // The array keeps the same dimensions as before
581 memset(fADC,0,sizeof(Short_t)*fNAdim);
584 //________________________________________________________________________________
585 Short_t AliTRDarrayADC::GetData(Int_t nrow, Int_t ncol, Int_t ntime) const
588 // Get the data using the pad numbering.
589 // To access data using the mcm scheme use instead
590 // the method GetDataByAdcCol
593 Int_t corrcolumn = fLutPadNumbering[ncol];
595 return fADC[(nrow*fNumberOfChannels+corrcolumn)*fNtime+ntime];
598 //________________________________________________________________________________
599 void AliTRDarrayADC::SetData(Int_t nrow, Int_t ncol, Int_t ntime, Short_t value)
602 // Set the data using the pad numbering.
603 // To write data using the mcm scheme use instead
604 // the method SetDataByAdcCol
607 Int_t colnumb = fLutPadNumbering[ncol];
609 fADC[(nrow*fNumberOfChannels+colnumb)*fNtime+ntime]=value;
613 //________________________________________________________________________________
614 void AliTRDarrayADC::CreateLut()
617 // Initializes the Look Up Table to relate
618 // pad numbering and mcm channel numbering
623 delete [] fLutPadNumbering;
626 fLutPadNumbering = new Short_t[fNcol];
627 memset(fLutPadNumbering,0,sizeof(Short_t)*fNcol);
629 for(Int_t mcm=0; mcm<8; mcm++)
631 Int_t lowerlimit=0+mcm*18;
632 Int_t upperlimit=18+mcm*18;
633 Int_t shiftposition = 1+3*mcm;
634 for(Int_t index=lowerlimit;index<upperlimit;index++)
636 fLutPadNumbering[index]=index+shiftposition;