]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/comp/AliHLTTPCCompModelConverterComponent.cxx
converting to component registration by library agent - getting rid of global objects
[u/mrichter/AliRoot.git] / HLT / TPCLib / comp / AliHLTTPCCompModelConverterComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTPCCompModelConverterComponent.cxx
20     @author Timm Steinbeck
21     @author changed by J. Wagner
22     @date   17-11-2007
23     @brief  A copy processing component for the HLT. */
24
25 #if __GNUC__ >= 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTTPCCompModelConverterComponent.h"
30 #include "AliHLTTPCDefinitions.h"
31 //#include "AliHLTTPCCompModelAnalysis.h"
32 #include <errno.h>
33 /** An implementiation of a converter component that
34  * takes in clusters and tracks in the standard HLT format
35  * and converts them into the Vestbo-format
36  * such that the Vestbo compression can then be 
37  * applied to these tracks and clusters
38  */
39
40 /** ROOT macro for the implementation of ROOT specific class methods */
41 ClassImp(AliHLTTPCCompModelConverterComponent)
42     
43   AliHLTTPCCompModelConverterComponent::AliHLTTPCCompModelConverterComponent() :
44     fConverter(NULL),
45     fModelAnalysisInstance(NULL),
46     fDumpFileName(),
47     fGraphFileName(),
48     fModelAnalysis(0),
49     fTrackAnalysis(0),
50     fFillingFirstTrackArray(0)
51     {
52       // see header file for class documentation
53     }
54
55 AliHLTTPCCompModelConverterComponent::~AliHLTTPCCompModelConverterComponent()
56     {
57       // see header file for class documentation
58     }
59
60 const char* AliHLTTPCCompModelConverterComponent::GetComponentID()
61     {
62       // see header file for class documentation
63       return "TPCCompModelConverter"; // The ID of this component
64     }
65
66 void AliHLTTPCCompModelConverterComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
67     {
68       // see header file for class documentation
69       list.clear(); // We do not have any requirements for our input data type(s).
70       list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
71       list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
72     }
73
74 AliHLTComponent_DataType AliHLTTPCCompModelConverterComponent::GetOutputDataType()
75     {
76       // see header file for class documentation
77       return AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
78     }
79
80 void AliHLTTPCCompModelConverterComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
81     {
82       // see header file for class documentation
83       constBase = 4+4+216; // Format versions + 1 byte per patch
84       inputMultiplier = 4.;
85       //#warning Adapt input Multiplier to something more realistic
86     }
87
88 // Spawn function, return new instance of this class
89 AliHLTComponent* AliHLTTPCCompModelConverterComponent::Spawn()
90     {
91       // see header file for class documentation
92       return new AliHLTTPCCompModelConverterComponent;
93     };
94
95 int AliHLTTPCCompModelConverterComponent::DoInit( int argc, const char** argv )
96 {
97   // see header file for class documentation
98   Int_t i = 0;
99   // get input argument either -modelanalysis or -trackanalysis
100   while(i < argc)
101     {
102       if ( !strcmp( argv[i], "-modelanalysis" ) ) 
103         {
104           fModelAnalysis = 1;
105           HLTInfo("Model analysis starting.");
106           ++i;
107           continue;
108         }
109  
110         
111       if ( !strcmp( argv[i], "-trackanalysis" ) ) 
112         {
113           fTrackAnalysis = 1;
114           fFillingFirstTrackArray = 1;
115           HLTInfo("Tracking analysis starting.");
116           ++i;
117           continue;
118         }
119
120       if ( !strcmp( argv[i], "-dumptofile" ) ) 
121         {
122
123           //check if any analysis has been specified (otherwise -dumptofile makes no sense!)
124           if(!fTrackAnalysis && !fModelAnalysis)
125             {
126               HLTError("Dump to file called without any model analysis specified.");
127               return EINVAL;
128             }
129
130           // read in filename (including path)
131            if ( argc <= i+1 ) 
132             {
133               HLTError("Missing filename to write analysis results");
134               return ENOTSUP;
135             }
136            
137            fDumpFileName = argv[i+1];
138            HLTInfo("File name of dump file for results set to %s.", fDumpFileName.Data());
139           ++i;
140           ++i;
141           continue;
142         }
143
144       // specify if graphical output is wanted (histograms, saved in a root file)
145       if ( !strcmp( argv[i], "-graphs" ) ) 
146         {
147
148           //check if any analysis has been specified (otherwise -graphs makes no sense!)
149           if(!fTrackAnalysis && !fModelAnalysis)
150             {
151               HLTError("Creation of histgrams called without any model analysis specified.");
152               return EINVAL;
153             }
154
155           // read in filename (including path like /afsuser/johndoe/TrackModelHistograms.root)
156            if ( argc <= i+1 ) 
157             {
158               HLTError("Missing filename to write histograms");
159               return ENOTSUP;
160             }
161            
162            fGraphFileName = argv[i+1];
163            HLTInfo("File name of file for graphical results set to %s.", fGraphFileName.Data());
164           ++i;
165           ++i;
166           continue;
167         }
168
169       HLTError("Unknown Option '%s'", argv[i] );
170       return EINVAL;
171
172     }
173   
174   // start new analysis by intialising respective arrays
175   if(fModelAnalysis || fTrackAnalysis)
176     {
177       fModelAnalysisInstance = new AliHLTTPCCompModelAnalysis(fModelAnalysis, fTrackAnalysis, fDumpFileName, fGraphFileName);
178       fModelAnalysisInstance->Init(); 
179       fConverter = new AliHLTTPCCompModelConverter(fModelAnalysisInstance);
180
181       if(fModelAnalysis)
182         {
183           HLTInfo("Model Analysis initiated, calculating loss due to convertion to Vestbo-Model.");
184         }
185       else
186         {
187           HLTInfo("Track Analysis initiated, showing influence of Vestbo-Model on tracking.");
188         }
189     }
190   else
191     {
192       fConverter = new AliHLTTPCCompModelConverter();
193     }
194  
195   /*if ( argc )
196     {
197     Logging( kHLTLogDebug, "HLT::TPCCompModelConverter::DoInit", "Arguments", "argv[0] == %s", argv[0] );
198     Logging(kHLTLogError, "HLT::TPCCompModelConverter::DoInit", "Unknown Option", "Unknown option '%s'", argv[0] );
199     return EINVAL;
200     }*/
201   
202   return 0;
203 }
204
205 int AliHLTTPCCompModelConverterComponent::DoDeinit()
206     {
207       // see header file for class documentation
208       // display results
209       if(fModelAnalysisInstance)
210         {
211           fModelAnalysisInstance->DisplayResults();
212
213           delete fModelAnalysisInstance;
214           fModelAnalysisInstance = NULL;
215         };
216
217       if(fConverter)
218         {
219           delete fConverter;
220           fConverter = NULL;
221         }
222
223     return 0;
224     }
225
226 int AliHLTTPCCompModelConverterComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
227                                                    AliHLTComponent_TriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
228                                       AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
229     {
230       // see header file for class documentation
231       fConverter->Init();
232       // Process an event
233       // Loop over all input blocks in the event
234       AliHLTUInt8_t minSlice=0xFF, maxSlice=0xFF, minPatch=0xFF, maxPatch=0xFF;
235       for ( unsigned long n = 0; n < evtData.fBlockCnt; n++ )
236         {
237           AliHLTUInt8_t slice = 0;
238           AliHLTUInt8_t patch = 0;
239
240           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType ||
241                blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
242             {
243               slice = AliHLTTPCDefinitions::GetMinSliceNr( blocks[n].fSpecification );
244               patch = AliHLTTPCDefinitions::GetMinPatchNr( blocks[n].fSpecification );
245               if ( minSlice==0xFF || slice<minSlice )
246                 minSlice = slice;
247               if ( maxSlice==0xFF || slice>maxSlice )
248                 maxSlice = slice;
249               if ( minPatch==0xFF || patch<minPatch )
250                 minPatch = patch;
251               if ( maxPatch==0xFF || patch>maxPatch )
252                 maxPatch = patch;
253             }
254           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
255             {
256               fConverter->SetInputClusters( (AliHLTTPCClusterData*)blocks[n].fPtr, slice, patch );
257             }
258           if ( blocks[n].fDataType == AliHLTTPCDefinitions::fgkTracksDataType )
259             {
260               fConverter->SetInputTracks( (AliHLTTPCTrackletData*)blocks[n].fPtr );
261               
262               // if track analysis is desired, fill tracklets into track arrays of ModelAnalysis class to be compared
263               if(fTrackAnalysis)
264                 {
265                   fModelAnalysisInstance->SetTracks((AliHLTTPCTrackletData*)blocks[n].fPtr, fFillingFirstTrackArray);
266                   
267                   // set flag for filling first array to zero --> second array is filled then
268                   fFillingFirstTrackArray = 0;
269                 }
270             }
271         }
272       
273       if(fTrackAnalysis)
274         {
275           if(fModelAnalysis == 0) // stop processing if not required
276             return 0;
277         };
278       
279       fConverter->Convert();
280       
281       unsigned long outputSize = fConverter->GetOutputModelDataSize();
282       if ( outputSize> size )
283         {
284           HLTError( "Not enough output memory size for clusters&tracks model data. %lu needed",
285                     outputSize );
286           return ENOBUFS;
287         }
288       
289       fConverter->OutputModelData( outputPtr );
290       
291       AliHLTComponent_BlockData ob;
292       // Let the structure be filled with the default values.
293       // This takes care of setting the shared memory and data type values to default values,
294       // so that they can be filled in by the calling code.
295       FillBlockData( ob );
296       // This block's start (offset) is after all other blocks written so far
297       ob.fOffset = 0;
298       // the size of this block's data.
299       ob.fSize = outputSize;
300       // The specification of the data is copied from the input block.
301       ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
302       // The type of the data is copied from the input block.
303       ob.fDataType = AliHLTTPCDefinitions::fgkClusterTracksModelDataType;
304       // Place this block into the list of output blocks
305       outputBlocks.push_back( ob );
306       
307       outputPtr += ob.fSize;
308       
309       if ( outputSize+fConverter->GetRemainingClustersOutputDataSize()>size )
310         {
311           HLTError( "Not enough output memory size for remaining clusters model data. %lu needed in total (clusters&tracks + rem. clusters)",
312                     outputSize+fConverter->GetRemainingClustersOutputDataSize() );
313           return ENOBUFS;
314         }
315       unsigned long clusterSize = size-outputSize;
316       printf( "clusterSize0: %lu\n", clusterSize );
317       fConverter->GetRemainingClusters( outputPtr, clusterSize );
318       printf( "clusterSize1: %lu\n", clusterSize );
319       
320       FillBlockData( ob );
321       // This block's start (offset) is after all other blocks written so far
322       ob.fOffset = outputSize;
323       // the size of this block's data.
324       ob.fSize = clusterSize;
325       // The specification of the data is copied from the input block.
326       ob.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( minSlice, maxSlice, minPatch, maxPatch );
327       // The type of the data is copied from the input block.
328       ob.fDataType = AliHLTTPCDefinitions::fgkRemainingClustersModelDataType;
329       // Place this block into the list of output blocks
330       outputBlocks.push_back( ob );
331       
332       outputSize += ob.fSize;
333       
334       // Finally we set the total size of output memory we consumed.
335       size = outputSize;
336       return 0;
337     }