1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
18 //***************************************************************************
21 /** @file AliHLTTPCCATrackerOutputConverter.cxx
22 @author Matthias Kretz
24 @brief HLT TPC CA global merger component.
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"
41 #include "AliCDBEntry.h"
42 #include "AliCDBManager.h"
43 #include "TObjString.h"
44 #include "TObjArray.h"
45 #include "AliHLTExternalTrackParam.h"
52 // ROOT macro for the implementation of ROOT specific class methods
53 ClassImp( AliHLTTPCCATrackerOutputConverter )
56 AliHLTTPCCATrackerOutputConverter::AliHLTTPCCATrackerOutputConverter()
57 : fBenchmark("TPCCATrackerOutputConverter")
59 // see header file for class documentation
62 // Public functions to implement AliHLTComponent's interface.
63 // These functions are required for the registration process
65 const char *AliHLTTPCCATrackerOutputConverter::GetComponentID()
67 // see header file for class documentation
68 return "TPCCATrackerOutputConverter";
71 void AliHLTTPCCATrackerOutputConverter::GetInputDataTypes( AliHLTComponentDataTypeList &list )
73 // see header file for class documentation
75 list.push_back( AliHLTTPCCADefinitions::fgkTrackletsDataType );
78 AliHLTComponentDataType AliHLTTPCCATrackerOutputConverter::GetOutputDataType()
80 // see header file for class documentation
81 return kAliHLTDataTypeTrack|kAliHLTDataOriginTPC;
84 void AliHLTTPCCATrackerOutputConverter::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
86 // see header file for class documentation
87 // XXX TODO: Find more realistic values.
89 inputMultiplier = 1.0;
92 AliHLTComponent *AliHLTTPCCATrackerOutputConverter::Spawn()
94 // see header file for class documentation
95 return new AliHLTTPCCATrackerOutputConverter;
99 void AliHLTTPCCATrackerOutputConverter::SetDefaultConfiguration()
101 // Set default configuration for the CA merger component
102 // Some parameters can be later overwritten from the OCDB
105 fBenchmark.SetTimer(0,"total");
108 int AliHLTTPCCATrackerOutputConverter::ReadConfigurationString( const char* arguments )
110 // Set configuration parameters for the CA merger component from the string
113 if ( !arguments ) return iResult;
115 TString allArgs = arguments;
117 int bMissingParam = 0;
119 TObjArray* pTokens = allArgs.Tokenize( " " );
121 int nArgs = pTokens ? pTokens->GetEntries() : 0;
123 for ( int i = 0; i < nArgs; i++ ) {
124 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
125 if ( argument.IsNull() ) continue;
127 HLTError( "Unknown option \"%s\"", argument.Data() );
132 if ( bMissingParam ) {
133 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
141 int AliHLTTPCCATrackerOutputConverter::ReadCDBEntry( const char* cdbEntry, const char* chainId )
143 // see header file for class documentation
145 const char* defaultNotify = "";
148 cdbEntry = "HLT/ConfigTPC/TPCCAGlobalMerger";
149 defaultNotify = " (default)";
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());
157 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
161 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
164 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
168 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
170 return ReadConfigurationString( pString->GetString().Data() );
175 int AliHLTTPCCATrackerOutputConverter::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
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
181 //* read hard-coded values
183 SetDefaultConfiguration();
185 //* read the default CDB entry
187 int iResult1 = ReadCDBEntry( NULL, chainId );
190 //* read the actual CDB entry if required
192 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
194 //* read extra parameters from input (if they are)
198 if ( commandLine && commandLine[0] != '\0' ) {
199 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
200 iResult3 = ReadConfigurationString( commandLine );
203 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
209 int AliHLTTPCCATrackerOutputConverter::DoInit( int argc, const char** argv )
211 // see header file for class documentation
213 TString arguments = "";
214 for ( int i = 0; i < argc; i++ ) {
215 if ( !arguments.IsNull() ) arguments += " ";
216 arguments += argv[i];
219 return Configure( NULL, NULL, arguments.Data() );
222 int AliHLTTPCCATrackerOutputConverter::Reconfigure( const char* cdbEntry, const char* chainId )
224 // Reconfigure the component from OCDB
226 return Configure( cdbEntry, chainId, NULL );
231 int AliHLTTPCCATrackerOutputConverter::DoDeinit()
233 // see header file for class documentation
237 int AliHLTTPCCATrackerOutputConverter::DoEvent( const AliHLTComponentEventData &evtData,
238 const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
239 AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
241 // see header file for class documentation
243 unsigned int maxBufferSize = size;
250 if ( !IsDataEvent() ) {
253 fBenchmark.StartNewEvent();
256 const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt;
257 for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) {
258 if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) {
262 fBenchmark.AddInput(block->fSize);
264 int slice = AliHLTTPCDefinitions::GetMinSliceNr( *block );
265 if ( slice < 0 || slice >= AliHLTTPCTransform::GetNSlice() ) {
266 HLTError( "invalid slice number %d extracted from specification 0x%08lx, skipping block of type %s",
267 slice, block->fSpecification, DataType2Text( block->fDataType ).c_str() );
268 // just remember the error, if there are other valid blocks ignore the error, return code otherwise
273 if ( slice != AliHLTTPCDefinitions::GetMaxSliceNr( *block ) ) {
274 // the code was not written for/ never used with multiple slices in one data block/ specification
275 HLTWarning( "specification 0x%08lx indicates multiple slices in data block %s: never used before, please audit the code",
276 block->fSpecification, DataType2Text( block->fDataType ).c_str() );
280 const AliHLTTPCCASliceOutput &sliceOut = *(reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr ));
281 const AliHLTTPCCASliceOutTrack *sliceTr = sliceOut.GetFirstTrack();
285 unsigned int blockSize = 0;
286 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
287 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
288 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr );
290 AliHLTTPCCAParam sliceParam;
292 for ( int itr = 0; itr < sliceOut.NTracks(); itr++ ) {
294 int nClu = sliceTr->NClusters();
296 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClu * sizeof( unsigned int );
298 if ( size + blockSize + dSize > maxBufferSize ) {
299 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, blockSize );
304 // first convert to AliExternalTrackParam
306 AliHLTTPCCATrackParam t0;
308 t0.SetParam(sliceTr->Param());
310 AliExternalTrackParam tp;
311 AliHLTTPCCATrackConvertor::GetExtParam( t0, tp, sliceParam.Alpha( slice ) );
313 // normalize the angle to +-Pi
315 currOutTrack->fAlpha = tp.GetAlpha() - CAMath::Nint(tp.GetAlpha()/CAMath::TwoPi())*CAMath::TwoPi();
316 currOutTrack->fX = tp.GetX();
317 currOutTrack->fY = tp.GetY();
318 currOutTrack->fZ = tp.GetZ();
319 currOutTrack->fq1Pt = tp.GetSigned1Pt();
320 currOutTrack->fSinPsi = tp.GetSnp();
321 currOutTrack->fTgl = tp.GetTgl();
322 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
323 currOutTrack->fTrackID = itr;
324 currOutTrack->fFlags = 0;
325 currOutTrack->fNPoints = nClu;
326 for( int i = 0; i< nClu; i++ ) {
327 currOutTrack->fPointIDs[i] = sliceTr->Cluster( i ).GetId();
329 currOutTrack->fLastX = sliceTr->Cluster( i ).GetX();
330 currOutTrack->fLastY = sliceTr->Cluster( i ).GetY();
331 currOutTrack->fLastZ = sliceTr->Cluster( i ).GetZ();
334 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
337 sliceTr = sliceTr->GetNextTrack();
340 AliHLTComponentBlockData resultData;
341 FillBlockData( resultData );
342 resultData.fOffset = size;
343 resultData.fSize = blockSize;
344 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginTPC;
345 resultData.fSpecification = block->fSpecification;
346 outputBlocks.push_back( resultData );
347 fBenchmark.AddOutput(resultData.fSize);
348 size += resultData.fSize;
352 HLTInfo( fBenchmark.GetStatistics() );