]>
Commit | Line | Data |
---|---|---|
a38a7850 | 1 | // $Id$ |
2 | ||
67fada6b | 3 | //************************************************************************* |
4 | // This file is property of and copyright by the ALICE HLT Project * | |
5 | // ALICE Experiment at CERN, All rights reserved. * | |
6 | // * | |
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. * | |
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 | //*************************************************************************/ | |
a38a7850 | 20 | |
84645eb0 | 21 | /** @file AliHLTTPCDigitReaderUnpacked.cxx |
22 | @author Timm Steinbeck, Jochen Thaeder, Matthias Richter | |
23 | @date | |
24 | @brief A digit reader implementation for unpacked TPC data. | |
25 | */ | |
a38a7850 | 26 | |
27 | #if __GNUC__== 3 | |
28 | using namespace std; | |
29 | #endif | |
30 | ||
67fada6b | 31 | #include <cassert> |
a38a7850 | 32 | #include "AliHLTTPCDigitReaderUnpacked.h" |
33 | #include "AliHLTTPCDigitData.h" | |
84645eb0 | 34 | #include "AliHLTTPCTransform.h" |
35 | #include "AliHLTStdIncludes.h" | |
deba5d85 | 36 | #include "AliHLTTPCMapping.h" |
a38a7850 | 37 | |
84645eb0 | 38 | ClassImp(AliHLTTPCDigitReaderUnpacked) |
a38a7850 | 39 | |
84645eb0 | 40 | AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked() |
41 | : | |
42 | fDigitRowData(NULL), | |
43 | fActRowData(NULL), | |
44 | fData(NULL), | |
45 | fPtr(NULL), | |
46 | fSize(0), | |
47 | fBin(0), | |
48 | fRow(0), | |
49 | fFirstRow(0), | |
deba5d85 | 50 | fLastRow(0), |
51 | fUnsorted(kFALSE), | |
52 | fDataBunch(), | |
53 | fTrackIDs(), | |
54 | fTrackIDCounts(), | |
55 | fEndOfDataReached(kFALSE), | |
56 | fEndOfChannelReached(kFALSE), | |
57 | fPrevTime(0), | |
58 | fEndTimeBinOfBunch(0), | |
59 | fPrevSignal(0), | |
959cfda3 | 60 | fPrevPad(-1), |
deba5d85 | 61 | fPrevRow(-1), |
62 | fNextChannelIsAlreadyConfirmed(kFALSE), | |
63 | fMapping(NULL), | |
64 | fDigitsVector(), | |
959cfda3 | 65 | fBinRowPositionSorted(), |
deba5d85 | 66 | fPatch(0) |
84645eb0 | 67 | { |
5df0cbb9 | 68 | // see header file for class documentation |
69 | // or | |
70 | // refer to README to build package | |
71 | // or | |
72 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
84645eb0 | 73 | } |
a38a7850 | 74 | |
a38a7850 | 75 | AliHLTTPCDigitReaderUnpacked::~AliHLTTPCDigitReaderUnpacked(){ |
5df0cbb9 | 76 | // see header file for class documentation |
37c9ee0f | 77 | if(fMapping){ |
78 | delete fMapping; | |
79 | } | |
80 | fMapping=NULL; | |
a38a7850 | 81 | } |
82 | ||
84645eb0 | 83 | int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){ |
5df0cbb9 | 84 | // see header file for class documentation |
67fada6b | 85 | int iResult=0; |
5df0cbb9 | 86 | AliHLTTPCUnpackedRawData *tmpptr=NULL; |
a38a7850 | 87 | fPtr = ptr; |
88 | fSize = size; | |
89 | ||
deba5d85 | 90 | fPatch=patch; |
37c9ee0f | 91 | fEndOfDataReached=kFALSE; |
92 | fEndOfChannelReached=kFALSE; | |
93 | fPrevTime=0; | |
94 | fEndTimeBinOfBunch=0; | |
95 | fPrevSignal=0; | |
959cfda3 | 96 | fPrevPad=-1; |
37c9ee0f | 97 | fPrevRow=-1; |
98 | fNextChannelIsAlreadyConfirmed=kFALSE; | |
99 | fDigitsVector.clear(); | |
deba5d85 | 100 | |
d3905cf0 | 101 | tmpptr = reinterpret_cast<AliHLTTPCUnpackedRawData*>(fPtr); |
a38a7850 | 102 | fDigitRowData = (AliHLTTPCDigitRowData*) tmpptr->fDigits; |
67fada6b | 103 | fActRowData = fDigitRowData; |
a38a7850 | 104 | |
deba5d85 | 105 | if(!fMapping){ |
106 | fMapping = new AliHLTTPCMapping(patch); | |
107 | } | |
108 | ||
95e36f3d | 109 | while (fActRowData && ((iResult=GetNextRowData(fActRowData))>=0)) {/* empty body */}; |
67fada6b | 110 | |
111 | if (iResult>=0) { | |
112 | fActRowData = fDigitRowData; | |
a38a7850 | 113 | fBin = -1; |
114 | ||
055fed30 | 115 | int dummy=0; |
116 | AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetFirstRow(patch), dummy, fFirstRow); | |
117 | AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetLastRow(patch), dummy, fLastRow); | |
84645eb0 | 118 | |
a38a7850 | 119 | fRow = fFirstRow; |
120 | ||
121 | if ((Int_t)fActRowData->fRow != fRow){ | |
84645eb0 | 122 | HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow); |
a38a7850 | 123 | } |
67fada6b | 124 | } else { |
125 | fActRowData=NULL; | |
126 | } | |
127 | return iResult; | |
128 | } | |
129 | ||
130 | int AliHLTTPCDigitReaderUnpacked::GetNextRowData(AliHLTTPCDigitRowData*& pRow) const | |
131 | { | |
132 | // get new row data from the current row data | |
133 | int iResult=0; | |
134 | AliHLTTPCDigitRowData* pCurrent=pRow; | |
135 | assert(pCurrent); | |
136 | pRow=NULL; | |
137 | Byte_t *tmp = (Byte_t*) pCurrent; | |
138 | Int_t size = sizeof(AliHLTTPCDigitRowData) + pCurrent->fNDigit*sizeof(AliHLTTPCDigitData); | |
139 | tmp += size; | |
140 | pRow = reinterpret_cast<AliHLTTPCDigitRowData*>(tmp); | |
141 | ||
142 | // check if the new pointer is within the range | |
143 | if (((Byte_t*)fPtr) + fSize <= tmp){ | |
144 | if (((Byte_t*)fPtr) + fSize < tmp) { | |
145 | // if the increment does not match exactly there is a format error | |
146 | HLTError("input format not recognized: buffer %p %d, current row data %p, %d digits", fPtr, fSize, pCurrent, pCurrent->fNDigit); | |
147 | iResult=-EBADF; | |
148 | } | |
149 | pRow=NULL; | |
150 | } else { | |
151 | // check if the current row structure has the right format | |
152 | size = sizeof(AliHLTTPCDigitRowData) + pRow->fNDigit*sizeof(AliHLTTPCDigitData); | |
153 | tmp += size; | |
154 | if (((Byte_t*)fPtr) + fSize < tmp){ | |
155 | HLTError("Current row data not recognized %p (buffer %p %d) %d digits", pRow, fPtr, fSize, pRow->fNDigit); | |
156 | pRow=NULL; | |
157 | iResult=-EBADF; | |
158 | } | |
159 | } | |
160 | ||
161 | return iResult; | |
a38a7850 | 162 | } |
959cfda3 | 163 | void AliHLTTPCDigitReaderUnpacked::SortBunchBinVector(){ |
164 | fBinRowPositionSorted.clear(); | |
165 | ||
166 | fBinRowPositionSorted.push_back(0); | |
167 | Int_t nAdded=0; | |
168 | Int_t beginningOfPadIndex=0; | |
169 | Int_t totalAdded=0; | |
170 | for(Int_t i=1;i<(Int_t)fActRowData->fNDigit;i++){ | |
171 | if(fData[i-1].fPad == fData[i].fPad){// means that these sinals belong to the same pad | |
172 | if(fData[i-1].fTime+1 == fData[i].fTime){ //means that the signal belong to the same bunch | |
173 | nAdded++; | |
174 | totalAdded++; | |
175 | fBinRowPositionSorted.insert(fBinRowPositionSorted.begin()+beginningOfPadIndex+nAdded,i); | |
176 | } | |
177 | else{//we have a new bunch on this pad, put it in fornt of the previous bunch | |
178 | totalAdded++; | |
179 | nAdded=0; | |
180 | fBinRowPositionSorted.insert(fBinRowPositionSorted.begin()+beginningOfPadIndex,i); | |
181 | } | |
182 | } | |
183 | else{ | |
184 | totalAdded++; | |
185 | beginningOfPadIndex=totalAdded; | |
186 | fBinRowPositionSorted.push_back(i); | |
187 | nAdded=0; | |
188 | } | |
189 | } | |
190 | } | |
a38a7850 | 191 | |
f44e97dc | 192 | bool AliHLTTPCDigitReaderUnpacked::NextSignal(){ |
5df0cbb9 | 193 | // see header file for class documentation |
67fada6b | 194 | if (fActRowData==NULL) return false; |
195 | ||
a38a7850 | 196 | bool rreadvalue = true; |
197 | ||
198 | fBin++; | |
199 | ||
0191ac8f | 200 | while ( fBin >= (Int_t)fActRowData->fNDigit ){ |
a38a7850 | 201 | fRow++; |
a38a7850 | 202 | if ((fRow >= fFirstRow) && (fRow <= fLastRow)){ |
0191ac8f | 203 | |
a38a7850 | 204 | //new row |
67fada6b | 205 | if (GetNextRowData(fActRowData)<0) { |
a38a7850 | 206 | rreadvalue = false; |
207 | return rreadvalue; | |
208 | } | |
a38a7850 | 209 | fBin = 0; |
210 | } | |
211 | else { | |
212 | rreadvalue = false; | |
213 | return rreadvalue; | |
214 | } | |
0191ac8f | 215 | if(!fActRowData){ |
216 | return false; | |
217 | } | |
a38a7850 | 218 | if ((Int_t)fActRowData->fRow != fRow){ |
84645eb0 | 219 | HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow); |
a38a7850 | 220 | } |
221 | } | |
0191ac8f | 222 | |
a38a7850 | 223 | fData = fActRowData->fDigitData; |
959cfda3 | 224 | |
225 | if(fBin==0){ | |
226 | SortBunchBinVector(); | |
227 | } | |
228 | ||
229 | if(fPrevPad == -1){ | |
230 | fPrevPad = GetSortedPad(); | |
231 | } | |
a38a7850 | 232 | |
233 | return rreadvalue; | |
234 | } | |
235 | ||
236 | int AliHLTTPCDigitReaderUnpacked::GetRow(){ | |
5df0cbb9 | 237 | // see header file for class documentation |
a38a7850 | 238 | int rrow; |
deba5d85 | 239 | |
240 | if(fUnsorted == kFALSE){ | |
241 | rrow = fRow; | |
242 | } | |
243 | else{ | |
244 | rrow = fRow-AliHLTTPCTransform::GetFirstRow(fPatch); | |
245 | if(fPatch>1){ | |
246 | rrow += AliHLTTPCTransform::GetFirstRow(2); | |
247 | } | |
248 | } | |
249 | ||
a38a7850 | 250 | return rrow; |
251 | } | |
252 | ||
253 | int AliHLTTPCDigitReaderUnpacked::GetPad(){ | |
5df0cbb9 | 254 | // see header file for class documentation |
a38a7850 | 255 | int rpad; |
deba5d85 | 256 | if(fUnsorted == kFALSE){ |
257 | rpad = GetSortedPad(); | |
258 | } | |
259 | else{ | |
260 | rpad = fPrevPad; | |
261 | } | |
a38a7850 | 262 | return rpad ; |
263 | } | |
264 | ||
265 | int AliHLTTPCDigitReaderUnpacked::GetSignal(){ | |
5df0cbb9 | 266 | // see header file for class documentation |
a38a7850 | 267 | int rsignal; |
deba5d85 | 268 | if(fUnsorted == kFALSE){ |
269 | rsignal = GetSortedSignal(); | |
270 | } | |
271 | else{ | |
272 | rsignal = fPrevSignal; | |
273 | } | |
a38a7850 | 274 | return rsignal; |
275 | } | |
276 | ||
277 | int AliHLTTPCDigitReaderUnpacked::GetTime(){ | |
deba5d85 | 278 | // see header file for class documentation |
279 | int rtime; | |
280 | if(fUnsorted==kFALSE){ | |
281 | rtime = GetSortedTime(); | |
282 | } | |
283 | else{ | |
284 | rtime = fPrevTime+1-fDataBunch.size(); | |
285 | } | |
286 | return rtime; | |
287 | } | |
288 | ||
289 | AliHLTUInt32_t AliHLTTPCDigitReaderUnpacked::GetAltroBlockHWaddr() const | |
290 | { | |
291 | // see header file for class documentation | |
292 | return (AliHLTUInt32_t)(fMapping->GetHwAddress((UInt_t)GetSortedRow(),(UInt_t)GetSortedPad()));//fTPCRawStream->GetHWAddress(); | |
293 | } | |
294 | ||
deeb43e0 | 295 | AliHLTTPCDigitData AliHLTTPCDigitReaderUnpacked::GetSortedDigit(){ |
296 | // see header file for class documentation | |
297 | assert(fData); | |
298 | if (!fData) return AliHLTTPCDigitData(); | |
299 | return fData[fBinRowPositionSorted.at(fBin)]; | |
300 | } | |
301 | ||
deba5d85 | 302 | Int_t AliHLTTPCDigitReaderUnpacked::GetSortedTime(){ |
5df0cbb9 | 303 | // see header file for class documentation |
67fada6b | 304 | assert(fData); |
f44e97dc | 305 | if (!fData) return -1; |
a38a7850 | 306 | int rtime; |
959cfda3 | 307 | rtime = (int)fData[fBinRowPositionSorted.at(fBin)].fTime; |
deba5d85 | 308 | if(fDataBunch.size()>1){ |
309 | fEndTimeBinOfBunch=rtime; | |
310 | } | |
a38a7850 | 311 | return rtime; |
312 | } | |
deba5d85 | 313 | |
314 | Int_t AliHLTTPCDigitReaderUnpacked::GetSortedSignal(){ | |
315 | // see header file for class documentation | |
316 | assert(fData); | |
317 | if (!fData) return -1; | |
318 | int rsignal; | |
959cfda3 | 319 | rsignal = (int)fData[fBinRowPositionSorted.at(fBin)].fCharge; |
deba5d85 | 320 | return rsignal; |
321 | ||
322 | } | |
323 | ||
324 | Int_t AliHLTTPCDigitReaderUnpacked::GetSortedPad() const{ | |
325 | // see header file for class documentation | |
326 | assert(fData); | |
327 | if (!fData) return -1; | |
328 | int rpad; | |
959cfda3 | 329 | rpad = (int)fData[fBinRowPositionSorted.at(fBin)].fPad; |
deba5d85 | 330 | return rpad ; |
331 | } | |
332 | ||
333 | int AliHLTTPCDigitReaderUnpacked::GetSortedRow() const { | |
334 | // see header file for class documentation | |
335 | int rrow; | |
336 | rrow = fRow-AliHLTTPCTransform::GetFirstRow(fPatch); | |
337 | if(fPatch>1){ | |
338 | rrow += AliHLTTPCTransform::GetFirstRow(2); | |
339 | } | |
340 | return rrow; | |
341 | } | |
342 | ||
343 | bool AliHLTTPCDigitReaderUnpacked::NextChannel() | |
344 | { | |
345 | // see header file for class documentation | |
346 | ||
347 | // If the next channel is already confirmed by the next bunch function | |
348 | // or there are more signals (this will only be for the first signal) | |
349 | ||
350 | if(fEndOfDataReached == kTRUE){ | |
351 | return false; | |
352 | } | |
353 | if(fNextChannelIsAlreadyConfirmed){ | |
354 | fNextChannelIsAlreadyConfirmed = kFALSE; | |
355 | fPrevTime=GetSortedTime(); | |
356 | fPrevSignal=GetSortedSignal(); | |
357 | fPrevPad = GetSortedPad(); | |
358 | fPrevRow = GetSortedRow(); | |
959cfda3 | 359 | |
360 | if(GetAltroBlockHWaddr() == (UInt_t)-1){ | |
361 | fPrevPad = -1; | |
362 | return NextChannel(); | |
363 | } | |
364 | ||
deba5d85 | 365 | return true; |
366 | } | |
367 | else if(NextSignal()) { // there is data | |
959cfda3 | 368 | |
369 | if(GetAltroBlockHWaddr() == (UInt_t)-1){ | |
370 | fPrevPad = -1; | |
371 | return NextChannel(); | |
372 | } | |
deba5d85 | 373 | return true; |
374 | } | |
375 | return false; | |
376 | } | |
377 | ||
378 | int AliHLTTPCDigitReaderUnpacked::NextBunch() | |
379 | { | |
380 | // see header file for class documentation | |
381 | ||
382 | if(fEndOfDataReached == kTRUE || fEndOfChannelReached == kTRUE){ | |
383 | // sets fEndOfChannelReached back to false, for the next channel | |
384 | // and returns 0 to tell stop the NextBunch calls for this channel. | |
385 | fEndOfChannelReached=kFALSE; | |
386 | return 0; | |
387 | } | |
388 | ||
389 | ||
390 | fDataBunch.clear(); | |
391 | fDigitsVector.clear(); | |
392 | ||
393 | //adding the first signal (will always be the leftover from either NextChannel call or previous bunch) | |
394 | fPrevTime=GetSortedTime(); | |
395 | fPrevSignal=GetSortedSignal(); | |
396 | fPrevPad = GetSortedPad(); | |
397 | fPrevRow = GetSortedRow(); | |
398 | fDataBunch.push_back(GetSortedSignal()); | |
deeb43e0 | 399 | fDigitsVector.push_back(GetSortedDigit()); |
deba5d85 | 400 | |
401 | do{ | |
402 | if(NextSignal()){ | |
403 | if((fPrevPad == GetSortedPad()) && (fPrevRow == GetSortedRow())){//check if there is a change in channel(new pad or row) | |
404 | if(fPrevTime+1 == GetSortedTime()){//if true means that we have consecutive signals | |
405 | fPrevTime = GetSortedTime(); | |
406 | //fDataBunch.insert(fDataBunch.begin(), GetSortedSignal());// add the signal to the beginning of the buffer | |
407 | fDataBunch.push_back(GetSortedSignal());// add the signal to the beginning of the buffer | |
deeb43e0 | 408 | fDigitsVector.push_back(GetSortedDigit()); |
deba5d85 | 409 | } |
410 | else{//end of bunch but not of channel | |
411 | break; | |
412 | } | |
413 | } | |
414 | else{ | |
415 | // end of channel, last bunch will be completed | |
416 | fEndOfChannelReached = kTRUE; | |
417 | // the next channel is already confirmed since the next channel returned true | |
418 | fNextChannelIsAlreadyConfirmed = kTRUE; | |
419 | break; | |
420 | } | |
421 | } | |
422 | else{ | |
423 | // end of data, but there is one bunch to be completed. | |
424 | fEndOfDataReached = kTRUE; | |
425 | break; | |
426 | } | |
427 | }while(1); | |
428 | ||
429 | return fDataBunch.size(); | |
430 | } | |
431 | ||
432 | int AliHLTTPCDigitReaderUnpacked::GetBunchSize(){ | |
433 | // see header file for class documentation | |
434 | return fDataBunch.size(); | |
435 | } | |
436 | ||
437 | const UInt_t* AliHLTTPCDigitReaderUnpacked::GetSignals() | |
438 | { | |
439 | // see header file for class documentation | |
440 | return &fDataBunch[0]; | |
441 | } | |
442 | ||
443 | const AliHLTTPCDigitData* AliHLTTPCDigitReaderUnpacked::GetBunchDigits() | |
444 | { | |
445 | // see header file for class documentation | |
446 | return &fDigitsVector[0]; | |
447 | } | |
448 | int AliHLTTPCDigitReaderUnpacked::GetRowOffset() const | |
449 | { | |
450 | // see header file for class documentation | |
451 | return AliHLTTPCTransform::GetFirstRow(fPatch); | |
452 | } |