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 //#if ENABLE_PAD_SORTING
56 //#endif // ENABLE_PAD_SORTING
57 fRawMemoryReader(NULL),
59 fOldRCUFormat(kFALSE),
62 fRawMemoryReader = new AliRawReaderMemory;
64 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
66 //#if ENABLE_PAD_SORTING
67 // get max number of rows
68 for (Int_t ii=0; ii < 6; ii++)
69 if (AliHLTTPCTransform::GetNRows(ii) > fNMaxRows)
70 fNMaxRows = AliHLTTPCTransform::GetNRows(ii);
72 // get max number of pads
73 for (Int_t ii=0; ii < AliHLTTPCTransform::GetNRows();ii++ )
74 if (AliHLTTPCTransform::GetNPads(ii) > fNMaxPads)
75 fNMaxPads = AliHLTTPCTransform::GetNPads(ii);
77 // get max number of bins
78 fNTimeBins = AliHLTTPCTransform::GetNTimeBins();
80 HLTDebug("Array Borders ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d",
81 fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads);
84 fData = new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
85 //#endif // ENABLE_PAD_SORTING
88 AliHLTTPCDigitReaderPacked::~AliHLTTPCDigitReaderPacked(){
89 if ( fRawMemoryReader )
90 delete fRawMemoryReader;
91 fRawMemoryReader = NULL;
95 //#if ENABLE_PAD_SORTING
99 //#endif // ENABLE_PAD_SORTING
102 Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,ULong_t size, Int_t patch, Int_t slice)
105 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( ptr ), size );
107 //get DDL ID in order to tell the memory reader which slice/patch to use
110 DDLid = 768 + 2*slice + patch;
112 DDLid = 840 + 4*slice + patch-2;
114 fRawMemoryReader->SetEquipmentID(DDLid);
115 //fRawMemoryReader->SetEquipmentID(1);
117 fTPCRawStream->SetOldRCUFormat(kTRUE);
118 HLTInfo("set old RCU format (1 trailer word: 40bit payload)");
120 fRawMemoryReader->RewindEvents();
121 fRawMemoryReader->NextEvent();
124 //#if ENABLE_PAD_SORTING
130 Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch);
131 Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch);
132 fNRows = lastrow - firstrow + 1;
135 if (patch > 1) offset = AliHLTTPCTransform::GetFirstRow( 2 );
137 fRowOffset = firstrow - offset;
141 // Init array with -1
142 memset( fData, 0xFF, sizeof(Int_t)*(fNMaxRows*fNMaxPads*fNTimeBins) );
144 // read data and fill in array
145 while( fTPCRawStream->Next()){
147 Int_t row = fTPCRawStream->GetRow();
148 Int_t pad = fTPCRawStream->GetPad();
149 Int_t bin = fTPCRawStream->GetTime();
151 if ( row < firstrow || row > lastrow || pad > AliHLTTPCTransform::GetNPads(row + offset) || bin > fNTimeBins){
152 HLTFatal("Index out of Range Probably wrong patch! %d - %d", slice, patch);
153 if ( row < firstrow || row > lastrow )
154 HLTFatal("Row out of Range %d < %d < %d",firstrow, row, lastrow);
155 if ( pad > AliHLTTPCTransform::GetNPads(row + offset) )
156 HLTFatal("Pad out of Range %d < %d < %d",pad, AliHLTTPCTransform::GetNPads(row + offset));
157 if ( bin > fNTimeBins )
158 HLTFatal("Bin out of Range %d < %d < %d",bin, fNTimeBins);
161 if ((row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
162 HLTFatal("Index out of array range PAD=%d ||| ROW=%d ||| BIN=%d ||| OFFSET=%d ||| ROWOFFSET=%d", pad, row, bin, offset, fRowOffset);
166 fData[ (row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin ] = fTPCRawStream->GetSignal() ;
170 //#endif // ENABLE_PAD_SORTING
175 Bool_t AliHLTTPCDigitReaderPacked::NextSignal(){
176 Bool_t readvalue = kTRUE;
178 if(!fUnsorted){//added for test
179 //#if ENABLE_PAD_SORTING
182 if (fCurrentBin >= fNTimeBins){
186 if (fCurrentPad >=fNMaxPads){
190 if (fCurrentRow >= fNMaxRows){
197 if (fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
198 HLTFatal("Overflow: row=%d pad=%d bin=%d", fCurrentRow, fCurrentPad, fCurrentBin);
203 if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin ] != -1) break;
206 else{//added for test
207 //#else // !ENABLE_PAD_SORTING
208 readvalue = fTPCRawStream->Next();
210 //#endif // ENABLE_PAD_SORTING
215 Int_t AliHLTTPCDigitReaderPacked::GetRow(){
216 /*#if ENABLE_PAD_SORTING
217 return (fCurrentRow + fRowOffset);
218 #else // !ENABLE_PAD_SORTING
219 return (Int_t) fTPCRawStream->GetRow();
220 #endif // ENABLE_PAD_SORTING
223 return (fCurrentRow + fRowOffset);
226 return (Int_t) fTPCRawStream->GetRow();
230 int AliHLTTPCDigitReaderPacked::GetPad(){
231 /*#if ENABLE_PAD_SORTING
233 #else // !ENABLE_PAD_SORTING
234 return fTPCRawStream->GetPad();
235 #endif // ENABLE_PAD_SORTING
241 return fTPCRawStream->GetPad();
245 AliHLTUInt32_t AliHLTTPCDigitReaderPacked::GetAltroBlockHWaddr() const
247 return fTPCRawStream->GetHWAddress();
250 Int_t AliHLTTPCDigitReaderPacked::GetSignal(){
252 #if ENABLE_PAD_SORTING
253 return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
254 #else // !ENABLE_PAD_SORTING
255 return fTPCRawStream->GetSignal();
256 #endif // ENABLE_PAD_SORTING
259 return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
262 return fTPCRawStream->GetSignal();
266 Int_t AliHLTTPCDigitReaderPacked::GetTime(){
268 #if ENABLE_PAD_SORTING
270 #else // !ENABLE_PAD_SORTING
271 return fTPCRawStream->GetTime();
272 #endif // ENABLE_PAD_SORTING
278 return fTPCRawStream->GetTime();