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:
272 SetData(row, col, time, signal);
277 //____________________________________________________________________________________
278 Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
281 // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
283 // Adapted from code of the class AliTRDdataArrayDigits
286 Short_t signal = GetData(row,col,time);
287 return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
291 //____________________________________________________________________________________
292 void AliTRDarrayADC::Compress()
295 // Compress the array
305 longm = new Int_t[fNAdim];
307 longz = new Int_t[fNAdim];
309 memset(longz,0,sizeof(Int_t)*fNAdim);
310 memset(longm,0,sizeof(Int_t)*fNAdim);
312 for(Int_t i=0;i<fNAdim; i++)
317 for(k=i;k<fNAdim;k++)
319 if((fADC[k]==-1)&&(j<16000))
334 for(k=i;k<fNAdim;k++)
336 if((fADC[k]==0)&&(l<32767))
355 //Calculate the size of the compressed array
356 for(Int_t i=0; i<fNAdim;i++)
360 counter=counter+longm[i]-1;
364 counter=counter+(longz[i]-16001)-1;
367 newDim = fNAdim-counter; //Dimension of the compressed array
369 buffer = new Short_t[newDim];
372 //Fill the buffer of the compressed array
375 for(Int_t i=0; i<newDim; i++)
377 if(counterTwo<fNAdim)
379 if(fADC[counterTwo]>0)
381 buffer[i]=fADC[counterTwo];
383 if(fADC[counterTwo]==-1)
385 buffer[i]=-(longm[g]);
386 counterTwo=counterTwo+longm[g]-1;
389 if(fADC[counterTwo]==0)
391 buffer[i]=-(longz[h]);
392 counterTwo=counterTwo+(longz[h]-16001)-1;
405 fADC = new Short_t[newDim];
407 for(Int_t i=0; i<newDim; i++)
412 //Delete auxiliary arrays
431 //____________________________________________________________________________________
432 void AliTRDarrayADC::Expand()
438 //Check if the array has not been already expanded
440 for(Int_t i=0; i<fNAdim; i++)
450 // AliDebug(1,"Nothing to expand");
455 longz = new Int_t[fNAdim];
457 longm = new Int_t[fNAdim];
460 memset(longz,0,sizeof(Int_t)*fNAdim);
461 memset(longm,0,sizeof(Int_t)*fNAdim);
464 for(Int_t i=0; i<fNAdim;i++)
466 if((fADC[i]<0)&&(fADC[i]>=-16000))
473 longz[r3]=-fADC[i]-16001;
477 //Calculate the new dimensions of the array
478 for(Int_t i=0; i<fNAdim;i++)
482 dimexp=dimexp+longm[i]-1;
486 dimexp=dimexp+longz[i]-1;
489 dimexp=dimexp+fNAdim;
491 //Write in the buffer the new array
493 bufferE = new Short_t[dimexp];
497 for(Int_t i=0; i<dimexp; i++)
501 bufferE[i]=fADC[contaexp];
504 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
506 for(Int_t j=0; j<longm[h];j++)
513 if(fADC[contaexp]<-16000)
515 for(Int_t j=0; j<longz[l];j++)
531 fADC = new Short_t[dimexp];
533 for(Int_t i=0; i<dimexp; i++)
535 fADC[i] = bufferE[i];
538 //Delete auxiliary arrays
539 if(bufferE) delete [] bufferE;
540 if(longm) delete [] longm;
541 if(longz) delete [] longz;
544 //____________________________________________________________________________________
545 void AliTRDarrayADC::DeleteNegatives()
549 //This method modifies the digits array, changing the negative values (-1)
550 //Produced during digitization into zero.
553 for(Int_t a=0; a<fNAdim; a++)
561 //________________________________________________________________________________
562 void AliTRDarrayADC::Reset()
565 // Reset the array, the old contents are deleted
566 // The array keeps the same dimensions as before
569 memset(fADC,0,sizeof(Short_t)*fNAdim);
571 //________________________________________________________________________________
572 void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
575 // Reset the array, the old contents are deleted
576 // The array keeps the same dimensions as before
579 if(idx->GetNoOfIndexes()>25)
580 memset(fADC,0,sizeof(Short_t)*fNAdim);
584 while(idx->NextRCIndex(row, col)){
585 for(Int_t time=0; time<fNtime; time++)
586 SetData(row, col, time, 0);
592 //________________________________________________________________________________
593 void AliTRDarrayADC::CreateLut()
596 // Initializes the Look Up Table to relate
597 // pad numbering and mcm channel numbering
600 if(fgLutPadNumbering) return;
602 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
603 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
605 for(Int_t mcm=0; mcm<8; mcm++)
607 Int_t lowerlimit=0+mcm*18;
608 Int_t upperlimit=18+mcm*18;
609 Int_t shiftposition = 1+3*mcm;
610 for(Int_t index=lowerlimit;index<upperlimit;index++)
612 fgLutPadNumbering[index]=index+shiftposition;