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 * for The ALICE Off-line Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // a TPC cluster finder processing component for the HLT //
23 ///////////////////////////////////////////////////////////////////////////////
29 #include "AliHLTTPCRawDataUnpackerComponent.h"
30 #include "AliTPCRawStream.h"
31 #include "AliRawDataHeader.h"
32 #include "AliRawReaderMemory.h"
33 #include "AliHLTTPCRawDataFormat.h"
34 #include "AliHLTTPCDigitData.h"
35 #include "AliHLTTPCTransform.h"
39 // this is a global object used for automatic component registration, do not use this
40 AliHLTTPCRawDataUnpackerComponent gAliHLTTPCRawDataUnpackerComponent;
42 ClassImp(AliHLTTPCRawDataUnpackerComponent)
44 AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent()
46 fRawMemoryReader = NULL;
50 AliHLTTPCRawDataUnpackerComponent::~AliHLTTPCRawDataUnpackerComponent()
54 // Public functions to implement AliHLTComponent's interface.
55 // These functions are required for the registration process
57 const char* AliHLTTPCRawDataUnpackerComponent::GetComponentID()
59 return "TPCRawDataUnpacker";
62 void AliHLTTPCRawDataUnpackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
65 list.push_back( AliHLTTPCDefinitions::gkDDLPackedRawDataType );
68 AliHLTComponent_DataType AliHLTTPCRawDataUnpackerComponent::GetOutputDataType()
70 return AliHLTTPCDefinitions::gkUnpackedRawDataType;
73 void AliHLTTPCRawDataUnpackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
75 // XXX TODO: Find more realistic values.
77 inputMultiplier = 6.0;
80 AliHLTComponent* AliHLTTPCRawDataUnpackerComponent::Spawn()
82 return new AliHLTTPCRawDataUnpackerComponent;
85 int AliHLTTPCRawDataUnpackerComponent::DoInit( int argc, const char** argv )
87 if ( fRawMemoryReader || fTPCRawStream )
91 // const char* tableFileBaseDir = NULL;
94 // if ( !strcmp( argv[i], "table-dir" ) )
98 // Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Missing Argument", "Missing -table-dir parameter");
101 // tableFileBaseDir = argv[i+1];
105 Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
109 // if ( !tableFileBaseDir )
111 // Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Table file directory missing ",
112 // "Table file base directory has to be set using the -table-dir component parameter." );
116 fRawMemoryReader = new AliRawReaderMemory;
117 //fTPCRawStream = new AliTPCRawStream( fRawMemoryReader, tableFileBaseDir );
118 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
123 int AliHLTTPCRawDataUnpackerComponent::DoDeinit()
125 if ( fRawMemoryReader )
126 delete fRawMemoryReader;
127 fRawMemoryReader = NULL;
129 delete fTPCRawStream;
130 fTPCRawStream = NULL;
134 int AliHLTTPCRawDataUnpackerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
135 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
136 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
138 const AliHLTComponent_BlockData* iter = NULL;
141 AliHLTUInt8_t* outBPtr;
142 AliHLTTPCUnpackedRawData* outPtr;
143 AliHLTTPCDigitRowData* currentRow;
144 AliHLTTPCDigitData* currentDigit;
145 unsigned long long outputSize = 0;
146 unsigned long blockOutputSize = 0;
147 unsigned long rowSize = 0;
148 Int_t slice, patch, rows[2];
150 outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
151 currentRow = outPtr->fDigits;
152 currentDigit = currentRow->fDigitData;
154 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
155 "Event 0x%08LX (%Lu) received with %lu blocks. Output data size: %lu",
156 evtData.fEventID, evtData.fEventID, evtData.fBlockCnt, size);
157 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
160 char tmp1[14], tmp2[14];
161 DataType2Text( iter->fDataType, tmp1 );
162 DataType2Text( AliHLTTPCDefinitions::gkDDLPackedRawDataType, tmp2 );
163 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
164 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
165 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
166 if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType )
170 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
171 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
172 rows[0] = AliHLTTPCTransform::GetFirstRow( patch );
173 rows[1] = AliHLTTPCTransform::GetLastRow( patch );
176 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Input Raw Packed Data",
177 "Input: Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
178 slice, patch, rows[0], rows[1] );
180 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
181 bool readValue = true;
182 readValue = fTPCRawStream->Next();
183 int row = -1, oldRow = -1;
185 if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
186 rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
190 row = fTPCRawStream->GetRow();
193 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
195 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
196 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
197 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
200 if ( size < outputSize+sizeof(AliHLTTPCDigitRowData) )
202 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
203 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
204 evtData.fEventID, evtData.fEventID );
207 currentRow = (AliHLTTPCDigitRowData*)(outBPtr+outputSize);
208 currentDigit = currentRow->fDigitData;
209 currentRow->fRow = row+rowOffset;
210 currentRow->fNDigit = 0;
212 outputSize += sizeof(AliHLTTPCDigitRowData);
213 blockOutputSize += sizeof(AliHLTTPCDigitRowData);
214 rowSize += sizeof(AliHLTTPCDigitRowData);
216 if ( size < outputSize+sizeof(AliHLTTPCDigitData) )
218 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
219 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
220 evtData.fEventID, evtData.fEventID );
223 currentDigit->fCharge = fTPCRawStream->GetSignal();
224 currentDigit->fPad = fTPCRawStream->GetPad();
225 currentDigit->fTime = fTPCRawStream->GetTime();
226 currentRow->fNDigit++;
228 outputSize += sizeof(AliHLTTPCDigitData);
229 blockOutputSize += sizeof(AliHLTTPCDigitData);
230 rowSize += sizeof(AliHLTTPCDigitData);
231 readValue = fTPCRawStream->Next();
233 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
235 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
236 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
237 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
240 AliHLTComponent_BlockData bd;
242 bd.fOffset = outputSize-blockOutputSize;
243 bd.fSize = blockOutputSize;
244 bd.fSpecification = iter->fSpecification;
245 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
246 "Event 0x%08LX (%Lu) output data block %lu of %lu bytes at offset %lu",
247 evtData.fEventID, evtData.fEventID, ndx, blockOutputSize, outputSize-blockOutputSize );
248 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
249 outputBlocks.push_back( bd );