]>
Commit | Line | Data |
---|---|---|
7a436c89 | 1 | // $Id$ |
2 | // splitted from AliHLTConfiguration.cxx,v 1.25 2007/10/12 13:24:47 | |
3 | /************************************************************************** | |
4 | * This file is property of and copyright by the ALICE HLT Project * | |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
6 | * * | |
7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * | |
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 | /** @file AliHLTTask.cxx | |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief Implementation of HLT tasks. | |
23 | */ | |
24 | ||
25 | // see header file for class documentation | |
26 | // or | |
27 | // refer to README to build package | |
28 | // or | |
29 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
30 | ||
31 | #if __GNUC__>= 3 | |
32 | using namespace std; | |
33 | #endif | |
34 | ||
35 | #include <cerrno> | |
b46ca65e | 36 | #include <cassert> |
7a436c89 | 37 | #include <iostream> |
38 | #include <string> | |
39 | #include "AliHLTTask.h" | |
40 | #include "AliHLTConfiguration.h" | |
41 | #include "AliHLTComponent.h" | |
42 | #include "AliHLTComponentHandler.h" | |
43 | #include "TList.h" | |
44 | ||
45 | /** ROOT macro for the implementation of ROOT specific class methods */ | |
46 | ClassImp(AliHLTTask) | |
47 | ||
48 | AliHLTTask::AliHLTTask() | |
49 | : | |
50 | fpConfiguration(NULL), | |
51 | fpComponent(NULL), | |
52 | fpDataBuffer(NULL), | |
53 | fListTargets(), | |
54 | fListDependencies(), | |
55 | fBlockDataArray() | |
56 | { | |
57 | // see header file for class documentation | |
58 | // or | |
59 | // refer to README to build package | |
60 | // or | |
61 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
62 | } | |
63 | ||
64 | AliHLTTask::AliHLTTask(AliHLTConfiguration* pConf) | |
65 | : | |
66 | fpConfiguration(pConf), | |
67 | fpComponent(NULL), | |
68 | fpDataBuffer(NULL), | |
69 | fListTargets(), | |
70 | fListDependencies(), | |
71 | fBlockDataArray() | |
72 | { | |
73 | // see header file for function documentation | |
74 | } | |
75 | ||
76 | AliHLTTask::~AliHLTTask() | |
77 | { | |
78 | // see header file for function documentation | |
79 | TObjLink* lnk=fListDependencies.FirstLink(); | |
80 | ||
81 | while (lnk!=NULL) { | |
82 | AliHLTTask* pTask=(AliHLTTask*)lnk->GetObject(); | |
83 | pTask->UnsetTarget(this); | |
84 | lnk=lnk->Next(); | |
85 | } | |
86 | lnk=fListTargets.FirstLink(); | |
87 | ||
88 | while (lnk!=NULL) { | |
89 | AliHLTTask* pTask=(AliHLTTask*)lnk->GetObject(); | |
90 | pTask->UnsetDependency(this); | |
91 | lnk=lnk->Next(); | |
92 | } | |
93 | ||
94 | if (fpComponent) delete fpComponent; | |
95 | fpComponent=NULL; | |
96 | } | |
97 | ||
98 | int AliHLTTask::Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH) | |
99 | { | |
100 | // see header file for function documentation | |
101 | int iResult=0; | |
102 | if (fpConfiguration!=NULL && pConf!=NULL && fpConfiguration!=pConf) { | |
103 | HLTWarning("overriding existing reference to configuration object %p (%s) by %p", | |
104 | fpConfiguration, GetName(), pConf); | |
105 | } | |
106 | if (pConf!=NULL) fpConfiguration=pConf; | |
107 | if (fpConfiguration) { | |
108 | if (pCH) { | |
109 | int argc=0; | |
110 | const char** argv=NULL; | |
111 | if ((iResult=fpConfiguration->GetArguments(&argv))>=0) { | |
112 | argc=iResult; // just to make it clear | |
113 | // TODO: we have to think about the optional environment parameter, | |
114 | // currently just set to NULL. | |
115 | iResult=pCH->CreateComponent(fpConfiguration->GetComponentID(), NULL, argc, argv, fpComponent); | |
116 | if (fpComponent || iResult<=0) { | |
117 | //HLTDebug("component %s (%p) created", fpComponent->GetComponentID(), fpComponent); | |
118 | } else { | |
e642a402 | 119 | //HLTError("can not find component \"%s\" (%d)", fpConfiguration->GetComponentID(), iResult); |
7a436c89 | 120 | } |
121 | } else { | |
122 | HLTError("can not get argument list for configuration %s (%s)", fpConfiguration->GetName(), fpConfiguration->GetComponentID()); | |
123 | iResult=-EINVAL; | |
124 | } | |
125 | } else { | |
126 | HLTError("component handler instance needed for task initialization"); | |
127 | iResult=-EINVAL; | |
128 | } | |
129 | } else { | |
130 | HLTError("configuration object instance needed for task initialization"); | |
131 | iResult=-EINVAL; | |
132 | } | |
133 | return iResult; | |
134 | } | |
135 | ||
136 | int AliHLTTask::Deinit() | |
137 | { | |
138 | // see header file for function documentation | |
139 | int iResult=0; | |
140 | AliHLTComponent* pComponent=GetComponent(); | |
141 | fpComponent=NULL; | |
142 | if (pComponent) { | |
143 | //HLTDebug("delete component %s (%p)", pComponent->GetComponentID(), pComponent); | |
144 | pComponent->Deinit(); | |
145 | delete pComponent; | |
146 | } else { | |
147 | HLTWarning("task %s (%p) doesn't seem to be in initialized", GetName(), this); | |
148 | } | |
149 | return iResult; | |
150 | } | |
151 | ||
152 | const char *AliHLTTask::GetName() const | |
153 | { | |
154 | // see header file for function documentation | |
155 | if (fpConfiguration) | |
156 | return fpConfiguration->GetName(); | |
157 | return TObject::GetName(); | |
158 | } | |
159 | ||
160 | AliHLTConfiguration* AliHLTTask::GetConf() const | |
161 | { | |
162 | // see header file for function documentation | |
163 | return fpConfiguration; | |
164 | } | |
165 | ||
166 | AliHLTComponent* AliHLTTask::GetComponent() const | |
167 | { | |
168 | // see header file for function documentation | |
169 | return fpComponent; | |
170 | } | |
171 | ||
172 | AliHLTTask* AliHLTTask::FindDependency(const char* id) | |
173 | { | |
174 | // see header file for function documentation | |
175 | AliHLTTask* pTask=NULL; | |
176 | if (id) { | |
177 | pTask=(AliHLTTask*)fListDependencies.FindObject(id); | |
178 | } | |
179 | return pTask; | |
180 | } | |
181 | ||
182 | int AliHLTTask::FollowDependency(const char* id, TList* pTgtList) | |
183 | { | |
184 | // see header file for function documentation | |
185 | int iResult=0; | |
186 | if (id) { | |
187 | AliHLTTask* pDep=NULL; | |
188 | if ((pDep=(AliHLTTask*)fListDependencies.FindObject(id))!=NULL) { | |
189 | if (pTgtList) pTgtList->Add(pDep); | |
190 | iResult++; | |
191 | } else { | |
192 | TObjLink* lnk=fListDependencies.FirstLink(); | |
193 | while (lnk && iResult==0) { | |
194 | pDep=(AliHLTTask*)lnk->GetObject(); | |
195 | if (pDep) { | |
196 | if ((iResult=pDep->FollowDependency(id, pTgtList))>0) { | |
197 | if (pTgtList) pTgtList->AddFirst(pDep); | |
198 | iResult++; | |
199 | } | |
200 | } else { | |
201 | iResult=-EFAULT; | |
202 | } | |
203 | lnk=lnk->Next(); | |
204 | } | |
205 | } | |
206 | } else { | |
207 | iResult=-EINVAL; | |
208 | } | |
209 | return iResult; | |
210 | } | |
211 | ||
212 | void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration) | |
213 | { | |
214 | // see header file for function documentation | |
215 | HLTLogKeyword("task dependencies"); | |
216 | int iResult=0; | |
217 | TList tgtList; | |
218 | if (bFromConfiguration) { | |
219 | if (fpConfiguration) | |
220 | iResult=fpConfiguration->FollowDependency(id, &tgtList); | |
221 | else | |
222 | iResult=-EFAULT; | |
223 | } else | |
224 | iResult=FollowDependency(id, &tgtList); | |
225 | if (iResult>0) { | |
226 | HLTMessage(" task \"%s\": dependency level %d ", GetName(), iResult); | |
227 | TObjLink* lnk=tgtList.FirstLink(); | |
228 | int i=iResult; | |
229 | char* pSpace = new char[iResult+1]; | |
230 | if (pSpace) { | |
231 | memset(pSpace, 32, iResult); | |
232 | pSpace[i]=0; | |
233 | while (lnk) { | |
234 | TObject* obj=lnk->GetObject(); | |
235 | HLTMessage(" %s^-- %s ", &pSpace[i--], obj->GetName()); | |
236 | lnk=lnk->Next(); | |
237 | } | |
238 | delete [] pSpace; | |
239 | } else { | |
240 | iResult=-ENOMEM; | |
241 | } | |
242 | } | |
243 | } | |
244 | ||
245 | int AliHLTTask::SetDependency(AliHLTTask* pDep) | |
246 | { | |
247 | // see header file for function documentation | |
248 | int iResult=0; | |
249 | if (pDep) { | |
250 | if (FindDependency(pDep->GetName())==NULL) { | |
251 | fListDependencies.Add(pDep); | |
252 | } else { | |
253 | iResult=-EEXIST; | |
254 | } | |
255 | } else { | |
256 | iResult=-EINVAL; | |
257 | } | |
258 | return iResult; | |
259 | } | |
260 | ||
261 | int AliHLTTask::UnsetDependency(AliHLTTask* pDep) | |
262 | { | |
263 | // see header file for function documentation | |
264 | fListDependencies.Remove(pDep); | |
265 | if (fpConfiguration) { | |
266 | fpConfiguration->InvalidateSources(); | |
267 | } | |
268 | return 0; | |
269 | } | |
270 | ||
271 | int AliHLTTask::CheckDependencies() | |
272 | { | |
273 | // see header file for function documentation | |
274 | int iResult=0; | |
275 | AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource(); | |
276 | while (pSrc) { | |
277 | if (FindDependency(pSrc->GetName())==NULL) { | |
278 | //HLTDebug("dependency \"%s\" unresolved", pSrc->GetName()); | |
279 | iResult++; | |
280 | } | |
281 | pSrc=fpConfiguration->GetNextSource(); | |
282 | } | |
283 | return iResult; | |
284 | } | |
285 | ||
286 | ||
287 | int AliHLTTask::Depends(AliHLTTask* pTask) | |
288 | { | |
289 | // see header file for function documentation | |
290 | int iResult=0; | |
291 | if (pTask) { | |
292 | if (fpConfiguration) { | |
293 | iResult=fpConfiguration->GetSource(pTask->GetName())!=NULL; | |
294 | if (iResult>0) { | |
295 | //HLTDebug("task \"%s\" depends on \"%s\"", GetName(), pTask->GetName()); | |
296 | } else { | |
297 | //HLTDebug("task \"%s\" independend of \"%s\"", GetName(), pTask->GetName()); | |
298 | } | |
299 | } else { | |
300 | iResult=-EFAULT; | |
301 | } | |
302 | } else { | |
303 | iResult=-EINVAL; | |
304 | } | |
305 | return iResult; | |
306 | } | |
307 | ||
308 | AliHLTTask* AliHLTTask::FindTarget(const char* id) | |
309 | { | |
310 | // see header file for function documentation | |
311 | AliHLTTask* pTask=NULL; | |
312 | if (id) { | |
313 | pTask=(AliHLTTask*)fListTargets.FindObject(id); | |
314 | } | |
315 | return pTask; | |
316 | } | |
317 | ||
318 | int AliHLTTask::SetTarget(AliHLTTask* pTgt) | |
319 | { | |
320 | // see header file for function documentation | |
321 | int iResult=0; | |
322 | if (pTgt) { | |
323 | if (FindTarget(pTgt->GetName())==NULL) { | |
324 | fListTargets.Add(pTgt); | |
325 | } else { | |
326 | iResult=-EEXIST; | |
327 | } | |
328 | } else { | |
329 | iResult=-EINVAL; | |
330 | } | |
331 | return iResult; | |
332 | } | |
333 | ||
334 | int AliHLTTask::UnsetTarget(AliHLTTask* pTarget) | |
335 | { | |
336 | // see header file for function documentation | |
337 | fListTargets.Remove(pTarget); | |
338 | return 0; | |
339 | } | |
340 | ||
341 | int AliHLTTask::StartRun() | |
342 | { | |
343 | // see header file for function documentation | |
344 | int iResult=0; | |
345 | int iNofInputDataBlocks=0; | |
346 | AliHLTComponent* pComponent=GetComponent(); | |
347 | if (pComponent) { | |
348 | // determine the number of input data blocks provided from the source tasks | |
f7561f8d | 349 | { // set scope for lnk as a local variable |
7a436c89 | 350 | TObjLink* lnk=fListDependencies.FirstLink(); |
351 | while (lnk && iResult>=0) { | |
352 | AliHLTTask* pSrcTask=(AliHLTTask*)lnk->GetObject(); | |
353 | if (pSrcTask) { | |
354 | if ((iResult=pSrcTask->GetNofMatchingDataTypes(this))>0) { | |
355 | iNofInputDataBlocks+=iResult; | |
356 | } else if (iResult==0) { | |
357 | HLTWarning("source task %s (%p) does not provide any matching data type for task %s (%p)", pSrcTask->GetName(), pSrcTask, GetName(), this); | |
358 | } else { | |
359 | HLTError("task %s (%p): error getting matching data types for source task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask); | |
360 | iResult=-EFAULT; | |
361 | } | |
362 | } | |
363 | lnk=lnk->Next(); | |
364 | } | |
f7561f8d | 365 | } |
7a436c89 | 366 | if (iResult>=0) { |
367 | if (fBlockDataArray.size()>0) { | |
368 | HLTWarning("block data array for task %s (%p) was not cleaned", GetName(), this); | |
457ec821 | 369 | fBlockDataArray.clear(); |
7a436c89 | 370 | } |
371 | ||
372 | // component init | |
373 | // the initialization of the component is done by the ComponentHandler after creation | |
374 | // of the component. | |
375 | //iResult=Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv ); | |
376 | ||
7a436c89 | 377 | // allocate the data buffer, which controls the output buffer and subscriptions |
378 | if (iResult>=0) { | |
379 | fpDataBuffer=new AliHLTDataBuffer; | |
380 | if (fpDataBuffer!=NULL) { | |
dba03d72 | 381 | fpDataBuffer->SetLocalLoggingLevel(GetLocalLoggingLevel()); |
7a436c89 | 382 | HLTDebug("created data buffer %p for task %s (%p)", fpDataBuffer, GetName(), this); |
383 | TObjLink* lnk=fListTargets.FirstLink(); | |
384 | while (lnk && iResult>=0) { | |
385 | AliHLTTask* pTgtTask=(AliHLTTask*)lnk->GetObject(); | |
386 | if (pTgtTask) { | |
387 | if ((iResult=fpDataBuffer->SetConsumer(pTgtTask->GetComponent()))>=0) { | |
388 | } | |
389 | } else { | |
390 | break; | |
391 | iResult=-EFAULT; | |
392 | } | |
393 | lnk=lnk->Next(); | |
394 | } | |
395 | } else { | |
396 | HLTFatal("can not create data buffer object, memory allocation failed"); | |
397 | iResult=-ENOMEM; | |
398 | } | |
399 | } | |
400 | } | |
457ec821 | 401 | if (iResult>=0) { |
402 | // send the SOR event | |
403 | ||
404 | } | |
7a436c89 | 405 | } else { |
406 | HLTError("task %s (%p) does not have a component", GetName(), this); | |
407 | iResult=-EFAULT; | |
408 | } | |
409 | return iResult; | |
410 | } | |
411 | ||
412 | int AliHLTTask::EndRun() | |
413 | { | |
414 | // see header file for function documentation | |
415 | int iResult=0; | |
416 | if (fBlockDataArray.size()>0) { | |
457ec821 | 417 | fBlockDataArray.clear(); |
7a436c89 | 418 | } |
419 | if (fpDataBuffer) { | |
420 | AliHLTDataBuffer* pBuffer=fpDataBuffer; | |
421 | fpDataBuffer=NULL; | |
422 | delete pBuffer; | |
423 | } | |
424 | return iResult; | |
425 | } | |
426 | ||
427 | int AliHLTTask::ProcessTask(Int_t eventNo) | |
428 | { | |
429 | // see header file for function documentation | |
430 | int iResult=0; | |
431 | AliHLTComponent* pComponent=GetComponent(); | |
432 | if (pComponent && fpDataBuffer) { | |
433 | HLTDebug("Processing task %s (%p) fpDataBuffer %p", GetName(), this, fpDataBuffer); | |
434 | fpDataBuffer->Reset(); | |
435 | int iSourceDataBlock=0; | |
436 | int iInputDataVolume=0; | |
437 | ||
438 | AliHLTTask* pSrcTask=NULL; | |
b46ca65e | 439 | AliHLTTaskPList subscribedTaskList; |
7a436c89 | 440 | TObjLink* lnk=fListDependencies.FirstLink(); |
441 | ||
457ec821 | 442 | // instances of SOR and EOR events to be kept |
443 | int iSOR=-1; | |
444 | int iEOR=-1; | |
445 | ||
7a436c89 | 446 | // subscribe to all source tasks |
457ec821 | 447 | fBlockDataArray.clear(); |
7a436c89 | 448 | while (lnk && iResult>=0) { |
449 | pSrcTask=(AliHLTTask*)lnk->GetObject(); | |
450 | if (pSrcTask) { | |
451 | int iMatchingDB=pSrcTask->GetNofMatchingDataBlocks(this); | |
457ec821 | 452 | if (iMatchingDB<0) { |
453 | HLTError("task %s (%p): error getting no of matching data blocks from task %s (%p), error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iMatchingDB); | |
454 | iResult=iMatchingDB; | |
455 | break; | |
456 | } else if (iMatchingDB==0) { | |
457 | HLTDebug("source task %s (%p) does not provide any matching data type for task %s (%p)", pSrcTask->GetName(), pSrcTask, GetName(), this); | |
7a436c89 | 458 | } |
457ec821 | 459 | if ((iResult=pSrcTask->Subscribe(this, fBlockDataArray))>=0) { |
460 | iSOR=iEOR=-1; | |
461 | AliHLTComponentBlockDataList::iterator block=fBlockDataArray.begin(); | |
462 | for (int i=0; block!=fBlockDataArray.end(); i++) { | |
463 | bool bRemove=0; | |
464 | bRemove|=(*block).fDataType==kAliHLTDataTypeSOR && !(iSOR<0 && (iSOR=i)>=0); | |
465 | bRemove|=(*block).fDataType==kAliHLTDataTypeEOR && !(iEOR<0 && (iEOR=i)>=0); | |
466 | //HLTInfo("block %d, iSOR=%d iEOR=%d remove=%d", i, iSOR, iEOR, bRemove); | |
467 | if (i<iSourceDataBlock) { | |
468 | assert(!bRemove); | |
469 | } else if (bRemove) { | |
470 | HLTDebug("remove duplicated event %s (%d)", AliHLTComponent::DataType2Text((*block).fDataType).c_str(), i); | |
471 | pSrcTask->Release(&(*block), this); | |
472 | block=fBlockDataArray.erase(block); | |
473 | continue; | |
474 | } else { | |
475 | iInputDataVolume+=(*block).fSize; | |
7a436c89 | 476 | // put the source task as many times into the list as it provides data blocks |
477 | // makes the bookkeeping for the data release easier | |
b46ca65e | 478 | subscribedTaskList.push_back(pSrcTask); |
457ec821 | 479 | } |
480 | block++; | |
7a436c89 | 481 | } |
482 | HLTDebug("Task %s (%p) successfully subscribed to %d data block(s) of task %s (%p)", GetName(), this, iResult, pSrcTask->GetName(), pSrcTask); | |
457ec821 | 483 | iSourceDataBlock=fBlockDataArray.size(); |
7a436c89 | 484 | iResult=0; |
485 | } else { | |
486 | HLTError("Task %s (%p): subscription to task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iResult); | |
487 | iResult=-EFAULT; | |
488 | } | |
489 | } else { | |
490 | HLTFatal("fatal internal error in ROOT list handling"); | |
491 | iResult=-EFAULT; | |
492 | } | |
493 | lnk=lnk->Next(); | |
457ec821 | 494 | } |
7a436c89 | 495 | |
496 | // process the event | |
497 | int iNofTrial=0; // repeat processing if component returns -ENOSPC | |
498 | AliHLTUInt32_t size=0; | |
499 | if (iResult>=0) { | |
500 | do { | |
032c5e5e | 501 | long unsigned int iOutputDataSize=0; |
502 | AliHLTConfiguration* pConf=GetConf(); | |
503 | assert(pConf); | |
504 | // check if there was a buffer size specified, query output size | |
505 | // estimator from component otherwize | |
506 | if (pConf && pConf->GetOutputBufferSize()>=0) { | |
507 | iOutputDataSize=pConf->GetOutputBufferSize(); | |
508 | } else { | |
7a436c89 | 509 | long unsigned int iConstBase=0; |
510 | double fInputMultiplier=0; | |
511 | if (pComponent->GetComponentType()!=AliHLTComponent::kSink) | |
512 | pComponent->GetOutputDataSize(iConstBase, fInputMultiplier); | |
513 | if (fInputMultiplier<0) { | |
514 | HLTWarning("ignoring negative input multiplier"); | |
515 | fInputMultiplier=0; | |
516 | } | |
032c5e5e | 517 | iOutputDataSize=int(fInputMultiplier*iInputDataVolume) + iConstBase; |
7a436c89 | 518 | //HLTDebug("task %s: reqired output size %d", GetName(), iOutputDataSize); |
032c5e5e | 519 | } |
7a436c89 | 520 | if (iNofTrial>0) { |
521 | // dont process again if the buffer size is the same | |
522 | if (size==iOutputDataSize) break; | |
523 | HLTInfo("processing task %s again with buffer size %d", GetName(), iOutputDataSize); | |
524 | } | |
525 | AliHLTUInt8_t* pTgtBuffer=NULL; | |
526 | if (iOutputDataSize>0) pTgtBuffer=fpDataBuffer->GetTargetBuffer(iOutputDataSize); | |
527 | //HLTDebug("provided raw buffer %p", pTgtBuffer); | |
528 | AliHLTComponentEventData evtData; | |
529 | AliHLTComponent::FillEventData(evtData); | |
530 | evtData.fEventID=(AliHLTEventID_t)eventNo; | |
531 | evtData.fBlockCnt=iSourceDataBlock; | |
532 | AliHLTComponentTriggerData trigData; | |
533 | size=iOutputDataSize; | |
534 | AliHLTUInt32_t outputBlockCnt=0; | |
535 | AliHLTComponentBlockData* outputBlocks=NULL; | |
536 | AliHLTComponentEventDoneData* edd; | |
537 | if (pTgtBuffer!=NULL || iOutputDataSize==0) { | |
538 | iResult=pComponent->ProcessEvent(evtData, &fBlockDataArray[0], trigData, pTgtBuffer, size, outputBlockCnt, outputBlocks, edd); | |
539 | HLTDebug("task %s: component %s ProcessEvent finnished (%d): size=%d blocks=%d", GetName(), pComponent->GetComponentID(), iResult, size, outputBlockCnt); | |
b46ca65e | 540 | if (iResult>=0 && outputBlocks) { |
457ec821 | 541 | if (fListTargets.First()!=NULL) { |
542 | AliHLTComponentBlockDataList segments; | |
543 | for (AliHLTUInt32_t oblock=0; oblock<outputBlockCnt; oblock++) { | |
544 | AliHLTUInt32_t iblock=0; | |
545 | for (; iblock<evtData.fBlockCnt; iblock++) { | |
546 | if (fBlockDataArray[iblock].fPtr==outputBlocks[oblock].fPtr) { | |
547 | assert(subscribedTaskList[iblock]!=NULL); | |
548 | if (subscribedTaskList[iblock]==NULL) continue; | |
549 | HLTDebug("forward segment %d (source task %s %p) to data buffer %p", iblock, pSrcTask->GetName(), pSrcTask, fpDataBuffer); | |
550 | fpDataBuffer->Forward(subscribedTaskList[iblock], &fBlockDataArray[iblock]); | |
551 | subscribedTaskList[iblock]=NULL; // not to be released in the loop further down | |
552 | break; | |
553 | } | |
554 | } | |
555 | if (iblock==evtData.fBlockCnt) segments.push_back(outputBlocks[oblock]); | |
042b7a5d | 556 | } |
557 | if (pTgtBuffer && segments.size()>0) { | |
558 | iResult=fpDataBuffer->SetSegments(pTgtBuffer, &segments[0], segments.size()); | |
b46ca65e | 559 | } |
457ec821 | 560 | } else { |
561 | // no forwarding, actually we dont even need to keep the data, this is a | |
562 | // dead end (fListTargets empty) | |
563 | //iResult=fpDataBuffer->SetSegments(pTgtBuffer, outputBlocks, outputBlockCnt); | |
b46ca65e | 564 | } |
7a436c89 | 565 | delete [] outputBlocks; outputBlocks=NULL; outputBlockCnt=0; |
566 | } else { | |
567 | fpDataBuffer->Reset(); | |
568 | } | |
457ec821 | 569 | if (fListTargets.First()!=NULL) { |
570 | if (iSOR>=0 && subscribedTaskList[iSOR]!=NULL) { | |
571 | HLTDebug("forward SOR event segment %d (source task %s %p) to data buffer %p", iSOR, pSrcTask->GetName(), pSrcTask, fpDataBuffer); | |
572 | fpDataBuffer->Forward(subscribedTaskList[iSOR], &fBlockDataArray[iSOR]); | |
573 | subscribedTaskList[iSOR]=NULL; // not to be released in the loop further down | |
574 | } | |
575 | if (iEOR>=0 && subscribedTaskList[iEOR]!=NULL) { | |
576 | HLTDebug("forward EOR event (%s) segment %d (source task %s %p) to data buffer %p", AliHLTComponent::DataType2Text(fBlockDataArray[iEOR].fDataType).c_str(), iEOR, pSrcTask->GetName(), pSrcTask, fpDataBuffer); | |
577 | fpDataBuffer->Forward(subscribedTaskList[iEOR], &fBlockDataArray[iEOR]); | |
578 | subscribedTaskList[iEOR]=NULL; // not to be released in the loop further down | |
579 | } | |
580 | } | |
7a436c89 | 581 | } else { |
582 | HLTError("task %s: no target buffer available", GetName()); | |
583 | iResult=-EFAULT; | |
584 | } | |
585 | } while (iResult==-ENOSPC && iNofTrial++<1); | |
586 | } | |
587 | ||
588 | // now release all buffers which we have subscribed to | |
589 | iSourceDataBlock=0; | |
b46ca65e | 590 | AliHLTTaskPList::iterator element; |
591 | while ((element=subscribedTaskList.begin())!=subscribedTaskList.end()) { | |
592 | pSrcTask=*element; | |
7a436c89 | 593 | if (pSrcTask) { |
594 | int iTempRes=0; | |
595 | if ((iTempRes=pSrcTask->Release(&fBlockDataArray[iSourceDataBlock], this))>=0) { | |
596 | HLTDebug("Task %s (%p) successfully released segment of task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask); | |
597 | } else { | |
598 | HLTError("Task %s (%p): realease of task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iTempRes); | |
599 | } | |
7a436c89 | 600 | } |
b46ca65e | 601 | subscribedTaskList.erase(element); |
7a436c89 | 602 | iSourceDataBlock++; |
603 | } | |
b46ca65e | 604 | if (subscribedTaskList.size()>0) { |
7a436c89 | 605 | HLTError("task %s (%p): could not release all data buffers", GetName(), this); |
606 | } | |
607 | } else { | |
608 | HLTError("task %s (%p): internal failure (not initialized component %p, data buffer %p)", GetName(), this, fpComponent, fpDataBuffer); | |
609 | iResult=-EFAULT; | |
610 | } | |
611 | return iResult; | |
612 | } | |
613 | ||
614 | int AliHLTTask::GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask) const | |
615 | { | |
616 | // see header file for function documentation | |
617 | int iResult=0; | |
618 | if (pConsumerTask) { | |
619 | if (fpDataBuffer) { | |
620 | iResult=fpDataBuffer->FindMatchingDataBlocks(pConsumerTask->GetComponent(), NULL); | |
621 | } else { | |
622 | HLTFatal("internal data buffer missing"); | |
623 | iResult=-EFAULT; | |
624 | } | |
625 | } else { | |
626 | iResult=-EINVAL; | |
627 | } | |
628 | return iResult; | |
629 | } | |
630 | ||
631 | int AliHLTTask::GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask) const | |
632 | { | |
633 | // see header file for function documentation | |
634 | int iResult=0; | |
635 | if (pConsumerTask) { | |
636 | AliHLTComponent* pComponent=GetComponent(); | |
637 | if (!pComponent) { | |
638 | // init ? | |
639 | HLTError("component not initialized"); | |
640 | iResult=-EFAULT; | |
641 | } | |
642 | if (pComponent) { | |
643 | iResult=pComponent->FindMatchingDataTypes(pConsumerTask->GetComponent(), NULL); | |
644 | } else { | |
645 | HLTFatal("task initialization failed"); | |
646 | iResult=-EFAULT; | |
647 | } | |
648 | } else { | |
649 | iResult=-EINVAL; | |
650 | } | |
651 | return iResult; | |
652 | } | |
653 | ||
457ec821 | 654 | int AliHLTTask::Subscribe(const AliHLTTask* pConsumerTask, AliHLTComponentBlockDataList& blockDescList) |
7a436c89 | 655 | { |
656 | // see header file for function documentation | |
657 | int iResult=0; | |
658 | if (pConsumerTask) { | |
659 | if (fpDataBuffer) { | |
457ec821 | 660 | iResult=fpDataBuffer->Subscribe(pConsumerTask->GetComponent(), blockDescList); |
7a436c89 | 661 | } else { |
662 | HLTFatal("internal data buffer missing"); | |
663 | iResult=-EFAULT; | |
664 | } | |
665 | } else { | |
666 | iResult=-EINVAL; | |
667 | } | |
668 | return iResult; | |
669 | } | |
670 | ||
671 | int AliHLTTask::Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTTask* pConsumerTask) | |
672 | { | |
673 | // see header file for function documentation | |
674 | int iResult=0; | |
675 | if (pConsumerTask && pBlockDesc) { | |
676 | if (fpDataBuffer) { | |
b46ca65e | 677 | iResult=fpDataBuffer->Release(pBlockDesc, pConsumerTask->GetComponent(), this); |
7a436c89 | 678 | } else { |
679 | HLTFatal("internal data buffer missing"); | |
680 | iResult=-EFAULT; | |
681 | } | |
682 | } else { | |
683 | iResult=-EINVAL; | |
684 | } | |
685 | return iResult; | |
686 | } | |
687 | ||
688 | void AliHLTTask::PrintStatus() | |
689 | { | |
690 | // see header file for function documentation | |
691 | HLTLogKeyword("task properties"); | |
692 | AliHLTComponent* pComponent=GetComponent(); | |
693 | if (pComponent) { | |
694 | HLTMessage(" component: %s (%p)", pComponent->GetComponentID(), pComponent); | |
695 | } else { | |
696 | HLTMessage(" no component set!"); | |
697 | } | |
698 | if (fpConfiguration) { | |
699 | AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource(); | |
700 | while (pSrc) { | |
701 | const char* pQualifier="unresolved"; | |
702 | if (FindDependency(pSrc->GetName())) | |
703 | pQualifier="resolved"; | |
704 | HLTMessage(" source: %s (%s)", pSrc->GetName(), pQualifier); | |
705 | pSrc=fpConfiguration->GetNextSource(); | |
706 | } | |
707 | TObjLink* lnk = fListTargets.FirstLink(); | |
708 | while (lnk) { | |
709 | TObject *obj = lnk->GetObject(); | |
710 | HLTMessage(" target: %s", obj->GetName()); | |
711 | lnk = lnk->Next(); | |
712 | } | |
713 | } else { | |
714 | HLTMessage(" task \"%s\" not initialized", GetName()); | |
715 | } | |
716 | } |