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 );
189 //* read magnetic field
191 int iResult2 = 0;//ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
193 //* read the actual CDB entry if required
195 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
197 //* read extra parameters from input (if they are)
201 if ( commandLine && commandLine[0] != '\0' ) {
202 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
203 iResult4 = ReadConfigurationString( commandLine );
206 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
212 int AliHLTTPCCATrackerOutputConverter::DoInit( int argc, const char** argv )
214 // see header file for class documentation
216 TString arguments = "";
217 for ( int i = 0; i < argc; i++ ) {
218 if ( !arguments.IsNull() ) arguments += " ";
219 arguments += argv[i];
222 return Configure( NULL, NULL, arguments.Data() );
225 int AliHLTTPCCATrackerOutputConverter::Reconfigure( const char* cdbEntry, const char* chainId )
227 // Reconfigure the component from OCDB
229 return Configure( cdbEntry, chainId, NULL );
234 int AliHLTTPCCATrackerOutputConverter::DoDeinit()
236 // see header file for class documentation
240 int AliHLTTPCCATrackerOutputConverter::DoEvent( const AliHLTComponentEventData &evtData,
241 const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
242 AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
244 // see header file for class documentation
246 unsigned int maxBufferSize = size;
253 if ( !IsDataEvent() ) {
256 fBenchmark.StartNewEvent();
259 const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt;
260 for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) {
261 if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) {
265 fBenchmark.AddInput(block->fSize);
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
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() );
283 const AliHLTTPCCASliceOutput &sliceOut = *(reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr ));
284 const AliHLTTPCCASliceOutTrack *sliceTr = sliceOut.GetFirstTrack();
288 unsigned int blockSize = 0;
289 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
290 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
291 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr );
293 AliHLTTPCCAParam sliceParam;
295 for ( int itr = 0; itr < sliceOut.NTracks(); itr++ ) {
297 int nClu = sliceTr->NClusters();
299 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClu * sizeof( unsigned int );
301 if ( size + blockSize + dSize > maxBufferSize ) {
302 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, blockSize );
307 // first convert to AliExternalTrackParam
309 AliHLTTPCCATrackParam t0;
311 t0.SetParam(sliceTr->Param());
313 AliExternalTrackParam tp;
314 AliHLTTPCCATrackConvertor::GetExtParam( t0, tp, sliceParam.Alpha( slice ) );
316 // normalize the angle to +-Pi
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++ ) {
332 sliceTr->Cluster( i ).Get(slice,id,row,x,y,z);
333 currOutTrack->fPointIDs[i] = id;
335 currOutTrack->fLastX = x;
336 currOutTrack->fLastY = y;
337 currOutTrack->fLastZ = z;
340 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
343 sliceTr = sliceTr->GetNextTrack();
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;
358 HLTInfo( fBenchmark.GetStatistics() );