]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCRawDataUnpackerComponent.cxx
corrected copy and paste typo
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCRawDataUnpackerComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
71d7c760 6 * *
9be2600f 7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
71d7c760 10 * *
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 **************************************************************************/
19
20///////////////////////////////////////////////////////////////////////////////
21// //
22// a TPC cluster finder processing component for the HLT //
23// //
24///////////////////////////////////////////////////////////////////////////////
25
26#if __GNUC__== 3
27using namespace std;
28#endif
29
30#include "AliHLTTPCRawDataUnpackerComponent.h"
31#include "AliTPCRawStream.h"
32#include "AliRawDataHeader.h"
33#include "AliRawReaderMemory.h"
a6c02c85 34#include "AliHLTTPCDigitData.h"
35#include "AliHLTTPCTransform.h"
71d7c760 36#include <stdlib.h>
37#include <errno.h>
38
39// this is a global object used for automatic component registration, do not use this
40AliHLTTPCRawDataUnpackerComponent gAliHLTTPCRawDataUnpackerComponent;
41
42ClassImp(AliHLTTPCRawDataUnpackerComponent)
43
44AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent()
e419b223 45 :
46 fRawMemoryReader(NULL),
47 fTPCRawStream(NULL)
48{
49}
50
51AliHLTTPCRawDataUnpackerComponent::AliHLTTPCRawDataUnpackerComponent(const AliHLTTPCRawDataUnpackerComponent&)
52 :
53 fRawMemoryReader(NULL),
54 fTPCRawStream(NULL)
55{
56 // see header file for class documentation
57}
58
59AliHLTTPCRawDataUnpackerComponent& AliHLTTPCRawDataUnpackerComponent::operator=(const AliHLTTPCRawDataUnpackerComponent&)
60{
61 // see header file for class documentation
62 return *this;
63}
71d7c760 64
65AliHLTTPCRawDataUnpackerComponent::~AliHLTTPCRawDataUnpackerComponent()
e419b223 66{
67}
71d7c760 68
69// Public functions to implement AliHLTComponent's interface.
70// These functions are required for the registration process
71
72const char* AliHLTTPCRawDataUnpackerComponent::GetComponentID()
73 {
74 return "TPCRawDataUnpacker";
75 }
76
8ede8717 77void AliHLTTPCRawDataUnpackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
71d7c760 78 {
79 list.clear();
96bda103 80 list.push_back( AliHLTTPCDefinitions::fgkDDLPackedRawDataType );
71d7c760 81 }
82
8ede8717 83AliHLTComponentDataType AliHLTTPCRawDataUnpackerComponent::GetOutputDataType()
71d7c760 84 {
96bda103 85 return AliHLTTPCDefinitions::fgkUnpackedRawDataType;
71d7c760 86 }
87
88void AliHLTTPCRawDataUnpackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
89 {
90 // XXX TODO: Find more realistic values.
91 constBase = 0;
a6c02c85 92 inputMultiplier = 6.0;
71d7c760 93 }
94
95AliHLTComponent* AliHLTTPCRawDataUnpackerComponent::Spawn()
96 {
97 return new AliHLTTPCRawDataUnpackerComponent;
98 }
99
100int AliHLTTPCRawDataUnpackerComponent::DoInit( int argc, const char** argv )
101 {
102 if ( fRawMemoryReader || fTPCRawStream )
103 return EINPROGRESS;
104
105 int i = 0;
a6c02c85 106// const char* tableFileBaseDir = NULL;
71d7c760 107 while ( i < argc )
108 {
a6c02c85 109// if ( !strcmp( argv[i], "table-dir" ) )
5a9b6c00 110// {
111// if ( i+1>=argc )
112// {
113// Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Missing Argument", "Missing -table-dir parameter");
114// return ENOTSUP;
115// }
116// tableFileBaseDir = argv[i+1];
117// i += 2;
118// continue;
119// }
71d7c760 120 Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
121 return EINVAL;
122 }
123
5a9b6c00 124// if ( !tableFileBaseDir )
125// {
126// Logging(kHLTLogError, "HLT::TPCRawDataUnpacker::DoInit", "Table file directory missing ",
127// "Table file base directory has to be set using the -table-dir component parameter." );
128// return EINVAL;
129// }
71d7c760 130
131 fRawMemoryReader = new AliRawReaderMemory;
132 //fTPCRawStream = new AliTPCRawStream( fRawMemoryReader, tableFileBaseDir );
133 fTPCRawStream = new AliTPCRawStream( fRawMemoryReader );
134
135 return 0;
136 }
137
138int AliHLTTPCRawDataUnpackerComponent::DoDeinit()
139 {
140 if ( fRawMemoryReader )
141 delete fRawMemoryReader;
142 fRawMemoryReader = NULL;
143 if ( fTPCRawStream )
144 delete fTPCRawStream;
145 fTPCRawStream = NULL;
146 return 0;
147 }
148
8ede8717 149int AliHLTTPCRawDataUnpackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
150 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
151 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
71d7c760 152 {
8ede8717 153 const AliHLTComponentBlockData* iter = NULL;
71d7c760 154 unsigned long ndx;
155
156 AliHLTUInt8_t* outBPtr;
157 AliHLTTPCUnpackedRawData* outPtr;
a6c02c85 158 AliHLTTPCDigitRowData* currentRow;
159 AliHLTTPCDigitData* currentDigit;
71d7c760 160 unsigned long long outputSize = 0;
161 unsigned long blockOutputSize = 0;
162 unsigned long rowSize = 0;
a6c02c85 163 Int_t slice, patch, rows[2];
71d7c760 164 outBPtr = outputPtr;
165 outPtr = (AliHLTTPCUnpackedRawData*)outputPtr;
166 currentRow = outPtr->fDigits;
167 currentDigit = currentRow->fDigitData;
a6c02c85 168
169 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
170 "Event 0x%08LX (%Lu) received with %lu blocks. Output data size: %lu",
171 evtData.fEventID, evtData.fEventID, evtData.fBlockCnt, size);
71d7c760 172 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
173 {
174 iter = blocks+ndx;
a6c02c85 175 char tmp1[14], tmp2[14];
176 DataType2Text( iter->fDataType, tmp1 );
96bda103 177 DataType2Text( AliHLTTPCDefinitions::fgkDDLPackedRawDataType, tmp2 );
a6c02c85 178 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
179 "Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
180 evtData.fEventID, evtData.fEventID, tmp1, tmp2 );
96bda103 181 if ( iter->fDataType != AliHLTTPCDefinitions::fgkDDLPackedRawDataType )
71d7c760 182 {
183 continue;
184 }
185 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
186 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
a6c02c85 187 rows[0] = AliHLTTPCTransform::GetFirstRow( patch );
188 rows[1] = AliHLTTPCTransform::GetLastRow( patch );
71d7c760 189 blockOutputSize = 0;
190
a6c02c85 191 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Input Raw Packed Data",
192 "Input: Slice/Patch/RowMin/RowMax: %d/%d/%d/%d.",
193 slice, patch, rows[0], rows[1] );
194
71d7c760 195 fRawMemoryReader->SetMemory( reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize );
196 bool readValue = true;
197 readValue = fTPCRawStream->Next();
198 int row = -1, oldRow = -1;
199 Int_t rowOffset = 0;
200 if ( patch >= 2 ) // Outer sector, patches 2, 3, 4, 5
a6c02c85 201 rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
71d7c760 202
203 while ( readValue )
204 {
205 row = fTPCRawStream->GetRow();
206 if ( row != oldRow )
207 {
a6c02c85 208 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
71d7c760 209 {
a6c02c85 210 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
71d7c760 211 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
a6c02c85 212 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
71d7c760 213 }
214 rowSize = 0;
a6c02c85 215 if ( size < outputSize+sizeof(AliHLTTPCDigitRowData) )
71d7c760 216 {
a6c02c85 217 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
71d7c760 218 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
219 evtData.fEventID, evtData.fEventID );
220 return 0;
221 }
a6c02c85 222 currentRow = (AliHLTTPCDigitRowData*)(outBPtr+outputSize);
71d7c760 223 currentDigit = currentRow->fDigitData;
224 currentRow->fRow = row+rowOffset;
225 currentRow->fNDigit = 0;
226 oldRow = row;
a6c02c85 227 outputSize += sizeof(AliHLTTPCDigitRowData);
228 blockOutputSize += sizeof(AliHLTTPCDigitRowData);
229 rowSize += sizeof(AliHLTTPCDigitRowData);
71d7c760 230 }
a6c02c85 231 if ( size < outputSize+sizeof(AliHLTTPCDigitData) )
71d7c760 232 {
a6c02c85 233 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Too much data",
71d7c760 234 "Output data too big, output memory full. Aborting event 0x%08lX (%lu)" ,
235 evtData.fEventID, evtData.fEventID );
236 return 0;
237 }
238 currentDigit->fCharge = fTPCRawStream->GetSignal();
239 currentDigit->fPad = fTPCRawStream->GetPad();
240 currentDigit->fTime = fTPCRawStream->GetTime();
241 currentRow->fNDigit++;
242 currentDigit++;
a6c02c85 243 outputSize += sizeof(AliHLTTPCDigitData);
244 blockOutputSize += sizeof(AliHLTTPCDigitData);
245 rowSize += sizeof(AliHLTTPCDigitData);
71d7c760 246 readValue = fTPCRawStream->Next();
247 }
a6c02c85 248 if ( oldRow!=-1 && rowSize != sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData) )
71d7c760 249 {
a6c02c85 250 Logging( kHLTLogFatal, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Size inconsistency",
71d7c760 251 "Size inconsistency for row %d data: %lu != %lu (%lu digits).", oldRow, rowSize,
a6c02c85 252 sizeof(AliHLTTPCDigitRowData)+currentRow->fNDigit*sizeof(AliHLTTPCDigitData), currentRow->fNDigit );
71d7c760 253 }
254
8ede8717 255 AliHLTComponentBlockData bd;
71d7c760 256 FillBlockData( bd );
257 bd.fOffset = outputSize-blockOutputSize;
258 bd.fSize = blockOutputSize;
259 bd.fSpecification = iter->fSpecification;
a6c02c85 260 Logging( kHLTLogDebug, "HLT::TPCRawDataUnpackerSubscriber::DoEvent", "Event received",
261 "Event 0x%08LX (%Lu) output data block %lu of %lu bytes at offset %lu",
262 evtData.fEventID, evtData.fEventID, ndx, blockOutputSize, outputSize-blockOutputSize );
71d7c760 263 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
264 outputBlocks.push_back( bd );
265 }
266
267
268 size = outputSize;
269 return 0;
270 }
271
272