]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTTask.cxx
Changes required to handle software triggers correctly in the global trigger component.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTTask.cxx
CommitLineData
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
32using namespace std;
33#endif
34
35#include <cerrno>
b46ca65e 36#include <cassert>
7a436c89 37#include <iostream>
38#include <string>
dd5b6088 39#include <ctime>
7a436c89 40#include "AliHLTTask.h"
41#include "AliHLTConfiguration.h"
38cbb439 42#include "AliHLTConfigurationHandler.h"
7a436c89 43#include "AliHLTComponent.h"
44#include "AliHLTComponentHandler.h"
45#include "TList.h"
46
47/** ROOT macro for the implementation of ROOT specific class methods */
48ClassImp(AliHLTTask)
49
50AliHLTTask::AliHLTTask()
51 :
52 fpConfiguration(NULL),
53 fpComponent(NULL),
54 fpDataBuffer(NULL),
55 fListTargets(),
56 fListDependencies(),
57 fBlockDataArray()
58{
59 // see header file for class documentation
60 // or
61 // refer to README to build package
62 // or
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
64}
65
66AliHLTTask::AliHLTTask(AliHLTConfiguration* pConf)
67 :
68 fpConfiguration(pConf),
69 fpComponent(NULL),
70 fpDataBuffer(NULL),
71 fListTargets(),
72 fListDependencies(),
73 fBlockDataArray()
74{
75 // see header file for function documentation
76}
77
78AliHLTTask::~AliHLTTask()
79{
80 // see header file for function documentation
81 TObjLink* lnk=fListDependencies.FirstLink();
82
83 while (lnk!=NULL) {
84 AliHLTTask* pTask=(AliHLTTask*)lnk->GetObject();
85 pTask->UnsetTarget(this);
86 lnk=lnk->Next();
87 }
88 lnk=fListTargets.FirstLink();
89
90 while (lnk!=NULL) {
91 AliHLTTask* pTask=(AliHLTTask*)lnk->GetObject();
92 pTask->UnsetDependency(this);
93 lnk=lnk->Next();
94 }
95
96 if (fpComponent) delete fpComponent;
97 fpComponent=NULL;
98}
99
100int AliHLTTask::Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH)
101{
102 // see header file for function documentation
103 int iResult=0;
104 if (fpConfiguration!=NULL && pConf!=NULL && fpConfiguration!=pConf) {
97d2b87a 105 HLTWarning("overriding existing reference to configuration object %p by %p",
106 fpConfiguration, pConf);
7a436c89 107 }
108 if (pConf!=NULL) fpConfiguration=pConf;
48abe484 109 iResult=CreateComponent(fpConfiguration, pCH, fpComponent);
110 if (iResult>=0) {
111 iResult=CustomInit(pCH);
112 }
113 return iResult;
114}
115
38cbb439 116int AliHLTTask::CreateComponent(AliHLTConfiguration* pConfiguration, AliHLTComponentHandler* pCH, AliHLTComponent*& pComponent) const
48abe484 117{
118 // see header file for class documentation
119 int iResult=0;
38cbb439 120 if (!pConfiguration) return -EINVAL;
121
122 const AliHLTConfiguration* pConf=AliHLTConfigurationHandler::FindSubstitution(*pConfiguration);
123 if (!pConf) pConf=pConfiguration;
48abe484 124 if (pConf) {
7a436c89 125 if (pCH) {
126 int argc=0;
127 const char** argv=NULL;
48abe484 128 if ((iResult=pConf->GetArguments(&argv))>=0) {
7a436c89 129 argc=iResult; // just to make it clear
130 // TODO: we have to think about the optional environment parameter,
48abe484 131 // currently just set to NULL.
132 iResult=pCH->CreateComponent(pConf->GetComponentID(), pComponent);
133 if (pComponent && iResult>=0) {
134 TString description;
135 description.Form("chainid=%s", GetName());
136 pComponent->SetComponentDescription(description.Data());
137 const AliHLTAnalysisEnvironment* pEnv=pCH->GetEnvironment();
138 if ((iResult=pComponent->Init(pEnv, NULL, argc, argv))>=0) {
139 //HLTDebug("component %s (%p) created", pComponent->GetComponentID(), pComponent);
140 } else {
141 HLTError("Initialization of component \"%s\" failed with error %d", pComponent->GetComponentID(), iResult);
142 }
7a436c89 143 } else {
48abe484 144 //HLTError("can not find component \"%s\" (%d)", pConf->GetComponentID(), iResult);
7a436c89 145 }
146 } else {
48abe484 147 HLTError("can not get argument list for configuration %s (%s)", pConf->GetName(), pConf->GetComponentID());
7a436c89 148 iResult=-EINVAL;
149 }
150 } else {
151 HLTError("component handler instance needed for task initialization");
152 iResult=-EINVAL;
153 }
154 } else {
155 HLTError("configuration object instance needed for task initialization");
156 iResult=-EINVAL;
157 }
158 return iResult;
159}
160
161int AliHLTTask::Deinit()
162{
163 // see header file for function documentation
164 int iResult=0;
7131ea63 165 CustomCleanup();
7a436c89 166 AliHLTComponent* pComponent=GetComponent();
167 fpComponent=NULL;
168 if (pComponent) {
169 //HLTDebug("delete component %s (%p)", pComponent->GetComponentID(), pComponent);
170 pComponent->Deinit();
171 delete pComponent;
172 } else {
97d2b87a 173 HLTWarning("task doesn't seem to be in initialized");
7a436c89 174 }
175 return iResult;
176}
177
178const char *AliHLTTask::GetName() const
179{
180 // see header file for function documentation
181 if (fpConfiguration)
182 return fpConfiguration->GetName();
183 return TObject::GetName();
184}
185
186AliHLTConfiguration* AliHLTTask::GetConf() const
187{
188 // see header file for function documentation
189 return fpConfiguration;
190}
191
192AliHLTComponent* AliHLTTask::GetComponent() const
193{
194 // see header file for function documentation
195 return fpComponent;
196}
197
198AliHLTTask* AliHLTTask::FindDependency(const char* id)
199{
200 // see header file for function documentation
201 AliHLTTask* pTask=NULL;
202 if (id) {
203 pTask=(AliHLTTask*)fListDependencies.FindObject(id);
204 }
205 return pTask;
206}
207
208int AliHLTTask::FollowDependency(const char* id, TList* pTgtList)
209{
210 // see header file for function documentation
211 int iResult=0;
212 if (id) {
213 AliHLTTask* pDep=NULL;
214 if ((pDep=(AliHLTTask*)fListDependencies.FindObject(id))!=NULL) {
215 if (pTgtList) pTgtList->Add(pDep);
216 iResult++;
217 } else {
218 TObjLink* lnk=fListDependencies.FirstLink();
219 while (lnk && iResult==0) {
220 pDep=(AliHLTTask*)lnk->GetObject();
221 if (pDep) {
222 if ((iResult=pDep->FollowDependency(id, pTgtList))>0) {
223 if (pTgtList) pTgtList->AddFirst(pDep);
224 iResult++;
225 }
226 } else {
227 iResult=-EFAULT;
228 }
229 lnk=lnk->Next();
230 }
231 }
232 } else {
233 iResult=-EINVAL;
234 }
235 return iResult;
236}
237
238void AliHLTTask::PrintDependencyTree(const char* id, int bFromConfiguration)
239{
240 // see header file for function documentation
241 HLTLogKeyword("task dependencies");
242 int iResult=0;
243 TList tgtList;
244 if (bFromConfiguration) {
245 if (fpConfiguration)
246 iResult=fpConfiguration->FollowDependency(id, &tgtList);
247 else
248 iResult=-EFAULT;
249 } else
250 iResult=FollowDependency(id, &tgtList);
251 if (iResult>0) {
97d2b87a 252 HLTMessage(" dependency level %d ", iResult);
7a436c89 253 TObjLink* lnk=tgtList.FirstLink();
254 int i=iResult;
255 char* pSpace = new char[iResult+1];
256 if (pSpace) {
257 memset(pSpace, 32, iResult);
258 pSpace[i]=0;
259 while (lnk) {
260 TObject* obj=lnk->GetObject();
261 HLTMessage(" %s^-- %s ", &pSpace[i--], obj->GetName());
262 lnk=lnk->Next();
263 }
264 delete [] pSpace;
265 } else {
266 iResult=-ENOMEM;
267 }
268 }
269}
270
271int AliHLTTask::SetDependency(AliHLTTask* pDep)
272{
273 // see header file for function documentation
274 int iResult=0;
275 if (pDep) {
276 if (FindDependency(pDep->GetName())==NULL) {
277 fListDependencies.Add(pDep);
278 } else {
279 iResult=-EEXIST;
280 }
281 } else {
282 iResult=-EINVAL;
283 }
284 return iResult;
285}
286
287int AliHLTTask::UnsetDependency(AliHLTTask* pDep)
288{
289 // see header file for function documentation
290 fListDependencies.Remove(pDep);
291 if (fpConfiguration) {
292 fpConfiguration->InvalidateSources();
293 }
294 return 0;
295}
296
297int AliHLTTask::CheckDependencies()
298{
299 // see header file for function documentation
300 int iResult=0;
301 AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
302 while (pSrc) {
303 if (FindDependency(pSrc->GetName())==NULL) {
304 //HLTDebug("dependency \"%s\" unresolved", pSrc->GetName());
305 iResult++;
306 }
307 pSrc=fpConfiguration->GetNextSource();
308 }
309 return iResult;
310}
311
312
313int AliHLTTask::Depends(AliHLTTask* pTask)
314{
315 // see header file for function documentation
316 int iResult=0;
317 if (pTask) {
318 if (fpConfiguration) {
319 iResult=fpConfiguration->GetSource(pTask->GetName())!=NULL;
320 if (iResult>0) {
321 //HLTDebug("task \"%s\" depends on \"%s\"", GetName(), pTask->GetName());
322 } else {
323 //HLTDebug("task \"%s\" independend of \"%s\"", GetName(), pTask->GetName());
324 }
325 } else {
326 iResult=-EFAULT;
327 }
328 } else {
329 iResult=-EINVAL;
330 }
331 return iResult;
332}
333
334AliHLTTask* AliHLTTask::FindTarget(const char* id)
335{
336 // see header file for function documentation
337 AliHLTTask* pTask=NULL;
338 if (id) {
339 pTask=(AliHLTTask*)fListTargets.FindObject(id);
340 }
341 return pTask;
342}
343
344int AliHLTTask::SetTarget(AliHLTTask* pTgt)
345{
346 // see header file for function documentation
347 int iResult=0;
348 if (pTgt) {
349 if (FindTarget(pTgt->GetName())==NULL) {
350 fListTargets.Add(pTgt);
351 } else {
352 iResult=-EEXIST;
353 }
354 } else {
355 iResult=-EINVAL;
356 }
357 return iResult;
358}
359
360int AliHLTTask::UnsetTarget(AliHLTTask* pTarget)
361{
362 // see header file for function documentation
363 fListTargets.Remove(pTarget);
364 return 0;
365}
366
367int AliHLTTask::StartRun()
368{
369 // see header file for function documentation
370 int iResult=0;
371 int iNofInputDataBlocks=0;
372 AliHLTComponent* pComponent=GetComponent();
373 if (pComponent) {
374 // determine the number of input data blocks provided from the source tasks
f7561f8d 375 { // set scope for lnk as a local variable
7a436c89 376 TObjLink* lnk=fListDependencies.FirstLink();
377 while (lnk && iResult>=0) {
378 AliHLTTask* pSrcTask=(AliHLTTask*)lnk->GetObject();
379 if (pSrcTask) {
380 if ((iResult=pSrcTask->GetNofMatchingDataTypes(this))>0) {
381 iNofInputDataBlocks+=iResult;
382 } else if (iResult==0) {
383 HLTWarning("source task %s (%p) does not provide any matching data type for task %s (%p)", pSrcTask->GetName(), pSrcTask, GetName(), this);
384 } else {
385 HLTError("task %s (%p): error getting matching data types for source task %s (%p)", GetName(), this, pSrcTask->GetName(), pSrcTask);
386 iResult=-EFAULT;
387 }
388 }
389 lnk=lnk->Next();
390 }
f7561f8d 391 }
7a436c89 392 if (iResult>=0) {
393 if (fBlockDataArray.size()>0) {
394 HLTWarning("block data array for task %s (%p) was not cleaned", GetName(), this);
457ec821 395 fBlockDataArray.clear();
7a436c89 396 }
397
398 // component init
399 // the initialization of the component is done by the ComponentHandler after creation
400 // of the component.
a3c9b745 401 //iResult=Init( AliHLTAnalysisEnvironment* environ, void* environ_param, int argc, const char** argv );
7a436c89 402
7a436c89 403 // allocate the data buffer, which controls the output buffer and subscriptions
404 if (iResult>=0) {
405 fpDataBuffer=new AliHLTDataBuffer;
406 if (fpDataBuffer!=NULL) {
dba03d72 407 fpDataBuffer->SetLocalLoggingLevel(GetLocalLoggingLevel());
7a436c89 408 HLTDebug("created data buffer %p for task %s (%p)", fpDataBuffer, GetName(), this);
409 TObjLink* lnk=fListTargets.FirstLink();
410 while (lnk && iResult>=0) {
411 AliHLTTask* pTgtTask=(AliHLTTask*)lnk->GetObject();
412 if (pTgtTask) {
413 if ((iResult=fpDataBuffer->SetConsumer(pTgtTask->GetComponent()))>=0) {
414 }
415 } else {
416 break;
417 iResult=-EFAULT;
418 }
419 lnk=lnk->Next();
420 }
421 } else {
422 HLTFatal("can not create data buffer object, memory allocation failed");
423 iResult=-ENOMEM;
424 }
425 }
426 }
457ec821 427 if (iResult>=0) {
428 // send the SOR event
429
430 }
7a436c89 431 } else {
432 HLTError("task %s (%p) does not have a component", GetName(), this);
433 iResult=-EFAULT;
434 }
435 return iResult;
436}
437
438int AliHLTTask::EndRun()
439{
440 // see header file for function documentation
441 int iResult=0;
442 if (fBlockDataArray.size()>0) {
457ec821 443 fBlockDataArray.clear();
7a436c89 444 }
445 if (fpDataBuffer) {
446 AliHLTDataBuffer* pBuffer=fpDataBuffer;
447 fpDataBuffer=NULL;
448 delete pBuffer;
449 }
450 return iResult;
451}
452
ffd0cf01 453int AliHLTTask::ProcessTask(Int_t eventNo, AliHLTUInt32_t eventType, AliHLTUInt64_t trgMask, AliHLTUInt32_t timestamp)
7a436c89 454{
455 // see header file for function documentation
456 int iResult=0;
457 AliHLTComponent* pComponent=GetComponent();
458 if (pComponent && fpDataBuffer) {
459 HLTDebug("Processing task %s (%p) fpDataBuffer %p", GetName(), this, fpDataBuffer);
460 fpDataBuffer->Reset();
461 int iSourceDataBlock=0;
462 int iInputDataVolume=0;
463
464 AliHLTTask* pSrcTask=NULL;
b46ca65e 465 AliHLTTaskPList subscribedTaskList;
7a436c89 466 TObjLink* lnk=fListDependencies.FirstLink();
467
457ec821 468 // instances of SOR and EOR events to be kept
469 int iSOR=-1;
470 int iEOR=-1;
3baf1595 471 // TODO 2009-09-30
472 // generalize handling of the special blocks to be forwarded on SOR and EOR
473 // just adding a new specific handling for the ECS parameter block as a quick
474 // solution
475 int iECS=-1;
457ec821 476
7a436c89 477 // subscribe to all source tasks
457ec821 478 fBlockDataArray.clear();
7a436c89 479 while (lnk && iResult>=0) {
480 pSrcTask=(AliHLTTask*)lnk->GetObject();
481 if (pSrcTask) {
482 int iMatchingDB=pSrcTask->GetNofMatchingDataBlocks(this);
457ec821 483 if (iMatchingDB<0) {
484 HLTError("task %s (%p): error getting no of matching data blocks from task %s (%p), error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iMatchingDB);
485 iResult=iMatchingDB;
486 break;
487 } else if (iMatchingDB==0) {
488 HLTDebug("source task %s (%p) does not provide any matching data type for task %s (%p)", pSrcTask->GetName(), pSrcTask, GetName(), this);
7a436c89 489 }
457ec821 490 if ((iResult=pSrcTask->Subscribe(this, fBlockDataArray))>=0) {
3baf1595 491 iSOR=iEOR=iECS=-1;
457ec821 492 AliHLTComponentBlockDataList::iterator block=fBlockDataArray.begin();
493 for (int i=0; block!=fBlockDataArray.end(); i++) {
494 bool bRemove=0;
495 bRemove|=(*block).fDataType==kAliHLTDataTypeSOR && !(iSOR<0 && (iSOR=i)>=0);
496 bRemove|=(*block).fDataType==kAliHLTDataTypeEOR && !(iEOR<0 && (iEOR=i)>=0);
3baf1595 497 bRemove|=(*block).fDataType==kAliHLTDataTypeECSParam && !(iECS<0 && (iECS=i)>=0);
457ec821 498 //HLTInfo("block %d, iSOR=%d iEOR=%d remove=%d", i, iSOR, iEOR, bRemove);
499 if (i<iSourceDataBlock) {
500 assert(!bRemove);
501 } else if (bRemove) {
502 HLTDebug("remove duplicated event %s (%d)", AliHLTComponent::DataType2Text((*block).fDataType).c_str(), i);
503 pSrcTask->Release(&(*block), this);
504 block=fBlockDataArray.erase(block);
505 continue;
506 } else {
507 iInputDataVolume+=(*block).fSize;
7a436c89 508 // put the source task as many times into the list as it provides data blocks
509 // makes the bookkeeping for the data release easier
b46ca65e 510 subscribedTaskList.push_back(pSrcTask);
457ec821 511 }
512 block++;
7a436c89 513 }
514 HLTDebug("Task %s (%p) successfully subscribed to %d data block(s) of task %s (%p)", GetName(), this, iResult, pSrcTask->GetName(), pSrcTask);
457ec821 515 iSourceDataBlock=fBlockDataArray.size();
7a436c89 516 iResult=0;
517 } else {
518 HLTError("Task %s (%p): subscription to task %s (%p) failed with error %d", GetName(), this, pSrcTask->GetName(), pSrcTask, iResult);
519 iResult=-EFAULT;
520 }
521 } else {
522 HLTFatal("fatal internal error in ROOT list handling");
523 iResult=-EFAULT;
524 }
525 lnk=lnk->Next();
457ec821 526 }
7a436c89 527
528 // process the event
529 int iNofTrial=0; // repeat processing if component returns -ENOSPC
3ee8781a 530 AliHLTUInt32_t iLastOutputDataSize=0;
7a436c89 531 if (iResult>=0) {
532 do {
032c5e5e 533 long unsigned int iOutputDataSize=0;
534 AliHLTConfiguration* pConf=GetConf();
032c5e5e 535 // check if there was a buffer size specified, query output size
536 // estimator from component otherwize
537 if (pConf && pConf->GetOutputBufferSize()>=0) {
538 iOutputDataSize=pConf->GetOutputBufferSize();
539 } else {
7a436c89 540 long unsigned int iConstBase=0;
541 double fInputMultiplier=0;
53f79557 542 if (pComponent->GetComponentType()!=AliHLTComponent::kSink) {
7a436c89 543 pComponent->GetOutputDataSize(iConstBase, fInputMultiplier);
53f79557 544 // add a small margin to the buffer to allow optional component
545 // statistics
546 iConstBase+=100;
ae962989 547#if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
548 for (AliHLTComponentBlockDataList::iterator element=fBlockDataArray.begin();
549 element!=fBlockDataArray.end(); element++) {
550 if (element->fDataType==kAliHLTDataTypeComponentStatistics) {
551 iConstBase+=element->fSize;
552 }
553 }
554#endif
53f79557 555 }
7a436c89 556 if (fInputMultiplier<0) {
557 HLTWarning("ignoring negative input multiplier");
558 fInputMultiplier=0;
559 }
032c5e5e 560 iOutputDataSize=int(fInputMultiplier*iInputDataVolume) + iConstBase;
7a436c89 561 //HLTDebug("task %s: reqired output size %d", GetName(), iOutputDataSize);
032c5e5e 562 }
7a436c89 563 if (iNofTrial>0) {
564 // dont process again if the buffer size is the same
3ee8781a 565 if (iLastOutputDataSize==iOutputDataSize) break;
97d2b87a 566 HLTImportant("processing event %d again with buffer size %d", eventNo, iOutputDataSize);
7a436c89 567 }
568 AliHLTUInt8_t* pTgtBuffer=NULL;
569 if (iOutputDataSize>0) pTgtBuffer=fpDataBuffer->GetTargetBuffer(iOutputDataSize);
570 //HLTDebug("provided raw buffer %p", pTgtBuffer);
571 AliHLTComponentEventData evtData;
572 AliHLTComponent::FillEventData(evtData);
48abe484 573 if (eventNo>=0)
574 evtData.fEventID=(AliHLTEventID_t)eventNo;
ffd0cf01 575 if (timestamp) evtData.fEventCreation_s=timestamp;
576 else
dd5b6088 577 evtData.fEventCreation_s=static_cast<AliHLTUInt32_t>(time(NULL));
7a436c89 578 AliHLTComponentTriggerData trigData;
a0dec225 579 AliHLTEventTriggerData evtTrigData;
804007a6 580 trigData.fStructSize=sizeof(trigData);
a0dec225 581 trigData.fDataSize=sizeof(AliHLTEventTriggerData);
582 memset(&evtTrigData, 0, trigData.fDataSize);
9e14734f 583 // Setup the CDH in the trigger data, based on the event type and CTP trigger.
a0dec225 584 evtTrigData.fCommonHeaderWordCnt=gkAliHLTCommonHeaderCount;
9e14734f 585 AliHLTUInt8_t l1msg = 0x0;
586 switch (eventType)
587 {
588 case gkAliEventTypeData: l1msg = 0x00; break;
589 case gkAliEventTypeDataReplay: l1msg = 0x00; break;
590 case gkAliEventTypeStartOfRun: l1msg = (0xE << 2) | 0x01; break;
591 case gkAliEventTypeEndOfRun: l1msg = (0xF << 2) | 0x01; break;
592 case gkAliEventTypeCalibration: l1msg = (0x1 << 6) | 0x01; break;
593 case gkAliEventTypeSoftware: l1msg = 0x01; break;
594 }
595 evtTrigData.fCommonHeader[1] = AliHLTUInt32_t(l1msg) << 14;
c4ffab2c 596 evtTrigData.fCommonHeader[5]=trgMask&0xffffffff;
597 trgMask>>=32;
a904c7d0 598 evtTrigData.fCommonHeader[6]=trgMask&0x3ffff;
a0dec225 599 trigData.fData=&evtTrigData;
3ee8781a 600 iLastOutputDataSize=iOutputDataSize;
601 AliHLTUInt32_t size=iOutputDataSize;
7a436c89 602 AliHLTUInt32_t outputBlockCnt=0;
603 AliHLTComponentBlockData* outputBlocks=NULL;
a0aeb701 604 AliHLTComponentEventDoneData* edd=NULL;
7a436c89 605 if (pTgtBuffer!=NULL || iOutputDataSize==0) {
48abe484 606 // add event type data block
7e81df35 607 // the block is removed immediately after processing from the list
48abe484 608 AliHLTComponentBlockData eventTypeBlock;
609 AliHLTComponent::FillBlockData(eventTypeBlock);
610 // Note: no payload!
611 eventTypeBlock.fDataType=kAliHLTDataTypeEvent;
612 eventTypeBlock.fSpecification=eventType;
613 fBlockDataArray.push_back(eventTypeBlock);
614
615 // process
616 evtData.fBlockCnt=fBlockDataArray.size();
7a436c89 617 iResult=pComponent->ProcessEvent(evtData, &fBlockDataArray[0], trigData, pTgtBuffer, size, outputBlockCnt, outputBlocks, edd);
97d2b87a 618 HLTDebug("component %s ProcessEvent finnished (%d): size=%d blocks=%d", pComponent->GetComponentID(), iResult, size, outputBlockCnt);
48abe484 619
324ca3b4 620 // EventDoneData is for the moment ignored in AliHLTSystem
621 if (edd) {
622 HLTDebug("got EventDoneData size %d", edd->fDataSize);
623 delete [] reinterpret_cast<char*>(edd);
624 edd=NULL;
625 }
626
48abe484 627 // remove event data block
628 fBlockDataArray.pop_back();
629
7e81df35 630 // check for forwarded blocks.
631 // loop over all output blocks and check
632 // 1. for duplicate blocks (pointing to same location in output buffer
633 // or to the same buffer)
634 // 2. for blocks forwarded from the input.
b46ca65e 635 if (iResult>=0 && outputBlocks) {
457ec821 636 if (fListTargets.First()!=NULL) {
637 AliHLTComponentBlockDataList segments;
638 for (AliHLTUInt32_t oblock=0; oblock<outputBlockCnt; oblock++) {
7e81df35 639 // consistency check for data reference
0ad4ebd1 640 if (outputBlocks[oblock].fPtr!=NULL && outputBlocks[oblock].fPtr!=pTgtBuffer &&
641 outputBlocks[oblock].fOffset!=0) {
7e81df35 642 HLTWarning("output block %s 0x%08x has inconsistent data reference ptr=%p offset=0x%08x: "
643 "for new blocks use offset only, forwarded blocks have fPtr set only",
644 AliHLTComponent::DataType2Text(outputBlocks[oblock].fDataType).c_str(),
645 outputBlocks[oblock].fSpecification,
646 outputBlocks[oblock].fPtr, outputBlocks[oblock].fOffset);
647 }
648
649 // check for duplicates in the output
650 AliHLTUInt32_t checkblock=0;
651 for (; checkblock<oblock; checkblock++) {
0ad4ebd1 652 if (outputBlocks[oblock].fPtr!=NULL && outputBlocks[oblock].fPtr!=pTgtBuffer &&
653 outputBlocks[checkblock].fPtr==outputBlocks[oblock].fPtr) {
7e81df35 654 if (outputBlocks[checkblock].fSize!=outputBlocks[oblock].fSize ||
655 outputBlocks[checkblock].fDataType!=outputBlocks[oblock].fDataType) {
656 HLTWarning("output blocks %d (%s 0x%08x) and %d (%s 0x%08x) have identical data references ptr=%p "
657 "but differ in data type and/or size: %d vs. %d",
658 oblock,
659 AliHLTComponent::DataType2Text(outputBlocks[oblock].fDataType).c_str(),
660 outputBlocks[oblock].fSpecification,
661 checkblock,
662 AliHLTComponent::DataType2Text(outputBlocks[checkblock].fDataType).c_str(),
663 outputBlocks[checkblock].fSpecification,
664 outputBlocks[oblock].fPtr,
665 outputBlocks[oblock].fSize,
666 outputBlocks[checkblock].fSize);
667 }
668 // ignore from the second copy
669 break;
670 }
671 }
672 if (checkblock<oblock) continue;
673
674 // search for the forwarded data blocks
675 // new data blocks are announced to the data buffer, forwarded data blocks
676 // to the publisher task. The publisher task of a forwarded data block is
677 // removed from the list in order to keep the buffer open. It will be releases
678 // when the subscribing task releases it
457ec821 679 AliHLTUInt32_t iblock=0;
48abe484 680 for (; iblock<fBlockDataArray.size(); iblock++) {
0ad4ebd1 681 if (outputBlocks[oblock].fDataType==kAliHLTDataTypeEvent) {
682 // the event type data block is ignored if it was forwarded
0925276e 683 break;
0ad4ebd1 684 }
457ec821 685 if (fBlockDataArray[iblock].fPtr==outputBlocks[oblock].fPtr) {
686 assert(subscribedTaskList[iblock]!=NULL);
687 if (subscribedTaskList[iblock]==NULL) continue;
688 HLTDebug("forward segment %d (source task %s %p) to data buffer %p", iblock, pSrcTask->GetName(), pSrcTask, fpDataBuffer);
689 fpDataBuffer->Forward(subscribedTaskList[iblock], &fBlockDataArray[iblock]);
690 subscribedTaskList[iblock]=NULL; // not to be released in the loop further down
691 break;
692 }
693 }
48abe484 694 if (iblock==fBlockDataArray.size()) segments.push_back(outputBlocks[oblock]);
042b7a5d 695 }
696 if (pTgtBuffer && segments.size()>0) {
697 iResult=fpDataBuffer->SetSegments(pTgtBuffer, &segments[0], segments.size());
b46ca65e 698 }
457ec821 699 } else {
700 // no forwarding, actually we dont even need to keep the data, this is a
701 // dead end (fListTargets empty)
702 //iResult=fpDataBuffer->SetSegments(pTgtBuffer, outputBlocks, outputBlockCnt);
b46ca65e 703 }
7a436c89 704 delete [] outputBlocks; outputBlocks=NULL; outputBlockCnt=0;
705 } else {
706 fpDataBuffer->Reset();
707 }
457ec821 708 if (fListTargets.First()!=NULL) {
709 if (iSOR>=0 && subscribedTaskList[iSOR]!=NULL) {
710 HLTDebug("forward SOR event segment %d (source task %s %p) to data buffer %p", iSOR, pSrcTask->GetName(), pSrcTask, fpDataBuffer);
711 fpDataBuffer->Forward(subscribedTaskList[iSOR], &fBlockDataArray[iSOR]);
712 subscribedTaskList[iSOR]=NULL; // not to be released in the loop further down
713 }
714 if (iEOR>=0 && subscribedTaskList[iEOR]!=NULL) {
715 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);
716 fpDataBuffer->Forward(subscribedTaskList[iEOR], &fBlockDataArray[iEOR]);
717 subscribedTaskList[iEOR]=NULL; // not to be released in the loop further down
718 }
3baf1595 719 if (iECS>=0 && subscribedTaskList[iECS]!=NULL) {
720 HLTDebug("forward EOR event (%s) segment %d (source task %s %p) to data buffer %p", AliHLTComponent::DataType2Text(fBlockDataArray[iECS].fDataType).c_str(), iECS, pSrcTask->GetName(), pSrcTask, fpDataBuffer);
721 fpDataBuffer->Forward(subscribedTaskList[iECS], &fBlockDataArray[iECS]);
722 subscribedTaskList[iECS]=NULL; // not to be released in the loop further down
723 }
457ec821 724 }
7a436c89 725 } else {
97d2b87a 726 HLTError("no target buffer available");
7a436c89 727 iResult=-EFAULT;
728 }
729 } while (iResult==-ENOSPC && iNofTrial++<1);
730 }
731
732 // now release all buffers which we have subscribed to
733 iSourceDataBlock=0;
b46ca65e 734 AliHLTTaskPList::iterator element;
735 while ((element=subscribedTaskList.begin())!=subscribedTaskList.end()) {
736 pSrcTask=*element;
7a436c89 737 if (pSrcTask) {
738 int iTempRes=0;
739 if ((iTempRes=pSrcTask->Release(&fBlockDataArray[iSourceDataBlock], this))>=0) {
97d2b87a 740 HLTDebug("successfully released segment of task %s (%p)", pSrcTask->GetName(), pSrcTask);
7a436c89 741 } else {
97d2b87a 742 HLTError("realease of task %s (%p) failed with error %d", pSrcTask->GetName(), pSrcTask, iTempRes);
7a436c89 743 }
7a436c89 744 }
b46ca65e 745 subscribedTaskList.erase(element);
7a436c89 746 iSourceDataBlock++;
747 }
b46ca65e 748 if (subscribedTaskList.size()>0) {
97d2b87a 749 HLTError("could not release all data buffers");
7a436c89 750 }
751 } else {
97d2b87a 752 HLTError("internal failure (not initialized component %p, data buffer %p)", fpComponent, fpDataBuffer);
7a436c89 753 iResult=-EFAULT;
754 }
755 return iResult;
756}
757
758int AliHLTTask::GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask) const
759{
760 // see header file for function documentation
761 int iResult=0;
762 if (pConsumerTask) {
763 if (fpDataBuffer) {
764 iResult=fpDataBuffer->FindMatchingDataBlocks(pConsumerTask->GetComponent(), NULL);
765 } else {
766 HLTFatal("internal data buffer missing");
767 iResult=-EFAULT;
768 }
769 } else {
770 iResult=-EINVAL;
771 }
772 return iResult;
773}
774
775int AliHLTTask::GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask) const
776{
777 // see header file for function documentation
778 int iResult=0;
779 if (pConsumerTask) {
780 AliHLTComponent* pComponent=GetComponent();
781 if (!pComponent) {
782 // init ?
783 HLTError("component not initialized");
784 iResult=-EFAULT;
785 }
786 if (pComponent) {
787 iResult=pComponent->FindMatchingDataTypes(pConsumerTask->GetComponent(), NULL);
788 } else {
789 HLTFatal("task initialization failed");
790 iResult=-EFAULT;
791 }
792 } else {
793 iResult=-EINVAL;
794 }
795 return iResult;
796}
797
457ec821 798int AliHLTTask::Subscribe(const AliHLTTask* pConsumerTask, AliHLTComponentBlockDataList& blockDescList)
7a436c89 799{
800 // see header file for function documentation
801 int iResult=0;
802 if (pConsumerTask) {
803 if (fpDataBuffer) {
457ec821 804 iResult=fpDataBuffer->Subscribe(pConsumerTask->GetComponent(), blockDescList);
7a436c89 805 } else {
806 HLTFatal("internal data buffer missing");
807 iResult=-EFAULT;
808 }
809 } else {
810 iResult=-EINVAL;
811 }
812 return iResult;
813}
814
815int AliHLTTask::Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTTask* pConsumerTask)
816{
817 // see header file for function documentation
818 int iResult=0;
819 if (pConsumerTask && pBlockDesc) {
820 if (fpDataBuffer) {
b46ca65e 821 iResult=fpDataBuffer->Release(pBlockDesc, pConsumerTask->GetComponent(), this);
7a436c89 822 } else {
823 HLTFatal("internal data buffer missing");
824 iResult=-EFAULT;
825 }
826 } else {
827 iResult=-EINVAL;
828 }
829 return iResult;
830}
831
832void AliHLTTask::PrintStatus()
833{
834 // see header file for function documentation
835 HLTLogKeyword("task properties");
836 AliHLTComponent* pComponent=GetComponent();
837 if (pComponent) {
838 HLTMessage(" component: %s (%p)", pComponent->GetComponentID(), pComponent);
839 } else {
840 HLTMessage(" no component set!");
841 }
842 if (fpConfiguration) {
843 AliHLTConfiguration* pSrc=fpConfiguration->GetFirstSource();
844 while (pSrc) {
845 const char* pQualifier="unresolved";
846 if (FindDependency(pSrc->GetName()))
847 pQualifier="resolved";
848 HLTMessage(" source: %s (%s)", pSrc->GetName(), pQualifier);
849 pSrc=fpConfiguration->GetNextSource();
850 }
851 TObjLink* lnk = fListTargets.FirstLink();
852 while (lnk) {
853 TObject *obj = lnk->GetObject();
854 HLTMessage(" target: %s", obj->GetName());
855 lnk = lnk->Next();
856 }
857 } else {
97d2b87a 858 HLTMessage(" task not initialized");
7a436c89 859 }
860}
7131ea63 861
862int AliHLTTask::CustomInit(AliHLTComponentHandler* /*pCH*/)
863{
864 // default implementation nothing to do
865 return 0;
866}
867
868int AliHLTTask::CustomCleanup()
869{
870 // default implementation nothing to do
871 return 0;
872}
97d2b87a 873
874int AliHLTTask::LoggingVarargs(AliHLTComponentLogSeverity severity,
875 const char* originClass, const char* originFunc,
876 const char* file, int line, ... ) const
877{
878 // see header file for function documentation
879 int iResult=0;
880
881 va_list args;
882 va_start(args, line);
883
7efb6418 884 AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", GetName());
97d2b87a 885 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
886 va_end(args);
887
888 return iResult;
889}