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
126 fNumberOfChannels = b.fNumberOfChannels;
129 fADC = new Short_t[fNAdim];
130 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
136 //____________________________________________________________________________________
137 void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
140 // Allocate memory for an AliTRDarrayADC array with dimensions
141 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
147 Int_t adcchannelspermcm = AliTRDfeeParam::GetNadcMcm();
148 Int_t padspermcm = AliTRDfeeParam::GetNcolMcm();
149 Int_t numberofmcms = fNcol/padspermcm;
150 fNumberOfChannels = numberofmcms*adcchannelspermcm;
151 fNAdim=nrow*fNumberOfChannels*ntime;
158 fADC = new Short_t[fNAdim];
159 memset(fADC,0,sizeof(Short_t)*fNAdim);
163 //____________________________________________________________________________________
164 Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
167 // Get the ADC value for a given position: row, col, time
168 // Taking bit masking into account
170 // Adapted from code of the class AliTRDclusterizer
173 Short_t tempval = GetData(row,col,time);
174 // Be aware of manipulations introduced by pad masking in the RawReader
175 // Only output the manipulated Value
183 //____________________________________________________________________________________
184 UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
187 // Returns the pad status stored in the pad signal
189 // Output is a UChar_t value
192 // Bridged Left Masking 8
193 // Bridged Right Masking 8
194 // Not Connected Masking Digits
196 // Adapted from code of the class AliTRDclusterizer
199 UChar_t padstatus = 0;
200 Short_t signal = GetData(row,col,time);
201 if(signal > 0 && TESTBIT(signal, 10)){
202 if(TESTBIT(signal, 11))
203 if(TESTBIT(signal, 12))
204 padstatus = AliTRDCalPadStatus::kPadBridgedRight;
206 padstatus = AliTRDCalPadStatus::kNotConnected;
208 if(TESTBIT(signal, 12))
209 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
211 padstatus = AliTRDCalPadStatus::kMasked;
218 //____________________________________________________________________________________
219 void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
222 // Setting the pad status into the signal using the Bits 10 to 14
223 // (currently used: 10 to 12)
225 // Input codes (Unsigned char):
227 // Bridged Left Masking 8
228 // Bridged Right Masking 8
229 // Not Connected Masking 32
231 // Status codes: Any masking: Bit 10(1)
232 // Noisy masking: Bit 11(0), Bit 12(0)
233 // No Connection masking: Bit 11(1), Bit 12(0)
234 // Bridged Left masking: Bit 11(0), Bit 12(1)
235 // Bridged Right masking: Bit 11(1), Bit 12(1)
237 // Adapted from code of the class AliTRDclusterizer
240 Short_t signal = GetData(row,col,time);
242 // Only set the Pad Status if the signal is > 0
247 case AliTRDCalPadStatus::kMasked:
252 case AliTRDCalPadStatus::kNotConnected:
257 case AliTRDCalPadStatus::kPadBridgedLeft:
262 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 AliTRDclusterizer
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
298 if(fNAdim!=fNrow*fNumberOfChannels*fNtime)
300 AliDebug(1,"The ADC array is already compressed");
312 Int_t *longm = new Int_t[fNAdim];
313 Int_t *longz = new Int_t[fNAdim];
315 if(longz && longm && fADC)
318 memset(longz,0,sizeof(Int_t)*fNAdim);
319 memset(longm,0,sizeof(Int_t)*fNAdim);
321 for(Int_t i=0;i<fNAdim; i++)
326 for(k=i;k<fNAdim;k++)
328 if((fADC[k]==-1)&&(j<16000))
343 for(k=i;k<fNAdim;k++)
345 if((fADC[k]==0)&&(l<32767))
364 //Calculate the size of the compressed array
365 for(Int_t i=0; i<fNAdim;i++)
369 counter=counter+longm[i]-1;
373 counter=counter+(longz[i]-16001)-1;
378 newDim = fNAdim-counter; //Dimension of the compressed array
379 Short_t* 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;
414 fADC = new Short_t[newDim];
416 for(Int_t i=0; i<newDim; i++)
421 //Delete auxiliary arrays
442 //____________________________________________________________________________________
443 void AliTRDarrayADC::Expand()
452 //Check if the array has not been already expanded
454 for(Int_t i=0; i<fNAdim; i++)
464 AliDebug(1,"Nothing to expand");
469 Int_t *longz = new Int_t[fNAdim];
470 Int_t *longm = new Int_t[fNAdim];
476 memset(longz,0,sizeof(Int_t)*fNAdim);
477 memset(longm,0,sizeof(Int_t)*fNAdim);
480 for(Int_t i=0; i<fNAdim;i++)
482 if((fADC[i]<0)&&(fADC[i]>=-16000))
489 longz[r3]=-fADC[i]-16001;
494 //Calculate the new dimensions of the array
495 for(Int_t i=0; i<fNAdim;i++)
499 dimexp=dimexp+longm[i]-1;
503 dimexp=dimexp+longz[i]-1;
506 dimexp=dimexp+fNAdim;
508 //Write in the buffer the new array
512 Short_t* bufferE = new Short_t[dimexp];
515 for(Int_t i=0; i<dimexp; i++)
519 bufferE[i]=fADC[contaexp];
521 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
523 for(Int_t j=0; j<longm[h];j++)
530 if(fADC[contaexp]<-16000)
532 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];
554 //Delete auxiliary arrays
563 //____________________________________________________________________________________
564 void AliTRDarrayADC::DeleteNegatives()
568 //This method modifies the digits array, changing the negative values (-1)
569 //Produced during digitization into zero.
572 for(Int_t a=0; a<fNAdim; a++)
580 //________________________________________________________________________________
581 void AliTRDarrayADC::Reset()
584 // Reset the array, the old contents are deleted
585 // The array keeps the same dimensions as before
588 memset(fADC,0,sizeof(Short_t)*fNAdim);
590 //________________________________________________________________________________
591 void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
594 // Reset the array, the old contents are deleted
595 // The array keeps the same dimensions as before
598 if(idx->GetNoOfIndexes()>25)
599 memset(fADC,0,sizeof(Short_t)*fNAdim);
603 while(idx->NextRCIndex(row, col)){
604 Int_t colnumb = fgLutPadNumbering[col];
605 memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime);
611 //________________________________________________________________________________
612 void AliTRDarrayADC::CreateLut()
615 // Initializes the Look Up Table to relate
616 // pad numbering and mcm channel numbering
619 if(fgLutPadNumbering) return;
621 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
622 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
624 for(Int_t mcm=0; mcm<8; mcm++)
626 Int_t lowerlimit=0+mcm*18;
627 Int_t upperlimit=18+mcm*18;
628 Int_t shiftposition = 1+3*mcm;
629 for(Int_t index=lowerlimit;index<upperlimit;index++)
631 fgLutPadNumbering[index]=index+shiftposition;