]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDarrayADC.cxx
bugfix
[u/mrichter/AliRoot.git] / TRD / AliTRDarrayADC.cxx
CommitLineData
abf2a9d8 1/*************************************************************************
2* Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
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**************************************************************************/
15
16/* $Id: AliTRDarrayADC.cxx 25392 2008-04-23 19:40:29Z cblume $ */
17
18////////////////////////////////////////////////////////
19// //
20// Container class for ADC values //
21// //
22// Author: //
23// Hermes Leon Vargas (hleon@ikf.uni-frankfurt.de) //
24// //
25////////////////////////////////////////////////////////
26
27#include "AliTRDarrayADC.h"
28#include "Cal/AliTRDCalPadStatus.h"
29#include "AliTRDfeeParam.h"
534529cb 30#include "AliTRDSignalIndex.h"
abf2a9d8 31ClassImp(AliTRDarrayADC)
32
33Short_t *AliTRDarrayADC::fgLutPadNumbering = 0x0;
34
35//____________________________________________________________________________________
36AliTRDarrayADC::AliTRDarrayADC()
37 :TObject()
38 ,fNdet(0)
39 ,fNrow(0)
40 ,fNcol(0)
41 ,fNumberOfChannels(0)
42 ,fNtime(0)
43 ,fNAdim(0)
44 ,fADC(0)
45{
46 //
47 // AliTRDarrayADC default constructor
48 //
49
50 CreateLut();
51
52}
53
54//____________________________________________________________________________________
55AliTRDarrayADC::AliTRDarrayADC(Int_t nrow, Int_t ncol, Int_t ntime)
56 :TObject()
57 ,fNdet(0)
58 ,fNrow(0)
59 ,fNcol(0)
60 ,fNumberOfChannels(0)
61 ,fNtime(0)
62 ,fNAdim(0)
63 ,fADC(0)
64{
65 //
66 // AliTRDarrayADC constructor
67 //
68
69 CreateLut();
70 Allocate(nrow,ncol,ntime);
71
72}
73
74//____________________________________________________________________________________
75AliTRDarrayADC::AliTRDarrayADC(const AliTRDarrayADC &b)
76 :TObject()
77 ,fNdet(b.fNdet)
78 ,fNrow(b.fNrow)
79 ,fNcol(b.fNcol)
80 ,fNumberOfChannels(b.fNumberOfChannels)
81 ,fNtime(b.fNtime)
82 ,fNAdim(b.fNAdim)
83 ,fADC(0)
84{
85 //
86 // AliTRDarrayADC copy constructor
87 //
88
89 fADC = new Short_t[fNAdim];
90 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
91
92}
93
94//____________________________________________________________________________________
95AliTRDarrayADC::~AliTRDarrayADC()
96{
97 //
98 // AliTRDarrayADC destructor
99 //
100
101 if(fADC)
102 {
103 delete [] fADC;
104 fADC=0;
105 }
106
107}
108
109//____________________________________________________________________________________
110AliTRDarrayADC &AliTRDarrayADC::operator=(const AliTRDarrayADC &b)
111{
112 //
113 // Assignment operator
114 //
115
116 if(this==&b)
117 {
118 return *this;
119 }
120 if(fADC)
121 {
122 delete [] fADC;
123 }
124 fNdet=b.fNdet;
125 fNrow=b.fNrow;
126 fNcol=b.fNcol;
127 fNumberOfChannels = b.fNumberOfChannels;
128 fNtime=b.fNtime;
129 fNAdim=b.fNAdim;
130 fADC = new Short_t[fNAdim];
131 memcpy(fADC,b.fADC, fNAdim*sizeof(Short_t));
132
133 return *this;
134
135}
136
137//____________________________________________________________________________________
138void AliTRDarrayADC::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
139{
140 //
141 // Allocate memory for an AliTRDarrayADC array with dimensions
142 // Row*NumberOfNecessaryMCMs*ADCchannelsInMCM*Time
143 //
144
145 fNrow=nrow;
146 fNcol=ncol;
147 fNtime=ntime;
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;
153
154 if(fADC)
155 {
156 delete [] fADC;
157 }
158
159 fADC = new Short_t[fNAdim];
160 memset(fADC,0,sizeof(Short_t)*fNAdim);
161
162}
163
164//____________________________________________________________________________________
165Short_t AliTRDarrayADC::GetDataBits(Int_t row, Int_t col, Int_t time) const
166{
167 //
168 // Get the ADC value for a given position: row, col, time
169 // Taking bit masking into account
170 //
171 // Adapted from code of the class AliTRDdataArrayDigits
172 //
173
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
177 CLRBIT(tempval, 10);
178 CLRBIT(tempval, 11);
179 CLRBIT(tempval, 12);
180 return tempval;
181
182}
183
184//____________________________________________________________________________________
185UChar_t AliTRDarrayADC::GetPadStatus(Int_t row, Int_t col, Int_t time) const
186{
187 //
188 // Returns the pad status stored in the pad signal
189 //
190 // Output is a UChar_t value
191 // Status Codes:
192 // Noisy Masking: 2
193 // Bridged Left Masking 8
194 // Bridged Right Masking 8
195 // Not Connected Masking Digits
196 //
197 // Adapted from code of the class AliTRDdataArrayDigits
198 //
199
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;
206 else
207 padstatus = AliTRDCalPadStatus::kNotConnected;
208 else
209 if(TESTBIT(signal, 12))
210 padstatus = AliTRDCalPadStatus::kPadBridgedLeft;
211 else
212 padstatus = AliTRDCalPadStatus::kMasked;
213 }
214
215 return padstatus;
216
217}
218
219//____________________________________________________________________________________
220void AliTRDarrayADC::SetPadStatus(Int_t row, Int_t col, Int_t time, UChar_t status)
221{
222 //
223 // Setting the pad status into the signal using the Bits 10 to 14
224 // (currently used: 10 to 12)
225 //
226 // Input codes (Unsigned char):
227 // Noisy Masking: 2
228 // Bridged Left Masking 8
229 // Bridged Right Masking 8
230 // Not Connected Masking 32
231 //
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)
237 //
238 // Adapted from code of the class AliTRDdataArrayDigits
239 //
240
241 Short_t signal = GetData(row,col,time);
242
243 // Only set the Pad Status if the signal is > 0
244 if(signal > 0)
245 {
246 switch(status)
247 {
248 case AliTRDCalPadStatus::kMasked:
249 SETBIT(signal, 10);
250 CLRBIT(signal, 11);
251 CLRBIT(signal, 12);
252 break;
253 case AliTRDCalPadStatus::kNotConnected:
254 SETBIT(signal, 10);
255 SETBIT(signal, 11);
256 CLRBIT(signal, 12);
257 break;
258 case AliTRDCalPadStatus::kPadBridgedLeft:
259 SETBIT(signal, 10);
260 CLRBIT(signal, 11);
261 SETBIT(signal, 12);
262 break;
263 case AliTRDCalPadStatus::kPadBridgedRight:
264 SETBIT(signal, 10);
265 SETBIT(signal, 11);
266 SETBIT(signal, 12);
267 default:
268 CLRBIT(signal, 10);
269 CLRBIT(signal, 11);
270 CLRBIT(signal, 12);
271 }
272 SetData(row, col, time, signal);
273 }
274
275}
276
277//____________________________________________________________________________________
278Bool_t AliTRDarrayADC::IsPadCorrupted(Int_t row, Int_t col, Int_t time)
279{
280 //
281 // Checks if the pad has any masking as corrupted (Bit 10 in signal set)
282 //
283 // Adapted from code of the class AliTRDdataArrayDigits
284 //
285
286 Short_t signal = GetData(row,col,time);
287 return (signal > 0 && TESTBIT(signal, 10)) ? kTRUE : kFALSE;
288
289}
290
291//____________________________________________________________________________________
292void AliTRDarrayADC::Compress()
293{
294 //
295 // Compress the array
296 //
297
298 Int_t counter=0;
299 Int_t newDim=0;
300 Int_t j;
301 Int_t l;
302 Int_t r=0;
303 Int_t s=0;
304 Int_t *longm;
305 longm = new Int_t[fNAdim];
306 Int_t *longz;
307 longz = new Int_t[fNAdim];
308 Int_t k=0;
309 memset(longz,0,sizeof(Int_t)*fNAdim);
310 memset(longm,0,sizeof(Int_t)*fNAdim);
311
312 for(Int_t i=0;i<fNAdim; i++)
313 {
314 j=0;
315 if(fADC[i]==-1)
316 {
317 for(k=i;k<fNAdim;k++)
318 {
319 if((fADC[k]==-1)&&(j<16000))
320 {
321 j=j+1;
322 longm[r]=j;
323 }
324 else
325 {
326 break;
327 }
328 }
329 r=r+1;
330 }
331 l=16001;
332 if(fADC[i]==0)
333 {
334 for(k=i;k<fNAdim;k++)
335 {
336 if((fADC[k]==0)&&(l<32767))
337 {
338 l=l+1;
339 longz[s]=l;
340 }
341 else
342 {
343 break;
344 }
345 }
346 s=s+1;
347 }
348 if(fADC[i]>0)
349 {
350 i=i+1;
351 }
352 i=i+j+(l-16001-1);
353 }
354
355 //Calculate the size of the compressed array
356 for(Int_t i=0; i<fNAdim;i++)
357 {
358 if(longm[i]!=0)
359 {
360 counter=counter+longm[i]-1;
361 }
362 if(longz[i]!=0)
363 {
364 counter=counter+(longz[i]-16001)-1;
365 }
366 }
367 newDim = fNAdim-counter; //Dimension of the compressed array
368 Short_t* buffer;
369 buffer = new Short_t[newDim];
370 Int_t counterTwo=0;
371
372 //Fill the buffer of the compressed array
373 Int_t g=0;
374 Int_t h=0;
375 for(Int_t i=0; i<newDim; i++)
376 {
377 if(counterTwo<fNAdim)
378 {
379 if(fADC[counterTwo]>0)
380 {
381 buffer[i]=fADC[counterTwo];
382 }
383 if(fADC[counterTwo]==-1)
384 {
385 buffer[i]=-(longm[g]);
386 counterTwo=counterTwo+longm[g]-1;
387 g++;
388 }
389 if(fADC[counterTwo]==0)
390 {
391 buffer[i]=-(longz[h]);
392 counterTwo=counterTwo+(longz[h]-16001)-1;
393 h++;
394 }
395 counterTwo++;
396 }
397 }
398
399 //Copy the buffer
400 if(fADC)
401 {
402 delete [] fADC;
403 fADC=0;
404 }
405 fADC = new Short_t[newDim];
406 fNAdim = newDim;
407 for(Int_t i=0; i<newDim; i++)
408 {
409 fADC[i] = buffer[i];
410 }
411
412 //Delete auxiliary arrays
413 if(buffer)
414 {
415 delete [] buffer;
416 buffer=0;
417 }
418 if(longz)
419 {
420 delete [] longz;
421 longz=0;
422 }
423 if(longm)
424 {
425 delete [] longm;
426 longm=0;
427 }
428
429}
430
431//____________________________________________________________________________________
432void AliTRDarrayADC::Expand()
433{
434 //
435 // Expand the array
436 //
437
438 //Check if the array has not been already expanded
439 Int_t verif=0;
440 for(Int_t i=0; i<fNAdim; i++)
441 {
442 if(fADC[i]<-1)
443 {
444 verif++;
445 }
446 }
447
448 if(verif==0)
449 {
450 // AliDebug(1,"Nothing to expand");
451 return;
452 }
453
454 Int_t *longz;
455 longz = new Int_t[fNAdim];
456 Int_t *longm;
457 longm = new Int_t[fNAdim];
458 Int_t dimexp=0;
459 //Initialize arrays
460 memset(longz,0,sizeof(Int_t)*fNAdim);
461 memset(longm,0,sizeof(Int_t)*fNAdim);
462 Int_t r2=0;
463 Int_t r3=0;
464 for(Int_t i=0; i<fNAdim;i++)
465 {
466 if((fADC[i]<0)&&(fADC[i]>=-16000))
467 {
468 longm[r2]=-fADC[i];
469 r2++;
470 }
471 if(fADC[i]<-16000)
472 {
473 longz[r3]=-fADC[i]-16001;
474 r3++;
475 }
476 }
477 //Calculate the new dimensions of the array
478 for(Int_t i=0; i<fNAdim;i++)
479 {
480 if(longm[i]!=0)
481 {
482 dimexp=dimexp+longm[i]-1;
483 }
484 if(longz[i]!=0)
485 {
486 dimexp=dimexp+longz[i]-1;
487 }
488 }
489 dimexp=dimexp+fNAdim;
490
491 //Write in the buffer the new array
492 Short_t* bufferE;
493 bufferE = new Short_t[dimexp];
494 Int_t contaexp =0;
495 Int_t h=0;
496 Int_t l=0;
497 for(Int_t i=0; i<dimexp; i++)
498 {
499 if(fADC[contaexp]>0)
500 {
501 bufferE[i]=fADC[contaexp];
502 }
503
504 if((fADC[contaexp]<0)&&(fADC[contaexp]>=-16000))
505 {
506 for(Int_t j=0; j<longm[h];j++)
507 {
508 bufferE[i+j]=-1;
509 }
510 i=i+longm[h]-1;
511 h++;
512 }
513 if(fADC[contaexp]<-16000)
514 {
515 for(Int_t j=0; j<longz[l];j++)
516 {
517 bufferE[i+j]=0;
518 }
519 i=i+longz[l]-1;
520 l++;
521 }
522 contaexp++;
523 }
524 //Copy the buffer
525 if(fADC)
526 {
527 delete [] fADC;
528 fADC=0;
529 }
530
531 fADC = new Short_t[dimexp];
532 fNAdim = dimexp;
533 for(Int_t i=0; i<dimexp; i++)
534 {
535 fADC[i] = bufferE[i];
536 }
537
538 //Delete auxiliary arrays
539 if(bufferE) delete [] bufferE;
540 if(longm) delete [] longm;
541 if(longz) delete [] longz;
542
543}
544//____________________________________________________________________________________
545void AliTRDarrayADC::DeleteNegatives()
546{
547
548 //
549 //This method modifies the digits array, changing the negative values (-1)
550 //Produced during digitization into zero.
551 //
552
553 for(Int_t a=0; a<fNAdim; a++)
554 {
555 if(fADC[a]==-1)
556 {
557 fADC[a]=0;
558 }
559 }
560}
561//________________________________________________________________________________
562void AliTRDarrayADC::Reset()
563{
564 //
565 // Reset the array, the old contents are deleted
566 // The array keeps the same dimensions as before
567 //
568
569 memset(fADC,0,sizeof(Short_t)*fNAdim);
534529cb 570}
571//________________________________________________________________________________
572void AliTRDarrayADC::ConditionalReset(AliTRDSignalIndex* idx)
573{
574 //
575 // Reset the array, the old contents are deleted
576 // The array keeps the same dimensions as before
577 //
578
579 if(idx->GetNoOfIndexes()>25)
580 memset(fADC,0,sizeof(Short_t)*fNAdim);
581 else
582 {
583 Int_t row, col;
584 while(idx->NextRCIndex(row, col)){
9a3528ba 585 Int_t colnumb = fgLutPadNumbering[col];
586 memset(&fADC[(row*fNumberOfChannels+colnumb)*fNtime],0,fNtime);
534529cb 587 }
588 }
abf2a9d8 589
abf2a9d8 590}
591
592//________________________________________________________________________________
593void AliTRDarrayADC::CreateLut()
594{
595 //
596 // Initializes the Look Up Table to relate
597 // pad numbering and mcm channel numbering
598 //
599
600 if(fgLutPadNumbering) return;
601
602 fgLutPadNumbering = new Short_t[AliTRDfeeParam::GetNcol()];
603 memset(fgLutPadNumbering,0,sizeof(Short_t)*AliTRDfeeParam::GetNcol());
604
605 for(Int_t mcm=0; mcm<8; mcm++)
606 {
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++)
611 {
612 fgLutPadNumbering[index]=index+shiftposition;
613 }
614 }
615}