]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerOutputConverter.cxx
removing unnecessary include files, updating description
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATrackerOutputConverter.cxx
1 // $Id$
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project          *
4 // ALICE Experiment at CERN, All rights reserved.                           *
5 //                                                                          *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
8 //                  Matthias Kretz <kretz@kde.org>                          *
9 //                  for The ALICE HLT Project.                              *
10 //                                                                          *
11 // Permission to use, copy, modify and distribute this software and its     *
12 // documentation strictly for non-commercial purposes is hereby granted     *
13 // without fee, provided that the above copyright notice appears in all     *
14 // copies and that both the copyright notice and this permission notice     *
15 // appear in the supporting documentation. The authors make no claims       *
16 // about the suitability of this software for any purpose. It is            *
17 // provided "as is" without express or implied warranty.                    *
18 //                                                                          *
19 //***************************************************************************
20
21 /// @file   AliHLTTPCCATrackerOutputConverter.cxx
22 /// @author Sergey Gorbunov
23 /// @date
24 /// @brief  Converter of CA tracker output
25 ///
26
27 using namespace std;
28
29 #include "AliHLTTPCCATrackerOutputConverter.h"
30 #include "AliHLTTPCTransform.h"
31 #include "AliHLTTPCCADef.h"
32 #include "AliHLTTPCDefinitions.h"
33 #include "AliHLTTPCCATrackConvertor.h"
34 #include "AliHLTTPCCASliceOutput.h"
35 #include "AliHLTTPCCAParam.h"
36
37 #include "AliExternalTrackParam.h"
38 #include "AliCDBEntry.h"
39 #include "AliCDBManager.h"
40 #include "TObjString.h"
41 #include "TObjArray.h"
42 #include "AliHLTExternalTrackParam.h"
43
44 #include <climits>
45 #include <cstdlib>
46 #include <cerrno>
47
48
49 // ROOT macro for the implementation of ROOT specific class methods
50 ClassImp( AliHLTTPCCATrackerOutputConverter )
51
52
53 AliHLTTPCCATrackerOutputConverter::AliHLTTPCCATrackerOutputConverter()
54 : fBenchmark("TPCCATrackerOutputConverter")
55 {
56   // see header file for class documentation
57 }
58
59 // Public functions to implement AliHLTComponent's interface.
60 // These functions are required for the registration process
61
62 const char *AliHLTTPCCATrackerOutputConverter::GetComponentID()
63 {
64   // see header file for class documentation
65   return "TPCCATrackerOutputConverter";
66 }
67
68 void AliHLTTPCCATrackerOutputConverter::GetInputDataTypes( AliHLTComponentDataTypeList &list )
69 {
70   // see header file for class documentation
71   list.clear();
72   list.push_back( AliHLTTPCCADefinitions::fgkTrackletsDataType );
73 }
74
75 AliHLTComponentDataType AliHLTTPCCATrackerOutputConverter::GetOutputDataType()
76 {
77   // see header file for class documentation
78   return kAliHLTDataTypeTrack|kAliHLTDataOriginTPC;
79 }
80
81 void AliHLTTPCCATrackerOutputConverter::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
82 {
83   // see header file for class documentation
84   // XXX TODO: Find more realistic values.
85   constBase = 0;
86   inputMultiplier = 1.0;
87 }
88
89 AliHLTComponent *AliHLTTPCCATrackerOutputConverter::Spawn()
90 {
91   // see header file for class documentation
92   return new AliHLTTPCCATrackerOutputConverter;
93 }
94
95
96 void AliHLTTPCCATrackerOutputConverter::SetDefaultConfiguration()
97 {
98   // Set default configuration for the CA merger component
99   // Some parameters can be later overwritten from the OCDB
100
101   fBenchmark.Reset();
102   fBenchmark.SetTimer(0,"total");
103 }
104
105 int AliHLTTPCCATrackerOutputConverter::ReadConfigurationString(  const char* arguments )
106 {
107   // Set configuration parameters for the CA merger component from the string
108
109   int iResult = 0;
110   if ( !arguments ) return iResult;
111
112   TString allArgs = arguments;
113   TString argument;
114   int bMissingParam = 0;
115
116   TObjArray* pTokens = allArgs.Tokenize( " " );
117
118   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
119
120   for ( int i = 0; i < nArgs; i++ ) {
121     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
122     if ( argument.IsNull() ) continue;
123
124     HLTError( "Unknown option \"%s\"", argument.Data() );
125     iResult = -EINVAL;
126   }
127   delete pTokens;
128
129   if ( bMissingParam ) {
130     HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
131     iResult = -EINVAL;
132   }
133
134   return iResult;
135 }
136
137
138 int AliHLTTPCCATrackerOutputConverter::ReadCDBEntry( const char* cdbEntry, const char* chainId )
139 {
140   // see header file for class documentation
141
142   const char* defaultNotify = "";
143
144   if ( !cdbEntry ) {
145     cdbEntry = "HLT/ConfigTPC/TPCCAGlobalMerger";
146     defaultNotify = " (default)";
147     chainId = 0;
148   }
149
150   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
151   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
152
153   if ( !pEntry ) {
154     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
155     return -EINVAL;
156   }
157
158   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
159
160   if ( !pString ) {
161     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
162     return -EINVAL;
163   }
164
165   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
166
167   return  ReadConfigurationString( pString->GetString().Data() );
168 }
169
170
171
172 int AliHLTTPCCATrackerOutputConverter::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
173 {
174   // Configure the component
175   // There are few levels of configuration,
176   // parameters which are set on one step can be overwritten on the next step
177
178   //* read hard-coded values
179
180   SetDefaultConfiguration();
181
182   //* read the default CDB entry
183
184   int iResult1 = ReadCDBEntry( NULL, chainId );
185
186
187   //* read the actual CDB entry if required
188   
189   int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
190
191   //* read extra parameters from input (if they are)
192
193   int iResult3 = 0;
194
195   if ( commandLine && commandLine[0] != '\0' ) {
196     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
197     iResult3 = ReadConfigurationString( commandLine );
198   }
199
200   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3  );
201 }
202
203
204
205
206 int AliHLTTPCCATrackerOutputConverter::DoInit( int argc, const char** argv )
207 {
208   // see header file for class documentation
209
210   TString arguments = "";
211   for ( int i = 0; i < argc; i++ ) {
212     if ( !arguments.IsNull() ) arguments += " ";
213     arguments += argv[i];
214   }
215
216   return Configure( NULL, NULL, arguments.Data()  );
217 }
218
219 int AliHLTTPCCATrackerOutputConverter::Reconfigure( const char* cdbEntry, const char* chainId )
220 {
221   // Reconfigure the component from OCDB
222
223   return Configure( cdbEntry, chainId, NULL );
224 }
225
226
227
228 int AliHLTTPCCATrackerOutputConverter::DoDeinit()
229 {
230   // see header file for class documentation
231   return 0;
232 }
233
234 int AliHLTTPCCATrackerOutputConverter::DoEvent( const AliHLTComponentEventData &evtData,
235     const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
236     AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
237 {
238   // see header file for class documentation
239   int iResult = 0;
240   unsigned int maxBufferSize = size;
241
242   size = 0;
243
244   if ( !outputPtr ) {
245     return -ENOSPC;
246   }
247   if ( !IsDataEvent() ) {
248     return 0;
249   }
250   fBenchmark.StartNewEvent();
251   fBenchmark.Start(0);
252
253   const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt;
254   for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) {
255     if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) {
256       continue;
257     }
258
259     fBenchmark.AddInput(block->fSize);
260
261     int slice = AliHLTTPCDefinitions::GetMinSliceNr( *block );
262     if ( slice < 0 || slice >= AliHLTTPCTransform::GetNSlice() ) {
263       HLTError( "invalid slice number %d extracted from specification 0x%08lx,  skipping block of type %s",
264                 slice, block->fSpecification, DataType2Text( block->fDataType ).c_str() );
265       // just remember the error, if there are other valid blocks ignore the error, return code otherwise
266       iResult = -EBADF;
267       continue;
268     }
269
270     if ( slice != AliHLTTPCDefinitions::GetMaxSliceNr( *block ) ) {
271       // the code was not written for/ never used with multiple slices in one data block/ specification
272       HLTWarning( "specification 0x%08lx indicates multiple slices in data block %s: never used before, please audit the code",
273                   block->fSpecification, DataType2Text( block->fDataType ).c_str() );
274     }
275
276     
277     const AliHLTTPCCASliceOutput &sliceOut =  *(reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr ));
278     const AliHLTTPCCASliceOutTrack *sliceTr = sliceOut.GetFirstTrack();
279    
280     // Output block
281
282     unsigned int blockSize = 0;
283     AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
284     AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
285     blockSize =   ( ( AliHLTUInt8_t * )currOutTrack ) -  ( ( AliHLTUInt8_t * )outputPtr );
286     outPtr->fCount = 0;   
287     AliHLTTPCCAParam sliceParam;
288
289     for ( int itr = 0; itr < sliceOut.NTracks(); itr++ ) {
290       
291       int nClu = sliceTr->NClusters();
292
293       unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClu * sizeof( unsigned int );
294
295       if ( size + blockSize + dSize > maxBufferSize ) {
296         HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, blockSize );
297         iResult = -ENOSPC;
298         break;
299       }
300
301      // first convert to AliExternalTrackParam
302
303       AliHLTTPCCATrackParam t0;
304       t0.InitParam();
305       t0.SetParam(sliceTr->Param());
306
307       AliExternalTrackParam tp;
308       AliHLTTPCCATrackConvertor::GetExtParam( t0, tp, sliceParam.Alpha( slice ) );
309       
310       // normalize the angle to +-Pi
311               
312       currOutTrack->fAlpha = tp.GetAlpha() - CAMath::Nint(tp.GetAlpha()/CAMath::TwoPi())*CAMath::TwoPi();      
313       currOutTrack->fX = tp.GetX();
314       currOutTrack->fY = tp.GetY();
315       currOutTrack->fZ = tp.GetZ();      
316       currOutTrack->fq1Pt = tp.GetSigned1Pt();
317       currOutTrack->fSinPsi = tp.GetSnp();
318       currOutTrack->fTgl = tp.GetTgl();
319       for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
320       currOutTrack->fTrackID = itr;
321       currOutTrack->fFlags = 0;
322       currOutTrack->fNPoints = nClu;    
323       for( int i = 0; i< nClu; i++ ) {  
324         currOutTrack->fPointIDs[i] = sliceTr->Cluster( i ).GetId();
325         if( i == nClu-1 ){
326           currOutTrack->fLastX = sliceTr->Cluster( i ).GetX();
327           currOutTrack->fLastY = sliceTr->Cluster( i ).GetY();
328           currOutTrack->fLastZ = sliceTr->Cluster( i ).GetZ();
329         }
330       }
331       currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
332       blockSize += dSize;
333       outPtr->fCount++;
334       sliceTr = sliceTr->GetNextTrack();
335     }
336  
337     AliHLTComponentBlockData resultData;
338     FillBlockData( resultData );
339     resultData.fOffset = size;
340     resultData.fSize = blockSize;
341     resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginTPC;
342     resultData.fSpecification = block->fSpecification;
343     outputBlocks.push_back( resultData );
344     fBenchmark.AddOutput(resultData.fSize);
345     size += resultData.fSize;
346   }
347
348   fBenchmark.Stop(0);
349   HLTInfo( fBenchmark.GetStatistics() );
350   return iResult;
351 }
352