3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Author: Jenny Wagner (jwagner@cern.ch) *
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 **************************************************************************/
18 /** @file AliHLTCOMPHuffmanAltroComponent.cxx
21 @brief The Huffman compressor component.
28 #include "AliHLTCOMPHuffmanAltroComponent.h"
29 #include "AliHLTCOMPHuffmanAltro.h"
30 #include "AliHLTCOMPHuffmanData.h"
31 #include "AliHLTCompDefinitions.h"
32 #include "AliHLTStdIncludes.h"
35 ClassImp(AliHLTCOMPHuffmanAltroComponent)
37 /* constructur with arguments */
38 AliHLTCOMPHuffmanAltroComponent::AliHLTCOMPHuffmanAltroComponent(bool compression)
40 fHuffmanCompressor(NULL),
41 fCompressionSwitch(compression),
42 fTrainingMode(kFALSE),
43 fOrigin(kAliHLTVoidDataOrigin),
50 // see header file for class documentation
52 // refer to README to build package
54 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
57 AliHLTCOMPHuffmanAltroComponent::~AliHLTCOMPHuffmanAltroComponent()
59 // see header file for class documentation
62 // Public functions to implement AliHLTComponent's interface.
63 // These functions are required for the registration process
65 const char* AliHLTCOMPHuffmanAltroComponent::GetComponentID()
67 // see header file for class documentation
68 if(fCompressionSwitch)
70 return "COMPHuffmanCompressor";
74 return "COMPHuffmanDecompressor";
78 void AliHLTCOMPHuffmanAltroComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
80 // see header file for class documentation
84 // if compression is to be done, input data is packed raw data
85 // else (decompression): input data is special entropy encoded raw data
86 if (fCompressionSwitch) list.push_back( kAliHLTDataTypeDDLRaw );
87 else list.push_back( AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType);
91 AliHLTComponentDataType AliHLTCOMPHuffmanAltroComponent::GetOutputDataType()
93 // see header file for class documentation
94 // if compression is to be one, output data is special entropy encoded raw data
95 // else (decompression): output data is packed raw data
96 AliHLTComponentDataType dt=kAliHLTDataTypeDDLRaw;
97 if(fCompressionSwitch)
98 dt=AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType;
99 if (!fOrigin.IsNull()) SetDataType(dt, NULL, fOrigin.Data());
103 void AliHLTCOMPHuffmanAltroComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
105 // see header file for class documentation
106 // reserved outputsize = inputside * inputMultiplier
108 if (fCompressionSwitch == kFALSE)
110 // for decompression: compressed * 4 = (enough space for) decompressed
111 inputMultiplier = 4.0 ;
115 // for compression: original * 1 = (enough space for) compressed
116 inputMultiplier = 1.0;
120 AliHLTComponent* AliHLTCOMPHuffmanAltroComponent::Spawn()
122 // see header file for class documentation
123 return new AliHLTCOMPHuffmanAltroComponent(fCompressionSwitch);
127 int AliHLTCOMPHuffmanAltroComponent::DoInit( int argc, const char** argv )
130 // see header file for class documentation
132 if ( fHuffmanCompressor )
141 // -- training mode wrongly called here
142 if ( !strcmp( argv[i], "-training" ) )
144 fTrainingMode = kTRUE;
146 HLTInfo("HuffmanCompressor called in training mode, please call HuffmanCalibration instead.");
151 // mode option: compress or decompress
152 // if ( !strcmp( argv[i], "-compress" ) )
154 // fCompressionSwitch = kTRUE;
160 //if(!strcmp( argv[i], "-decompress" ) )
162 // fCompressionSwitch = kFALSE;
168 // -- argument to load correct code table for respective data specifications (origin, runnumber, specification)
169 if ( !strcmp( argv[i], "-origin" ) )
174 HLTError("Missing data origin specification");
178 // get data origin (TPC, PHOS, ...)
181 while(fOrigin.Length() < kAliHLTComponentDataTypefOriginSize)
186 HLTDebug("Origin is set to %s.", fOrigin.Data());
192 // -- get run number specification
193 if ( !strcmp( argv[i], "-runnumber" ) )
197 HLTError("Missing run number specification");
202 const char* runnumber = argv[i+1];
204 fRunNumber = atoi(runnumber);
206 HLTDebug("Run number set to %d (Dec) = %X (Hex).", fRunNumber, fRunNumber);
208 // validation check of run number?!
215 // -- get data specification (e.g. TPC: slice and patch information contained in "dataspec")
216 if ( !strcmp( argv[i], "-dataspec" ) )
220 HLTError("Missing data specification");
225 fDataSpec = strtoul(argv[i+1], NULL, 16);
227 HLTDebug("Dataspecification set to %d (Dec) = %08X (Hex).", fDataSpec, fDataSpec);
229 // validation check of specification?!
235 // -- get tablepathname (e.g. ../HLT-data/)
236 if ( !strcmp( argv[i], "-tablepath" ) )
240 HLTDebug("Missing table path argument.");
244 fTablePath=argv[i+1];
246 HLTDebug("Table path set to %s.", fTablePath.Data());
248 // validation check of specification?!
254 // -- number of trailerwords: from 1 to 3
255 if ( !strcmp( argv[i], "-trailerwords" ) )
259 HLTError("Missing trailerword specification");
263 if ( !strcmp( argv[i+1], "1" ) )
264 fNrcuTrailerwords = 1;
265 else if ( !strcmp( argv[i+1], "2" ) )
266 fNrcuTrailerwords = 2;
267 else if ( !strcmp( argv[i+1], "3" ) )
268 fNrcuTrailerwords = 3;
271 HLTError("Missing number of trailerwords, cannot accept argument '%s'.", argv[i+1] );
280 HLTError("Unknown Option '%s'", argv[i] );
284 // load HuffmanData from root-file to acquire translation table
285 fHuffmanData = new AliHLTCOMPHuffmanData();
287 TString rootfilename;
288 if(fTablePath.IsNull())
290 // if no table path is explicity set, take current path as table path
291 rootfilename.Form("huffmanData_%s_%08X_%08X.root", fOrigin.Data(), fRunNumber, fDataSpec);
295 rootfilename.Form("%shuffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), fRunNumber, fDataSpec);
298 TFile* huffmancodefile = new TFile(rootfilename, "READ");
300 if(huffmancodefile->IsZombie())
302 HLTFatal("No Huffman code table available for %s.", rootfilename.Data());
305 fHuffmanData = (AliHLTCOMPHuffmanData*) huffmancodefile->Get("HuffmanData");
307 // create a new Huffman compressor
308 fHuffmanCompressor = new AliHLTCOMPHuffmanAltro(fCompressionSwitch, kFALSE, NULL, fNrcuTrailerwords);
310 // get translation table for pure encoding and decoding from HuffmanData
311 fHuffmanCompressor->GetTranslationTable(fHuffmanData);
316 int AliHLTCOMPHuffmanAltroComponent::DoDeinit()
319 // see header file for class documentation
320 if (fHuffmanCompressor)
321 delete fHuffmanCompressor;
322 fHuffmanCompressor = NULL;
331 int AliHLTCOMPHuffmanAltroComponent::DoEvent( const AliHLTComponentEventData& evtData,
332 const AliHLTComponentBlockData* blocks,
333 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr,
334 AliHLTUInt32_t& size,
335 vector<AliHLTComponentBlockData>& outputBlocks )
337 // see header file for class documentation
339 // == init iter (pointer to datablock)
340 const AliHLTComponentBlockData* iter = NULL;
343 // == OUTdatatype pointer
344 // AliHLTTPCClusterData* outPtr;
346 AliHLTUInt8_t* outBPtr;
347 UInt_t offset, mysize, tSize = 0;
350 // outPtr = (AliHLTTPCClusterData*)outBPtr;
353 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
359 if(fCompressionSwitch) // show selected mode
361 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",evtData.fEventID, evtData.fEventID,
362 DataType2Text(iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw|fOrigin.Data()).c_str());
364 // check if current block has correct data format
365 // if not, take next block
366 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw|fOrigin.Data()) ) continue;
370 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",evtData.fEventID, evtData.fEventID,
371 DataType2Text(iter->fDataType).c_str(), DataType2Text(AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType|fOrigin.Data()).c_str());
373 // check if current block has correct data format
374 // if not, take next block
375 if ( iter->fDataType != (AliHLTCompDefinitions::fgkDDLEncodedHuffmanAltroDataType|fOrigin.Data()) ) continue;
378 // HLTDebug("HLT::HuffmanCompressor::DoEvent", "Event received", "Starting to process data");
380 fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize);
383 // HLTDebug("input data pointer (HEX) = %x ", iter->fPtr);
384 // HLTDebug("input data size (bytes) = %i ", iter->fSize);
386 fHuffmanCompressor->SetOutputData(outBPtr, size);
389 // HLTDebug("output data pointer (HEX) = %x ", outBPtr);
390 // HLTDebug("reserved output data size (bytes) = %i ", size);
392 fHuffmanCompressor->ProcessData();
394 // outPtr = (AliHLTTPCClusterData*)outBPtr;
396 mysize = fHuffmanCompressor->GetOutputDataSize();
400 AliHLTComponentBlockData bd;
404 bd.fSpecification = iter->fSpecification;
405 //AliHLTSubEventDescriptor::FillBlockAttributes( bd.fAttributes );
406 outputBlocks.push_back( bd );
410 //outPtr = (AliHLTTPCClusterData*)outBPtr;
414 HLTFatal("HLT::TPCHuffmanCompressor::DoEvent: Too much data, data written over allowed buffer. Amount written: %lu, allowed amount: %lu.",tSize, size );
418 } // end of output-block-generation