]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/comp/AliHLTCOMPHuffmanAltroCalibComponent.cxx
AliTPCcalibDB - Applying filters for calration graphs using AliTPCcalibDButil
[u/mrichter/AliRoot.git] / HLT / comp / AliHLTCOMPHuffmanAltroCalibComponent.cxx
CommitLineData
c2440081 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
5 * for The ALICE Off-line Project. *
6 * *
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 **************************************************************************/
15
16/** @file AliHLTCOMPHuffmanAltroCalibComponent.cxx
17 @author Jochen Thaeder
18 @date
19 @brief A calibration component for the Huffman code creation.
20*/
21
22#if __GNUC__>= 3
23using namespace std;
24#endif
25
26#include "AliHLTCOMPHuffmanAltroCalibComponent.h"
27#include "AliHLTCOMPHuffmanAltro.h"
28#include "AliHLTCompDefinitions.h"
29#include "AliHLTStdIncludes.h"
30#include "TFile.h" // necessary for HuffmanData writing
31
32ClassImp(AliHLTCOMPHuffmanAltroCalibComponent)
33
34AliHLTCOMPHuffmanAltroCalibComponent::AliHLTCOMPHuffmanAltroCalibComponent()
35 :
36 fHuffmanCompressor(NULL),
af2ed151 37 fHuffmanData(NULL),
5eefc803 38 fOrigin(kAliHLTVoidDataOrigin),
c2440081 39 fRunNumber(0),
40 fSpecification(0),
41 fTablePath(),
42 fNRCUTrailerWords(0) {
43 // see header file for class documentation
44 // or
45 // refer to README to build package
46 // or
47 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
48}
49
50AliHLTCOMPHuffmanAltroCalibComponent::~AliHLTCOMPHuffmanAltroCalibComponent() {
51 // see header file for class documentation
52}
53
54// Public functions to implement AliHLTComponent's interface.
55// These functions are required for the registration process
56
57const char* AliHLTCOMPHuffmanAltroCalibComponent::GetComponentID() {
58 // see header file for class documentation
59
60 return "COMPHuffmanTrainer";
61}
62
63void AliHLTCOMPHuffmanAltroCalibComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
64 // see header file for class documentation
c2440081 65 list.clear();
66 list.push_back( kAliHLTDataTypeDDLRaw );
67}
68
69AliHLTComponentDataType AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataType() {
70 // see header file for class documentation
c2440081 71 AliHLTComponentDataType dt=AliHLTCompDefinitions::fgkHuffmanAltroCalDataType;
72 if (!fOrigin.IsNull()) dt=dt|fOrigin.Data();
73 return dt;
bf7a3243 74
c2440081 75}
76
77void AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
78 // see header file for class documentation
c2440081 79 constBase = sizeof(AliHLTCOMPHuffmanData);
80 inputMultiplier = (0.0);
81}
82
83AliHLTComponent* AliHLTCOMPHuffmanAltroCalibComponent::Spawn() {
84 // see header file for class documentation
85
86 return new AliHLTCOMPHuffmanAltroCalibComponent();
87}
88
89
90Int_t AliHLTCOMPHuffmanAltroCalibComponent::ScanArgument( Int_t argc, const char** argv ) {
91 // see header file for class documentation
92
93 Int_t iResult = 0;
94 TString argument = " ";
95 TString parameter = " ";
96
97 if ( !argc )
98 return -EINVAL;
99
100 argument = argv[iResult];
101
102 if ( argument.IsNull() )
103 return -EINVAL;
104
105 // get data origin
106 if ( argument.CompareTo("-origin") == 0 )
107 {
108
109 if ( ++iResult >= argc )
110 {
111 iResult = -EPROTO;
112 }
113 else
114 {
115 fOrigin = argv[1];
116
bf7a3243 117 while(fOrigin.Length() < kAliHLTComponentDataTypefOriginSize)
118 {
119 fOrigin.Append(" ");
120 }
121
c2440081 122 HLTInfo("Origin is set to %s.", fOrigin.Data());
123
124 }
125 }
126
127 else
128 {
129 // get run number
130 if ( argument.CompareTo("-runnumber") == 0 )
131 {
132
133 if ( ++iResult >= argc )
134 {
135 iResult = -EPROTO;
136 }
137 else
138 {
139 parameter = argv[1];
140
141 // get run number
142
143 fRunNumber = atoi(parameter.Data());
144
145 HLTInfo( "Run number is set to %d (Dec) = %X (Hex).", fRunNumber, fRunNumber );
146 }
147 }
148 else
149 {
150 // get data specification
151 if(argument.CompareTo("-dataspec") == 0 )
152 {
153 if ( ++iResult >= argc )
154 {
155 iResult = -EPROTO;
156 }
157 else
158 {
159 // get data specification
160 fSpecification = strtoul( argv[1], NULL, 16);
161
162 HLTInfo( "Specification is set to %d (Dec) = %08X (Hex).", fSpecification, fSpecification );
163 }
164 }
165 // get number of trailer words
166 else
167 {
168
169 if ( argument.CompareTo("-tablepath") == 0)
170 {
171 if ( ++iResult >= argc )
172 {
173 iResult = -EPROTO;
174 }
175 else
176 {
177 // get table path
178 fTablePath = argv[1];
bf7a3243 179 HLTInfo( "Path for Huffman table output is set to %s.", fTablePath.Data() );
c2440081 180 if (!fTablePath.IsNull() && !fTablePath.EndsWith("/"))
bf7a3243 181 fTablePath+="/";
c2440081 182 }
183 }
184
185 else
186 {
187 if ( argument.CompareTo("-trailerwords") == 0 )
188 {
189
190 if ( ++iResult >= argc )
191 {
192 iResult = -EPROTO;
193 }
194 else
195 {
196 parameter = argv[1];
197 if ( parameter.CompareTo("1") == 0 )
198 {
199 fNRCUTrailerWords = 1;
200 HLTInfo( "Number of trailer words is set to 1." );
201 }
202 else if ( parameter.CompareTo("2") == 0 )
203 {
204 fNRCUTrailerWords = 2;
205 HLTInfo( "Number of trailer words is set to 2." );
206 }
207 else if ( parameter.CompareTo("3") == 0 )
208 {
209 fNRCUTrailerWords = 3;
210 HLTInfo( "Number of trailer words is set to 3." );
211 }
212 else
213 {
214 HLTError( "Invalid number of trailerwords: '%s'.", argv[1] );
215 iResult = -EPROTO;
216 }
217 }
218 }
219 else
220 {
221 iResult = -EINVAL;
222 }
223 }
224 }
225 }
226 }
227
228 return iResult;
229}
230
231Int_t AliHLTCOMPHuffmanAltroCalibComponent::InitCalibration() {
232 // see header file for class documentation
233
234 // ** Create a calibration instance to train the Huffman code table
235 if ( fHuffmanCompressor )
236 return EINPROGRESS;
237
238 if ( fHuffmanData )
239 return EINPROGRESS;
240
241 // create a new instance of HuffmanData to write results from training in
242 fHuffmanData = new AliHLTCOMPHuffmanData();
243
244 fHuffmanCompressor = new AliHLTCOMPHuffmanAltro(kTRUE, kTRUE, NULL, fNRCUTrailerWords);
245
246 // initialise new training table
247 fHuffmanCompressor->InitNewTrainingTable();
248
249 return 0;
250}
251
252Int_t AliHLTCOMPHuffmanAltroCalibComponent::DeinitCalibration() {
253 // see header file for class documentation
254
255 if ( fHuffmanCompressor )
256 delete fHuffmanCompressor;
257 fHuffmanCompressor = NULL;
258
259 if ( fHuffmanData )
260 delete fHuffmanData;
261 fHuffmanData = NULL;
262
263 return 0;
264}
265
266/** function to do the calibration */
a2ba9ae9 267Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/ ) {
c2440081 268 // see header file for class documentation
269
a2ba9ae9 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.
273 }
274
c2440081 275 const AliHLTComponentBlockData* iter = NULL;
276
277 //AliHLTUInt8_t slice, patch;
278
279 // ** Loop over all input blocks and specify which data format should be read - only select Raw Data
280 iter = GetFirstInputBlock( kAliHLTDataTypeDDLRaw );
c2440081 281
bf7a3243 282 if ( iter != NULL ) do {
283
c2440081 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());
287
288
289 TString blockorigin("");
290 blockorigin.Insert(0, iter->fDataType.fOrigin, kAliHLTComponentDataTypefOriginSize);
291
292 if (fOrigin.IsNull())
293 {
294 // if origin is not explicitly set by command line, take origin from data block
295 fOrigin=blockorigin;
296 HLTDebug("Origin of current data block set by block itself is %s.", blockorigin.Data());
297 }
298 else
299 {
bf7a3243 300 // if set origin is not equal to current block origin, printout warning!
c2440081 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());
303 continue;
304 }
305 }
306
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 );
310
311 //HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d.", fSlice, fPatch);
312
313 fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize);
314
315 // only necessary for output in binary file
316 //fHuffmanCompressor->SetSlice(fSlice);
317 //fHuffmanCompressor->SetPatch(fPatch);
318
319 fHuffmanCompressor->ProcessData();
320
321 // ** Get next input block, with the same specification as defined in GetFirstInputBlock()
322 } while ( (iter = GetNextInputBlock()) != NULL );
323
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;
328
329 // ** PushBack data to shared memory ...
330
331 // DATA TYE to DEFINE !!! XXXX
332 PushBack( (TObject*) fHuffmanData, AliHLTCompDefinitions::fgkHuffmanAltroCalDataType|fOrigin.Data(), fSpecification);
333
334 return 0;
335} // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {
336
337
5eefc803 338Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) {
c2440081 339 // see header file for class documentation
340
341 // create code from training table
342 fHuffmanCompressor->CreateCodeTable();
343
344 // write code table and occurrence table to HuffmanData instance
345 fHuffmanCompressor->SetHuffmanData(fHuffmanData);
346
347 TString rootfilename;
348 if(fTablePath.IsNull() )
349 {
350 // if there is no explicit table path, take current path
bf7a3243 351 rootfilename.Form("huffmanData_%s_%08X_%08X.root", fOrigin.Data(), fRunNumber, fSpecification);
c2440081 352 }
353 else
354 {
bf7a3243 355 rootfilename.Form("%shuffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), fRunNumber, fSpecification);
c2440081 356 }
357
358 TFile* huffmanrootfile = new TFile(rootfilename, "RECREATE");
359 huffmanrootfile->WriteObject(fHuffmanData,"HuffmanData");
360 huffmanrootfile->Write();
361 huffmanrootfile->Close();
362
363 // ** PushBack data to FXS ...
92272b35 364 // currently specification has to be put in by command line argument!
365 Int_t dataspec = (Int_t) fSpecification;
c2440081 366
92272b35 367 fHuffmanData->SetOCDBSpecifications(fOrigin, dataspec);
c2440081 368 PushToFXS( (TObject*) fHuffmanData, "TPC", "HuffmanData" ) ;
369
370 return 0;
371} // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) {