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 "AliL3DigitData.h"
35 #include "AliL3Transform.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::gkPackedRawDataType );
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 = 3.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 AliL3DigitRowData* currentRow;
144 AliL3DigitData* currentDigit;
145 unsigned long long outputSize = 0;
146 unsigned long blockOutputSize = 0;
147 unsigned long rowSize = 0;
148 Int_t slice, patch, row[2];
150 outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
151 currentRow = outPtr->fDigits;
152 currentDigit = currentRow->fDigitData;
154 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
157 if ( iter->fDataType != AliHLTTPCDefinitions::gkDDLPackedRawDataType )
161 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
162 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
163 row[0] = AliL3Transform::GetFirstRow( patch );
164 row[1] = AliL3Transform::GetLastRow( patch );
167 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
168 bool readValue = true;
169 readValue = fTPCRawStream->Next();
170 int row = -1, oldRow = -1;
172 if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
173 rowOffset = AliL3Transform::GetFirstRow( 2 );
177 row = fTPCRawStream->GetRow();
180 if ( oldRow!=-1 && rowSize != sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData) )
182 Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Size inconsistency",
183 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
184 sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData), currentRow->fNDigit );
187 if ( size < outputSize+sizeof(AliL3DigitRowData) )
189 Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Too much data",
190 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
191 evtData.fEventID, evtData.fEventID );
194 currentRow = (AliL3DigitRowData*)(outBPtr+outputSize);
195 currentDigit = currentRow->fDigitData;
196 currentRow->fRow = row+rowOffset;
197 currentRow->fNDigit = 0;
199 outputSize += sizeof(AliL3DigitRowData);
200 blockOutputSize += sizeof(AliL3DigitRowData);
201 rowSize += sizeof(AliL3DigitRowData);
203 if ( size < outputSize+sizeof(AliL3DigitData) )
205 Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Too much data",
206 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
207 evtData.fEventID, evtData.fEventID );
210 currentDigit->fCharge = fTPCRawStream->GetSignal();
211 currentDigit->fPad = fTPCRawStream->GetPad();
212 currentDigit->fTime = fTPCRawStream->GetTime();
213 currentRow->fNDigit++;
215 outputSize += sizeof(AliL3DigitData);
216 blockOutputSize += sizeof(AliL3DigitData);
217 rowSize += sizeof(AliL3DigitData);
218 readValue = fTPCRawStream->Next();
220 if ( oldRow!=-1 && rowSize != sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData) )
222 Logging( kHLTLogFatal, "TPCRawDataUnpackerSubscriber::ProcessEvent", "Size inconsistency",
223 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
224 sizeof(AliL3DigitRowData)+currentRow->fNDigit*sizeof(AliL3DigitData), currentRow->fNDigit );
227 AliHLTComponent_BlockData bd;
229 bd.fOffset = outputSize-blockOutputSize;
230 bd.fSize = blockOutputSize;
231 bd.fSpecification = iter->fSpecification;
232 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
233 outputBlocks.push_back( bd );