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