3 //*************************************************************************
4 // This file is property of and copyright by the ALICE HLT Project *
5 // ALICE Experiment at CERN, All rights reserved. *
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. *
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 //*************************************************************************/
21 /** @file AliHLTTPCDigitReaderUnpacked.cxx
22 @author Timm Steinbeck, Jochen Thaeder, Matthias Richter
24 @brief A digit reader implementation for unpacked TPC data.
32 #include "AliHLTTPCDigitReaderUnpacked.h"
33 #include "AliHLTTPCDigitData.h"
34 #include "AliHLTTPCTransform.h"
35 #include "AliHLTStdIncludes.h"
36 #include "AliHLTTPCMapping.h"
38 ClassImp(AliHLTTPCDigitReaderUnpacked)
40 AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked()
55 fEndOfDataReached(kFALSE),
56 fEndOfChannelReached(kFALSE),
58 fEndTimeBinOfBunch(0),
62 fNextChannelIsAlreadyConfirmed(kFALSE),
67 // see header file for class documentation
69 // refer to README to build package
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
74 AliHLTTPCDigitReaderUnpacked::~AliHLTTPCDigitReaderUnpacked(){
75 // see header file for class documentation
82 int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
83 // see header file for class documentation
85 AliHLTTPCUnpackedRawData *tmpptr=NULL;
90 fEndOfDataReached=kFALSE;
91 fEndOfChannelReached=kFALSE;
97 fNextChannelIsAlreadyConfirmed=kFALSE;
98 fDigitsVector.clear();
100 tmpptr = reinterpret_cast<AliHLTTPCUnpackedRawData*>(fPtr);
101 fDigitRowData = (AliHLTTPCDigitRowData*) tmpptr->fDigits;
102 fActRowData = fDigitRowData;
105 fMapping = new AliHLTTPCMapping(patch);
108 while (fActRowData && ((iResult=GetNextRowData(fActRowData))>=0)) {/* empty body */};
111 fActRowData = fDigitRowData;
115 AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetFirstRow(patch), dummy, fFirstRow);
116 AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetLastRow(patch), dummy, fLastRow);
120 if ((Int_t)fActRowData->fRow != fRow){
121 HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
129 int AliHLTTPCDigitReaderUnpacked::GetNextRowData(AliHLTTPCDigitRowData*& pRow) const
131 // get new row data from the current row data
133 AliHLTTPCDigitRowData* pCurrent=pRow;
136 Byte_t *tmp = (Byte_t*) pCurrent;
137 Int_t size = sizeof(AliHLTTPCDigitRowData) + pCurrent->fNDigit*sizeof(AliHLTTPCDigitData);
139 pRow = reinterpret_cast<AliHLTTPCDigitRowData*>(tmp);
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);
150 // check if the current row structure has the right format
151 size = sizeof(AliHLTTPCDigitRowData) + pRow->fNDigit*sizeof(AliHLTTPCDigitData);
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);
163 bool AliHLTTPCDigitReaderUnpacked::NextSignal(){
164 // see header file for class documentation
165 if (fActRowData==NULL) return false;
167 bool rreadvalue = true;
171 if ( fBin >= (Int_t)fActRowData->fNDigit ){
173 if ((fRow >= fFirstRow) && (fRow <= fLastRow)){
176 if (GetNextRowData(fActRowData)<0) {
190 if ((Int_t)fActRowData->fRow != fRow){
191 HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
195 fData = fActRowData->fDigitData;
200 int AliHLTTPCDigitReaderUnpacked::GetRow(){
201 // see header file for class documentation
204 if(fUnsorted == kFALSE){
208 rrow = fRow-AliHLTTPCTransform::GetFirstRow(fPatch);
210 rrow += AliHLTTPCTransform::GetFirstRow(2);
217 int AliHLTTPCDigitReaderUnpacked::GetPad(){
218 // see header file for class documentation
220 if(fUnsorted == kFALSE){
221 rpad = GetSortedPad();
229 int AliHLTTPCDigitReaderUnpacked::GetSignal(){
230 // see header file for class documentation
232 if(fUnsorted == kFALSE){
233 rsignal = GetSortedSignal();
236 rsignal = fPrevSignal;
241 int AliHLTTPCDigitReaderUnpacked::GetTime(){
242 // see header file for class documentation
244 if(fUnsorted==kFALSE){
245 rtime = GetSortedTime();
248 rtime = fPrevTime+1-fDataBunch.size();
253 AliHLTUInt32_t AliHLTTPCDigitReaderUnpacked::GetAltroBlockHWaddr() const
255 // see header file for class documentation
256 return (AliHLTUInt32_t)(fMapping->GetHwAddress((UInt_t)GetSortedRow(),(UInt_t)GetSortedPad()));//fTPCRawStream->GetHWAddress();
259 Int_t AliHLTTPCDigitReaderUnpacked::GetSortedTime(){
260 // see header file for class documentation
262 if (!fData) return -1;
264 rtime = (int)fData[fBin].fTime;
265 if(fDataBunch.size()>1){
266 fEndTimeBinOfBunch=rtime;
271 Int_t AliHLTTPCDigitReaderUnpacked::GetSortedSignal(){
272 // see header file for class documentation
274 if (!fData) return -1;
276 rsignal = (int)fData[fBin].fCharge;
281 Int_t AliHLTTPCDigitReaderUnpacked::GetSortedPad() const{
282 // see header file for class documentation
284 if (!fData) return -1;
286 rpad = (int)fData[fBin].fPad;
290 int AliHLTTPCDigitReaderUnpacked::GetSortedRow() const {
291 // see header file for class documentation
293 rrow = fRow-AliHLTTPCTransform::GetFirstRow(fPatch);
295 rrow += AliHLTTPCTransform::GetFirstRow(2);
300 bool AliHLTTPCDigitReaderUnpacked::NextChannel()
302 // see header file for class documentation
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)
307 if(fEndOfDataReached == kTRUE){
310 if(fNextChannelIsAlreadyConfirmed){
311 fNextChannelIsAlreadyConfirmed = kFALSE;
312 fPrevTime=GetSortedTime();
313 fPrevSignal=GetSortedSignal();
314 fPrevPad = GetSortedPad();
315 fPrevRow = GetSortedRow();
318 else if(NextSignal()) { // there is data
324 int AliHLTTPCDigitReaderUnpacked::NextBunch()
326 // see header file for class documentation
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;
337 fDigitsVector.clear();
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]);
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]);
356 else{//end of bunch but not of channel
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;
369 // end of data, but there is one bunch to be completed.
370 fEndOfDataReached = kTRUE;
375 return fDataBunch.size();
378 int AliHLTTPCDigitReaderUnpacked::GetBunchSize(){
379 // see header file for class documentation
380 return fDataBunch.size();
383 const UInt_t* AliHLTTPCDigitReaderUnpacked::GetSignals()
385 // see header file for class documentation
386 return &fDataBunch[0];
389 const AliHLTTPCDigitData* AliHLTTPCDigitReaderUnpacked::GetBunchDigits()
391 // see header file for class documentation
392 return &fDigitsVector[0];
394 int AliHLTTPCDigitReaderUnpacked::GetRowOffset() const
396 // see header file for class documentation
397 return AliHLTTPCTransform::GetFirstRow(fPatch);