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"
31 ClassImp(AliTRDarrayADC)
33 Short_t *AliTRDarrayADC::fgLutPadNumbering = 0x0;
35 //____________________________________________________________________________________
36 AliTRDarrayADC::AliTRDarrayADC()
47 // AliTRDarrayADC default constructor
54 //____________________________________________________________________________________
55 AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime)
66 // AliTRDarrayADC constructor
70 Allocate(nrow,ncol,ntime);
74 //____________________________________________________________________________________
75 AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
80 ,fNumberOfChannels(b.fNumberOfChannels)
86 // AliTRDarrayADC copy constructor
89 fADC = new Short_t[fNAdim];
90 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
94 //____________________________________________________________________________________
95 AliTRDarrayADC::~AliTRDarrayADC()
98 // AliTRDarrayADC destructor
109 //____________________________________________________________________________________
110 AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
113 // Assignment operator
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 AliTRDdataArrayDigits
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 AliTRDdataArrayDigits
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 AliTRDdataArrayDigits
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 AliTRDdataArrayDigits
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
307 Int_t *longm = new Int_t[fNAdim];
308 Int_t *longz = new Int_t[fNAdim];
310 if(longz && longm && fADC)
313 memset(longz,0,sizeof(Int_t)*fNAdim);
314 memset(longm,0,sizeof(Int_t)*fNAdim);
316 for(Int_t i=0;i<fNAdim; i++)
321 for(k=i;k<fNAdim;k++)
323 if((fADC[k]==-1)&&(j<16000))
338 for(k=i;k<fNAdim;k++)
340 if((fADC[k]==0)&&(l<32767))
359 //Calculate the size of the compressed array
360 for(Int_t i=0; i<fNAdim;i++)
364 counter=counter+longm[i]-1;
368 counter=counter+(longz[i]-16001)-1;
373 newDim = fNAdim-counter; //Dimension of the compressed array
374 Short_t* buffer = new Short_t[newDim];
379 //Fill the buffer of the compressed array
382 for(Int_t i=0; i<newDim; i++)
384 if(counterTwo<fNAdim)
386 if(fADC[counterTwo]>0)
388 buffer[i]=fADC[counterTwo];
390 if(fADC[counterTwo]==-1)
392 buffer[i]=-(longm[g]);
393 counterTwo=counterTwo+longm[g]-1;
396 if(fADC[counterTwo]==0)
398 buffer[i]=-(longz[h]);
399 counterTwo=counterTwo+(longz[h]-16001)-1;
409 fADC = new Short_t[newDim];
411 for(Int_t i=0; i<newDim; i++)
416 //Delete auxiliary arrays
437 //____________________________________________________________________________________
438 void AliTRDarrayADC::Expand()
447 //Check if the array has not been already expanded
449 for(Int_t i=0; i<fNAdim; i++)
459 //AliDebug(1,"Nothing to expand");
464 Int_t *longz = new Int_t[fNAdim];
465 Int_t *longm = new Int_t[fNAdim];
471 memset(longz,0,sizeof(Int_t)*fNAdim);
472 memset(longm,0,sizeof(Int_t)*fNAdim);
475 for(Int_t i=0; i<fNAdim;i++)
477 if((fADC[i]<0)&&(fADC[i]>=-16000))
484 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
507 Short_t* bufferE = new Short_t[dimexp];
510 for(Int_t i=0; i<dimexp; i++)
514 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++)
538 fADC = new Short_t[dimexp];
540 for(Int_t i=0; i<dimexp; i++)
542 fADC[i] = bufferE[i];
549 //Delete auxiliary arrays
558 //____________________________________________________________________________________
559 void AliTRDarrayADC::DeleteNegatives()
563 //This method modifies the digits array, changing the negative values (-1)
564 //Produced during digitization into zero.
567 for(Int_t a=0; a<fNAdim; a++)
575 //________________________________________________________________________________
576 void AliTRDarrayADC::Reset()
579 // Reset the array, the old contents are deleted
580 // The array keeps the same dimensions as before
583 memset(fADC,0,sizeof(Short_t)*fNAdim);
585 //________________________________________________________________________________
586 void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
589 // Reset the array, the old contents are deleted
590 // The array keeps the same dimensions as before
593 if(idx->GetNoOfIndexes()>25)
594 memset(fADC,0,sizeof(Short_t)*fNAdim);
598 while(idx->NextRCIndex(row, col)){
599 Int_t colnumb = fgLutPadNumbering[col];
600 memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime);
606 //________________________________________________________________________________
607 void AliTRDarrayADC::CreateLut()
610 // Initializes the Look Up Table to relate
611 // pad numbering and mcm channel numbering
614 if(fgLutPadNumbering) return;
616 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
617 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
619 for(Int_t mcm=0; mcm<8; mcm++)
621 Int_t lowerlimit=0+mcm*18;
622 Int_t upperlimit=18+mcm*18;
623 Int_t shiftposition = 1+3*mcm;
624 for(Int_t index=lowerlimit;index<upperlimit;index++)
626 fgLutPadNumbering[index]=index+shiftposition;