Line data Source code
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 : #include "AliHLTTPCCATrackerOutputConverter.h"
28 : #include "AliHLTTPCGeometry.h"
29 : #include "AliHLTTPCCADef.h"
30 : #include "AliHLTTPCDefinitions.h"
31 : #include "AliHLTTPCCATrackConvertor.h"
32 : #include "AliHLTTPCCASliceOutput.h"
33 : #include "AliHLTTPCCAParam.h"
34 :
35 : #include "AliExternalTrackParam.h"
36 : #include "AliCDBEntry.h"
37 : #include "AliCDBManager.h"
38 : #include "TObjString.h"
39 : #include "TObjArray.h"
40 : #include "AliHLTExternalTrackParam.h"
41 :
42 : #include <climits>
43 : #include <cstdlib>
44 : #include <cerrno>
45 :
46 : using namespace std;
47 :
48 :
49 : // ROOT macro for the implementation of ROOT specific class methods
50 6 : ClassImp( AliHLTTPCCATrackerOutputConverter )
51 :
52 :
53 3 : AliHLTTPCCATrackerOutputConverter::AliHLTTPCCATrackerOutputConverter()
54 3 : : fBenchmark("TPCCATrackerOutputConverter")
55 15 : {
56 : // see header file for class documentation
57 6 : }
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 546 : return "TPCCATrackerOutputConverter";
66 : }
67 :
68 : void AliHLTTPCCATrackerOutputConverter::GetInputDataTypes( AliHLTComponentDataTypeList &list )
69 : {
70 : // see header file for class documentation
71 0 : list.clear();
72 0 : list.push_back( AliHLTTPCCADefinitions::fgkTrackletsDataType );
73 0 : }
74 :
75 : AliHLTComponentDataType AliHLTTPCCATrackerOutputConverter::GetOutputDataType()
76 : {
77 : // see header file for class documentation
78 0 : 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 0 : constBase = 0;
86 0 : inputMultiplier = 1.0;
87 0 : }
88 :
89 : AliHLTComponent *AliHLTTPCCATrackerOutputConverter::Spawn()
90 : {
91 : // see header file for class documentation
92 0 : return new AliHLTTPCCATrackerOutputConverter;
93 0 : }
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 0 : fBenchmark.Reset();
102 0 : fBenchmark.SetTimer(0,"total");
103 0 : }
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 0 : if ( !arguments ) return iResult;
111 :
112 0 : TString allArgs = arguments;
113 0 : TString argument;
114 : int bMissingParam = 0;
115 :
116 0 : TObjArray* pTokens = allArgs.Tokenize( " " );
117 :
118 0 : int nArgs = pTokens ? pTokens->GetEntries() : 0;
119 :
120 0 : for ( int i = 0; i < nArgs; i++ ) {
121 0 : argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
122 0 : if ( argument.IsNull() ) continue;
123 :
124 0 : HLTError( "Unknown option \"%s\"", argument.Data() );
125 : iResult = -EINVAL;
126 0 : }
127 0 : delete pTokens;
128 :
129 0 : if ( bMissingParam ) {
130 0 : HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
131 : iResult = -EINVAL;
132 0 : }
133 :
134 : return iResult;
135 0 : }
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 0 : if ( !cdbEntry ) {
145 : cdbEntry = "HLT/ConfigTPC/TPCCAGlobalMerger";
146 : defaultNotify = " (default)";
147 : chainId = 0;
148 0 : }
149 :
150 0 : HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
151 0 : AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
152 :
153 0 : if ( !pEntry ) {
154 0 : HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
155 0 : return -EINVAL;
156 : }
157 :
158 0 : TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
159 :
160 0 : if ( !pString ) {
161 0 : HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
162 0 : return -EINVAL;
163 : }
164 :
165 0 : HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
166 :
167 0 : return ReadConfigurationString( pString->GetString().Data() );
168 0 : }
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 0 : SetDefaultConfiguration();
181 :
182 : //* read the default CDB entry
183 :
184 0 : int iResult1 = ReadCDBEntry( NULL, chainId );
185 :
186 :
187 : //* read the actual CDB entry if required
188 :
189 0 : int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
190 :
191 : //* read extra parameters from input (if they are)
192 :
193 : int iResult3 = 0;
194 :
195 0 : if ( commandLine && commandLine[0] != '\0' ) {
196 0 : HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
197 0 : iResult3 = ReadConfigurationString( commandLine );
198 0 : }
199 :
200 0 : 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 0 : TString arguments = "";
211 0 : for ( int i = 0; i < argc; i++ ) {
212 0 : if ( !arguments.IsNull() ) arguments += " ";
213 0 : arguments += argv[i];
214 : }
215 :
216 0 : return Configure( NULL, NULL, arguments.Data() );
217 0 : }
218 :
219 : int AliHLTTPCCATrackerOutputConverter::Reconfigure( const char* cdbEntry, const char* chainId )
220 : {
221 : // Reconfigure the component from OCDB
222 :
223 0 : return Configure( cdbEntry, chainId, NULL );
224 : }
225 :
226 :
227 :
228 : int AliHLTTPCCATrackerOutputConverter::DoDeinit()
229 : {
230 : // see header file for class documentation
231 0 : 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 0 : unsigned int maxBufferSize = size;
241 :
242 0 : size = 0;
243 :
244 0 : if ( !outputPtr ) {
245 0 : return -ENOSPC;
246 : }
247 0 : if ( !IsDataEvent() ) {
248 0 : return 0;
249 : }
250 0 : fBenchmark.StartNewEvent();
251 0 : fBenchmark.Start(0);
252 :
253 0 : const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt;
254 0 : for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) {
255 0 : if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) {
256 : continue;
257 : }
258 :
259 0 : fBenchmark.AddInput(block->fSize);
260 :
261 0 : int slice = AliHLTTPCDefinitions::GetMinSliceNr( *block );
262 0 : if ( slice < 0 || slice >= AliHLTTPCGeometry::GetNSlice() ) {
263 0 : 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 0 : continue;
268 : }
269 :
270 0 : if ( slice != AliHLTTPCDefinitions::GetMaxSliceNr( *block ) ) {
271 : // the code was not written for/ never used with multiple slices in one data block/ specification
272 0 : 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 0 : const AliHLTTPCCASliceOutput &sliceOut = *(reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr ));
278 0 : const AliHLTTPCCASliceOutTrack *sliceTr = sliceOut.GetFirstTrack();
279 :
280 : // Output block
281 :
282 : unsigned int blockSize = 0;
283 0 : AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
284 0 : AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
285 0 : blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr );
286 0 : outPtr->fCount = 0;
287 0 : AliHLTTPCCAParam sliceParam;
288 :
289 0 : for ( int itr = 0; itr < sliceOut.NTracks(); itr++ ) {
290 :
291 0 : int nClu = sliceTr->NClusters();
292 :
293 0 : unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClu * sizeof( unsigned int );
294 :
295 0 : if ( size + blockSize + dSize > maxBufferSize ) {
296 0 : HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, blockSize );
297 : iResult = -ENOSPC;
298 0 : break;
299 : }
300 :
301 : // first convert to AliExternalTrackParam
302 :
303 0 : AliHLTTPCCATrackParam t0;
304 0 : t0.InitParam();
305 0 : t0.SetParam(sliceTr->Param());
306 :
307 0 : AliExternalTrackParam tp;
308 0 : AliHLTTPCCATrackConvertor::GetExtParam( t0, tp, sliceParam.Alpha( slice ) );
309 :
310 : // normalize the angle to +-Pi
311 :
312 0 : currOutTrack->fAlpha = tp.GetAlpha() - CAMath::Nint(tp.GetAlpha()/CAMath::TwoPi())*CAMath::TwoPi();
313 0 : currOutTrack->fX = tp.GetX();
314 0 : currOutTrack->fY = tp.GetY();
315 0 : currOutTrack->fZ = tp.GetZ();
316 0 : currOutTrack->fq1Pt = tp.GetSigned1Pt();
317 0 : currOutTrack->fSinPsi = tp.GetSnp();
318 0 : currOutTrack->fTgl = tp.GetTgl();
319 0 : for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
320 0 : currOutTrack->fTrackID = itr;
321 0 : currOutTrack->fFlags = 0;
322 0 : currOutTrack->fNPoints = nClu;
323 0 : for( int i = 0; i< nClu; i++ ) {
324 0 : currOutTrack->fPointIDs[i] = sliceTr->Cluster( i ).GetId();
325 0 : if( i == nClu-1 ){
326 0 : currOutTrack->fLastX = sliceTr->Cluster( i ).GetX();
327 0 : currOutTrack->fLastY = sliceTr->Cluster( i ).GetY();
328 0 : currOutTrack->fLastZ = sliceTr->Cluster( i ).GetZ();
329 0 : }
330 : }
331 0 : currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
332 0 : blockSize += dSize;
333 0 : outPtr->fCount++;
334 0 : sliceTr = sliceTr->GetNextTrack();
335 0 : }
336 :
337 0 : AliHLTComponentBlockData resultData;
338 0 : FillBlockData( resultData );
339 0 : resultData.fOffset = size;
340 0 : resultData.fSize = blockSize;
341 0 : resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginTPC;
342 0 : resultData.fSpecification = block->fSpecification;
343 0 : outputBlocks.push_back( resultData );
344 0 : fBenchmark.AddOutput(resultData.fSize);
345 0 : size += resultData.fSize;
346 0 : }
347 :
348 0 : fBenchmark.Stop(0);
349 0 : HLTInfo( fBenchmark.GetStatistics() );
350 : return iResult;
351 0 : }
352 :
|