f7336fa3 |
1 | #ifndef TRDdataArray_H |
2 | #define TRDdataArray_H |
3 | |
4 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * |
5 | * See cxx source for full Copyright notice */ |
6 | |
7 | /* $Id$ */ |
8 | |
9 | #include "AliTRDarrayI.h" |
6f1e466d |
10 | #include "AliTRDarrayF.h" |
f7336fa3 |
11 | #include "AliTRDsegmentID.h" |
12 | |
13 | ///////////////////////////////////////////////////////////// |
14 | // General container for data from TRD detector segments // |
15 | // Adapted from AliDigits, origin M.Ivanov // |
16 | ///////////////////////////////////////////////////////////// |
17 | |
18 | class AliTRDdataArray : public AliTRDsegmentID { |
19 | |
20 | public: |
21 | |
22 | AliTRDdataArray(); |
6f1e466d |
23 | AliTRDdataArray(Int_t nrow, Int_t ncol,Int_t ntime); |
f7336fa3 |
24 | ~AliTRDdataArray(); |
25 | |
6f1e466d |
26 | virtual void Allocate(Int_t nrow, Int_t ncol,Int_t ntime); |
27 | virtual void Reset(); |
f7336fa3 |
28 | |
f7336fa3 |
29 | virtual Int_t GetNRow() { return fNrow; }; |
30 | virtual Int_t GetNCol() { return fNcol; }; |
31 | virtual Int_t GetNtime() { return fNtime; }; |
32 | |
f7336fa3 |
33 | inline Int_t GetIndex(Int_t row, Int_t col, Int_t time); |
34 | |
35 | protected: |
36 | |
37 | inline Int_t GetIdx1(Int_t row, Int_t col); |
38 | inline Bool_t CheckBounds(const char *where, Int_t idx1, Int_t idx2); |
39 | inline Bool_t OutOfBoundsError(const char *where, Int_t idx1, Int_t idx2); |
f7336fa3 |
40 | |
41 | Int_t fNrow; // Number of rows of the detector segement |
42 | Int_t fNcol; // Number of columns of the detector segment |
43 | Int_t fNtime; // Number of timebins of the detector segment |
44 | |
45 | Int_t fNdim1; // First dimension of the array (row * column) |
46 | Int_t fNdim2; // Second dimension of the array (time, not compressed) |
f7336fa3 |
47 | |
f7336fa3 |
48 | AliTRDarrayI *fIndex; // Index position of column |
49 | Int_t fBufType; // Type of the buffer - defines the compression algorithm |
f7336fa3 |
50 | Int_t fNelems; // Total number of elements |
51 | Int_t fCurrentIdx1; // !Current index 1 |
52 | Int_t fCurrentIdx2; // !Current index 2 |
53 | Int_t fCurrentIndex; // !Current index in field |
54 | |
55 | ClassDef(AliTRDdataArray,1) // Data container for one TRD detector segment |
56 | |
57 | }; |
58 | |
59 | //_____________________________________________________________________________ |
60 | inline Int_t AliTRDdataArray::GetIndex(Int_t row, Int_t col, Int_t time) |
61 | { |
62 | // |
63 | // Maps the row/column/time into one number |
64 | // |
65 | |
6f1e466d |
66 | if (time > fNtime) { |
67 | TObject::Error("GetIdx1" |
68 | ,"time %d out of bounds (size: %d, this: 0x%08x)" |
69 | ,time,fNtime,this); |
70 | return -1; |
71 | } |
72 | |
f7336fa3 |
73 | return time * fNrow*fNcol + GetIdx1(row,col); |
74 | |
75 | } |
76 | |
77 | //_____________________________________________________________________________ |
78 | inline Int_t AliTRDdataArray::GetIdx1(Int_t row, Int_t col) |
79 | { |
80 | // |
81 | // Maps the two-dimensional row/column plane into an one-dimensional array. |
82 | // |
83 | |
6f1e466d |
84 | if (row >= fNrow) { |
85 | TObject::Error("GetIdx1" |
86 | ,"row %d out of bounds (size: %d, this: 0x%08x)" |
87 | ,row,fNrow,this); |
88 | return -1; |
89 | } |
90 | |
91 | if (col >= fNcol) { |
92 | TObject::Error("GetIdx1" |
93 | ,"col %d out of bounds (size: %d, this: 0x%08x)" |
94 | ,col,fNcol,this); |
95 | return -1; |
96 | } |
97 | |
98 | return row + col * fNrow; |
f7336fa3 |
99 | |
100 | } |
101 | |
102 | //_____________________________________________________________________________ |
103 | inline Bool_t AliTRDdataArray::CheckBounds(const char *where |
104 | , Int_t idx1, Int_t idx2) |
105 | { |
106 | // |
107 | // Does the boundary checking |
108 | // |
109 | |
110 | if ((idx2 >= fNdim2) || (idx2 < 0)) |
111 | return OutOfBoundsError(where,idx1,idx2); |
112 | |
113 | Int_t index = (*fIndex).At(idx2) + idx1; |
114 | if ((index < 0) || (index > fNelems)) |
115 | return OutOfBoundsError(where,idx1,idx2); |
116 | |
117 | return kTRUE; |
118 | |
119 | } |
120 | |
121 | //_____________________________________________________________________________ |
122 | inline Bool_t AliTRDdataArray::OutOfBoundsError(const char *where |
123 | , Int_t idx1, Int_t idx2) |
124 | { |
125 | // |
126 | // Generate an out-of-bounds error. Always returns false. |
127 | // |
128 | |
6f1e466d |
129 | TObject::Error(where, "idx1 %d idx2 %d out of bounds (size: %d x %d, this: 0x%08x)" |
130 | ,idx1,idx2,fNdim1,fNdim2,this); |
f7336fa3 |
131 | |
132 | return kFALSE; |
133 | |
134 | } |
135 | |
f7336fa3 |
136 | #endif |
137 | |