]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCDigitReaderUnpacked.cxx
adding AliHLTAltroGenerator including unit test for simulation of Altro data and...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderUnpacked.cxx
1 // $Id$
2
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 //*************************************************************************/
20
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 */
26
27 #if __GNUC__== 3
28 using namespace std;
29 #endif
30
31 #include <cassert>
32 #include "AliHLTTPCDigitReaderUnpacked.h"
33 #include "AliHLTTPCDigitData.h"
34 #include "AliHLTTPCTransform.h"
35 #include "AliHLTStdIncludes.h"
36
37 ClassImp(AliHLTTPCDigitReaderUnpacked)
38
39 AliHLTTPCDigitReaderUnpacked::AliHLTTPCDigitReaderUnpacked()
40   :
41   fDigitRowData(NULL),
42   fActRowData(NULL),
43   fData(NULL),
44   fPtr(NULL),
45   fSize(0),
46   fBin(0),
47   fRow(0),
48   fFirstRow(0),
49   fLastRow(0)
50 {
51   // see header file for class documentation
52   // or
53   // refer to README to build package
54   // or
55   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 }
57
58 AliHLTTPCDigitReaderUnpacked::~AliHLTTPCDigitReaderUnpacked(){
59   // see header file for class documentation
60 }
61
62 int AliHLTTPCDigitReaderUnpacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
63   // see header file for class documentation
64   int iResult=0;
65   AliHLTTPCUnpackedRawData *tmpptr=NULL;
66   fPtr = ptr;
67   fSize = size;
68
69   tmpptr = reinterpret_cast<AliHLTTPCUnpackedRawData*>(fPtr);
70   fDigitRowData = (AliHLTTPCDigitRowData*) tmpptr->fDigits;
71   fActRowData = fDigitRowData;
72
73   while (fActRowData && ((iResult=GetNextRowData(fActRowData))>=0));
74
75   if (iResult>=0) {
76   fActRowData = fDigitRowData;
77   fBin = -1;
78
79   int dummy=0;
80   AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetFirstRow(patch), dummy, fFirstRow);
81   AliHLTTPCTransform::Slice2Sector(slice, AliHLTTPCTransform::GetLastRow(patch), dummy, fLastRow);
82
83   fRow = fFirstRow; 
84
85   if ((Int_t)fActRowData->fRow != fRow){
86       HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
87   }
88   } else {
89     fActRowData=NULL;
90   }
91   return iResult;
92 }
93
94 int AliHLTTPCDigitReaderUnpacked::GetNextRowData(AliHLTTPCDigitRowData*& pRow) const
95 {
96   // get new row data from the current row data
97   int iResult=0;
98   AliHLTTPCDigitRowData* pCurrent=pRow;
99   assert(pCurrent);
100   pRow=NULL;
101   Byte_t *tmp = (Byte_t*) pCurrent;
102   Int_t size = sizeof(AliHLTTPCDigitRowData) + pCurrent->fNDigit*sizeof(AliHLTTPCDigitData);
103   tmp += size;
104   pRow = reinterpret_cast<AliHLTTPCDigitRowData*>(tmp);
105   
106   // check if the new pointer is within the range
107   if (((Byte_t*)fPtr) + fSize <= tmp){
108     if (((Byte_t*)fPtr) + fSize < tmp) {
109       // if the increment does not match exactly there is a format error
110       HLTError("input format not recognized: buffer %p %d, current row data %p, %d digits", fPtr, fSize, pCurrent, pCurrent->fNDigit);
111       iResult=-EBADF;
112     }
113     pRow=NULL;
114   } else {
115     // check if the current row structure has the right format
116     size = sizeof(AliHLTTPCDigitRowData) + pRow->fNDigit*sizeof(AliHLTTPCDigitData);
117     tmp += size;
118     if (((Byte_t*)fPtr) + fSize < tmp){
119       HLTError("Current row data not recognized %p (buffer %p %d) %d digits", pRow, fPtr, fSize, pRow->fNDigit);
120       pRow=NULL;
121       iResult=-EBADF;
122     }
123   }
124     
125   return iResult;
126 }
127
128 bool AliHLTTPCDigitReaderUnpacked::NextSignal(){
129   // see header file for class documentation
130   if (fActRowData==NULL) return false;
131
132   bool rreadvalue = true;
133
134   fBin++;
135
136   if ( fBin >= (Int_t)fActRowData->fNDigit ){
137     fRow++;
138     if ((fRow >= fFirstRow) && (fRow <= fLastRow)){
139
140       //new row 
141       if (GetNextRowData(fActRowData)<0) {
142         rreadvalue = false;
143         return rreadvalue;
144       }
145
146       fBin = 0;
147     }
148     else {
149       rreadvalue = false;
150       return rreadvalue;
151     }
152   if(!fActRowData){
153     return false;
154   }
155     if ((Int_t)fActRowData->fRow != fRow){
156       HLTWarning("Row number should match! fActRowData->fRow=%d fRow=%d", fActRowData->fRow, fRow);
157     }
158   }
159
160   fData = fActRowData->fDigitData;
161  
162   return rreadvalue;
163 }
164
165 int AliHLTTPCDigitReaderUnpacked::GetRow(){
166   // see header file for class documentation
167   int rrow;
168   rrow = fRow;
169   return rrow;
170 }
171
172 int AliHLTTPCDigitReaderUnpacked::GetPad(){
173   // see header file for class documentation
174   assert(fData);
175   if (!fData) return -1;
176   int rpad;
177   rpad = (int)fData[fBin].fPad;
178   return rpad   ;
179 }
180
181 int AliHLTTPCDigitReaderUnpacked::GetSignal(){ 
182   // see header file for class documentation
183   assert(fData);
184   if (!fData) return -1;
185   int rsignal;
186   rsignal = (int)fData[fBin].fCharge;
187   return rsignal;
188 }
189
190 int AliHLTTPCDigitReaderUnpacked::GetTime(){
191   // see header file for class documentation
192   assert(fData);
193   if (!fData) return -1;
194   int rtime;
195   rtime = (int)fData[fBin].fTime;
196   return rtime;
197 }