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