2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
19 //***************************************************************************
21 /// @file AliHLTTPCCATrackerOutputConverter.cxx
22 /// @author Sergey Gorbunov
24 /// @brief Converter of CA tracker output
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"
37 #include "AliExternalTrackParam.h"
38 #include "AliCDBEntry.h"
39 #include "AliCDBManager.h"
40 #include "TObjString.h"
41 #include "TObjArray.h"
42 #include "AliHLTExternalTrackParam.h"
49 // ROOT macro for the implementation of ROOT specific class methods
50 ClassImp( AliHLTTPCCATrackerOutputConverter )
53 AliHLTTPCCATrackerOutputConverter::AliHLTTPCCATrackerOutputConverter()
54 : fBenchmark("TPCCATrackerOutputConverter")
56 // see header file for class documentation
59 // Public functions to implement AliHLTComponent's interface.
60 // These functions are required for the registration process
62 const char *AliHLTTPCCATrackerOutputConverter::GetComponentID()
64 // see header file for class documentation
65 return "TPCCATrackerOutputConverter";
68 void AliHLTTPCCATrackerOutputConverter::GetInputDataTypes( AliHLTComponentDataTypeList &list )
70 // see header file for class documentation
72 list.push_back( AliHLTTPCCADefinitions::fgkTrackletsDataType );
75 AliHLTComponentDataType AliHLTTPCCATrackerOutputConverter::GetOutputDataType()
77 // see header file for class documentation
78 return kAliHLTDataTypeTrack|kAliHLTDataOriginTPC;
81 void AliHLTTPCCATrackerOutputConverter::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
83 // see header file for class documentation
84 // XXX TODO: Find more realistic values.
86 inputMultiplier = 1.0;
89 AliHLTComponent *AliHLTTPCCATrackerOutputConverter::Spawn()
91 // see header file for class documentation
92 return new AliHLTTPCCATrackerOutputConverter;
96 void AliHLTTPCCATrackerOutputConverter::SetDefaultConfiguration()
98 // Set default configuration for the CA merger component
99 // Some parameters can be later overwritten from the OCDB
102 fBenchmark.SetTimer(0,"total");
105 int AliHLTTPCCATrackerOutputConverter::ReadConfigurationString( const char* arguments )
107 // Set configuration parameters for the CA merger component from the string
110 if ( !arguments ) return iResult;
112 TString allArgs = arguments;
114 int bMissingParam = 0;
116 TObjArray* pTokens = allArgs.Tokenize( " " );
118 int nArgs = pTokens ? pTokens->GetEntries() : 0;
120 for ( int i = 0; i < nArgs; i++ ) {
121 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
122 if ( argument.IsNull() ) continue;
124 HLTError( "Unknown option \"%s\"", argument.Data() );
129 if ( bMissingParam ) {
130 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
138 int AliHLTTPCCATrackerOutputConverter::ReadCDBEntry( const char* cdbEntry, const char* chainId )
140 // see header file for class documentation
142 const char* defaultNotify = "";
145 cdbEntry = "HLT/ConfigTPC/TPCCAGlobalMerger";
146 defaultNotify = " (default)";
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());
154 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
158 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
161 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
165 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
167 return ReadConfigurationString( pString->GetString().Data() );
172 int AliHLTTPCCATrackerOutputConverter::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
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
178 //* read hard-coded values
180 SetDefaultConfiguration();
182 //* read the default CDB entry
184 int iResult1 = ReadCDBEntry( NULL, chainId );
187 //* read the actual CDB entry if required
189 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
191 //* read extra parameters from input (if they are)
195 if ( commandLine && commandLine[0] != '\0' ) {
196 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
197 iResult3 = ReadConfigurationString( commandLine );
200 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
206 int AliHLTTPCCATrackerOutputConverter::DoInit( int argc, const char** argv )
208 // see header file for class documentation
210 TString arguments = "";
211 for ( int i = 0; i < argc; i++ ) {
212 if ( !arguments.IsNull() ) arguments += " ";
213 arguments += argv[i];
216 return Configure( NULL, NULL, arguments.Data() );
219 int AliHLTTPCCATrackerOutputConverter::Reconfigure( const char* cdbEntry, const char* chainId )
221 // Reconfigure the component from OCDB
223 return Configure( cdbEntry, chainId, NULL );
228 int AliHLTTPCCATrackerOutputConverter::DoDeinit()
230 // see header file for class documentation
234 int AliHLTTPCCATrackerOutputConverter::DoEvent( const AliHLTComponentEventData &evtData,
235 const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
236 AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
238 // see header file for class documentation
240 unsigned int maxBufferSize = size;
247 if ( !IsDataEvent() ) {
250 fBenchmark.StartNewEvent();
253 const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt;
254 for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) {
255 if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) {
259 fBenchmark.AddInput(block->fSize);
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
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() );
277 const AliHLTTPCCASliceOutput &sliceOut = *(reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr ));
278 const AliHLTTPCCASliceOutTrack *sliceTr = sliceOut.GetFirstTrack();
282 unsigned int blockSize = 0;
283 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
284 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
285 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr );
287 AliHLTTPCCAParam sliceParam;
289 for ( int itr = 0; itr < sliceOut.NTracks(); itr++ ) {
291 int nClu = sliceTr->NClusters();
293 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClu * sizeof( unsigned int );
295 if ( size + blockSize + dSize > maxBufferSize ) {
296 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, blockSize );
301 // first convert to AliExternalTrackParam
303 AliHLTTPCCATrackParam t0;
305 t0.SetParam(sliceTr->Param());
307 AliExternalTrackParam tp;
308 AliHLTTPCCATrackConvertor::GetExtParam( t0, tp, sliceParam.Alpha( slice ) );
310 // normalize the angle to +-Pi
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();
326 currOutTrack->fLastX = sliceTr->Cluster( i ).GetX();
327 currOutTrack->fLastY = sliceTr->Cluster( i ).GetY();
328 currOutTrack->fLastZ = sliceTr->Cluster( i ).GetZ();
331 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
334 sliceTr = sliceTr->GetNextTrack();
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;
349 HLTInfo( fBenchmark.GetStatistics() );