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),
38 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 if (evtData.fEventID==0) {
271 // this is only to avoid missing parameter warning when compiling for non
272 // debug. The parameter is used in the HLTDebug message only.
275 const AliHLTComponentBlockData* iter = NULL;
277 //AliHLTUInt8_t slice, patch;
279 // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
280 iter = GetFirstInputBlock( kAliHLTDataTypeDDLRaw );
282 if ( iter != NULL ) do {
284 // ** Print Debug output which data format was received
285 HLTDebug ( "Event received - Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
286 evtData.fEventID, evtData.fEventID, DataType2Text(iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw).c_str());
289 TString blockorigin("");
290 blockorigin.Insert(0, iter->fDataType.fOrigin, kAliHLTComponentDataTypefOriginSize);
292 if (fOrigin.IsNull())
294 // if origin is not explicitly set by command line, take origin from data block
296 HLTDebug("Origin of current data block set by block itself is %s.", blockorigin.Data());
300 // if set origin is not equal to current block origin, printout warning!
301 if(fOrigin.CompareTo(blockorigin)!=0) {
302 HLTWarning("Origin %s of current data block does not match origin set by command line argument %s.", blockorigin.Data(), fOrigin.Data());
307 // ** Get DDL ID in order to tell the memory reader which slice/patch to use
308 //fSlice = AliHLTCompDefinitions::GetMinSliceNr( *iter );
309 //fPatch = AliHLTCompDefinitions::GetMinPatchNr( *iter );
311 //HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d.", fSlice, fPatch);
313 fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize);
315 // only necessary for output in binary file
316 //fHuffmanCompressor->SetSlice(fSlice);
317 //fHuffmanCompressor->SetPatch(fPatch);
319 fHuffmanCompressor->ProcessData();
321 // ** Get next input block, with the same specification as defined in GetFirstInputBlock()
322 } while ( (iter = GetNextInputBlock()) != NULL );
324 // ** Get output specification
325 // commented out for the moment to read spec in from command line argument
326 //fSpecification = AliHLTCompDefinitions::EncodeDataSpecification( fSlice, fSlice, fPatch, fPatch );
327 //fSpecification = fSlice<<24 | fSlice<<16 | fPatch<<8 | fPatch;
329 // ** PushBack data to shared memory ...
331 // DATA TYE to DEFINE !!! XXXX
332 PushBack( (TObject*) fHuffmanData, AliHLTCompDefinitions::fgkHuffmanAltroCalDataType|fOrigin.Data(), fSpecification);
335 } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
338 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) {
339 // see header file for class documentation
341 // create code from training table
342 fHuffmanCompressor->CreateCodeTable();
344 // write code table and occurrence table to HuffmanData instance
345 fHuffmanCompressor->SetHuffmanData(fHuffmanData);
347 TString rootfilename;
348 if(fTablePath.IsNull() )
350 // if there is no explicit table path, take current path
351 rootfilename.Form("huffmanData_%s_%08X_%08X.root", fOrigin.Data(), fRunNumber, fSpecification);
355 rootfilename.Form("%shuffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), fRunNumber, fSpecification);
358 TFile* huffmanrootfile = new TFile(rootfilename, "RECREATE");
359 huffmanrootfile->WriteObject(fHuffmanData,"HuffmanData");
360 huffmanrootfile->Write();
361 huffmanrootfile->Close();
363 // ** PushBack data to FXS ...
364 // currently specification has to be put in by command line argument!
365 Int_t dataspec = (Int_t) fSpecification;
367 fHuffmanData->SetOCDBSpecifications(fOrigin, dataspec);
368 PushToFXS( (TObject*) fHuffmanData, "TPC", "HuffmanData" ) ;
371 } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {