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