]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCDigitReaderUnpacked.cxx
AliTPCcalibCalib.cxx - use also alignmnet - not implemented yet
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderUnpacked.cxx
CommitLineData
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
28using 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 38ClassImp(AliHLTTPCDigitReaderUnpacked)
a38a7850 39
84645eb0 40AliHLTTPCDigitReaderUnpacked::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),
60 fPrevPad(0),
61 fPrevRow(-1),
62 fNextChannelIsAlreadyConfirmed(kFALSE),
63 fMapping(NULL),
64 fDigitsVector(),
65 fPatch(0)
84645eb0 66{
5df0cbb9 67 // see header file for class documentation
68 // or
69 // refer to README to build package
70 // or
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
84645eb0 72}
a38a7850 73
a38a7850 74AliHLTTPCDigitReaderUnpacked::~AliHLTTPCDigitReaderUnpacked(){
5df0cbb9 75 // see header file for class documentation
37c9ee0f 76 if(fMapping){
77 delete fMapping;
78 }
79 fMapping=NULL;
a38a7850 80}
81
84645eb0 82int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
5df0cbb9 83 // see header file for class documentation
67fada6b 84 int iResult=0;
5df0cbb9 85 AliHLTTPCUnpackedRawData *tmpptr=NULL;
a38a7850 86 fPtr = ptr;
87 fSize = size;
88
deba5d85 89 fPatch=patch;
37c9ee0f 90 fEndOfDataReached=kFALSE;
91 fEndOfChannelReached=kFALSE;
92 fPrevTime=0;
93 fEndTimeBinOfBunch=0;
94 fPrevSignal=0;
95 fPrevPad=0;
96 fPrevRow=-1;
97 fNextChannelIsAlreadyConfirmed=kFALSE;
98 fDigitsVector.clear();
deba5d85 99
d3905cf0 100 tmpptr = reinterpret_cast<AliHLTTPCUnpackedRawData*>(fPtr);
a38a7850 101 fDigitRowData = (AliHLTTPCDigitRowData*) tmpptr->fDigits;
67fada6b 102 fActRowData = fDigitRowData;
a38a7850 103
deba5d85 104 if(!fMapping){
105 fMapping = new AliHLTTPCMapping(patch);
106 }
107
95e36f3d 108 while (fActRowData && ((iResult=GetNextRowData(fActRowData))>=0)) {/* empty body */};
67fada6b 109
110 if (iResult>=0) {
111 fActRowData = fDigitRowData;
a38a7850 112 fBin = -1;
113
055fed30 114 int dummy=0;
115 AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetFirstRow(patch), dummy, fFirstRow);
116 AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetLastRow(patch), dummy, fLastRow);
84645eb0 117
a38a7850 118 fRow = fFirstRow;
119
120 if ((Int_t)fActRowData->fRow != fRow){
84645eb0 121 HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
a38a7850 122 }
67fada6b 123 } else {
124 fActRowData=NULL;
125 }
126 return iResult;
127}
128
129int AliHLTTPCDigitReaderUnpacked::GetNextRowData(AliHLTTPCDigitRowData*& pRow) const
130{
131 // get new row data from the current row data
132 int iResult=0;
133 AliHLTTPCDigitRowData* pCurrent=pRow;
134 assert(pCurrent);
135 pRow=NULL;
136 Byte_t *tmp = (Byte_t*) pCurrent;
137 Int_t size = sizeof(AliHLTTPCDigitRowData) + pCurrent->fNDigit*sizeof(AliHLTTPCDigitData);
138 tmp += size;
139 pRow = reinterpret_cast<AliHLTTPCDigitRowData*>(tmp);
140
141 // check if the new pointer is within the range
142 if (((Byte_t*)fPtr) + fSize <= tmp){
143 if (((Byte_t*)fPtr) + fSize < tmp) {
144 // if the increment does not match exactly there is a format error
145 HLTError("input format not recognized: buffer %p %d, current row data %p, %d digits", fPtr, fSize, pCurrent, pCurrent->fNDigit);
146 iResult=-EBADF;
147 }
148 pRow=NULL;
149 } else {
150 // check if the current row structure has the right format
151 size = sizeof(AliHLTTPCDigitRowData) + pRow->fNDigit*sizeof(AliHLTTPCDigitData);
152 tmp += size;
153 if (((Byte_t*)fPtr) + fSize < tmp){
154 HLTError("Current row data not recognized %p (buffer %p %d) %d digits", pRow, fPtr, fSize, pRow->fNDigit);
155 pRow=NULL;
156 iResult=-EBADF;
157 }
158 }
159
160 return iResult;
a38a7850 161}
162
f44e97dc 163bool AliHLTTPCDigitReaderUnpacked::NextSignal(){
5df0cbb9 164 // see header file for class documentation
67fada6b 165 if (fActRowData==NULL) return false;
166
a38a7850 167 bool rreadvalue = true;
168
169 fBin++;
170
171 if ( fBin >= (Int_t)fActRowData->fNDigit ){
a38a7850 172 fRow++;
a38a7850 173 if ((fRow >= fFirstRow) && (fRow <= fLastRow)){
174
175 //new row
67fada6b 176 if (GetNextRowData(fActRowData)<0) {
a38a7850 177 rreadvalue = false;
178 return rreadvalue;
179 }
180
181 fBin = 0;
182 }
183 else {
184 rreadvalue = false;
185 return rreadvalue;
186 }
afa4418c 187 if(!fActRowData){
188 return false;
189 }
a38a7850 190 if ((Int_t)fActRowData->fRow != fRow){
84645eb0 191 HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
a38a7850 192 }
193 }
194
195 fData = fActRowData->fDigitData;
196
197 return rreadvalue;
198}
199
200int AliHLTTPCDigitReaderUnpacked::GetRow(){
5df0cbb9 201 // see header file for class documentation
a38a7850 202 int rrow;
deba5d85 203
204 if(fUnsorted == kFALSE){
205 rrow = fRow;
206 }
207 else{
208 rrow = fRow-AliHLTTPCTransform::GetFirstRow(fPatch);
209 if(fPatch>1){
210 rrow += AliHLTTPCTransform::GetFirstRow(2);
211 }
212 }
213
a38a7850 214 return rrow;
215}
216
217int AliHLTTPCDigitReaderUnpacked::GetPad(){
5df0cbb9 218 // see header file for class documentation
a38a7850 219 int rpad;
deba5d85 220 if(fUnsorted == kFALSE){
221 rpad = GetSortedPad();
222 }
223 else{
224 rpad = fPrevPad;
225 }
a38a7850 226 return rpad ;
227}
228
229int AliHLTTPCDigitReaderUnpacked::GetSignal(){
5df0cbb9 230 // see header file for class documentation
a38a7850 231 int rsignal;
deba5d85 232 if(fUnsorted == kFALSE){
233 rsignal = GetSortedSignal();
234 }
235 else{
236 rsignal = fPrevSignal;
237 }
a38a7850 238 return rsignal;
239}
240
241int AliHLTTPCDigitReaderUnpacked::GetTime(){
deba5d85 242 // see header file for class documentation
243 int rtime;
244 if(fUnsorted==kFALSE){
245 rtime = GetSortedTime();
246 }
247 else{
248 rtime = fPrevTime+1-fDataBunch.size();
249 }
250 return rtime;
251}
252
253AliHLTUInt32_t AliHLTTPCDigitReaderUnpacked::GetAltroBlockHWaddr() const
254{
255 // see header file for class documentation
256 return (AliHLTUInt32_t)(fMapping->GetHwAddress((UInt_t)GetSortedRow(),(UInt_t)GetSortedPad()));//fTPCRawStream->GetHWAddress();
257}
258
259Int_t AliHLTTPCDigitReaderUnpacked::GetSortedTime(){
5df0cbb9 260 // see header file for class documentation
67fada6b 261 assert(fData);
f44e97dc 262 if (!fData) return -1;
a38a7850 263 int rtime;
264 rtime = (int)fData[fBin].fTime;
deba5d85 265 if(fDataBunch.size()>1){
266 fEndTimeBinOfBunch=rtime;
267 }
a38a7850 268 return rtime;
269}
deba5d85 270
271Int_t AliHLTTPCDigitReaderUnpacked::GetSortedSignal(){
272 // see header file for class documentation
273 assert(fData);
274 if (!fData) return -1;
275 int rsignal;
276 rsignal = (int)fData[fBin].fCharge;
277 return rsignal;
278
279}
280
281Int_t AliHLTTPCDigitReaderUnpacked::GetSortedPad() const{
282 // see header file for class documentation
283 assert(fData);
284 if (!fData) return -1;
285 int rpad;
286 rpad = (int)fData[fBin].fPad;
287 return rpad ;
288}
289
290int AliHLTTPCDigitReaderUnpacked::GetSortedRow() const {
291 // see header file for class documentation
292 int rrow;
293 rrow = fRow-AliHLTTPCTransform::GetFirstRow(fPatch);
294 if(fPatch>1){
295 rrow += AliHLTTPCTransform::GetFirstRow(2);
296 }
297 return rrow;
298}
299
300bool AliHLTTPCDigitReaderUnpacked::NextChannel()
301{
302 // see header file for class documentation
303
304 // If the next channel is already confirmed by the next bunch function
305 // or there are more signals (this will only be for the first signal)
306
307 if(fEndOfDataReached == kTRUE){
308 return false;
309 }
310 if(fNextChannelIsAlreadyConfirmed){
311 fNextChannelIsAlreadyConfirmed = kFALSE;
312 fPrevTime=GetSortedTime();
313 fPrevSignal=GetSortedSignal();
314 fPrevPad = GetSortedPad();
315 fPrevRow = GetSortedRow();
316 return true;
317 }
318 else if(NextSignal()) { // there is data
319 return true;
320 }
321 return false;
322}
323
324int AliHLTTPCDigitReaderUnpacked::NextBunch()
325{
326 // see header file for class documentation
327
328 if(fEndOfDataReached == kTRUE || fEndOfChannelReached == kTRUE){
329 // sets fEndOfChannelReached back to false, for the next channel
330 // and returns 0 to tell stop the NextBunch calls for this channel.
331 fEndOfChannelReached=kFALSE;
332 return 0;
333 }
334
335
336 fDataBunch.clear();
337 fDigitsVector.clear();
338
339 //adding the first signal (will always be the leftover from either NextChannel call or previous bunch)
340 fPrevTime=GetSortedTime();
341 fPrevSignal=GetSortedSignal();
342 fPrevPad = GetSortedPad();
343 fPrevRow = GetSortedRow();
344 fDataBunch.push_back(GetSortedSignal());
345 fDigitsVector.push_back(fData[fBin]);
346
347 do{
348 if(NextSignal()){
349 if((fPrevPad == GetSortedPad()) && (fPrevRow == GetSortedRow())){//check if there is a change in channel(new pad or row)
350 if(fPrevTime+1 == GetSortedTime()){//if true means that we have consecutive signals
351 fPrevTime = GetSortedTime();
352 //fDataBunch.insert(fDataBunch.begin(), GetSortedSignal());// add the signal to the beginning of the buffer
353 fDataBunch.push_back(GetSortedSignal());// add the signal to the beginning of the buffer
354 fDigitsVector.push_back(fData[fBin]);
355 }
356 else{//end of bunch but not of channel
357 break;
358 }
359 }
360 else{
361 // end of channel, last bunch will be completed
362 fEndOfChannelReached = kTRUE;
363 // the next channel is already confirmed since the next channel returned true
364 fNextChannelIsAlreadyConfirmed = kTRUE;
365 break;
366 }
367 }
368 else{
369 // end of data, but there is one bunch to be completed.
370 fEndOfDataReached = kTRUE;
371 break;
372 }
373 }while(1);
374
375 return fDataBunch.size();
376}
377
378int AliHLTTPCDigitReaderUnpacked::GetBunchSize(){
379 // see header file for class documentation
380 return fDataBunch.size();
381}
382
383const UInt_t* AliHLTTPCDigitReaderUnpacked::GetSignals()
384{
385 // see header file for class documentation
386 return &fDataBunch[0];
387}
388
389const AliHLTTPCDigitData* AliHLTTPCDigitReaderUnpacked::GetBunchDigits()
390{
391 // see header file for class documentation
392 return &fDigitsVector[0];
393}
394int AliHLTTPCDigitReaderUnpacked::GetRowOffset() const
395{
396 // see header file for class documentation
397 return AliHLTTPCTransform::GetFirstRow(fPatch);
398}