]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdataArrayF.cxx
compiling warnigs free
[u/mrichter/AliRoot.git] / TRD / AliTRDdataArrayF.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /*
17 $Log$
18 Revision 1.10.6.1  2002/06/10 15:28:58  hristov
19 Merged with v3-08-02
20
21 Revision 1.11  2002/03/28 14:59:07  cblume
22 Coding conventions
23
24 Revision 1.10  2002/02/11 14:27:54  cblume
25 Geometry and hit structure update
26
27 Revision 1.9  2001/05/07 08:08:05  cblume
28 Update of TRD code
29
30 Revision 1.8  2000/11/23 14:34:08  cblume
31 Fixed bug in expansion routine of arrays (initialize buffers properly)
32
33 Revision 1.7  2000/11/20 08:56:07  cblume
34 Cleanup of data arrays
35
36 Revision 1.6  2000/11/01 14:53:20  cblume
37 Merge with TRD-develop
38
39 Revision 1.1.2.3  2000/10/06 16:49:46  cblume
40 Made Getters const
41
42 Revision 1.1.2.2  2000/10/04 16:34:58  cblume
43 Replace include files by forward declarations
44
45 Revision 1.5  2000/06/27 13:08:50  cblume
46 Changed to Copy(TObject &A) to appease the HP-compiler
47
48 Revision 1.4  2000/06/09 11:10:07  cblume
49 Compiler warnings and coding conventions, next round
50
51 Revision 1.3  2000/06/08 18:32:58  cblume
52 Make code compliant to coding conventions
53
54 Revision 1.2  2000/05/08 16:17:27  cblume
55 Merge TRD-develop
56
57 Revision 1.1.2.1  2000/05/08 15:14:34  cblume
58 Add new data array classes
59
60 */
61
62 ///////////////////////////////////////////////////////////////////////////////
63 //                                                                           //
64 //  General container for integer data of a TRD detector segment.            //
65 //  Adapted from AliDigits (origin: M.Ivanov).                               //
66 //                                                                           //
67 ///////////////////////////////////////////////////////////////////////////////
68
69 #include "AliTRDdataArrayF.h"
70 #include "AliTRDarrayI.h"
71 #include "AliTRDarrayF.h"
72
73 ClassImp(AliTRDdataArrayF)
74
75 //_____________________________________________________________________________
76 AliTRDdataArrayF::AliTRDdataArrayF():AliTRDdataArray()
77 {
78   //
79   // Default constructor
80   //
81
82   fElements = 0;
83
84 }
85
86 //_____________________________________________________________________________
87 AliTRDdataArrayF::AliTRDdataArrayF(Int_t nrow, Int_t ncol, Int_t ntime)
88                  :AliTRDdataArray(nrow,ncol,ntime)
89 {
90   //
91   // Creates a AliTRDdataArrayF with the dimensions <nrow>, <ncol>, and <ntime>.
92   // The row- and column dimensions are compressible.
93   //
94
95   fElements = 0;
96
97   Allocate(nrow,ncol,ntime);
98   
99 }
100
101 //_____________________________________________________________________________
102 AliTRDdataArrayF::AliTRDdataArrayF(const AliTRDdataArrayF &a)
103 {
104   //
105   // AliTRDdataArrayF copy constructor
106   //
107
108   ((AliTRDdataArrayF &) a).Copy(*this);
109
110 }
111
112 //_____________________________________________________________________________
113 AliTRDdataArrayF::~AliTRDdataArrayF()
114 {
115   //
116   // Destructor
117   //
118
119   if (fElements) delete fElements;
120   
121 }
122
123 //_____________________________________________________________________________
124 void AliTRDdataArrayF::Allocate(Int_t nrow, Int_t ncol, Int_t ntime)
125 {
126   //
127   // Allocates memory for a AliTRDdataArrayF with the dimensions 
128   // <nrow>, <ncol>, and <ntime>.
129   // The row- and column dimensions are compressible.
130   //
131
132   if (fNelems < 0) AliTRDdataArray::Allocate(nrow,ncol,ntime);
133
134   if (fElements) delete fElements;
135   fElements = new AliTRDarrayF();
136   fElements->Set(fNelems);
137
138 }
139
140 //_____________________________________________________________________________
141 void AliTRDdataArrayF::Copy(TObject &a)
142 {
143   //
144   // Copy function
145   //
146
147   fElements->Copy(*((AliTRDdataArrayF &) a).fElements);
148
149   ((AliTRDdataArrayF &) a).fThreshold = fThreshold;
150
151   AliTRDdataArray::Copy(a);
152
153 }
154
155 //_____________________________________________________________________________
156 void AliTRDdataArrayF::Reset() 
157
158   //
159   // Reset the array (old content gets deleted)
160   //
161   
162   if (fElements) delete fElements;
163   fElements = new AliTRDarrayF();
164   fElements->Set(0); 
165
166   AliTRDdataArray::Reset();
167
168 }
169
170 //_____________________________________________________________________________
171 Int_t AliTRDdataArrayF::GetSize() const
172 {
173   //
174   // Returns the size of the complete object
175   //
176
177   Int_t size = sizeof(this);
178
179   if (fIndex)    size += sizeof(fIndex)    
180                          + fIndex->GetSize()    * sizeof(Int_t);
181   if (fElements) size += sizeof(fElements) 
182                          + fElements->GetSize() * sizeof(Float_t);
183
184   return size;
185
186 }
187
188 //_____________________________________________________________________________
189 Int_t AliTRDdataArrayF::GetDataSize() const 
190 {
191   //
192   // Returns the size of only the data part
193   //
194
195   if (fElements == 0) 
196     return 0;
197   else 
198     return sizeof(fElements) + fElements->GetSize() * sizeof(Float_t);
199
200 }
201
202 //_____________________________________________________________________________
203 Int_t AliTRDdataArrayF::GetOverThreshold(Float_t threshold) 
204 {
205   //
206   // Returns the number of entries over threshold
207   //
208  
209   if ((fElements == 0) || (fElements->GetSize() <= 0))
210     return 0;
211  
212   Int_t over = 0;
213
214   for (Bool_t cont = First(); cont == kTRUE; cont = Next()) {
215     if ((fCurrentIdx1 < 0) || (fCurrentIdx1 >= fNdim1)) continue;
216     if ((fCurrentIdx2 < 0) || (fCurrentIdx2 >= fNdim2)) continue;
217     if (fElements->At(fCurrentIndex) > threshold) over++;
218   }
219
220   return over;
221
222 }
223
224 //_____________________________________________________________________________
225 Float_t AliTRDdataArrayF::GetData(Int_t row, Int_t col, Int_t time) const
226 {
227   //
228   // Returns the data value at a given position of the array
229   // Includes boundary checking
230   //
231
232   if ((row >= 0) && (col >= 0) && (time >= 0)) {
233     Int_t idx1 = GetIdx1(row,col);
234     if ((idx1 >= 0) && (time < fNdim2)) {
235       if (fBufType == 0) return GetDataFast(idx1,time);
236       if (fBufType == 1) return GetData1(idx1,time);
237     }
238     else {
239       if (idx1 >= 0) {
240         TObject::Error("GetData"
241                       ,"time %d out of bounds (size: %d, this: 0x%08x)"
242                       ,time,fNdim2,this);
243       }
244     }
245   }
246
247   return -1;
248
249 }
250
251 //_____________________________________________________________________________
252 Float_t AliTRDdataArrayF::GetDataFast(Int_t idx1, Int_t idx2) const
253 {
254   //
255   // Returns the data value at a given position of the array
256   // No boundary checking
257   //
258
259   return fElements->At(fIndex->At(idx2)+idx1);
260
261 }
262
263 //_____________________________________________________________________________
264 void AliTRDdataArrayF::Compress(Int_t bufferType, Float_t threshold)
265 {
266   //
267   // Compresses the buffer
268   //
269
270   fThreshold = threshold;
271   Compress(bufferType);
272
273 }
274
275 //_____________________________________________________________________________
276 void AliTRDdataArrayF::Compress(Int_t bufferType)
277 {
278   //
279   // Compresses the buffer
280   //
281
282   if (fBufType  < 0) {
283     Error("AliTRDdataArrayF::Compress","Buffer does not exist");
284     return;
285   }
286   if (fBufType == bufferType) {
287     return;
288   }  
289   if (fBufType > 0) {
290     Expand();
291   }
292   if (fBufType !=0)  {
293     Error("AliTRDdataArrayF::Compress","Buffer does not exist");
294     return;
295   }
296
297   // Compress a buffer of type 1
298   if (bufferType == 1) {
299     Compress1();
300   }
301
302 }
303
304 //_____________________________________________________________________________
305 void AliTRDdataArrayF::Expand()
306 {  
307   //
308   // Expands the compressed buffer
309   //
310
311   if (fBufType  < 0) {
312     Error("AliTRDdataArrayF::Expand","Buffer does not exist");
313     return;
314   }
315   if (fBufType == 0) {  
316     return;
317   } 
318  
319   // Expand a buffer of type 1
320   if (fBufType == 1) Expand1();
321   
322   fBufType = 0;
323
324 }
325
326 //_____________________________________________________________________________
327 Bool_t AliTRDdataArrayF::First() 
328 {
329   //
330   // Returns the position of the first valid data value
331   //
332
333   if (fBufType == 0) return First0();
334   if (fBufType == 1) return First1();
335   return kFALSE;
336
337 }
338
339 //_____________________________________________________________________________
340 Bool_t  AliTRDdataArrayF::Next()
341 {
342   //
343   // Returns the position of the next valid data value
344   //
345
346   if (fBufType == 0) return Next0();
347   if (fBufType == 1) return Next1();
348   return kFALSE;
349
350 }
351
352 //_____________________________________________________________________________
353 void AliTRDdataArrayF::Expand1()
354 {
355   //
356   // Expands a buffer of type 1
357   //
358
359   Int_t i, k;
360
361   fNelems = fNdim1 * fNdim2;
362
363   Float_t *buf = new Float_t[fNelems];
364   memset(buf,0,fNelems*sizeof(Float_t)); 
365
366   fIndex->Set(fNdim2);
367
368   for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
369
370   Int_t idx1 = 0;
371   Int_t idx2 = 0;
372   Int_t n    = fElements->fN;
373
374   for (i = 0; i < n; i++){
375
376     // Negative sign counts the unwritten values (under threshold)
377     if ((*fElements)[i] < 0) {
378       idx1 -= TMath::Nint(fElements->At(i));
379     } 
380     else {
381       buf[(*fIndex)[idx2] + idx1] = (*fElements)[i];
382       idx1++;
383     }
384     if (idx1 == fNdim1) {
385       idx1 = 0;
386       idx2++;
387     }
388     else { 
389       if (idx1 > fNdim1){
390         Reset();
391         return;
392       }      
393     }
394   }
395
396   fElements->Adopt(fNelems,buf); 
397    
398 }
399
400 //_____________________________________________________________________________
401 void AliTRDdataArrayF::Compress1()
402 {
403   //
404   // Compress a buffer of type 1
405   //
406
407   AliTRDarrayF *buf   = new AliTRDarrayF();  
408   buf->Set(fNelems);
409   AliTRDarrayI *index = new AliTRDarrayI();
410   index->Set(fNdim2);
411
412   Int_t icurrent = -1;
413   Int_t izero;
414   for (Int_t idx2 = 0; idx2 < fNdim2; idx2++){      
415
416     // Set the idx2 pointer
417     (*index)[idx2] = icurrent + 1;
418
419     // Reset the zero counter 
420     izero = 0;  
421
422     for (Int_t idx1 = 0; idx1 < fNdim1; idx1++){
423       // If below threshold
424       if (GetDataFast(idx1,idx2) <= fThreshold) {
425         izero++;
426       }
427       else {
428         if (izero > 0) {
429           // If we have currently izero counts under threshold
430           icurrent++;     
431           if (icurrent >= buf->fN) buf->Expand(icurrent*2);
432           // Store the number of entries below zero
433           (*buf)[icurrent] = -izero;  
434           izero = 0;
435         } 
436         icurrent++;
437         if (icurrent >= buf->fN) buf->Expand(icurrent*2);
438         (*buf)[icurrent] = GetDataFast(idx1,idx2);          
439       } // If signal larger than threshold              
440     } // End of loop over idx1
441
442     if (izero > 0) {
443       icurrent++;         
444       if (icurrent >= buf->fN) buf->Expand(icurrent*2);
445       // Store the number of entries below zero
446       (*buf)[icurrent] = -izero;  
447     }
448
449   }
450
451   buf->Expand(icurrent+1);
452   if (fElements) delete fElements;
453   fElements = buf;
454   fNelems   = fElements->fN;
455   fBufType  = 1;
456   if (fIndex) delete fIndex;
457   fIndex    = index;
458
459 }
460
461 //_____________________________________________________________________________
462 void AliTRDdataArrayF::Expand2()
463 {
464   //
465   // Expands a buffer of type 2 
466   //
467
468   Int_t i, k;
469
470   Float_t *buf = new Float_t[fNelems];
471   memset(buf,0,fNelems*sizeof(Float_t)); 
472
473   fNelems = fNdim1 * fNdim2;
474   fIndex->Set(fNdim2);
475
476   for (i = 0, k = 0; i < fNdim2; i++, k += fNdim1) (*fIndex)[i] = k;
477
478   Int_t idx1 = 0;
479   Int_t idx2 = 0;
480   Int_t n    = fElements->fN;
481   for (i = 0; i < n; i++){
482     // Negative sign counts the unwritten values (under threshold)
483     if ((*fElements)[i] < 0) {
484       //idx1 -= (Int_t) fElements->At(i); 
485       idx1 -= TMath::Nint(fElements->At(i)); 
486     }
487     else {
488       buf[(*fIndex)[idx2]+idx1] = fElements->At(i);
489       idx1++;
490     }
491     if (idx1 == fNdim1) {
492       idx1 = 0;
493       idx2++;
494     }
495     else { 
496       if (idx1 > fNdim1){
497         Reset();
498         return;
499       }      
500     }
501   }
502
503   fElements->Adopt(fNelems,buf);    
504
505 }
506
507 //_____________________________________________________________________________
508 void AliTRDdataArrayF::Compress2()
509 {
510   //
511   // Compress a buffer of type 2 - not implemented!
512   //
513
514 }
515
516 //_____________________________________________________________________________
517 Bool_t AliTRDdataArrayF::First0() 
518 {
519   //
520   // Returns the first entry for a buffer of type 0
521   //
522
523   fCurrentIdx1  = -1;
524   fCurrentIdx2  = -1;
525   fCurrentIndex = -1;
526
527   Int_t i;
528   for (i = 0; ((i < fNelems) && (fElements->At(i) <= fThreshold)); i++)
529   if (i == fNelems) return kFALSE;
530
531   fCurrentIdx1  = i % fNdim1;
532   fCurrentIdx2  = i / fNdim1;
533   fCurrentIndex = i;
534   return kTRUE; 
535
536 }
537
538 //_____________________________________________________________________________
539 Bool_t AliTRDdataArrayF::Next0()
540 {
541   //
542   // Returns the next entry for a buffer of type 0
543   //
544
545   if (fCurrentIndex < 0) return kFALSE; 
546
547   Int_t i;
548   for (i = fCurrentIndex + 1; 
549        ((i < fNelems) && (fElements->At(i) <= fThreshold)); 
550        i++);
551   if (i >= fNelems)  {
552     fCurrentIndex = -1;
553     return kFALSE;
554   }
555
556   fCurrentIdx1  = i % fNdim1;
557   fCurrentIdx2  = i / fNdim1;
558   fCurrentIndex = i;
559   return kTRUE; 
560
561 }
562
563 //_____________________________________________________________________________
564 Bool_t AliTRDdataArrayF::First1() 
565 {
566   //
567   // Returns the first entry for a buffer of type 1
568   //
569
570   fCurrentIdx1  = -1;
571   fCurrentIdx2  =  0;
572   fCurrentIndex = -1;
573
574   Int_t i;
575   for (i = 0; i < fNelems; i++){
576     if (fElements->At(i) < 0) {
577       //fCurrentIdx1 -= (Int_t) fElements->At(i);
578       fCurrentIdx1 -= TMath::Nint(fElements->At(i));
579     }
580     else {     
581       fCurrentIdx1++;
582     }
583     if (fCurrentIdx1 >= fNdim1) {
584       fCurrentIdx2++;
585       fCurrentIdx1 -= fNdim1;
586     }
587     if (fElements->At(i) > fThreshold) break;
588   }
589
590   fCurrentIndex = i;
591   if (fCurrentIndex >= 0) return kTRUE;
592   fCurrentIdx1  = -1;
593   fCurrentIdx2  = -1;
594   return kFALSE;        
595
596 }
597
598 //_____________________________________________________________________________
599 Bool_t AliTRDdataArrayF::Next1() 
600 {
601   //
602   // Returns the next entry for a buffer of type 1
603   //
604
605   if (fCurrentIndex < 0) return kFALSE;
606
607   Int_t i;
608   for (i = fCurrentIndex + 1; i < fNelems; i++){
609     if (fElements->At(i) < 0) {
610       //fCurrentIdx1 -= (Int_t) fElements->At(i);
611       fCurrentIdx1 -= TMath::Nint(fElements->At(i));
612     }
613     else {      
614       fCurrentIdx1++;
615     }
616     if (fCurrentIdx1 >= fNdim1) {
617       fCurrentIdx2++;
618       fCurrentIdx1 -= fNdim1;
619     }
620     if (fElements->At(i) > fThreshold) break;
621   }
622
623   fCurrentIndex =  i;
624   if ((i >= 0) && (i < fNelems)) return kTRUE;
625   fCurrentIdx1  = -1;
626   fCurrentIdx2  = -1;
627   return kFALSE;
628
629 }
630
631 //_____________________________________________________________________________
632 Float_t AliTRDdataArrayF::GetData1(Int_t idx1, Int_t idx2) const
633 {
634   //
635   // Returns the value at a given position of the array
636   //
637   
638   Int_t i, n2;
639
640   if ((idx2 + 1) >= fNdim2) {
641     n2 = fNelems;
642   }
643   else {
644     n2 = fIndex->At(idx2 + 1);
645   }
646
647   // Current idx1    
648   Int_t curidx1 = 0; 
649  
650   for (i = fIndex->At(idx2); ((i < n2) && (curidx1 < idx1)); i++){
651     if (fElements->At(i) < 0) {
652       //curidx1 -= (Int_t) fElements->At(i);
653       curidx1 -= TMath::Nint(fElements->At(i));
654     }
655     else {      
656       curidx1++;
657     }
658   }
659
660   if ((curidx1 == idx1) && (fElements->At(i) > 0)) {
661     return fElements->At(i);
662   }
663   else {
664     return 0;
665   }
666
667 }
668
669 //_____________________________________________________________________________
670 void AliTRDdataArrayF::SetData(Int_t row, Int_t col, Int_t time, Float_t value)
671 {
672   //
673   // Sets the data value at a given position of the array
674   // Includes boundary checking
675   //
676
677   if ((row >= 0) && (col >= 0) && (time >= 0)) {
678     Int_t idx1 = GetIdx1(row,col);
679     if ((idx1 >= 0) && (time < fNdim2)) {
680       SetDataFast(idx1,time,value);
681     }
682     else {
683       if (idx1 >= 0) {
684         TObject::Error("SetData"
685                       ,"time %d out of bounds (size: %d, this: 0x%08x)"
686                       ,time,fNdim2,this);
687       }
688     }
689   }
690
691 }
692
693 //_____________________________________________________________________________
694 void AliTRDdataArrayF::SetDataFast(Int_t idx1, Int_t idx2, Float_t value)
695 {
696   //
697   // Sets the data value at a given position of the array
698   // No boundary checking
699   //
700
701   (*fElements)[fIndex->fArray[idx2]+idx1] = value;
702
703 }
704
705 //_____________________________________________________________________________
706 AliTRDdataArrayF &AliTRDdataArrayF::operator=(const AliTRDdataArrayF &a)
707 {
708   //
709   // Assignment operator
710   //
711
712   if (this != &a) ((AliTRDdataArrayF &) a).Copy(*this);
713   return *this;
714
715 }
716