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