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),
52 AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent(const AliHLTTPCRawDataUnpackerComponent&)
54 fRawMemoryReader(NULL),
57 // see header file for class documentation
60 AliHLTTPCRawDataUnpackerComponent& AliHLTTPCRawDataUnpackerComponent::operator=(const AliHLTTPCRawDataUnpackerComponent&)
62 // see header file for class documentation
66 AliHLTTPCRawDataUnpackerComponent::~AliHLTTPCRawDataUnpackerComponent()
70 // Public functions to implement AliHLTComponent's interface.
71 // These functions are required for the registration process
73 const char* AliHLTTPCRawDataUnpackerComponent::GetComponentID()
75 return "TPCRawDataUnpacker";
78 void AliHLTTPCRawDataUnpackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
81 list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
84 AliHLTComponentDataType AliHLTTPCRawDataUnpackerComponent::GetOutputDataType()
86 return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
89 void AliHLTTPCRawDataUnpackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
91 // XXX TODO: Find more realistic values.
93 inputMultiplier = 6.0;
96 AliHLTComponent* AliHLTTPCRawDataUnpackerComponent::Spawn()
98 return new AliHLTTPCRawDataUnpackerComponent;
101 int AliHLTTPCRawDataUnpackerComponent::DoInit( int argc, const char** argv )
103 if ( fRawMemoryReader || fTPCRawStream )
107 // const char* tableFileBaseDir = NULL;
110 // if ( !strcmp( argv[i], "table-dir" ) )
114 // Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Missing Argument", "Missing -table-dir parameter");
117 // tableFileBaseDir = argv[i+1];
121 Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
125 // if ( !tableFileBaseDir )
127 // Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Table file directory missing ",
128 // "Table file base directory has to be set using the -table-dir component parameter." );
132 fRawMemoryReader = new AliRawReaderMemory;
133 //fTPCRawStream = new AliTPCRawStream( fRawMemoryReader, tableFileBaseDir );
134 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
139 int AliHLTTPCRawDataUnpackerComponent::DoDeinit()
141 if ( fRawMemoryReader )
142 delete fRawMemoryReader;
143 fRawMemoryReader = NULL;
145 delete fTPCRawStream;
146 fTPCRawStream = NULL;
150 int AliHLTTPCRawDataUnpackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
151 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
152 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
154 const AliHLTComponentBlockData* iter = NULL;
157 AliHLTUInt8_t* outBPtr;
158 AliHLTTPCUnpackedRawData* outPtr;
159 AliHLTTPCDigitRowData* currentRow;
160 AliHLTTPCDigitData* currentDigit;
161 unsigned long long outputSize = 0;
162 unsigned long blockOutputSize = 0;
163 unsigned long rowSize = 0;
164 Int_t slice, patch, rows[2];
166 outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
167 currentRow = outPtr->fDigits;
168 currentDigit = currentRow->fDigitData;
170 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
171 "Event 0x%08LX (%Lu) received with %lu blocks. Output data size: %lu",
172 evtData.fEventID, evtData.fEventID, evtData.fBlockCnt, size);
173 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
176 char tmp1[14], tmp2[14];
177 DataType2Text( iter->fDataType, tmp1 );
178 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
179 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
180 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
181 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
182 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType )
186 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
187 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
188 rows[0] = AliHLTTPCTransform::GetFirstRow( patch );
189 rows[1] = AliHLTTPCTransform::GetLastRow( patch );
192 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Input Raw Packed Data",
193 "Input: Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
194 slice, patch, rows[0], rows[1] );
196 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
197 bool readValue = true;
198 readValue = fTPCRawStream->Next();
199 int row = -1, oldRow = -1;
201 if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
202 rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
206 row = fTPCRawStream->GetRow();
209 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
211 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
212 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
213 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
216 if ( size < outputSize+sizeof(AliHLTTPCDigitRowData) )
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 currentRow = (AliHLTTPCDigitRowData*)(outBPtr+outputSize);
224 currentDigit = currentRow->fDigitData;
225 currentRow->fRow = row+rowOffset;
226 currentRow->fNDigit = 0;
228 outputSize += sizeof(AliHLTTPCDigitRowData);
229 blockOutputSize += sizeof(AliHLTTPCDigitRowData);
230 rowSize += sizeof(AliHLTTPCDigitRowData);
232 if ( size < outputSize+sizeof(AliHLTTPCDigitData) )
234 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
235 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
236 evtData.fEventID, evtData.fEventID );
239 currentDigit->fCharge = fTPCRawStream->GetSignal();
240 currentDigit->fPad = fTPCRawStream->GetPad();
241 currentDigit->fTime = fTPCRawStream->GetTime();
242 currentRow->fNDigit++;
244 outputSize += sizeof(AliHLTTPCDigitData);
245 blockOutputSize += sizeof(AliHLTTPCDigitData);
246 rowSize += sizeof(AliHLTTPCDigitData);
247 readValue = fTPCRawStream->Next();
249 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
251 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
252 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
253 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
256 AliHLTComponentBlockData bd;
258 bd.fOffset = outputSize-blockOutputSize;
259 bd.fSize = blockOutputSize;
260 bd.fSpecification = iter->fSpecification;
261 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
262 "Event 0x%08LX (%Lu) output data block %lu of %lu bytes at offset %lu",
263 evtData.fEventID, evtData.fEventID, ndx, blockOutputSize, outputSize-blockOutputSize );
264 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
265 outputBlocks.push_back( bd );