]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCDigitReaderPacked.cxx
First step towards reading of the new RCU firmware trailer. Thanks to Luciano we...
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCDigitReaderPacked.cxx
CommitLineData
a38a7850 1// $Id$
2
e962f438 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 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 28using 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
42ClassImp(AliHLTTPCDigitReaderPacked)
43
84645eb0 44AliHLTTPCDigitReaderPacked::AliHLTTPCDigitReaderPacked()
45 :
13398559 46 fRawMemoryReader(NULL),
47 fTPCRawStream(NULL),
aff6e981 48 //#if ENABLE_PAD_SORTING
84645eb0 49 fCurrentRow(0),
50 fCurrentPad(0),
51 fCurrentBin(-1),
84645eb0 52 fRowOffset(0),
13398559 53 fNRows(0),
84645eb0 54 fNMaxRows(0),
55 fNMaxPads(0),
56 fNTimeBins(0),
57 fData(NULL),
aff6e981 58 //#endif // ENABLE_PAD_SORTING
aff6e981 59 fUnsorted(kFALSE)
84645eb0 60{
a38a7850 61 fRawMemoryReader = new AliRawReaderMemory;
db16520a 62
a38a7850 63 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
db16520a 64
aff6e981 65 //#if ENABLE_PAD_SORTING
db16520a 66 // get max number of rows
db16520a 67 for (Int_t ii=0; ii < 6; ii++)
68 if (AliHLTTPCTransform::GetNRows(ii) > fNMaxRows)
69 fNMaxRows = AliHLTTPCTransform::GetNRows(ii);
70
71 // get max number of pads
db16520a 72 for (Int_t ii=0; ii < AliHLTTPCTransform::GetNRows();ii++ )
73 if (AliHLTTPCTransform::GetNPads(ii) > fNMaxPads)
74 fNMaxPads = AliHLTTPCTransform::GetNPads(ii);
75
76 // get max number of bins
77 fNTimeBins = AliHLTTPCTransform::GetNTimeBins();
78
84645eb0 79 HLTDebug("Array Borders ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d",
db16520a 80 fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads);
81
82 // init Data array
83 fData = new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
aff6e981 84 //#endif // ENABLE_PAD_SORTING
a38a7850 85}
86
87AliHLTTPCDigitReaderPacked::~AliHLTTPCDigitReaderPacked(){
88 if ( fRawMemoryReader )
89 delete fRawMemoryReader;
90 fRawMemoryReader = NULL;
91 if ( fTPCRawStream )
db16520a 92 delete fTPCRawStream;
a38a7850 93 fTPCRawStream = NULL;
aff6e981 94 //#if ENABLE_PAD_SORTING
db16520a 95 if ( fData )
96 delete [] fData;
97 fData = NULL;
aff6e981 98 //#endif // ENABLE_PAD_SORTING
a38a7850 99}
100
e962f438 101Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch, Int_t slice)
102{
db16520a 103
a38a7850 104 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( ptr ), size );
db16520a 105
106 //get DDL ID in order to tell the memory reader which slice/patch to use
107 Int_t DDLid= 0;
108 if (patch < 2)
27f5f8ed 109 DDLid = 768 + 2*slice + patch;
db16520a 110 else
9f968107 111 DDLid = 840 + 4*slice + patch-2;
db16520a 112
27f5f8ed 113 fRawMemoryReader->SetEquipmentID(DDLid);
114 //fRawMemoryReader->SetEquipmentID(1);
70d0b23e 115 fRawMemoryReader->RewindEvents();
116 fRawMemoryReader->NextEvent();
db16520a 117
aff6e981 118 if(!fUnsorted){
119 //#if ENABLE_PAD_SORTING
db16520a 120
121 fCurrentRow = 0;
122 fCurrentPad = 0;
123 fCurrentBin = -1;
124
84645eb0 125 Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch);
126 Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch);
db16520a 127 fNRows = lastrow - firstrow + 1;
128
129 Int_t offset=0;
130 if (patch > 1) offset = AliHLTTPCTransform::GetFirstRow( 2 );
131
132 fRowOffset = firstrow - offset;
133 firstrow -= offset;
134 lastrow -= offset;
135
136 // Init array with -1
137 memset( fData, 0xFF, sizeof(Int_t)*(fNMaxRows*fNMaxPads*fNTimeBins) );
138
139 // read data and fill in array
140 while( fTPCRawStream->Next()){
141
142 Int_t row = fTPCRawStream->GetRow();
143 Int_t pad = fTPCRawStream->GetPad();
144 Int_t bin = fTPCRawStream->GetTime();
145
146 if ( row < firstrow || row > lastrow || pad > AliHLTTPCTransform::GetNPads(row + offset) || bin > fNTimeBins){
147 HLTFatal("Index out of Range Probably wrong patch! %d - %d", slice, patch);
148 if ( row < firstrow || row > lastrow )
149 HLTFatal("Row out of Range %d < %d < %d",firstrow, row, lastrow);
150 if ( pad > AliHLTTPCTransform::GetNPads(row + offset) )
151 HLTFatal("Pad out of Range %d < %d < %d",pad, AliHLTTPCTransform::GetNPads(row + offset));
152 if ( bin > fNTimeBins )
153 HLTFatal("Bin out of Range %d < %d < %d",bin, fNTimeBins);
154 }
155 else {
156 if ((row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
157 HLTFatal("Index out of array range PAD=%d ||| ROW=%d ||| BIN=%d ||| OFFSET=%d ||| ROWOFFSET=%d", pad, row, bin, offset, fRowOffset);
158 continue;
159 }
160 else {
161 fData[ (row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin ] = fTPCRawStream->GetSignal() ;
162 }
163 }
164 }
aff6e981 165 //#endif // ENABLE_PAD_SORTING
166 }
a38a7850 167 return 0;
168}
169
f44e97dc 170Bool_t AliHLTTPCDigitReaderPacked::NextSignal(){
db16520a 171 Bool_t readvalue = kTRUE;
172
aff6e981 173 if(!fUnsorted){//added for test
174 //#if ENABLE_PAD_SORTING
175 while (1) {
db16520a 176 fCurrentBin++;
177 if (fCurrentBin >= fNTimeBins){
178 fCurrentBin = 0;
179 fCurrentPad++;
180
181 if (fCurrentPad >=fNMaxPads){
182 fCurrentPad = 0;
183 fCurrentRow++;
184
185 if (fCurrentRow >= fNMaxRows){
186 readvalue = kFALSE;
187 break;
188 }
189 }
190 }
191
192 if (fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
193 HLTFatal("Overflow: row=%d pad=%d bin=%d", fCurrentRow, fCurrentPad, fCurrentBin);
194 readvalue = kFALSE;
195 break;
196 }
197
198 if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin ] != -1) break;
aff6e981 199 }
200 }// added for test
201 else{//added for test
202 //#else // !ENABLE_PAD_SORTING
203 readvalue = fTPCRawStream->Next();
204 }//added for test
205 //#endif // ENABLE_PAD_SORTING
db16520a 206
207 return readvalue;
a38a7850 208}
209
db16520a 210Int_t AliHLTTPCDigitReaderPacked::GetRow(){
aff6e981 211 /*#if ENABLE_PAD_SORTING
db16520a 212 return (fCurrentRow + fRowOffset);
213#else // !ENABLE_PAD_SORTING
214 return (Int_t) fTPCRawStream->GetRow();
215#endif // ENABLE_PAD_SORTING
aff6e981 216 */
217 if(!fUnsorted){
218 return (fCurrentRow + fRowOffset);
219 }
220 else{
221 return (Int_t) fTPCRawStream->GetRow();
222 }
a38a7850 223}
224
225int AliHLTTPCDigitReaderPacked::GetPad(){
aff6e981 226 /*#if ENABLE_PAD_SORTING
227 return fCurrentPad;
228 #else // !ENABLE_PAD_SORTING
229 return fTPCRawStream->GetPad();
230 #endif // ENABLE_PAD_SORTING
231 */
232 if(!fUnsorted){
233 return fCurrentPad;
234 }
235 else{
236 return fTPCRawStream->GetPad();
237 }
a38a7850 238}
239
70d0b23e 240AliHLTUInt32_t AliHLTTPCDigitReaderPacked::GetAltroBlockHWaddr() const
241{
242 return fTPCRawStream->GetHWAddress();
243}
244
db16520a 245Int_t AliHLTTPCDigitReaderPacked::GetSignal(){
aff6e981 246 /*
247 #if ENABLE_PAD_SORTING
248 return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
249 #else // !ENABLE_PAD_SORTING
250 return fTPCRawStream->GetSignal();
251 #endif // ENABLE_PAD_SORTING
252 */
253 if(!fUnsorted){
254 return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
255 }
256 else{
257 return fTPCRawStream->GetSignal();
258 }
a38a7850 259}
260
db16520a 261Int_t AliHLTTPCDigitReaderPacked::GetTime(){
aff6e981 262 /*
263 #if ENABLE_PAD_SORTING
264 return fCurrentBin;
265 #else // !ENABLE_PAD_SORTING
266 return fTPCRawStream->GetTime();
267 #endif // ENABLE_PAD_SORTING
268 */
269 if(!fUnsorted){
270 return fCurrentBin;
271 }
272 else{
273 return fTPCRawStream->GetTime();
274 }
a38a7850 275}