]>
Commit | Line | Data |
---|---|---|
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 | |
23 | using 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 | ||
32 | ClassImp(AliHLTCOMPHuffmanAltroCalibComponent) | |
33 | ||
34 | AliHLTCOMPHuffmanAltroCalibComponent::AliHLTCOMPHuffmanAltroCalibComponent() | |
35 | : | |
36 | fHuffmanCompressor(NULL), | |
37 | fHuffmanData(NULL), | |
38 | fOrigin(kAliHLTVoidDataOrigin), | |
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 | ||
50 | AliHLTCOMPHuffmanAltroCalibComponent::~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 | ||
57 | const char* AliHLTCOMPHuffmanAltroCalibComponent::GetComponentID() { | |
58 | // see header file for class documentation | |
59 | ||
60 | return "COMPHuffmanTrainer"; | |
61 | } | |
62 | ||
63 | void AliHLTCOMPHuffmanAltroCalibComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { | |
64 | // see header file for class documentation | |
65 | ||
66 | list.clear(); | |
67 | list.push_back( kAliHLTDataTypeDDLRaw ); | |
68 | } | |
69 | ||
70 | AliHLTComponentDataType AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataType() { | |
71 | // see header file for class documentation | |
72 | ||
73 | AliHLTComponentDataType dt=AliHLTCompDefinitions::fgkHuffmanAltroCalDataType; | |
74 | if (!fOrigin.IsNull()) dt=dt|fOrigin.Data(); | |
75 | return dt; | |
76 | } | |
77 | ||
78 | void AliHLTCOMPHuffmanAltroCalibComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { | |
79 | // see header file for class documentation | |
80 | ||
81 | constBase = sizeof(AliHLTCOMPHuffmanData); | |
82 | inputMultiplier = (0.0); | |
83 | } | |
84 | ||
85 | AliHLTComponent* AliHLTCOMPHuffmanAltroCalibComponent::Spawn() { | |
86 | // see header file for class documentation | |
87 | ||
88 | return new AliHLTCOMPHuffmanAltroCalibComponent(); | |
89 | } | |
90 | ||
91 | ||
92 | Int_t AliHLTCOMPHuffmanAltroCalibComponent::ScanArgument( Int_t argc, const char** argv ) { | |
93 | // see header file for class documentation | |
94 | ||
95 | Int_t iResult = 0; | |
96 | TString argument = " "; | |
97 | TString parameter = " "; | |
98 | ||
99 | if ( !argc ) | |
100 | return -EINVAL; | |
101 | ||
102 | argument = argv[iResult]; | |
103 | ||
104 | if ( argument.IsNull() ) | |
105 | return -EINVAL; | |
106 | ||
107 | // get data origin | |
108 | if ( argument.CompareTo("-origin") == 0 ) | |
109 | { | |
110 | ||
111 | if ( ++iResult >= argc ) | |
112 | { | |
113 | iResult = -EPROTO; | |
114 | } | |
115 | else | |
116 | { | |
117 | fOrigin = argv[1]; | |
118 | ||
119 | HLTInfo("Origin is set to %s.", fOrigin.Data()); | |
120 | ||
121 | } | |
122 | } | |
123 | ||
124 | else | |
125 | { | |
126 | // get run number | |
127 | if ( argument.CompareTo("-runnumber") == 0 ) | |
128 | { | |
129 | ||
130 | if ( ++iResult >= argc ) | |
131 | { | |
132 | iResult = -EPROTO; | |
133 | } | |
134 | else | |
135 | { | |
136 | parameter = argv[1]; | |
137 | ||
138 | // get run number | |
139 | ||
140 | fRunNumber = atoi(parameter.Data()); | |
141 | ||
142 | HLTInfo( "Run number is set to %d (Dec) = %X (Hex).", fRunNumber, fRunNumber ); | |
143 | } | |
144 | } | |
145 | else | |
146 | { | |
147 | // get data specification | |
148 | if(argument.CompareTo("-dataspec") == 0 ) | |
149 | { | |
150 | if ( ++iResult >= argc ) | |
151 | { | |
152 | iResult = -EPROTO; | |
153 | } | |
154 | else | |
155 | { | |
156 | // get data specification | |
157 | fSpecification = strtoul( argv[1], NULL, 16); | |
158 | ||
159 | HLTInfo( "Specification is set to %d (Dec) = %08X (Hex).", fSpecification, fSpecification ); | |
160 | } | |
161 | } | |
162 | // get number of trailer words | |
163 | else | |
164 | { | |
165 | ||
166 | if ( argument.CompareTo("-tablepath") == 0) | |
167 | { | |
168 | if ( ++iResult >= argc ) | |
169 | { | |
170 | iResult = -EPROTO; | |
171 | } | |
172 | else | |
173 | { | |
174 | // get table path | |
175 | fTablePath = argv[1]; | |
176 | HLTInfo( "Path for Huffman table output is set to %s.", fTablePath.Data() ); | |
177 | if (!fTablePath.IsNull() && !fTablePath.EndsWith("/")) | |
178 | fTablePath+="/"; | |
179 | } | |
180 | } | |
181 | ||
182 | else | |
183 | { | |
184 | if ( argument.CompareTo("-trailerwords") == 0 ) | |
185 | { | |
186 | ||
187 | if ( ++iResult >= argc ) | |
188 | { | |
189 | iResult = -EPROTO; | |
190 | } | |
191 | else | |
192 | { | |
193 | parameter = argv[1]; | |
194 | if ( parameter.CompareTo("1") == 0 ) | |
195 | { | |
196 | fNRCUTrailerWords = 1; | |
197 | HLTInfo( "Number of trailer words is set to 1." ); | |
198 | } | |
199 | else if ( parameter.CompareTo("2") == 0 ) | |
200 | { | |
201 | fNRCUTrailerWords = 2; | |
202 | HLTInfo( "Number of trailer words is set to 2." ); | |
203 | } | |
204 | else if ( parameter.CompareTo("3") == 0 ) | |
205 | { | |
206 | fNRCUTrailerWords = 3; | |
207 | HLTInfo( "Number of trailer words is set to 3." ); | |
208 | } | |
209 | else | |
210 | { | |
211 | HLTError( "Invalid number of trailerwords: '%s'.", argv[1] ); | |
212 | iResult = -EPROTO; | |
213 | } | |
214 | } | |
215 | } | |
216 | else | |
217 | { | |
218 | iResult = -EINVAL; | |
219 | } | |
220 | } | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | return iResult; | |
226 | } | |
227 | ||
228 | Int_t AliHLTCOMPHuffmanAltroCalibComponent::InitCalibration() { | |
229 | // see header file for class documentation | |
230 | ||
231 | // ** Create a calibration instance to train the Huffman code table | |
232 | if ( fHuffmanCompressor ) | |
233 | return EINPROGRESS; | |
234 | ||
235 | if ( fHuffmanData ) | |
236 | return EINPROGRESS; | |
237 | ||
238 | // create a new instance of HuffmanData to write results from training in | |
239 | fHuffmanData = new AliHLTCOMPHuffmanData(); | |
240 | ||
241 | fHuffmanCompressor = new AliHLTCOMPHuffmanAltro(kTRUE, kTRUE, NULL, fNRCUTrailerWords); | |
242 | ||
243 | // initialise new training table | |
244 | fHuffmanCompressor->InitNewTrainingTable(); | |
245 | ||
246 | return 0; | |
247 | } | |
248 | ||
249 | Int_t AliHLTCOMPHuffmanAltroCalibComponent::DeinitCalibration() { | |
250 | // see header file for class documentation | |
251 | ||
252 | if ( fHuffmanCompressor ) | |
253 | delete fHuffmanCompressor; | |
254 | fHuffmanCompressor = NULL; | |
255 | ||
256 | if ( fHuffmanData ) | |
257 | delete fHuffmanData; | |
258 | fHuffmanData = NULL; | |
259 | ||
260 | return 0; | |
261 | } | |
262 | ||
263 | /** function to do the calibration */ | |
264 | Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) { | |
265 | // see header file for class documentation | |
266 | ||
267 | const AliHLTComponentBlockData* iter = NULL; | |
268 | ||
269 | //AliHLTUInt8_t slice, patch; | |
270 | ||
271 | // ** Loop over all input blocks and specify which data format should be read - only select Raw Data | |
272 | iter = GetFirstInputBlock( kAliHLTDataTypeDDLRaw ); | |
273 | ||
274 | if ( iter != NULL ) do { | |
275 | ||
276 | // ** Print Debug output which data format was received | |
277 | HLTDebug ( "Event received - Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", | |
278 | evtData.fEventID, evtData.fEventID, DataType2Text(iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw).c_str()); | |
279 | ||
280 | ||
281 | TString blockorigin(""); | |
282 | blockorigin.Insert(0, iter->fDataType.fOrigin, kAliHLTComponentDataTypefOriginSize); | |
283 | ||
284 | if (fOrigin.IsNull()) | |
285 | { | |
286 | // if origin is not explicitly set by command line, take origin from data block | |
287 | fOrigin=blockorigin; | |
288 | HLTDebug("Origin of current data block set by block itself is %s.", blockorigin.Data()); | |
289 | } | |
290 | else | |
291 | { | |
292 | // if set origin is not equal to current block origin, printout warning! | |
293 | if(fOrigin.CompareTo(blockorigin)!=0) { | |
294 | HLTWarning("Origin %s of current data block does not match origin set by command line argument %s.", blockorigin.Data(), fOrigin.Data()); | |
295 | continue; | |
296 | } | |
297 | } | |
298 | ||
299 | // ** Get DDL ID in order to tell the memory reader which slice/patch to use | |
300 | //fSlice = AliHLTCompDefinitions::GetMinSliceNr( *iter ); | |
301 | //fPatch = AliHLTCompDefinitions::GetMinPatchNr( *iter ); | |
302 | ||
303 | //HLTDebug ( "Input Raw Data - Slice/Patch: %d/%d.", fSlice, fPatch); | |
304 | ||
305 | fHuffmanCompressor->SetInputData(iter->fPtr, iter->fSize); | |
306 | ||
307 | // only necessary for output in binary file | |
308 | //fHuffmanCompressor->SetSlice(fSlice); | |
309 | //fHuffmanCompressor->SetPatch(fPatch); | |
310 | ||
311 | fHuffmanCompressor->ProcessData(); | |
312 | ||
313 | // ** Get next input block, with the same specification as defined in GetFirstInputBlock() | |
314 | } while ( (iter = GetNextInputBlock()) != NULL ); | |
315 | ||
316 | // ** Get output specification | |
317 | // commented out for the moment to read spec in from command line argument | |
318 | //fSpecification = AliHLTCompDefinitions::EncodeDataSpecification( fSlice, fSlice, fPatch, fPatch ); | |
319 | //fSpecification = fSlice<<24 | fSlice<<16 | fPatch<<8 | fPatch; | |
320 | ||
321 | // ** PushBack data to shared memory ... | |
322 | ||
323 | // DATA TYE to DEFINE !!! XXXX | |
324 | PushBack( (TObject*) fHuffmanData, AliHLTCompDefinitions::fgkHuffmanAltroCalDataType|fOrigin.Data(), fSpecification); | |
325 | ||
326 | return 0; | |
327 | } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) { | |
328 | ||
329 | ||
330 | Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) { | |
331 | // see header file for class documentation | |
332 | ||
333 | // create code from training table | |
334 | fHuffmanCompressor->CreateCodeTable(); | |
335 | ||
336 | // write code table and occurrence table to HuffmanData instance | |
337 | fHuffmanCompressor->SetHuffmanData(fHuffmanData); | |
338 | ||
339 | TString rootfilename; | |
340 | if(fTablePath.IsNull() ) | |
341 | { | |
342 | // if there is no explicit table path, take current path | |
343 | rootfilename.Form("calib_huffmanData_%s_%08X_%08X.root", fOrigin.Data(), fRunNumber, fSpecification); | |
344 | } | |
345 | else | |
346 | { | |
347 | rootfilename.Form("%scalib_huffmanData_%s_%08X_%08X.root", fTablePath.Data(), fOrigin.Data(), fRunNumber, fSpecification); | |
348 | } | |
349 | ||
350 | TFile* huffmanrootfile = new TFile(rootfilename, "RECREATE"); | |
351 | huffmanrootfile->WriteObject(fHuffmanData,"HuffmanData"); | |
352 | huffmanrootfile->Write(); | |
353 | huffmanrootfile->Close(); | |
354 | ||
355 | // ** PushBack data to FXS ... | |
356 | ||
357 | PushToFXS( (TObject*) fHuffmanData, "TPC", "HuffmanData" ) ; | |
358 | ||
359 | return 0; | |
360 | } // Int_t AliHLTCOMPHuffmanAltroCalibComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData ) { |