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
111 //____________________________________________________________________________________
112 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
115 // Assignment operator
129 fNumberOfChannels = b.fNumberOfChannels;
132 fADC = new Short_t[fNAdim];
133 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
139 //____________________________________________________________________________________
140 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
143 // Allocate memory for an AliTRDarrayADC array with dimensions
144 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
150 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
151 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
152 Int_t numberofmcms = fNcol/padspermcm;
153 fNumberOfChannels = numberofmcms*adcchannelspermcm;
154 fNAdim=nrow*fNumberOfChannels*ntime;
161 fADC = new Short_t[fNAdim];
162 memset(fADC,0,sizeof(Short_t)*fNAdim);
166 //____________________________________________________________________________________
167 Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
170 // Get the ADC value for a given position: row, col, time
171 // Taking bit masking into account
173 // Adapted from code of the class AliTRDdataArrayDigits
176 Short_t tempval = GetData(row,col,time);
177 // Be aware of manipulations introduced by pad masking in the RawReader
178 // Only output the manipulated Value
186 //____________________________________________________________________________________
187 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
190 // Returns the pad status stored in the pad signal
192 // Output is a UChar_t value
195 // Bridged Left Masking 8
196 // Bridged Right Masking 8
197 // Not Connected Masking Digits
199 // Adapted from code of the class AliTRDdataArrayDigits
202 UChar_t padstatus = 0;
203 Short_t signal = GetData(row,col,time);
204 if(signal > 0 && TESTBIT(signal, 10)){
205 if(TESTBIT(signal, 11))
206 if(TESTBIT(signal, 12))
207 padstatus = AliTRDCalPadStatus::kPadBridgedRight;
209 padstatus = AliTRDCalPadStatus::kNotConnected;
211 if(TESTBIT(signal, 12))
212 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
214 padstatus = AliTRDCalPadStatus::kMasked;
221 //____________________________________________________________________________________
222 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
225 // Setting the pad status into the signal using the Bits 10 to 14
226 // (currently used: 10 to 12)
228 // Input codes (Unsigned char):
230 // Bridged Left Masking 8
231 // Bridged Right Masking 8
232 // Not Connected Masking 32
234 // Status codes: Any masking: Bit 10(1)
235 // Noisy masking: Bit 11(0), Bit 12(0)
236 // No Connection masking: Bit 11(1), Bit 12(0)
237 // Bridged Left masking: Bit 11(0), Bit 12(1)
238 // Bridged Right masking: Bit 11(1), Bit 12(1)
240 // Adapted from code of the class AliTRDdataArrayDigits
243 Short_t signal = GetData(row,col,time);
245 // Only set the Pad Status if the signal is > 0
250 case AliTRDCalPadStatus::kMasked:
255 case AliTRDCalPadStatus::kNotConnected:
260 case AliTRDCalPadStatus::kPadBridgedLeft:
265 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
301 if(fNAdim!=fNrow*fNumberOfChannels*fNtime)
303 AliDebug(1,"The ADC array is already compressed");
315 Int_t *longm = new Int_t[fNAdim];
316 Int_t *longz = new Int_t[fNAdim];
318 if(longz && longm && fADC)
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;
381 newDim = fNAdim-counter; //Dimension of the compressed array
382 Short_t* buffer = new Short_t[newDim];
387 //Fill the buffer of the compressed array
390 for(Int_t i=0; i<newDim; i++)
392 if(counterTwo<fNAdim)
394 if(fADC[counterTwo]>0)
396 buffer[i]=fADC[counterTwo];
398 if(fADC[counterTwo]==-1)
400 buffer[i]=-(longm[g]);
401 counterTwo=counterTwo+longm[g]-1;
404 if(fADC[counterTwo]==0)
406 buffer[i]=-(longz[h]);
407 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
445 //____________________________________________________________________________________
446 void AliTRDarrayADC::Expand()
455 //Check if the array has not been already expanded
457 for(Int_t i=0; i<fNAdim; i++)
467 AliDebug(1,"Nothing to expand");
472 Int_t *longz = new Int_t[fNAdim];
473 Int_t *longm = new Int_t[fNAdim];
479 memset(longz,0,sizeof(Int_t)*fNAdim);
480 memset(longm,0,sizeof(Int_t)*fNAdim);
483 for(Int_t i=0; i<fNAdim;i++)
485 if((fADC[i]<0)&&(fADC[i]>=-16000))
492 longz[r3]=-fADC[i]-16001;
497 //Calculate the new dimensions of the array
498 for(Int_t i=0; i<fNAdim;i++)
502 dimexp=dimexp+longm[i]-1;
506 dimexp=dimexp+longz[i]-1;
509 dimexp=dimexp+fNAdim;
511 //Write in the buffer the new array
515 Short_t* bufferE = new Short_t[dimexp];
518 for(Int_t i=0; i<dimexp; i++)
522 bufferE[i]=fADC[contaexp];
524 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
526 for(Int_t j=0; j<longm[h];j++)
533 if(fADC[contaexp]<-16000)
535 for(Int_t j=0; j<longz[l];j++)
546 fADC = new Short_t[dimexp];
548 for(Int_t i=0; i<dimexp; i++)
550 fADC[i] = bufferE[i];
557 //Delete auxiliary arrays
566 //____________________________________________________________________________________
567 void AliTRDarrayADC::DeleteNegatives()
571 //This method modifies the digits array, changing the negative values (-1)
572 //Produced during digitization into zero.
575 for(Int_t a=0; a<fNAdim; a++)
583 //________________________________________________________________________________
584 void AliTRDarrayADC::Reset()
587 // Reset the array, the old contents are deleted
588 // The array keeps the same dimensions as before
591 memset(fADC,0,sizeof(Short_t)*fNAdim);
593 //________________________________________________________________________________
594 void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
597 // Reset the array, the old contents are deleted
598 // The array keeps the same dimensions as before
601 if(idx->GetNoOfIndexes()>25)
602 memset(fADC,0,sizeof(Short_t)*fNAdim);
606 while(idx->NextRCIndex(row, col)){
607 Int_t colnumb = fgLutPadNumbering[col];
608 memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime);
614 //________________________________________________________________________________
615 void AliTRDarrayADC::CreateLut()
618 // Initializes the Look Up Table to relate
619 // pad numbering and mcm channel numbering
622 if(fgLutPadNumbering) return;
624 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
625 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
627 for(Int_t mcm=0; mcm<8; mcm++)
629 Int_t lowerlimit=0+mcm*18;
630 Int_t upperlimit=18+mcm*18;
631 Int_t shiftposition = 1+3*mcm;
632 for(Int_t index=lowerlimit;index<upperlimit;index++)
634 fgLutPadNumbering[index]=index+shiftposition;