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 AliHLTTPCDigitReaderPacked.cxx
22 @author Timm Steinbeck, Jochen Thaeder, Matthias Richter, Kenneth Aamodt
24 @brief A digit reader implementation for simulated, packed TPC 'raw' data.
31 #include "AliHLTTPCDigitReaderPacked.h"
33 #include "AliTPCRawStream.h"
34 #include "AliRawReaderMemory.h"
35 #include "AliRawDataHeader.h"
37 //#if ENABLE_PAD_SORTING
38 #include "AliHLTTPCTransform.h"
39 //#endif // ENABLE_PAD_SORTING
40 #include "AliHLTStdIncludes.h"
42 ClassImp(AliHLTTPCDigitReaderPacked)
44 AliHLTTPCDigitReaderPacked::AliHLTTPCDigitReaderPacked()
46 fRawMemoryReader(NULL),
48 //#if ENABLE_PAD_SORTING
58 //#endif // ENABLE_PAD_SORTING
61 fRawMemoryReader = new AliRawReaderMemory;
63 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
65 //#if ENABLE_PAD_SORTING
66 // get max number of rows
67 for (Int_t ii=0; ii < 6; ii++)
68 if (AliHLTTPCTransform::GetNRows(ii) > fNMaxRows)
69 fNMaxRows = AliHLTTPCTransform::GetNRows(ii);
71 // get max number of pads
72 for (Int_t ii=0; ii < AliHLTTPCTransform::GetNRows();ii++ )
73 if (AliHLTTPCTransform::GetNPads(ii) > fNMaxPads)
74 fNMaxPads = AliHLTTPCTransform::GetNPads(ii);
76 // get max number of bins
77 fNTimeBins = AliHLTTPCTransform::GetNTimeBins();
79 HLTDebug("Array Borders ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d",
80 fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads);
83 fData = new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
84 //#endif // ENABLE_PAD_SORTING
87 AliHLTTPCDigitReaderPacked::~AliHLTTPCDigitReaderPacked(){
88 if ( fRawMemoryReader )
89 delete fRawMemoryReader;
90 fRawMemoryReader = NULL;
94 //#if ENABLE_PAD_SORTING
98 //#endif // ENABLE_PAD_SORTING
101 Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch, Int_t slice)
104 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( ptr ), size );
106 //get DDL ID in order to tell the memory reader which slice/patch to use
109 DDLid = 768 + 2*slice + patch;
111 DDLid = 840 + 4*slice + patch-2;
113 fRawMemoryReader->SetEquipmentID(DDLid);
114 //fRawMemoryReader->SetEquipmentID(1);
115 fRawMemoryReader->RewindEvents();
116 fRawMemoryReader->NextEvent();
119 //#if ENABLE_PAD_SORTING
125 Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch);
126 Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch);
127 fNRows = lastrow - firstrow + 1;
130 if (patch > 1) offset = AliHLTTPCTransform::GetFirstRow( 2 );
132 fRowOffset = firstrow - offset;
136 // Init array with -1
137 memset( fData, 0xFF, sizeof(Int_t)*(fNMaxRows*fNMaxPads*fNTimeBins) );
139 // read data and fill in array
140 while( fTPCRawStream->Next()){
142 Int_t row = fTPCRawStream->GetRow();
143 Int_t pad = fTPCRawStream->GetPad();
144 Int_t bin = fTPCRawStream->GetTime();
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);
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);
161 fData[ (row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin ] = fTPCRawStream->GetSignal() ;
165 //#endif // ENABLE_PAD_SORTING
170 Bool_t AliHLTTPCDigitReaderPacked::NextSignal(){
171 Bool_t readvalue = kTRUE;
173 if(!fUnsorted){//added for test
174 //#if ENABLE_PAD_SORTING
177 if (fCurrentBin >= fNTimeBins){
181 if (fCurrentPad >=fNMaxPads){
185 if (fCurrentRow >= fNMaxRows){
192 if (fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
193 HLTFatal("Overflow: row=%d pad=%d bin=%d", fCurrentRow, fCurrentPad, fCurrentBin);
198 if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin ] != -1) break;
201 else{//added for test
202 //#else // !ENABLE_PAD_SORTING
203 readvalue = fTPCRawStream->Next();
205 //#endif // ENABLE_PAD_SORTING
210 Int_t AliHLTTPCDigitReaderPacked::GetRow(){
211 /*#if ENABLE_PAD_SORTING
212 return (fCurrentRow + fRowOffset);
213 #else // !ENABLE_PAD_SORTING
214 return (Int_t) fTPCRawStream->GetRow();
215 #endif // ENABLE_PAD_SORTING
218 return (fCurrentRow + fRowOffset);
221 return (Int_t) fTPCRawStream->GetRow();
225 int AliHLTTPCDigitReaderPacked::GetPad(){
226 /*#if ENABLE_PAD_SORTING
228 #else // !ENABLE_PAD_SORTING
229 return fTPCRawStream->GetPad();
230 #endif // ENABLE_PAD_SORTING
236 return fTPCRawStream->GetPad();
240 AliHLTUInt32_t AliHLTTPCDigitReaderPacked::GetAltroBlockHWaddr() const
242 return fTPCRawStream->GetHWAddress();
245 Int_t AliHLTTPCDigitReaderPacked::GetSignal(){
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
254 return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
257 return fTPCRawStream->GetSignal();
261 Int_t AliHLTTPCDigitReaderPacked::GetTime(){
263 #if ENABLE_PAD_SORTING
265 #else // !ENABLE_PAD_SORTING
266 return fTPCRawStream->GetTime();
267 #endif // ENABLE_PAD_SORTING
273 return fTPCRawStream->GetTime();