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"
30 #include "AliTRDSignalIndex.h"
33 ClassImp(AliTRDarrayADC)
35 Short_t *AliTRDarrayADC::fgLutPadNumbering = 0x0;
37 //____________________________________________________________________________________
38 AliTRDarrayADC::AliTRDarrayADC()
49 // AliTRDarrayADC default constructor
56 //____________________________________________________________________________________
57 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)
88 // AliTRDarrayADC copy constructor
91 fADC = new Short_t[fNAdim];
92 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
96 //____________________________________________________________________________________
97 AliTRDarrayADC::~AliTRDarrayADC()
100 // AliTRDarrayADC destructor
108 //____________________________________________________________________________________
109 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
112 // Assignment operator
123 TObject::operator=(b);
127 fNumberOfChannels = b.fNumberOfChannels;
130 fADC = new Short_t[fNAdim];
131 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
137 //____________________________________________________________________________________
138 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
141 // Allocate memory for an AliTRDarrayADC array with dimensions
142 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
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;
159 fADC = new Short_t[fNAdim];
160 memset(fADC,0,sizeof(Short_t)*fNAdim);
164 //____________________________________________________________________________________
165 Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
168 // Get the ADC value for a given position: row, col, time
169 // Taking bit masking into account
171 // Adapted from code of the class AliTRDclusterizer
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
184 //____________________________________________________________________________________
185 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
188 // Returns the pad status stored in the pad signal
190 // Output is a UChar_t value
193 // Bridged Left Masking 8
194 // Bridged Right Masking 8
195 // Not Connected Masking Digits
197 // Adapted from code of the class AliTRDclusterizer
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;
207 padstatus = AliTRDCalPadStatus::kNotConnected;
209 if(TESTBIT(signal, 12))
210 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
212 padstatus = AliTRDCalPadStatus::kMasked;
219 //____________________________________________________________________________________
220 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
223 // Setting the pad status into the signal using the Bits 10 to 14
224 // (currently used: 10 to 12)
226 // Input codes (Unsigned char):
228 // Bridged Left Masking 8
229 // Bridged Right Masking 8
230 // Not Connected Masking 32
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)
238 // Adapted from code of the class AliTRDclusterizer
241 Short_t signal = GetData(row,col,time);
243 // Only set the Pad Status if the signal is > 0
248 case AliTRDCalPadStatus::kMasked:
253 case AliTRDCalPadStatus::kNotConnected:
258 case AliTRDCalPadStatus::kPadBridgedLeft:
263 case AliTRDCalPadStatus::kPadBridgedRight:
273 SetData(row, col, time, signal);
278 //____________________________________________________________________________________
279 Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
282 // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
284 // Adapted from code of the class AliTRDclusterizer
287 Short_t signal = GetData(row,col,time);
288 return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
292 //____________________________________________________________________________________
293 void AliTRDarrayADC::Compress()
296 // Compress the array
299 if(fNAdim!=fNrow*fNumberOfChannels*fNtime)
301 AliDebug(1,"The ADC array is already compressed");
313 Int_t *longm = new Int_t[fNAdim];
314 Int_t *longz = new Int_t[fNAdim];
316 if(longz && longm && fADC)
319 memset(longz,0,sizeof(Int_t)*fNAdim);
320 memset(longm,0,sizeof(Int_t)*fNAdim);
322 for(Int_t i=0;i<fNAdim; i++)
327 for(k=i;k<fNAdim;k++)
329 if((fADC[k]==-1)&&(j<16000))
344 for(k=i;k<fNAdim;k++)
346 if((fADC[k]==0)&&(l<32767))
365 //Calculate the size of the compressed array
366 for(Int_t i=0; i<fNAdim;i++)
370 counter=counter+longm[i]-1;
374 counter=counter+(longz[i]-16001)-1;
379 newDim = fNAdim-counter; //Dimension of the compressed array
380 Short_t* buffer = new Short_t[newDim];
385 //Fill the buffer of the compressed array
388 for(Int_t i=0; i<newDim; i++)
390 if(counterTwo<fNAdim)
392 if(fADC[counterTwo]>0)
394 buffer[i]=fADC[counterTwo];
396 if(fADC[counterTwo]==-1)
398 buffer[i]=-(longm[g]);
399 counterTwo=counterTwo+longm[g]-1;
402 if(fADC[counterTwo]==0)
404 buffer[i]=-(longz[h]);
405 counterTwo=counterTwo+(longz[h]-16001)-1;
415 fADC = new Short_t[newDim];
417 for(Int_t i=0; i<newDim; i++)
422 //Delete auxiliary arrays
443 //____________________________________________________________________________________
444 void AliTRDarrayADC::Expand()
453 //Check if the array has not been already expanded
455 for(Int_t i=0; i<fNAdim; i++)
465 AliDebug(1,"Nothing to expand");
470 Int_t *longz = new Int_t[fNAdim];
471 Int_t *longm = new Int_t[fNAdim];
477 memset(longz,0,sizeof(Int_t)*fNAdim);
478 memset(longm,0,sizeof(Int_t)*fNAdim);
481 for(Int_t i=0; i<fNAdim;i++)
483 if((fADC[i]<0)&&(fADC[i]>=-16000))
490 longz[r3]=-fADC[i]-16001;
495 //Calculate the new dimensions of the array
496 for(Int_t i=0; i<fNAdim;i++)
500 dimexp=dimexp+longm[i]-1;
504 dimexp=dimexp+longz[i]-1;
507 dimexp=dimexp+fNAdim;
509 //Write in the buffer the new array
513 Short_t* bufferE = new Short_t[dimexp];
516 for(Int_t i=0; i<dimexp; i++)
520 bufferE[i]=fADC[contaexp];
522 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
524 for(Int_t j=0; j<longm[h];j++)
531 if(fADC[contaexp]<-16000)
533 for(Int_t j=0; j<longz[l];j++)
544 fADC = new Short_t[dimexp];
546 for(Int_t i=0; i<dimexp; i++)
548 fADC[i] = bufferE[i];
555 //Delete auxiliary arrays
564 //____________________________________________________________________________________
565 void AliTRDarrayADC::DeleteNegatives()
569 //This method modifies the digits array, changing the negative values (-1)
570 //Produced during digitization into zero.
573 for(Int_t a=0; a<fNAdim; a++)
581 //________________________________________________________________________________
582 void AliTRDarrayADC::Reset()
585 // Reset the array, the old contents are deleted
586 // The array keeps the same dimensions as before
589 memset(fADC,0,sizeof(Short_t)*fNAdim);
591 //________________________________________________________________________________
592 void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
595 // Reset the array, the old contents are deleted
596 // The array keeps the same dimensions as before
599 if(idx->GetNoOfIndexes()>25)
600 memset(fADC,0,sizeof(Short_t)*fNAdim);
604 while(idx->NextRCIndex(row, col)){
605 Int_t colnumb = fgLutPadNumbering[col];
606 memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime);
612 //________________________________________________________________________________
613 void AliTRDarrayADC::CreateLut()
616 // Initializes the Look Up Table to relate
617 // pad numbering and mcm channel numbering
620 if(fgLutPadNumbering) return;
622 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
623 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
625 for(Int_t mcm=0; mcm<8; mcm++)
627 Int_t lowerlimit=0+mcm*18;
628 Int_t upperlimit=18+mcm*18;
629 Int_t shiftposition = 1+3*mcm;
630 for(Int_t index=lowerlimit;index<upperlimit;index++)
632 fgLutPadNumbering[index]=index+shiftposition;