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