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