]>
Commit | Line | Data |
---|---|---|
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 | |
28 | using 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 | |
53 | ClassImp( AliHLTTPCCATrackerOutputConverter ) | |
54 | ||
55 | ||
56 | AliHLTTPCCATrackerOutputConverter::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 | ||
65 | const char *AliHLTTPCCATrackerOutputConverter::GetComponentID() | |
66 | { | |
67 | // see header file for class documentation | |
68 | return "TPCCATrackerOutputConverter"; | |
69 | } | |
70 | ||
71 | void AliHLTTPCCATrackerOutputConverter::GetInputDataTypes( AliHLTComponentDataTypeList &list ) | |
72 | { | |
73 | // see header file for class documentation | |
74 | list.clear(); | |
75 | list.push_back( AliHLTTPCCADefinitions::fgkTrackletsDataType ); | |
76 | } | |
77 | ||
78 | AliHLTComponentDataType AliHLTTPCCATrackerOutputConverter::GetOutputDataType() | |
79 | { | |
80 | // see header file for class documentation | |
81 | return kAliHLTDataTypeTrack|kAliHLTDataOriginTPC; | |
82 | } | |
83 | ||
84 | void 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 | ||
92 | AliHLTComponent *AliHLTTPCCATrackerOutputConverter::Spawn() | |
93 | { | |
94 | // see header file for class documentation | |
95 | return new AliHLTTPCCATrackerOutputConverter; | |
96 | } | |
97 | ||
98 | ||
99 | void 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 | ||
108 | int 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 | ||
141 | int 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 | ||
175 | int 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 | ||
ae481371 | 189 | |
190 | //* read the actual CDB entry if required | |
01c625bd | 191 | |
192 | int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0; | |
ae481371 | 193 | |
194 | //* read extra parameters from input (if they are) | |
195 | ||
01c625bd | 196 | int iResult3 = 0; |
ae481371 | 197 | |
198 | if ( commandLine && commandLine[0] != '\0' ) { | |
199 | HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine ); | |
01c625bd | 200 | iResult3 = ReadConfigurationString( commandLine ); |
ae481371 | 201 | } |
202 | ||
01c625bd | 203 | return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 ); |
ae481371 | 204 | } |
205 | ||
206 | ||
207 | ||
208 | ||
209 | int AliHLTTPCCATrackerOutputConverter::DoInit( int argc, const char** argv ) | |
210 | { | |
211 | // see header file for class documentation | |
212 | ||
213 | TString arguments = ""; | |
214 | for ( int i = 0; i < argc; i++ ) { | |
215 | if ( !arguments.IsNull() ) arguments += " "; | |
216 | arguments += argv[i]; | |
217 | } | |
218 | ||
219 | return Configure( NULL, NULL, arguments.Data() ); | |
220 | } | |
221 | ||
222 | int AliHLTTPCCATrackerOutputConverter::Reconfigure( const char* cdbEntry, const char* chainId ) | |
223 | { | |
224 | // Reconfigure the component from OCDB | |
225 | ||
226 | return Configure( cdbEntry, chainId, NULL ); | |
227 | } | |
228 | ||
229 | ||
230 | ||
231 | int AliHLTTPCCATrackerOutputConverter::DoDeinit() | |
232 | { | |
233 | // see header file for class documentation | |
234 | return 0; | |
235 | } | |
236 | ||
237 | int AliHLTTPCCATrackerOutputConverter::DoEvent( const AliHLTComponentEventData &evtData, | |
238 | const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/, | |
239 | AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks ) | |
240 | { | |
241 | // see header file for class documentation | |
242 | int iResult = 0; | |
243 | unsigned int maxBufferSize = size; | |
244 | ||
245 | size = 0; | |
246 | ||
247 | if ( !outputPtr ) { | |
248 | return -ENOSPC; | |
249 | } | |
250 | if ( !IsDataEvent() ) { | |
251 | return 0; | |
252 | } | |
253 | fBenchmark.StartNewEvent(); | |
254 | fBenchmark.Start(0); | |
255 | ||
256 | const AliHLTComponentBlockData *const blocksEnd = blocks + evtData.fBlockCnt; | |
257 | for ( const AliHLTComponentBlockData *block = blocks; block < blocksEnd; ++block ) { | |
258 | if ( block->fDataType != AliHLTTPCCADefinitions::fgkTrackletsDataType ) { | |
259 | continue; | |
260 | } | |
261 | ||
262 | fBenchmark.AddInput(block->fSize); | |
263 | ||
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 | |
269 | iResult = -EBADF; | |
270 | continue; | |
271 | } | |
272 | ||
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() ); | |
277 | } | |
278 | ||
279 | ||
280 | const AliHLTTPCCASliceOutput &sliceOut = *(reinterpret_cast<AliHLTTPCCASliceOutput *>( block->fPtr )); | |
281 | const AliHLTTPCCASliceOutTrack *sliceTr = sliceOut.GetFirstTrack(); | |
282 | ||
283 | // Output block | |
284 | ||
285 | unsigned int blockSize = 0; | |
286 | AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size ); | |
287 | AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets; | |
288 | blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr ); | |
289 | outPtr->fCount = 0; | |
290 | AliHLTTPCCAParam sliceParam; | |
291 | ||
292 | for ( int itr = 0; itr < sliceOut.NTracks(); itr++ ) { | |
293 | ||
294 | int nClu = sliceTr->NClusters(); | |
295 | ||
296 | unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClu * sizeof( unsigned int ); | |
297 | ||
298 | if ( size + blockSize + dSize > maxBufferSize ) { | |
299 | HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, blockSize ); | |
300 | iResult = -ENOSPC; | |
301 | break; | |
302 | } | |
303 | ||
304 | // first convert to AliExternalTrackParam | |
305 | ||
306 | AliHLTTPCCATrackParam t0; | |
307 | t0.InitParam(); | |
308 | t0.SetParam(sliceTr->Param()); | |
309 | ||
310 | AliExternalTrackParam tp; | |
311 | AliHLTTPCCATrackConvertor::GetExtParam( t0, tp, sliceParam.Alpha( slice ) ); | |
312 | ||
313 | // normalize the angle to +-Pi | |
314 | ||
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++ ) { | |
6d869045 | 327 | currOutTrack->fPointIDs[i] = sliceTr->Cluster( i ).GetId(); |
ae481371 | 328 | if( i == nClu-1 ){ |
6d869045 | 329 | currOutTrack->fLastX = sliceTr->Cluster( i ).GetX(); |
330 | currOutTrack->fLastY = sliceTr->Cluster( i ).GetY(); | |
331 | currOutTrack->fLastZ = sliceTr->Cluster( i ).GetZ(); | |
ae481371 | 332 | } |
333 | } | |
334 | currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize ); | |
335 | blockSize += dSize; | |
336 | outPtr->fCount++; | |
337 | sliceTr = sliceTr->GetNextTrack(); | |
338 | } | |
339 | ||
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; | |
349 | } | |
350 | ||
351 | fBenchmark.Stop(0); | |
352 | HLTInfo( fBenchmark.GetStatistics() ); | |
353 | return iResult; | |
354 | } | |
355 |