3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
9 * for The ALICE Off-line Project. *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
20 /** @file AliHLTTPCDigitReaderPacked.cxx
21 @author Timm Steinbeck, Jochen Thaeder, Matthias Richter
23 @brief A digit reader implementation for simulated, packed TPC 'raw' data.
30 #if defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)
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),
60 fRawMemoryReader = new AliRawReaderMemory;
62 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
64 #if ENABLE_PAD_SORTING
65 // get max number of rows
66 for (Int_t ii=0; ii < 6; ii++)
67 if (AliHLTTPCTransform::GetNRows(ii) > fNMaxRows)
68 fNMaxRows = AliHLTTPCTransform::GetNRows(ii);
70 // get max number of pads
71 for (Int_t ii=0; ii < AliHLTTPCTransform::GetNRows();ii++ )
72 if (AliHLTTPCTransform::GetNPads(ii) > fNMaxPads)
73 fNMaxPads = AliHLTTPCTransform::GetNPads(ii);
75 // get max number of bins
76 fNTimeBins = AliHLTTPCTransform::GetNTimeBins();
78 HLTDebug("Array Borders ||| MAXPAD=%d ||| MAXROW=%d ||| MAXBIN=%d ||| MAXMUL=%d",
79 fNMaxPads, fNMaxRows, fNTimeBins, fNTimeBins*fNMaxRows*fNMaxPads);
82 fData = new Int_t[ fNMaxRows*fNMaxPads*fNTimeBins ];
83 #endif // ENABLE_PAD_SORTING
86 AliHLTTPCDigitReaderPacked::AliHLTTPCDigitReaderPacked(const AliHLTTPCDigitReaderPacked& src)
88 #if ENABLE_PAD_SORTING
98 #endif // ENABLE_PAD_SORTING
99 fRawMemoryReader(NULL),
102 HLTFatal("copy constructor not for use");
105 AliHLTTPCDigitReaderPacked& AliHLTTPCDigitReaderPacked::operator=(const AliHLTTPCDigitReaderPacked& src)
107 #if ENABLE_PAD_SORTING
117 #endif // ENABLE_PAD_SORTING
118 fRawMemoryReader=NULL;
120 HLTFatal("assignment operator not for use");
124 AliHLTTPCDigitReaderPacked::~AliHLTTPCDigitReaderPacked(){
125 if ( fRawMemoryReader )
126 delete fRawMemoryReader;
127 fRawMemoryReader = NULL;
129 delete fTPCRawStream;
130 fTPCRawStream = NULL;
131 #if ENABLE_PAD_SORTING
135 #endif // ENABLE_PAD_SORTING
138 Int_t AliHLTTPCDigitReaderPacked::InitBlock(void* ptr,unsigned long size, Int_t patch, Int_t slice){
140 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( ptr ), size );
142 //get DDL ID in order to tell the memory reader which slice/patch to use
145 DDLid = 2 *slice + patch;
147 DDLid = 70 + 4*slice + patch;
149 //fRawMemoryReader->SetEquipmentID(DDLid);
150 //fRawMemoryReader->SetEquipmentID(1);
152 // fTPCRawStream->SetOldRCUFormat(kTRUE);
154 #if ENABLE_PAD_SORTING
160 Int_t firstrow=AliHLTTPCTransform::GetFirstRow(patch);
161 Int_t lastrow=AliHLTTPCTransform::GetLastRow(patch);
162 fNRows = lastrow - firstrow + 1;
165 if (patch > 1) offset = AliHLTTPCTransform::GetFirstRow( 2 );
167 fRowOffset = firstrow - offset;
171 // Init array with -1
172 memset( fData, 0xFF, sizeof(Int_t)*(fNMaxRows*fNMaxPads*fNTimeBins) );
174 // read data and fill in array
175 while( fTPCRawStream->Next()){
177 Int_t row = fTPCRawStream->GetRow();
178 Int_t pad = fTPCRawStream->GetPad();
179 Int_t bin = fTPCRawStream->GetTime();
181 if ( row < firstrow || row > lastrow || pad > AliHLTTPCTransform::GetNPads(row + offset) || bin > fNTimeBins){
182 HLTFatal("Index out of Range Probably wrong patch! %d - %d", slice, patch);
183 if ( row < firstrow || row > lastrow )
184 HLTFatal("Row out of Range %d < %d < %d",firstrow, row, lastrow);
185 if ( pad > AliHLTTPCTransform::GetNPads(row + offset) )
186 HLTFatal("Pad out of Range %d < %d < %d",pad, AliHLTTPCTransform::GetNPads(row + offset));
187 if ( bin > fNTimeBins )
188 HLTFatal("Bin out of Range %d < %d < %d",bin, fNTimeBins);
191 if ((row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
192 HLTFatal("Index out of array range PAD=%d ||| ROW=%d ||| BIN=%d ||| OFFSET=%d ||| ROWOFFSET=%d", pad, row, bin, offset, fRowOffset);
196 fData[ (row-fRowOffset)*fNMaxPads*fNTimeBins+ pad*fNTimeBins + bin ] = fTPCRawStream->GetSignal() ;
200 #endif // ENABLE_PAD_SORTING
205 Bool_t AliHLTTPCDigitReaderPacked::Next(){
206 Bool_t readvalue = kTRUE;
208 #if ENABLE_PAD_SORTING
211 if (fCurrentBin >= fNTimeBins){
215 if (fCurrentPad >=fNMaxPads){
219 if (fCurrentRow >= fNMaxRows){
226 if (fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin >= fNMaxRows*fNMaxPads*fNTimeBins ) {
227 HLTFatal("Overflow: row=%d pad=%d bin=%d", fCurrentRow, fCurrentPad, fCurrentBin);
232 if (fData[ fCurrentRow*fNMaxPads*fNTimeBins + fCurrentPad*fNTimeBins + fCurrentBin ] != -1) break;
234 #else // !ENABLE_PAD_SORTING
235 readvalue = fTPCRawStream->Next();
236 #endif // ENABLE_PAD_SORTING
241 Int_t AliHLTTPCDigitReaderPacked::GetRow(){
242 #if ENABLE_PAD_SORTING
243 return (fCurrentRow + fRowOffset);
244 #else // !ENABLE_PAD_SORTING
245 return (Int_t) fTPCRawStream->GetRow();
246 #endif // ENABLE_PAD_SORTING
249 int AliHLTTPCDigitReaderPacked::GetPad(){
250 #if ENABLE_PAD_SORTING
252 #else // !ENABLE_PAD_SORTING
253 return fTPCRawStream->GetPad();
254 #endif // ENABLE_PAD_SORTING
257 Int_t AliHLTTPCDigitReaderPacked::GetSignal(){
258 #if ENABLE_PAD_SORTING
259 return fData[ fCurrentRow*fNMaxPads*fNTimeBins+ fCurrentPad*fNTimeBins + fCurrentBin ];
260 #else // !ENABLE_PAD_SORTING
261 return fTPCRawStream->GetSignal();
262 #endif // ENABLE_PAD_SORTING
265 Int_t AliHLTTPCDigitReaderPacked::GetTime(){
266 #if ENABLE_PAD_SORTING
268 #else // !ENABLE_PAD_SORTING
269 return fTPCRawStream->GetTime();
270 #endif // ENABLE_PAD_SORTING
272 #endif //defined(HAVE_ALIRAWDATA) && defined(HAVE_ALITPCRAWSTREAM_H)