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 * for The ALICE HLT 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 ///////////////////////////////////////////////////////////////////////////////
22 // a TPC cluster finder processing component for the HLT //
24 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliHLTTPCRawDataUnpackerComponent.h"
31 #include "AliTPCRawStream.h"
32 #include "AliRawDataHeader.h"
33 #include "AliRawReaderMemory.h"
34 #include "AliHLTTPCRawDataFormat.h"
35 #include "AliHLTTPCDigitData.h"
36 #include "AliHLTTPCTransform.h"
40 // this is a global object used for automatic component registration, do not use this
41 AliHLTTPCRawDataUnpackerComponent gAliHLTTPCRawDataUnpackerComponent;
43 ClassImp(AliHLTTPCRawDataUnpackerComponent)
45 AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent()
47 fRawMemoryReader = NULL;
51 AliHLTTPCRawDataUnpackerComponent::~AliHLTTPCRawDataUnpackerComponent()
55 // Public functions to implement AliHLTComponent's interface.
56 // These functions are required for the registration process
58 const char* AliHLTTPCRawDataUnpackerComponent::GetComponentID()
60 return "TPCRawDataUnpacker";
63 void AliHLTTPCRawDataUnpackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
66 list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
69 AliHLTComponentDataType AliHLTTPCRawDataUnpackerComponent::GetOutputDataType()
71 return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
74 void AliHLTTPCRawDataUnpackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
76 // XXX TODO: Find more realistic values.
78 inputMultiplier = 6.0;
81 AliHLTComponent* AliHLTTPCRawDataUnpackerComponent::Spawn()
83 return new AliHLTTPCRawDataUnpackerComponent;
86 int AliHLTTPCRawDataUnpackerComponent::DoInit( int argc, const char** argv )
88 if ( fRawMemoryReader || fTPCRawStream )
92 // const char* tableFileBaseDir = NULL;
95 // if ( !strcmp( argv[i], "table-dir" ) )
99 // Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Missing Argument", "Missing -table-dir parameter");
102 // tableFileBaseDir = argv[i+1];
106 Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
110 // if ( !tableFileBaseDir )
112 // Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Table file directory missing ",
113 // "Table file base directory has to be set using the -table-dir component parameter." );
117 fRawMemoryReader = new AliRawReaderMemory;
118 //fTPCRawStream = new AliTPCRawStream( fRawMemoryReader, tableFileBaseDir );
119 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
124 int AliHLTTPCRawDataUnpackerComponent::DoDeinit()
126 if ( fRawMemoryReader )
127 delete fRawMemoryReader;
128 fRawMemoryReader = NULL;
130 delete fTPCRawStream;
131 fTPCRawStream = NULL;
135 int AliHLTTPCRawDataUnpackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
136 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
137 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
139 const AliHLTComponentBlockData* iter = NULL;
142 AliHLTUInt8_t* outBPtr;
143 AliHLTTPCUnpackedRawData* outPtr;
144 AliHLTTPCDigitRowData* currentRow;
145 AliHLTTPCDigitData* currentDigit;
146 unsigned long long outputSize = 0;
147 unsigned long blockOutputSize = 0;
148 unsigned long rowSize = 0;
149 Int_t slice, patch, rows[2];
151 outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
152 currentRow = outPtr->fDigits;
153 currentDigit = currentRow->fDigitData;
155 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
156 "Event 0x%08LX (%Lu) received with %lu blocks. Output data size: %lu",
157 evtData.fEventID, evtData.fEventID, evtData.fBlockCnt, size);
158 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
161 char tmp1[14], tmp2[14];
162 DataType2Text( iter->fDataType, tmp1 );
163 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
164 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
165 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
166 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
167 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType )
171 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
172 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
173 rows[0] = AliHLTTPCTransform::GetFirstRow( patch );
174 rows[1] = AliHLTTPCTransform::GetLastRow( patch );
177 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Input Raw Packed Data",
178 "Input: Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
179 slice, patch, rows[0], rows[1] );
181 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
182 bool readValue = true;
183 readValue = fTPCRawStream->Next();
184 int row = -1, oldRow = -1;
186 if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
187 rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
191 row = fTPCRawStream->GetRow();
194 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
196 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
197 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
198 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
201 if ( size < outputSize+sizeof(AliHLTTPCDigitRowData) )
203 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
204 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
205 evtData.fEventID, evtData.fEventID );
208 currentRow = (AliHLTTPCDigitRowData*)(outBPtr+outputSize);
209 currentDigit = currentRow->fDigitData;
210 currentRow->fRow = row+rowOffset;
211 currentRow->fNDigit = 0;
213 outputSize += sizeof(AliHLTTPCDigitRowData);
214 blockOutputSize += sizeof(AliHLTTPCDigitRowData);
215 rowSize += sizeof(AliHLTTPCDigitRowData);
217 if ( size < outputSize+sizeof(AliHLTTPCDigitData) )
219 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
220 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
221 evtData.fEventID, evtData.fEventID );
224 currentDigit->fCharge = fTPCRawStream->GetSignal();
225 currentDigit->fPad = fTPCRawStream->GetPad();
226 currentDigit->fTime = fTPCRawStream->GetTime();
227 currentRow->fNDigit++;
229 outputSize += sizeof(AliHLTTPCDigitData);
230 blockOutputSize += sizeof(AliHLTTPCDigitData);
231 rowSize += sizeof(AliHLTTPCDigitData);
232 readValue = fTPCRawStream->Next();
234 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
236 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
237 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
238 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
241 AliHLTComponentBlockData bd;
243 bd.fOffset = outputSize-blockOutputSize;
244 bd.fSize = blockOutputSize;
245 bd.fSpecification = iter->fSpecification;
246 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
247 "Event 0x%08LX (%Lu) output data block %lu of %lu bytes at offset %lu",
248 evtData.fEventID, evtData.fEventID, ndx, blockOutputSize, outputSize-blockOutputSize );
249 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
250 outputBlocks.push_back( bd );