]>
Commit | Line | Data |
---|---|---|
a38a7850 | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
a38a7850 | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * Timm Steinbeck <timm@kip.uni-heidelberg.de> * | |
9 | * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> * | |
10 | * for The ALICE HLT Project. * | |
a38a7850 | 11 | * * |
12 | * Permission to use, copy, modify and distribute this software and its * | |
13 | * documentation strictly for non-commercial purposes is hereby granted * | |
14 | * without fee, provided that the above copyright notice appears in all * | |
15 | * copies and that both the copyright notice and this permission notice * | |
16 | * appear in the supporting documentation. The authors make no claims * | |
17 | * about the suitability of this software for any purpose. It is * | |
18 | * provided "as is" without express or implied warranty. * | |
19 | **************************************************************************/ | |
20 | ||
84645eb0 | 21 | /** @file AliHLTTPCDigitReaderPacked.cxx |
27f5f8ed | 22 | @author Timm Steinbeck, Jochen Thaeder, Matthias Richter, Kenneth Aamodt |
84645eb0 | 23 | @date |
24 | @brief A digit reader implementation for simulated, packed TPC 'raw' data. | |
25 | */ | |
db16520a | 26 | |
27 | #if __GNUC__>= 3 | |
a38a7850 | 28 | using namespace std; |
29 | #endif | |
30 | ||
31 | #include "AliHLTTPCDigitReaderPacked.h" | |
db16520a | 32 | |
a38a7850 | 33 | #include "AliTPCRawStream.h" |
34 | #include "AliRawReaderMemory.h" | |
35 | #include "AliRawDataHeader.h" | |
36 | ||
aff6e981 | 37 | //#if ENABLE_PAD_SORTING |
db16520a | 38 | #include "AliHLTTPCTransform.h" |
aff6e981 | 39 | //#endif // ENABLE_PAD_SORTING |
74c73e5a | 40 | #include "AliHLTStdIncludes.h" |
a38a7850 | 41 | |
42 | ClassImp(AliHLTTPCDigitReaderPacked) | |
43 | ||
95316e9f | 44 | #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H) |
84645eb0 | 45 | AliHLTTPCDigitReaderPacked::AliHLTTPCDigitReaderPacked() |
46 | : | |
aff6e981 | 47 | //#if ENABLE_PAD_SORTING |
84645eb0 | 48 | fCurrentRow(0), |
49 | fCurrentPad(0), | |
50 | fCurrentBin(-1), | |
51 | fNRows(0), | |
52 | fRowOffset(0), | |
53 | fNMaxRows(0), | |
54 | fNMaxPads(0), | |
55 | fNTimeBins(0), | |
56 | fData(NULL), | |
aff6e981 | 57 | //#endif // ENABLE_PAD_SORTING |
84645eb0 | 58 | fRawMemoryReader(NULL), |
27f5f8ed | 59 | fTPCRawStream(NULL), |
aff6e981 | 60 | fOldRCUFormat(kFALSE), |
61 | fUnsorted(kFALSE) | |
84645eb0 | 62 | { |
a38a7850 | 63 | fRawMemoryReader = new AliRawReaderMemory; |
db16520a | 64 | |
a38a7850 | 65 | fTPCRawStream = new AliTPCRawStream( fRawMemoryReader ); |
db16520a | 66 | |
aff6e981 | 67 | //#if ENABLE_PAD_SORTING |
db16520a | 68 | // get max number of rows |
db16520a | 69 | for (Int_t ii=0; ii < 6; ii++) |
70 | if (AliHLTTPCTransform::GetNRows(ii) > fNMaxRows) | |
71 | fNMaxRows = AliHLTTPCTransform::GetNRows(ii); | |
72 | ||
73 | // get max number of pads | |
db16520a | 74 | for (Int_t ii=0; ii < AliHLTTPCTransform::GetNRows();ii++ ) |
75 | if (AliHLTTPCTransform::GetNPads(ii) > fNMaxPads) | |
76 | fNMaxPads = AliHLTTPCTransform::GetNPads(ii); | |
77 | ||
78 | // get max number of bins | |
79 | fNTimeBins = AliHLTTPCTransform::GetNTimeBins(); | |
80 | ||
84645eb0 | 81 | HLTDebug("Array Borders ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d", |
db16520a | 82 | fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads); |
83 | ||
84 | // init Data array | |
85 | fData = new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ]; | |
aff6e981 | 86 | //#endif // ENABLE_PAD_SORTING |
a38a7850 | 87 | } |
88 | ||
89 | AliHLTTPCDigitReaderPacked::~AliHLTTPCDigitReaderPacked(){ | |
90 | if ( fRawMemoryReader ) | |
91 | delete fRawMemoryReader; | |
92 | fRawMemoryReader = NULL; | |
93 | if ( fTPCRawStream ) | |
db16520a | 94 | delete fTPCRawStream; |
a38a7850 | 95 | fTPCRawStream = NULL; |
aff6e981 | 96 | //#if ENABLE_PAD_SORTING |
db16520a | 97 | if ( fData ) |
98 | delete [] fData; | |
99 | fData = NULL; | |
aff6e981 | 100 | //#endif // ENABLE_PAD_SORTING |
a38a7850 | 101 | } |
102 | ||
84645eb0 | 103 | Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){ |
db16520a | 104 | |
a38a7850 | 105 | fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( ptr ), size ); |
db16520a | 106 | |
107 | //get DDL ID in order to tell the memory reader which slice/patch to use | |
108 | Int_t DDLid= 0; | |
109 | if (patch < 2) | |
27f5f8ed | 110 | DDLid = 768 + 2*slice + patch; |
db16520a | 111 | else |
9f968107 | 112 | DDLid = 840 + 4*slice + patch-2; |
db16520a | 113 | |
27f5f8ed | 114 | fRawMemoryReader->SetEquipmentID(DDLid); |
115 | //fRawMemoryReader->SetEquipmentID(1); | |
116 | if(fOldRCUFormat) | |
117 | fTPCRawStream->SetOldRCUFormat(kTRUE); | |
db16520a | 118 | |
aff6e981 | 119 | if(!fUnsorted){ |
120 | //#if ENABLE_PAD_SORTING | |
db16520a | 121 | |
122 | fCurrentRow = 0; | |
123 | fCurrentPad = 0; | |
124 | fCurrentBin = -1; | |
125 | ||
84645eb0 | 126 | Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch); |
127 | Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch); | |
db16520a | 128 | fNRows = lastrow - firstrow + 1; |
129 | ||
130 | Int_t offset=0; | |
131 | if (patch > 1) offset = AliHLTTPCTransform::GetFirstRow( 2 ); | |
132 | ||
133 | fRowOffset = firstrow - offset; | |
134 | firstrow -= offset; | |
135 | lastrow -= offset; | |
136 | ||
137 | // Init array with -1 | |
138 | memset( fData, 0xFF, sizeof(Int_t)*(fNMaxRows*fNMaxPads*fNTimeBins) ); | |
139 | ||
140 | // read data and fill in array | |
141 | while( fTPCRawStream->Next()){ | |
142 | ||
143 | Int_t row = fTPCRawStream->GetRow(); | |
144 | Int_t pad = fTPCRawStream->GetPad(); | |
145 | Int_t bin = fTPCRawStream->GetTime(); | |
146 | ||
147 | if ( row < firstrow || row > lastrow || pad > AliHLTTPCTransform::GetNPads(row + offset) || bin > fNTimeBins){ | |
148 | HLTFatal("Index out of Range Probably wrong patch! %d - %d", slice, patch); | |
149 | if ( row < firstrow || row > lastrow ) | |
150 | HLTFatal("Row out of Range %d < %d < %d",firstrow, row, lastrow); | |
151 | if ( pad > AliHLTTPCTransform::GetNPads(row + offset) ) | |
152 | HLTFatal("Pad out of Range %d < %d < %d",pad, AliHLTTPCTransform::GetNPads(row + offset)); | |
153 | if ( bin > fNTimeBins ) | |
154 | HLTFatal("Bin out of Range %d < %d < %d",bin, fNTimeBins); | |
155 | } | |
156 | else { | |
157 | if ((row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin >= fNMaxRows*fNMaxPads*fNTimeBins ) { | |
158 | HLTFatal("Index out of array range PAD=%d ||| ROW=%d ||| BIN=%d ||| OFFSET=%d ||| ROWOFFSET=%d", pad, row, bin, offset, fRowOffset); | |
159 | continue; | |
160 | } | |
161 | else { | |
162 | fData[ (row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin ] = fTPCRawStream->GetSignal() ; | |
163 | } | |
164 | } | |
165 | } | |
aff6e981 | 166 | //#endif // ENABLE_PAD_SORTING |
167 | } | |
a38a7850 | 168 | return 0; |
169 | } | |
170 | ||
f44e97dc | 171 | Bool_t AliHLTTPCDigitReaderPacked::NextSignal(){ |
db16520a | 172 | Bool_t readvalue = kTRUE; |
173 | ||
aff6e981 | 174 | if(!fUnsorted){//added for test |
175 | //#if ENABLE_PAD_SORTING | |
176 | while (1) { | |
db16520a | 177 | fCurrentBin++; |
178 | if (fCurrentBin >= fNTimeBins){ | |
179 | fCurrentBin = 0; | |
180 | fCurrentPad++; | |
181 | ||
182 | if (fCurrentPad >=fNMaxPads){ | |
183 | fCurrentPad = 0; | |
184 | fCurrentRow++; | |
185 | ||
186 | if (fCurrentRow >= fNMaxRows){ | |
187 | readvalue = kFALSE; | |
188 | break; | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
193 | if (fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin >= fNMaxRows*fNMaxPads*fNTimeBins ) { | |
194 | HLTFatal("Overflow: row=%d pad=%d bin=%d", fCurrentRow, fCurrentPad, fCurrentBin); | |
195 | readvalue = kFALSE; | |
196 | break; | |
197 | } | |
198 | ||
199 | if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin ] != -1) break; | |
aff6e981 | 200 | } |
201 | }// added for test | |
202 | else{//added for test | |
203 | //#else // !ENABLE_PAD_SORTING | |
204 | readvalue = fTPCRawStream->Next(); | |
205 | }//added for test | |
206 | //#endif // ENABLE_PAD_SORTING | |
db16520a | 207 | |
208 | return readvalue; | |
a38a7850 | 209 | } |
210 | ||
db16520a | 211 | Int_t AliHLTTPCDigitReaderPacked::GetRow(){ |
aff6e981 | 212 | /*#if ENABLE_PAD_SORTING |
db16520a | 213 | return (fCurrentRow + fRowOffset); |
214 | #else // !ENABLE_PAD_SORTING | |
215 | return (Int_t) fTPCRawStream->GetRow(); | |
216 | #endif // ENABLE_PAD_SORTING | |
aff6e981 | 217 | */ |
218 | if(!fUnsorted){ | |
219 | return (fCurrentRow + fRowOffset); | |
220 | } | |
221 | else{ | |
222 | return (Int_t) fTPCRawStream->GetRow(); | |
223 | } | |
a38a7850 | 224 | } |
225 | ||
226 | int AliHLTTPCDigitReaderPacked::GetPad(){ | |
aff6e981 | 227 | /*#if ENABLE_PAD_SORTING |
228 | return fCurrentPad; | |
229 | #else // !ENABLE_PAD_SORTING | |
230 | return fTPCRawStream->GetPad(); | |
231 | #endif // ENABLE_PAD_SORTING | |
232 | */ | |
233 | if(!fUnsorted){ | |
234 | return fCurrentPad; | |
235 | } | |
236 | else{ | |
237 | return fTPCRawStream->GetPad(); | |
238 | } | |
a38a7850 | 239 | } |
240 | ||
db16520a | 241 | Int_t AliHLTTPCDigitReaderPacked::GetSignal(){ |
aff6e981 | 242 | /* |
243 | #if ENABLE_PAD_SORTING | |
244 | return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ]; | |
245 | #else // !ENABLE_PAD_SORTING | |
246 | return fTPCRawStream->GetSignal(); | |
247 | #endif // ENABLE_PAD_SORTING | |
248 | */ | |
249 | if(!fUnsorted){ | |
250 | return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ]; | |
251 | } | |
252 | else{ | |
253 | return fTPCRawStream->GetSignal(); | |
254 | } | |
a38a7850 | 255 | } |
256 | ||
db16520a | 257 | Int_t AliHLTTPCDigitReaderPacked::GetTime(){ |
aff6e981 | 258 | /* |
259 | #if ENABLE_PAD_SORTING | |
260 | return fCurrentBin; | |
261 | #else // !ENABLE_PAD_SORTING | |
262 | return fTPCRawStream->GetTime(); | |
263 | #endif // ENABLE_PAD_SORTING | |
264 | */ | |
265 | if(!fUnsorted){ | |
266 | return fCurrentBin; | |
267 | } | |
268 | else{ | |
269 | return fTPCRawStream->GetTime(); | |
270 | } | |
a38a7850 | 271 | } |
74c73e5a | 272 | #endif //defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H) |