]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/comp/AliHLTCOMPHuffmanAltroComponent.cxx
- introduced module Ids for agents
[u/mrichter/AliRoot.git] / HLT / comp / AliHLTCOMPHuffmanAltroComponent.cxx
CommitLineData
c2440081 1// $Id$
2
3/**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
6 * *
7 * Primary Author: Jenny Wagner (jwagner@cern.ch) *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/** @file AliHLTCOMPHuffmanAltroComponent.cxx
19 @author Jenny Wagner
20 @date 29-08-2007
21 @brief The Huffman compressor component.
22*/
23
24#if __GNUC__>= 3
25using namespace std;
26#endif
27
28#include "AliHLTCOMPHuffmanAltroComponent.h"
29#include "AliHLTCOMPHuffmanAltro.h"
30#include "AliHLTCOMPHuffmanData.h"
31#include "AliHLTCompDefinitions.h"
32#include "AliHLTStdIncludes.h"
33#include "TFile.h"
34
35ClassImp(AliHLTCOMPHuffmanAltroComponent)
36
37/* constructur with arguments */
38AliHLTCOMPHuffmanAltroComponent::AliHLTCOMPHuffmanAltroComponent(bool compression)
39 :
40 fHuffmanCompressor(NULL),
41 fCompressionSwitch(compression),
42 fTrainingMode(kFALSE),
43 fHuffmanData(NULL),
44 fOrigin(kAliHLTVoidDataOrigin),
45 fRunNumber(0),
46 fDataSpec(0),
47 fTablePath(),
48 fNrcuTrailerwords(0)
49
50{
51 // see header file for class documentation
52 // or
53 // refer to README to build package
54 // or
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56}
57
58AliHLTCOMPHuffmanAltroComponent::~AliHLTCOMPHuffmanAltroComponent()
59{
60 // see header file for class documentation
61}
62
63// Public functions to implement AliHLTComponent's interface.
64// These functions are required for the registration process
65
66const char* AliHLTCOMPHuffmanAltroComponent::GetComponentID()
67{
68 // see header file for class documentation
69 if(fCompressionSwitch)
70 {
71 return "COMPHuffmanCompressor";
72 }
73 else
74 {
75 return "COMPHuffmanDecompressor";
76 }
77}
78
79void AliHLTCOMPHuffmanAltroComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
80{
81 // see header file for class documentation
82 // initialise list
83 list.clear();
84
85 // if compression is to be done, input data is packed raw data
86 // else (decompression): input data is special entropy encoded raw data
87 if (fCompressionSwitch) list.push_back( kAliHLTDataTypeDDLRaw );
88 else list.push_back( AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType);
89
90}
91
92AliHLTComponentDataType AliHLTCOMPHuffmanAltroComponent::GetOutputDataType()
93{
94 // see header file for class documentation
95 // if compression is to be one, output data is special entropy encoded raw data
96 // else (decompression): output data is packed raw data
97 AliHLTComponentDataType dt=kAliHLTDataTypeDDLRaw;
98 if(fCompressionSwitch)
99 dt=AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType;
100 if (!fOrigin.IsNull()) SetDataType(dt, NULL, fOrigin.Data());
101 return dt;
102}
103
104void AliHLTCOMPHuffmanAltroComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
105{
106 // see header file for class documentation
107 // reserved outputsize = inputside * inputMultiplier
108 constBase = 0;
109 if (fCompressionSwitch == kFALSE)
110 {
111 // for decompression: compressed * 4 = (enough space for) decompressed
112 inputMultiplier = 4.0 ;
113 }
114 else
115 {
116 // for compression: original * 1 = (enough space for) compressed
117 inputMultiplier = 1.0;
118 }
119}
120
121AliHLTComponent* AliHLTCOMPHuffmanAltroComponent::Spawn()
122{
123 // see header file for class documentation
124 return new AliHLTCOMPHuffmanAltroComponent(fCompressionSwitch);
125}
126
127
128int AliHLTCOMPHuffmanAltroComponent::DoInit( int argc, const char** argv )
129{
130
131 // see header file for class documentation
132
133 if ( fHuffmanCompressor )
134 return EINPROGRESS;
135
136
137 Int_t i = 0;
138 Char_t* cpErr;
139
140 while ( i < argc )
141 {
142 // -- training mode wrongly called here
143 if ( !strcmp( argv[i], "-training" ) )
144 {
145 fTrainingMode = kTRUE;
146
147 HLTInfo("HuffmanCompressor called in training mode, please call HuffmanCalibration instead.");
148
149 return EINVAL;
150 }
151
152 // mode option: compress or decompress
153 // if ( !strcmp( argv[i], "-compress" ) )
154 // {
155 // fCompressionSwitch = kTRUE;
156
157 // ++i;
158 // continue;
159 //}
160
161 //if(!strcmp( argv[i], "-decompress" ) )
162 // {
163 // fCompressionSwitch = kFALSE;
164
165 // ++i;
166 // continue;
167 // }
168
169 // -- argument to load correct code table for respective data specifications (origin, runnumber, specification)
170 if ( !strcmp( argv[i], "-origin" ) )
171 {
172
173 if ( argc <= i+1 )
174 {
175 HLTError("Missing data origin specification");
176 return ENOTSUP;
177 }
178
bf7a3243 179 // get data origin (TPC, PHOS, ...)
c2440081 180 fOrigin=argv[i+1];
181
bf7a3243 182 while(fOrigin.Length() < kAliHLTComponentDataTypefOriginSize)
183 {
184 fOrigin.Append(" ");
185 }
186
c2440081 187 HLTDebug("Origin is set to %s.", fOrigin.Data());
bf7a3243 188
c2440081 189 i += 2;
190 continue;
191 }
192
193 // -- get run number specification
194 if ( !strcmp( argv[i], "-runnumber" ) )
195 {
196 if ( argc <= i+1 )
197 {
198 HLTError("Missing run number specification");
199 return ENOTSUP;
200 }
201
202 // get run number
203 const char* runnumber = argv[i+1];
204
205 fRunNumber = atoi(runnumber);
206
207 HLTDebug("Run number set to %d (Dec) = %X (Hex).", fRunNumber, fRunNumber);
208
209 // validation check of run number?!
210
211 i += 2;
212 continue;
213 }
214
215
216 // -- get data specification (e.g. TPC: slice and patch information contained in "dataspec")
217 if ( !strcmp( argv[i], "-dataspec" ) )
218 {
219 if ( argc <= i+1 )
220 {
221 HLTError("Missing data specification");
222 return ENOTSUP;
223 }
224
225 // get data spec
226 fDataSpec = strtoul(argv[i+1], NULL, 16);
227
228 HLTDebug("Dataspecification set to %d (Dec) = %08X (Hex).", fDataSpec, fDataSpec);
229
230 // validation check of specification?!
231
232 i += 2;
233 continue;
234 }
235
236 // -- get tablepathname (e.g. ../HLT-data/)
237 if ( !strcmp( argv[i], "-tablepath" ) )
238 {
239 if ( argc <= i+1 )
240 {
241 HLTDebug("Missing table path argument.");
242 }
243
244 // get data spec
245 fTablePath=argv[i+1];
246
247 HLTDebug("Table path set to %s.", fTablePath.Data());
248
249 // validation check of specification?!
250
251 i += 2;
252 continue;
253 }
254
255 // -- number of trailerwords: from 1 to 3
256 if ( !strcmp( argv[i], "-trailerwords" ) )
257 {
258 if ( argc <= i+1 )
259 {
260 HLTError("Missing trailerword specification");
261 return ENOTSUP;
262 }
263
264 if ( !strcmp( argv[i+1], "1" ) )
265 fNrcuTrailerwords = 1;
266 else if ( !strcmp( argv[i+1], "2" ) )
267 fNrcuTrailerwords = 2;
268 else if ( !strcmp( argv[i+1], "3" ) )
269 fNrcuTrailerwords = 3;
270 else
271 {
272 HLTError("Missing number of trailerwords, cannot accept argument '%s'.", argv[i+1] );
273
274 return EINVAL;
275 }
276
277 i += 2;
278 continue;
279 }
280
281 HLTError("Unknown Option '%s'", argv[i] );
282 return EINVAL;
283 } // end while-loop
284
285 // load HuffmanData from root-file to acquire translation table
286 fHuffmanData = new AliHLTCOMPHuffmanData();
287
288 TString rootfilename;
289 if(fTablePath.IsNull())
290 {
291 // if no table path is explicity set, take current path as table path
292 rootfilename.Form("huffmanData_%s_%08X_%08X.root", fOrigin.Data(), fRunNumber, fDataSpec);
293 }
294 else
295 {
296 rootfilename.Form("%shuffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), fRunNumber, fDataSpec);
297 }
298
299 TFile* huffmancodefile = new TFile(rootfilename, "READ");
300
301 if(huffmancodefile->IsZombie())
302 {
303 HLTFatal("No Huffman code table available for %s.", rootfilename.Data());
304 return EINVAL;
305 }
306 fHuffmanData = (AliHLTCOMPHuffmanData*) huffmancodefile->Get("HuffmanData");
307
308 // create a new Huffman compressor
309 fHuffmanCompressor = new AliHLTCOMPHuffmanAltro(fCompressionSwitch, kFALSE, NULL, fNrcuTrailerwords);
310
311 // get translation table for pure encoding and decoding from HuffmanData
312 fHuffmanCompressor->GetTranslationTable(fHuffmanData);
313
314 return 0;
315}
316
317int AliHLTCOMPHuffmanAltroComponent::DoDeinit()
318{
319
320 // see header file for class documentation
321 if (fHuffmanCompressor)
322 delete fHuffmanCompressor;
323 fHuffmanCompressor = NULL;
324
325 if ( fHuffmanData )
326 delete fHuffmanData;
327 fHuffmanData = NULL;
328
329 return 0;
330}
331
332int AliHLTCOMPHuffmanAltroComponent::DoEvent( const AliHLTComponentEventData& evtData,
333 const AliHLTComponentBlockData* blocks,
334 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
335 AliHLTUInt32_t& size,
336 vector<AliHLTComponentBlockData>& outputBlocks )
337{
338 // see header file for class documentation
339
340 // == init iter (pointer to datablock)
341 const AliHLTComponentBlockData* iter = NULL;
342 unsigned long ndx;
343
344 // == OUTdatatype pointer
345 // AliHLTTPCClusterData* outPtr;
346
347 AliHLTUInt8_t* outBPtr;
348 UInt_t offset, mysize, tSize = 0;
349
350 outBPtr = outputPtr;
351 // outPtr = (AliHLTTPCClusterData*)outBPtr;
352
353
354 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
355 {
356 iter = blocks+ndx;
357 mysize = 0;
358 offset = tSize;
359
360 if(fCompressionSwitch) // show selected mode
361 {
362 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",evtData.fEventID, evtData.fEventID,
bf7a3243 363 DataType2Text(iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw|fOrigin.Data()).c_str());
c2440081 364
365 // check if current block has correct data format
366 // if not, take next block
367 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw|fOrigin.Data()) ) continue;
368 }
369 else
370 {
371 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",evtData.fEventID, evtData.fEventID,
bf7a3243 372 DataType2Text(iter->fDataType).c_str(), DataType2Text(AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType|fOrigin.Data()).c_str());
c2440081 373
374 // check if current block has correct data format
375 // if not, take next block
376 if ( iter->fDataType != (AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType|fOrigin.Data()) ) continue;
377 }
378
379 // HLTDebug("HLT::HuffmanCompressor::DoEvent", "Event received", "Starting to process data");
380
381 fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize);
382
383 // validation test
384 // HLTDebug("input data pointer (HEX) = %x ", iter->fPtr);
385 // HLTDebug("input data size (bytes) = %i ", iter->fSize);
386
387 fHuffmanCompressor->SetOutputData(outBPtr, size);
388
389 // validation test
390 // HLTDebug("output data pointer (HEX) = %x ", outBPtr);
391 // HLTDebug("reserved output data size (bytes) = %i ", size);
392
393 fHuffmanCompressor->ProcessData();
394
395 // outPtr = (AliHLTTPCClusterData*)outBPtr;
396
397 mysize = fHuffmanCompressor->GetOutputDataSize();
398
399 if(mysize != 0)
400 {
401 AliHLTComponentBlockData bd;
402 FillBlockData( bd );
403 bd.fOffset = offset;
404 bd.fSize = mysize;
405 bd.fSpecification = iter->fSpecification;
406 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
407 outputBlocks.push_back( bd );
408
409 tSize += mysize;
410 outBPtr += mysize;
411 //outPtr = (AliHLTTPCClusterData*)outBPtr;
412
413 if ( tSize > size )
414 {
415 HLTFatal("HLT::TPCHuffmanCompressor::DoEvent: Too much data, data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",tSize, size );
416 return EMSGSIZE;
417 }
418
419 } // end of output-block-generation
420
421 }
422
423 size = tSize;
424
425 return 0;
426}
427