]>
Commit | Line | Data |
---|---|---|
a6fb14f5 | 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 | // for The ALICE HLT Project. * | |
7 | // * | |
8 | // Permission to use, copy, modify and distribute this software and its * | |
9 | // documentation strictly for non-commercial purposes is hereby granted * | |
10 | // without fee, provided that the above copyright notice appears in all * | |
11 | // copies and that both the copyright notice and this permission notice * | |
12 | // appear in the supporting documentation. The authors make no claims * | |
13 | // about the suitability of this software for any purpose. It is * | |
14 | // provided "as is" without express or implied warranty. * | |
15 | // * | |
16 | //*************************************************************************** | |
17 | ||
18 | ||
19 | #if __GNUC__>= 3 | |
20 | using namespace std; | |
21 | #endif | |
22 | ||
23 | #include "AliHLTTPCTrackMCMarkerComponent.h" | |
24 | #include "AliHLTTPCTransform.h" | |
25 | #include "AliHLTTPCTrackSegmentData.h" | |
26 | #include "AliHLTTPCTrack.h" | |
27 | #include "AliHLTTPCTrackArray.h" | |
28 | #include "AliHLTTPCTrackletDataFormat.h" | |
29 | #include "AliHLTTPCCADef.h" | |
30 | #include "AliHLTTPCDefinitions.h" | |
a371a266 | 31 | #include "AliHLTTPCSpacePointData.h" |
a6fb14f5 | 32 | |
33 | #include "AliCDBEntry.h" | |
34 | #include "AliCDBManager.h" | |
35 | #include "TObjString.h" | |
36 | #include "TObjArray.h" | |
37 | #include "AliHLTExternalTrackParam.h" | |
38 | #include "AliHLTTrackMCLabel.h" | |
39 | #include "AliHLTTPCClusterFinder.h" | |
40 | #include <climits> | |
41 | #include <cstdlib> | |
42 | #include <cerrno> | |
43 | ||
44 | ||
45 | // ROOT macro for the implementation of ROOT specific class methods | |
46 | ClassImp( AliHLTTPCTrackMCMarkerComponent ) | |
47 | ||
48 | ||
49 | AliHLTTPCTrackMCMarkerComponent::AliHLTTPCTrackMCMarkerComponent() | |
50 | { | |
51 | // see header file for class documentation | |
8668fb4b | 52 | for( int i=0; i<36*6; i++ ){ |
53 | fClusterLabels[i] = 0; | |
54 | fNClusterLabels[i] = 0; | |
55 | } | |
a6fb14f5 | 56 | } |
57 | ||
58 | // Public functions to implement AliHLTComponent's interface. | |
59 | // These functions are required for the registration process | |
60 | ||
61 | const char *AliHLTTPCTrackMCMarkerComponent::GetComponentID() | |
62 | { | |
63 | // see header file for class documentation | |
64 | return "TPCTrackMCMarker"; | |
65 | } | |
66 | ||
67 | void AliHLTTPCTrackMCMarkerComponent::GetInputDataTypes( AliHLTComponentDataTypeList &list ) | |
68 | { | |
69 | // see header file for class documentation | |
70 | list.clear(); | |
71 | list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ); | |
72 | list.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo); | |
73 | } | |
74 | ||
75 | AliHLTComponentDataType AliHLTTPCTrackMCMarkerComponent::GetOutputDataType() | |
76 | { | |
77 | // see header file for class documentation | |
78 | return kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC; | |
79 | } | |
80 | ||
81 | void AliHLTTPCTrackMCMarkerComponent::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier ) | |
82 | { | |
83 | // see header file for class documentation | |
84 | constBase = 0; | |
85 | inputMultiplier = 1.0; | |
86 | } | |
87 | ||
88 | AliHLTComponent *AliHLTTPCTrackMCMarkerComponent::Spawn() | |
89 | { | |
90 | // see header file for class documentation | |
91 | return new AliHLTTPCTrackMCMarkerComponent; | |
92 | } | |
93 | ||
94 | ||
95 | ||
96 | ||
97 | void AliHLTTPCTrackMCMarkerComponent::SetDefaultConfiguration() | |
98 | { | |
99 | // Set default configuration for the CA merger component | |
100 | // Some parameters can be later overwritten from the OCDB | |
101 | } | |
102 | ||
103 | int AliHLTTPCTrackMCMarkerComponent::ReadConfigurationString( const char* arguments ) | |
104 | { | |
105 | // Set configuration parameters for the CA merger component from the string | |
106 | ||
107 | int iResult = 0; | |
108 | if ( !arguments ) return iResult; | |
109 | ||
110 | TString allArgs = arguments; | |
111 | TString argument; | |
112 | int bMissingParam = 0; | |
113 | ||
114 | TObjArray* pTokens = allArgs.Tokenize( " " ); | |
115 | ||
116 | int nArgs = pTokens ? pTokens->GetEntries() : 0; | |
117 | ||
118 | for ( int i = 0; i < nArgs; i++ ) { | |
119 | argument = ( ( TObjString* )pTokens->At( i ) )->GetString(); | |
120 | if ( argument.IsNull() ) continue; | |
121 | ||
a6fb14f5 | 122 | HLTError( "Unknown option \"%s\"", argument.Data() ); |
123 | iResult = -EINVAL; | |
124 | } | |
125 | delete pTokens; | |
126 | ||
127 | if ( bMissingParam ) { | |
128 | HLTError( "Specifier missed for parameter \"%s\"", argument.Data() ); | |
129 | iResult = -EINVAL; | |
130 | } | |
131 | ||
132 | return iResult; | |
133 | } | |
134 | ||
135 | ||
136 | int AliHLTTPCTrackMCMarkerComponent::ReadCDBEntry( const char* /*cdbEntry*/, const char* /*chainId*/ ) | |
137 | { | |
138 | // see header file for class documentation | |
139 | ||
140 | // no settings for a moment, no CDB path, threfore return | |
141 | ||
142 | return 0; | |
143 | /* | |
144 | const char* defaultNotify = ""; | |
145 | ||
146 | if ( !cdbEntry ) { | |
147 | cdbEntry = "HLT/ConfigTPC/TPCTrackMCMarker"; | |
148 | defaultNotify = " (default)"; | |
149 | chainId = 0; | |
150 | } | |
151 | ||
152 | HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" ); | |
153 | AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo()); | |
154 | ||
155 | if ( !pEntry ) { | |
156 | HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry ); | |
157 | return -EINVAL; | |
158 | } | |
159 | ||
160 | TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() ); | |
161 | ||
162 | if ( !pString ) { | |
163 | HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry ); | |
164 | return -EINVAL; | |
165 | } | |
166 | ||
167 | HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() ); | |
168 | ||
169 | return ReadConfigurationString( pString->GetString().Data() ); | |
170 | */ | |
171 | } | |
172 | ||
173 | ||
174 | ||
175 | int AliHLTTPCTrackMCMarkerComponent::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 | ||
189 | //* read the actual CDB entry if required | |
190 | ||
191 | int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0; | |
192 | ||
193 | //* read extra parameters from input (if they are) | |
194 | ||
195 | int iResult3 = 0; | |
196 | ||
197 | if ( commandLine && commandLine[0] != '\0' ) { | |
198 | HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine ); | |
199 | iResult3 = ReadConfigurationString( commandLine ); | |
200 | } | |
201 | ||
202 | return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 ); | |
203 | } | |
204 | ||
205 | ||
206 | ||
207 | ||
208 | int AliHLTTPCTrackMCMarkerComponent::DoInit( int argc, const char** argv ) | |
209 | { | |
210 | // see header file for class documentation | |
211 | ||
212 | TString arguments = ""; | |
213 | for ( int i = 0; i < argc; i++ ) { | |
214 | if ( !arguments.IsNull() ) arguments += " "; | |
215 | arguments += argv[i]; | |
216 | } | |
217 | ||
218 | return Configure( NULL, NULL, arguments.Data() ); | |
219 | } | |
220 | ||
221 | ||
222 | int AliHLTTPCTrackMCMarkerComponent::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 AliHLTTPCTrackMCMarkerComponent::DoDeinit() | |
232 | { | |
233 | // see header file for class documentation | |
234 | ||
235 | return 0; | |
236 | } | |
237 | ||
238 | Int_t AliHLTTPCTrackMCMarkerComponent::GetTrackMCLabel( unsigned int *hits, int nHits ) | |
239 | { | |
240 | // get MC label for the track | |
241 | ||
242 | Int_t mcLabel = -1; | |
243 | ||
244 | std::vector<int> labels; | |
245 | ||
246 | for( Int_t ih=0; ih<nHits; ih++){ | |
247 | UInt_t id = hits[ih]; | |
a371a266 | 248 | int iSlice = AliHLTTPCSpacePointData::GetSlice(id); |
249 | int iPatch = AliHLTTPCSpacePointData::GetPatch(id); | |
250 | int iCluster = AliHLTTPCSpacePointData::GetNumber(id); | |
8668fb4b | 251 | if( iSlice<0 || iSlice>=36 || iPatch<0 || iPatch>5 ){ |
a6fb14f5 | 252 | HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d", |
253 | iSlice, iPatch,iCluster ); | |
254 | continue; | |
255 | } | |
256 | AliHLTTPCClusterFinder::ClusterMCInfo *patchLabels = fClusterLabels[iSlice*6 + iPatch]; | |
257 | if( !patchLabels ) continue; | |
258 | if( iCluster >= fNClusterLabels[iSlice*6 + iPatch] ){ | |
259 | HLTError("TPC slice %d, patch %d: ClusterID==%d >= N MC labels==%d ", | |
260 | iSlice, iPatch,iCluster, fNClusterLabels[iSlice*6 + iPatch] ); | |
261 | continue; | |
262 | } | |
263 | AliHLTTPCClusterFinder::ClusterMCInfo &lab = patchLabels[iCluster]; | |
264 | if ( lab.fClusterID[0].fMCID >= 0 ) labels.push_back( lab.fClusterID[0].fMCID ); | |
265 | if ( lab.fClusterID[1].fMCID >= 0 ) labels.push_back( lab.fClusterID[1].fMCID ); | |
266 | if ( lab.fClusterID[2].fMCID >= 0 ) labels.push_back( lab.fClusterID[2].fMCID ); | |
267 | } | |
268 | ||
269 | std::sort( labels.begin(), labels.end() ); | |
270 | ||
271 | labels.push_back( -1 ); // put -1 to the end | |
272 | ||
273 | int labelMax = -1, labelCur = -1, nLabelsMax = 0, nLabelsCurr = 0; | |
274 | for ( unsigned int iLab = 0; iLab < labels.size(); iLab++ ) { | |
275 | if ( labels[iLab] != labelCur ) { | |
276 | if ( labelCur >= 0 && nLabelsMax< nLabelsCurr ) { | |
277 | nLabelsMax = nLabelsCurr; | |
278 | labelMax = labelCur; | |
279 | } | |
280 | labelCur = labels[iLab]; | |
281 | nLabelsCurr = 0; | |
282 | } | |
283 | nLabelsCurr++; | |
284 | } | |
285 | ||
286 | if( labelMax>=0 && nLabelsMax < 0.9 * nHits ) labelMax = -labelMax; | |
287 | ||
288 | mcLabel = labelMax; | |
289 | ||
290 | return mcLabel; | |
291 | } | |
292 | ||
293 | ||
294 | int AliHLTTPCTrackMCMarkerComponent::DoEvent( const AliHLTComponentEventData &evtData, | |
295 | const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/, | |
296 | AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks ) | |
297 | { | |
298 | // see header file for class documentation | |
299 | ||
300 | int iResult = 0; | |
301 | unsigned int maxBufferSize = size; | |
302 | ||
303 | size = 0; | |
304 | ||
305 | if ( !outputPtr ) { | |
306 | return -ENOSPC; | |
307 | } | |
308 | if ( !IsDataEvent() ) { | |
309 | return 0; | |
310 | } | |
311 | ||
312 | for( int i=0; i<36*6; i++ ){ | |
313 | fClusterLabels[i] = 0; | |
314 | fNClusterLabels[i] = 0; | |
315 | } | |
316 | ||
317 | int nBlocks = (int)evtData.fBlockCnt; | |
318 | ||
319 | int nInputMCLabels = 0; | |
320 | int nInputTracks = 0; | |
321 | ||
322 | // first read all the MC information | |
323 | for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) { | |
324 | const AliHLTComponentBlockData* iter = blocks+ndx; | |
325 | if(iter->fDataType == AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo ) { | |
326 | Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification); | |
327 | Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification); | |
328 | fClusterLabels[ slice*6 + patch] = (AliHLTTPCClusterFinder::ClusterMCInfo *)iter->fPtr; | |
329 | fNClusterLabels[ slice*6 + patch] = iter->fSize/sizeof(AliHLTTPCClusterFinder::ClusterMCInfo); | |
330 | nInputMCLabels+=fNClusterLabels[ slice*6 + patch]; | |
331 | } | |
332 | } | |
333 | ||
334 | // read tracks and write output | |
335 | ||
336 | ||
337 | unsigned int mySize = 0; | |
338 | ||
339 | AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr ); | |
340 | AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels; | |
341 | ||
342 | mySize = ( ( AliHLTUInt8_t * )currOutLabel ) - ( ( AliHLTUInt8_t * )outPtr ); | |
343 | ||
344 | outPtr->fCount = 0; | |
345 | ||
346 | for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) { | |
347 | const AliHLTComponentBlockData* iter = blocks+ndx; | |
348 | ||
349 | if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){ | |
350 | AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr; | |
351 | int nTracks = dataPtr->fCount; | |
352 | AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets; | |
353 | for( int itr=0; itr<nTracks; itr++ ){ | |
354 | nInputTracks++; | |
355 | Int_t mcLabel = GetTrackMCLabel( currTrack->fPointIDs, currTrack->fNPoints ); | |
356 | ||
357 | currOutLabel->fTrackID = currTrack->fTrackID; | |
358 | currOutLabel->fMCLabel = mcLabel; | |
359 | ||
360 | if ( mySize + sizeof(AliHLTTrackMCLabel) > maxBufferSize ) { | |
361 | HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d mc labels are not stored", maxBufferSize, mySize, nTracks - itr + 1 ); | |
362 | iResult = -ENOSPC; | |
363 | break; | |
364 | } | |
365 | mySize += sizeof(AliHLTTrackMCLabel); | |
366 | currOutLabel++; | |
367 | outPtr->fCount++; | |
368 | ||
369 | unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int ); | |
370 | currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + dSize ); | |
371 | } | |
372 | } | |
373 | } | |
374 | ||
375 | ||
376 | AliHLTComponentBlockData resultData; | |
377 | FillBlockData( resultData ); | |
378 | resultData.fOffset = 0; | |
379 | resultData.fSize = mySize; | |
380 | resultData.fDataType = kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC; | |
381 | resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 ); | |
382 | outputBlocks.push_back( resultData ); | |
383 | size = resultData.fSize; | |
384 | ||
385 | HLTInfo( "TrackMCMarker:: input %d labels, %d tracks, output %d labels", nInputMCLabels, nInputTracks,outPtr->fCount ); | |
386 | ||
387 | return iResult; | |
388 | } | |
389 |