1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
5 * for The ALICE Off-line Project. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 /** @file AliHLTCOMPHuffmanAltroCalibComponent.cxx
17 @author Jochen Thaeder
19 @brief A calibration component for the Huffman code creation.
26 #include "AliHLTCOMPHuffmanAltroCalibComponent.h"
27 #include "AliHLTCOMPHuffmanAltro.h"
28 #include "AliHLTCompDefinitions.h"
29 #include "AliHLTStdIncludes.h"
30 #include "TFile.h" // necessary for HuffmanData writing
32 ClassImp(AliHLTCOMPHuffmanAltroCalibComponent)
34 AliHLTCOMPHuffmanAltroCalibComponent::AliHLTCOMPHuffmanAltroCalibComponent()
36 fHuffmanCompressor(NULL),
37 fOrigin(kAliHLTVoidDataOrigin),
42 fNRCUTrailerWords(0) {
43 // see header file for class documentation
45 // refer to README to build package
47 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50 AliHLTCOMPHuffmanAltroCalibComponent::~AliHLTCOMPHuffmanAltroCalibComponent() {
51 // see header file for class documentation
54 // Public functions to implement AliHLTComponent's interface.
55 // These functions are required for the registration process
57 const char* AliHLTCOMPHuffmanAltroCalibComponent::GetComponentID() {
58 // see header file for class documentation
60 return "COMPHuffmanTrainer";
63 void AliHLTCOMPHuffmanAltroCalibComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
64 // see header file for class documentation
66 list.push_back( kAliHLTDataTypeDDLRaw );
69 AliHLTComponentDataType AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataType() {
70 // see header file for class documentation
71 AliHLTComponentDataType dt=AliHLTCompDefinitions::fgkHuffmanAltroCalDataType;
72 if (!fOrigin.IsNull()) dt=dt|fOrigin.Data();
77 void AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
78 // see header file for class documentation
79 constBase = sizeof(AliHLTCOMPHuffmanData);
80 inputMultiplier = (0.0);
83 AliHLTComponent* AliHLTCOMPHuffmanAltroCalibComponent::Spawn() {
84 // see header file for class documentation
86 return new AliHLTCOMPHuffmanAltroCalibComponent();
90 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ScanArgument( Int_t argc, const char** argv ) {
91 // see header file for class documentation
94 TString argument = " ";
95 TString parameter = " ";
100 argument = argv[iResult];
102 if ( argument.IsNull() )
106 if ( argument.CompareTo("-origin") == 0 )
109 if ( ++iResult >= argc )
117 while(fOrigin.Length() < kAliHLTComponentDataTypefOriginSize)
122 HLTInfo("Origin is set to %s.", fOrigin.Data());
130 if ( argument.CompareTo("-runnumber") == 0 )
133 if ( ++iResult >= argc )
143 fRunNumber = atoi(parameter.Data());
145 HLTInfo( "Run number is set to %d (Dec) = %X (Hex).", fRunNumber, fRunNumber );
150 // get data specification
151 if(argument.CompareTo("-dataspec") == 0 )
153 if ( ++iResult >= argc )
159 // get data specification
160 fSpecification = strtoul( argv[1], NULL, 16);
162 HLTInfo( "Specification is set to %d (Dec) = %08X (Hex).", fSpecification, fSpecification );
165 // get number of trailer words
169 if ( argument.CompareTo("-tablepath") == 0)
171 if ( ++iResult >= argc )
178 fTablePath = argv[1];
179 HLTInfo( "Path for Huffman table output is set to %s.", fTablePath.Data() );
180 if (!fTablePath.IsNull() && !fTablePath.EndsWith("/"))
187 if ( argument.CompareTo("-trailerwords") == 0 )
190 if ( ++iResult >= argc )
197 if ( parameter.CompareTo("1") == 0 )
199 fNRCUTrailerWords = 1;
200 HLTInfo( "Number of trailer words is set to 1." );
202 else if ( parameter.CompareTo("2") == 0 )
204 fNRCUTrailerWords = 2;
205 HLTInfo( "Number of trailer words is set to 2." );
207 else if ( parameter.CompareTo("3") == 0 )
209 fNRCUTrailerWords = 3;
210 HLTInfo( "Number of trailer words is set to 3." );
214 HLTError( "Invalid number of trailerwords: '%s'.", argv[1] );
231 Int_t AliHLTCOMPHuffmanAltroCalibComponent::InitCalibration() {
232 // see header file for class documentation
234 // ** Create a calibration instance to train the Huffman code table
235 if ( fHuffmanCompressor )
241 // create a new instance of HuffmanData to write results from training in
242 fHuffmanData = new AliHLTCOMPHuffmanData();
244 fHuffmanCompressor = new AliHLTCOMPHuffmanAltro(kTRUE, kTRUE, NULL, fNRCUTrailerWords);
246 // initialise new training table
247 fHuffmanCompressor->InitNewTrainingTable();
252 Int_t AliHLTCOMPHuffmanAltroCalibComponent::DeinitCalibration() {
253 // see header file for class documentation
255 if ( fHuffmanCompressor )
256 delete fHuffmanCompressor;
257 fHuffmanCompressor = NULL;
266 /** function to do the calibration */
267 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
268 // see header file for class documentation
270 const AliHLTComponentBlockData* iter = NULL;
272 //AliHLTUInt8_t slice, patch;
274 // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
275 iter = GetFirstInputBlock( kAliHLTDataTypeDDLRaw );
277 if ( iter != NULL ) do {
279 // ** Print Debug output which data format was received
280 HLTDebug ( "Event received - Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
281 evtData.fEventID, evtData.fEventID, DataType2Text(iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw).c_str());
284 TString blockorigin("");
285 blockorigin.Insert(0, iter->fDataType.fOrigin, kAliHLTComponentDataTypefOriginSize);
287 if (fOrigin.IsNull())
289 // if origin is not explicitly set by command line, take origin from data block
291 HLTDebug("Origin of current data block set by block itself is %s.", blockorigin.Data());
295 // if set origin is not equal to current block origin, printout warning!
296 if(fOrigin.CompareTo(blockorigin)!=0) {
297 HLTWarning("Origin %s of current data block does not match origin set by command line argument %s.", blockorigin.Data(), fOrigin.Data());
302 // ** Get DDL ID in order to tell the memory reader which slice/patch to use
303 //fSlice = AliHLTCompDefinitions::GetMinSliceNr( *iter );
304 //fPatch = AliHLTCompDefinitions::GetMinPatchNr( *iter );
306 //HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d.", fSlice, fPatch);
308 fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize);
310 // only necessary for output in binary file
311 //fHuffmanCompressor->SetSlice(fSlice);
312 //fHuffmanCompressor->SetPatch(fPatch);
314 fHuffmanCompressor->ProcessData();
316 // ** Get next input block, with the same specification as defined in GetFirstInputBlock()
317 } while ( (iter = GetNextInputBlock()) != NULL );
319 // ** Get output specification
320 // commented out for the moment to read spec in from command line argument
321 //fSpecification = AliHLTCompDefinitions::EncodeDataSpecification( fSlice, fSlice, fPatch, fPatch );
322 //fSpecification = fSlice<<24 | fSlice<<16 | fPatch<<8 | fPatch;
324 // ** PushBack data to shared memory ...
326 // DATA TYE to DEFINE !!! XXXX
327 PushBack( (TObject*) fHuffmanData, AliHLTCompDefinitions::fgkHuffmanAltroCalDataType|fOrigin.Data(), fSpecification);
330 } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
333 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
334 // see header file for class documentation
336 // create code from training table
337 fHuffmanCompressor->CreateCodeTable();
339 // write code table and occurrence table to HuffmanData instance
340 fHuffmanCompressor->SetHuffmanData(fHuffmanData);
342 TString rootfilename;
343 if(fTablePath.IsNull() )
345 // if there is no explicit table path, take current path
346 rootfilename.Form("huffmanData_%s_%08X_%08X.root", fOrigin.Data(), fRunNumber, fSpecification);
350 rootfilename.Form("%shuffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), fRunNumber, fSpecification);
353 TFile* huffmanrootfile = new TFile(rootfilename, "RECREATE");
354 huffmanrootfile->WriteObject(fHuffmanData,"HuffmanData");
355 huffmanrootfile->Write();
356 huffmanrootfile->Close();
358 // ** PushBack data to FXS ...
359 // currently specification has to be put in by command line argument!
360 Int_t dataspec = (Int_t) fSpecification;
362 fHuffmanData->SetOCDBSpecifications(fOrigin, dataspec);
363 PushToFXS( (TObject*) fHuffmanData, "TPC", "HuffmanData" ) ;
366 } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {