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 "AliHLTReadoutList.h"
31 #include "TFile.h" // necessary for HuffmanData writing
33 ClassImp(AliHLTCOMPHuffmanAltroCalibComponent)
35 AliHLTCOMPHuffmanAltroCalibComponent::AliHLTCOMPHuffmanAltroCalibComponent()
37 fHuffmanCompressor(NULL),
39 fOrigin(kAliHLTVoidDataOrigin),
43 fNRCUTrailerWords(0) {
44 // see header file for class documentation
46 // refer to README to build package
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
51 AliHLTCOMPHuffmanAltroCalibComponent::~AliHLTCOMPHuffmanAltroCalibComponent() {
52 // see header file for class documentation
55 // Public functions to implement AliHLTComponent's interface.
56 // These functions are required for the registration process
58 const char* AliHLTCOMPHuffmanAltroCalibComponent::GetComponentID() {
59 // see header file for class documentation
61 return "COMPHuffmanTrainer";
64 void AliHLTCOMPHuffmanAltroCalibComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
65 // see header file for class documentation
67 list.push_back( kAliHLTDataTypeDDLRaw );
70 AliHLTComponentDataType AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataType() {
71 // see header file for class documentation
72 AliHLTComponentDataType dt=AliHLTCompDefinitions::fgkHuffmanAltroCalDataType;
73 if (!fOrigin.IsNull()) dt=dt|fOrigin.Data();
78 void AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
79 // see header file for class documentation
80 constBase = sizeof(AliHLTCOMPHuffmanData);
81 inputMultiplier = (0.0);
84 AliHLTComponent* AliHLTCOMPHuffmanAltroCalibComponent::Spawn() {
85 // see header file for class documentation
87 return new AliHLTCOMPHuffmanAltroCalibComponent();
91 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ScanArgument( Int_t argc, const char** argv ) {
92 // see header file for class documentation
95 TString argument = " ";
96 TString parameter = " ";
101 argument = argv[iResult];
103 if ( argument.IsNull() )
107 if ( argument.CompareTo("-origin") == 0 )
110 if ( ++iResult >= argc )
118 while(fOrigin.Length() < kAliHLTComponentDataTypefOriginSize)
123 HLTInfo("Origin is set to %s.", fOrigin.Data());
131 if ( argument.CompareTo("-runnumber") == 0 )
134 if ( ++iResult >= argc )
144 fRunNumber = atoi(parameter.Data());
146 HLTInfo( "Run number is set to %d (Dec) = %X (Hex).", fRunNumber, fRunNumber );
151 // get data specification
152 if(argument.CompareTo("-dataspec") == 0 )
154 if ( ++iResult >= argc )
160 // get data specification
161 fSpecification = strtoul( argv[1], NULL, 16);
163 HLTInfo( "Specification is set to %d (Dec) = %08X (Hex).", fSpecification, fSpecification );
166 // get number of trailer words
170 if ( argument.CompareTo("-tablepath") == 0)
172 if ( ++iResult >= argc )
179 fTablePath = argv[1];
180 HLTInfo( "Path for Huffman table output is set to %s.", fTablePath.Data() );
181 if (!fTablePath.IsNull() && !fTablePath.EndsWith("/"))
188 if ( argument.CompareTo("-trailerwords") == 0 )
191 if ( ++iResult >= argc )
198 if ( parameter.CompareTo("1") == 0 )
200 fNRCUTrailerWords = 1;
201 HLTInfo( "Number of trailer words is set to 1." );
203 else if ( parameter.CompareTo("2") == 0 )
205 fNRCUTrailerWords = 2;
206 HLTInfo( "Number of trailer words is set to 2." );
208 else if ( parameter.CompareTo("3") == 0 )
210 fNRCUTrailerWords = 3;
211 HLTInfo( "Number of trailer words is set to 3." );
215 HLTError( "Invalid number of trailerwords: '%s'.", argv[1] );
232 Int_t AliHLTCOMPHuffmanAltroCalibComponent::InitCalibration() {
233 // see header file for class documentation
235 // ** Create a calibration instance to train the Huffman code table
236 if ( fHuffmanCompressor )
242 // create a new instance of HuffmanData to write results from training in
243 fHuffmanData = new AliHLTCOMPHuffmanData();
245 fHuffmanCompressor = new AliHLTCOMPHuffmanAltro(kTRUE, kTRUE, NULL, fNRCUTrailerWords);
247 // initialise new training table
248 fHuffmanCompressor->InitNewTrainingTable();
253 Int_t AliHLTCOMPHuffmanAltroCalibComponent::DeinitCalibration() {
254 // see header file for class documentation
256 if ( fHuffmanCompressor )
257 delete fHuffmanCompressor;
258 fHuffmanCompressor = NULL;
267 /** function to do the calibration */
268 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/ ) {
269 // see header file for class documentation
271 if (evtData.fEventID==0) {
272 // this is only to avoid missing parameter warning when compiling for non
273 // debug. The parameter is used in the HLTDebug message only.
276 const AliHLTComponentBlockData* iter = NULL;
278 //AliHLTUInt8_t slice, patch;
280 // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
281 iter = GetFirstInputBlock( kAliHLTDataTypeDDLRaw );
283 if ( iter != NULL ) do {
285 // ** Print Debug output which data format was received
286 HLTDebug ( "Event received - Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
287 evtData.fEventID, evtData.fEventID, DataType2Text(iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw).c_str());
290 TString blockorigin("");
291 blockorigin.Insert(0, iter->fDataType.fOrigin, kAliHLTComponentDataTypefOriginSize);
293 if (fOrigin.IsNull())
295 // if origin is not explicitly set by command line, take origin from data block
297 HLTDebug("Origin of current data block set by block itself is %s.", blockorigin.Data());
301 // if set origin is not equal to current block origin, printout warning!
302 if(fOrigin.CompareTo(blockorigin)!=0) {
303 HLTWarning("Origin %s of current data block does not match origin set by command line argument %s.", blockorigin.Data(), fOrigin.Data());
308 // ** Get DDL ID in order to tell the memory reader which slice/patch to use
309 //fSlice = AliHLTCompDefinitions::GetMinSliceNr( *iter );
310 //fPatch = AliHLTCompDefinitions::GetMinPatchNr( *iter );
312 //HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d.", fSlice, fPatch);
314 fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize);
316 // only necessary for output in binary file
317 //fHuffmanCompressor->SetSlice(fSlice);
318 //fHuffmanCompressor->SetPatch(fPatch);
320 fHuffmanCompressor->ProcessData();
322 // ** Get next input block, with the same specification as defined in GetFirstInputBlock()
323 } while ( (iter = GetNextInputBlock()) != NULL );
325 // ** Get output specification
326 // commented out for the moment to read spec in from command line argument
327 //fSpecification = AliHLTCompDefinitions::EncodeDataSpecification( fSlice, fSlice, fPatch, fPatch );
328 //fSpecification = fSlice<<24 | fSlice<<16 | fPatch<<8 | fPatch;
330 // ** PushBack data to shared memory ...
332 // DATA TYE to DEFINE !!! XXXX
333 PushBack( (TObject*) fHuffmanData, AliHLTCompDefinitions::fgkHuffmanAltroCalDataType|fOrigin.Data(), fSpecification);
336 } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
339 Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) {
340 // see header file for class documentation
342 // create code from training table
343 fHuffmanCompressor->CreateCodeTable();
345 // write code table and occurrence table to HuffmanData instance
346 fHuffmanCompressor->SetHuffmanData(fHuffmanData);
348 TString rootfilename;
349 if(fTablePath.IsNull() )
351 // if there is no explicit table path, take current path
352 rootfilename.Form("huffmanData_%s_%08X_%08X.root", fOrigin.Data(), (unsigned)fRunNumber, (unsigned)fSpecification);
356 rootfilename.Form("%shuffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), (unsigned)fRunNumber, (unsigned)fSpecification);
359 TFile* huffmanrootfile = new TFile(rootfilename, "RECREATE");
360 huffmanrootfile->WriteObject(fHuffmanData,"HuffmanData");
361 huffmanrootfile->Write();
362 huffmanrootfile->Close();
364 // ** PushBack data to FXS ...
365 // currently specification has to be put in by command line argument!
366 Int_t dataspec = (Int_t) fSpecification;
368 fHuffmanData->SetOCDBSpecifications(fOrigin, dataspec);
369 static AliHLTReadoutList rdList(AliHLTReadoutList::kTPC);
370 PushToFXS( (TObject*) fHuffmanData, "TPC", "HuffmanData", &rdList ) ;
373 } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {