+int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
+ AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
+ AliHLTUInt32_t participatingDetectors)
+{
+ // see header file for class documentation
+ int iResult=0;
+ int iCount=0;
+ SetStatusFlags(kRunning);
+ if (fEventCount>=0 || (iResult=InitTasks())>=0) {
+ if (fEventCount>=0 || (iResult=StartTasks())>=0) {
+ if (fEventCount==0) {
+ InitBenchmarking(fStopwatches);
+ } else {
+ // Matthias Oct 11 2008 this is a bug
+ // By resuming the stopwatches at this point, all continued counting, but the
+ // starting and stopping is controlled by the AliHLTStopwatchGuard
+ //ResumeBenchmarking(fStopwatches);
+ }
+ for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
+ if (fpHLTOUTTask) {
+ if (iNofEvents>1 && i==fEventCount) {
+ HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block");
+ }
+ // reset and prepare for new data
+ fpHLTOUTTask->Reset();
+ }
+ if (eventtype == 0) {
+ eventtype = gkAliEventTypeData;
+ participatingDetectors = 0x0;
+ }
+ if ((iResult=ProcessTasks(i, trgMask, timestamp, eventtype, participatingDetectors))>=0) {
+ fGoodEvents++;
+ iCount++;
+ } else {
+ // TODO: define different running modes to either ignore errors in
+ // event processing or not
+ // currently ignored
+ iResult=0;
+ }
+ AliHLTDataBuffer::SetGlobalEventCount(iCount);
+ }
+ fEventCount+=iNofEvents;
+ if (bStop) StopTasks();
+ else PauseBenchmarking(fStopwatches);
+ }
+ if (bStop) DeinitTasks();
+ }
+ if (iResult>=0) {
+ iResult=iCount;
+ } else if (iResult==-126 /*ENOKEY*/) {
+ iResult=0; // do not propagate the error
+ }
+ ClearStatusFlags(kRunning);
+ AliHLTDataBuffer::PrintStatistics();
+ return iResult;
+}
+
+int AliHLTSystem::InitTasks()
+{
+ // see header file for class documentation
+ int iResult=0;
+ TObjLink *lnk=fTaskList.FirstLink();
+
+ if (lnk==NULL) {
+ HLTInfo("Task list is empty, skipping HLT");
+ return -126 /*ENOKEY*/;
+ }
+ while (lnk && iResult>=0) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ iResult=pTask->Init(NULL, fpComponentHandler);
+// ProcInfo_t ProcInfo;
+// gSystem->GetProcInfo(&ProcInfo);
+// HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
+ } else {
+ }
+ lnk = lnk->Next();
+ }
+ if (iResult<0) {
+ HLTError("can not initialize task list, error %d", iResult);
+ }
+
+ return iResult;
+}
+
+int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (pStopwatches==NULL) return 0;
+
+ for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+ TStopwatch* pStopwatch= new TStopwatch;
+ if (pStopwatch) {
+ pStopwatch->Reset();
+ pStopwatches->AddAt(pStopwatch, i);
+ } else {
+ iResult=-ENOMEM;
+ break;
+ }
+ }
+
+ TObjLink *lnk=fTaskList.FirstLink();
+ while (lnk && iResult>=0) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ AliHLTComponent* pComp=NULL;
+ if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
+ switch (pComp->GetComponentType()) {
+ case AliHLTComponent::kProcessor:
+ pComp->SetStopwatches(pStopwatches);
+ break;
+ case AliHLTComponent::kSource:
+ {
+ // this switch determines whether the time consumption of the
+ // AliHLTComponent base methods should be counted to the input
+ // stopwatch or base stopwatch.
+ //int inputBase=(int)AliHLTComponent::kSWBase;
+ int inputBase=(int)AliHLTComponent::kSWInput;
+ pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
+ pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
+ }
+ break;
+ case AliHLTComponent::kSink:
+ {
+ // this switch determines whether the time consumption of the
+ // AliHLTComponent base methods should be counted to the output
+ // stopwatch or base stopwatch.
+ //int outputBase=(int)AliHLTComponent::kSWBase;
+ int outputBase=(int)AliHLTComponent::kSWOutput;
+ pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
+ pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
+ }
+ break;
+ default:
+ HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
+ }
+ }
+ } else {
+ }
+ lnk = lnk->Next();
+ }
+ return iResult;
+}
+
+int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
+{
+ // see header file for class documentation
+ if (pStopwatches==NULL) return 0;
+
+ for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+ if (!pStopwatches->At(i)) continue;
+ TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
+ if (pSw) pSw->Stop();
+ }
+ return 0;
+}
+
+int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
+{
+ // see header file for class documentation
+ if (pStopwatches==NULL) return 0;
+
+ for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+ if (!pStopwatches->At(i)) continue;
+ TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
+ if (pSw) pSw->Continue();
+ }
+ return 0;
+}
+
+int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
+{
+ // see header file for class documentation
+ int iInitialized=1;
+ if (pStopwatches==NULL) return 0;
+
+ for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+ if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
+ iInitialized=0;
+ break;
+ }
+ }
+
+ if (iInitialized!=0) {
+ HLTImportant("HLT statistics:\n"
+ " base: R:%.3fs C:%.3fs\n"
+ " input: R:%.3fs C:%.3fs\n"
+ " output: R:%.3fs C:%.3fs\n"
+ " event processing : R:%.3fs C:%.3fs"
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
+ , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
+ );
+ }
+
+ if (bClean) {
+ for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
+ TObject* pObj=pStopwatches->RemoveAt(i);
+ if (pObj) delete pObj;
+ }
+ }
+ return 0;
+}
+
+int AliHLTSystem::StartTasks()
+{
+ // see header file for class documentation
+ int iResult=0;
+ TObjLink *lnk=fTaskList.FirstLink();
+ while (lnk && iResult>=0) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ iResult=pTask->StartRun();
+// ProcInfo_t ProcInfo;
+// gSystem->GetProcInfo(&ProcInfo);
+// HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
+ } else {
+ }
+ lnk = lnk->Next();
+ }
+ if (iResult<0) {
+ HLTError("can not start task list, error %d", iResult);
+ } else {
+ SetStatusFlags(kStarted);
+ fEventCount=0;
+ fGoodEvents=0;
+ if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
+ HLTError("can not send SOR event: error %d", iResult);
+ }
+ }
+ return iResult;
+}
+
+int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask,
+ AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
+ AliHLTUInt32_t participatingDetectors)
+{
+ // see header file for class documentation
+ int iResult=0;
+ HLTDebug("processing event no %d", eventNo);
+ TObjLink *lnk=fTaskList.FirstLink();
+ while (lnk) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ if (iResult>=0) {
+ iResult=pTask->ProcessTask(eventNo, eventtype, trgMask, timestamp, participatingDetectors);
+// ProcInfo_t ProcInfo;
+// gSystem->GetProcInfo(&ProcInfo);
+// HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
+ } else {
+ pTask->SubscribeSourcesAndSkip();
+ }
+ } else {
+ }
+ lnk = lnk->Next();
+ }
+
+ if (iResult>=0) {
+ HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
+ iResult=0;
+ } else {
+ HLTError("Processing of event %d failed (%d)", eventNo, iResult);
+ }
+
+ return iResult;
+}
+
+int AliHLTSystem::StopTasks()
+{
+ // see header file for class documentation
+ int iResult=0;
+ if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
+ HLTError("can not send EOR event");
+ }
+
+ // cleanup blocks from the last event. This is a bit awkward. All output
+ // blocks from the chains need to be stored in the HLTOUT task. Though,
+ // we do not know, whether HLTOUT is going to be processed or not.
+ if (fpHLTOUTTask)
+ fpHLTOUTTask->Reset();
+
+ TObjLink *lnk=fTaskList.FirstLink();
+ while (lnk) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ int locResult=pTask->EndRun();
+ if (iResult>=0 && locResult<0) iResult=locResult;
+// ProcInfo_t ProcInfo;
+// gSystem->GetProcInfo(&ProcInfo);
+// HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
+ } else {
+ }
+ lnk = lnk->Next();
+ }
+ PrintBenchmarking(fStopwatches, 1 /*clean*/);
+ if (fEventCount!=fGoodEvents) {
+ HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
+ }
+ ClearStatusFlags(kStarted);
+ return iResult;
+}
+
+int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
+{
+ // see header file for class documentation
+ int iResult=0;
+
+ AliHLTComponentBlockDataList controlBlocks;
+ AliHLTComponentBlockData bd;
+
+ // run decriptor block of type kAliHLTDataTypeSOR/kAliHLTDataTypeEOR
+ AliHLTComponent::FillBlockData(bd);
+ AliHLTRunDesc runDesc;
+ memset(&runDesc, 0, sizeof(AliHLTRunDesc));
+ runDesc.fStructSize=sizeof(AliHLTRunDesc);
+ runDesc.fRunNo=AliHLTMisc::Instance().GetCDBRunNo();
+ bd.fPtr=&runDesc;
+ bd.fSize=sizeof(AliHLTRunDesc);
+ bd.fDataType=dt;
+ bd.fSpecification=kAliHLTVoidDataSpec;
+ controlBlocks.push_back(bd);
+
+ // ECS parameter of type kAliHLTDataTypeECSParam
+ if (fECSParams.IsNull())
+ fECSParams="CTP_TRIGGER_CLASS=00:DUMMY-TRIGGER-ALL:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17";
+ AliHLTComponent::FillBlockData(bd);
+ bd.fPtr=(void*)fECSParams.Data();
+ bd.fSize=fECSParams.Length()+1;
+ bd.fDataType=kAliHLTDataTypeECSParam;
+ bd.fSpecification=kAliHLTVoidDataSpec;
+ controlBlocks.push_back(bd);
+
+ AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
+ HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
+ TObjLink *lnk=fTaskList.FirstLink();
+ while (lnk && iResult>=0) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
+ if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
+ else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
+ else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
+ iResult=pTask->ProcessTask(-1, eventType, 0, 0);
+ } else {
+ }
+ lnk = lnk->Next();
+ }
+
+ // control events are not supposed to go into the HLTOUT
+ if (fpHLTOUTTask)
+ fpHLTOUTTask->Reset();
+
+ HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
+ return iResult;
+}
+
+int AliHLTSystem::DeinitTasks()
+{
+ // see header file for class documentation
+ int iResult=0;
+ TObjLink *lnk=fTaskList.LastLink();
+ while (lnk) {
+ TObject* obj=lnk->GetObject();
+ if (obj) {
+ AliHLTTask* pTask=(AliHLTTask*)obj;
+ int localRes=pTask->Deinit();
+ if (iResult>=0) iResult=localRes;
+// ProcInfo_t ProcInfo;
+// gSystem->GetProcInfo(&ProcInfo);
+// HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
+ } else {
+ }
+ lnk = lnk->Prev();
+ }
+ fEventCount=-1;
+ fGoodEvents=-1;
+
+ return iResult;
+}
+
+int AliHLTSystem::CleanupHLTOUTHandlers()
+{
+ // see header file for class documentation
+ if (fpChainHandlers) {
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
+ fpChainHandlers=NULL;
+ if (pHandlers) {
+ AliHLTOUT::InvalidateBlocks(*pHandlers);
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
+ }
+ assert(pHandlers->size()==0);
+ delete pHandlers;
+ }
+
+ if (fpEsdHandlers) {
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
+ fpEsdHandlers=NULL;
+ if (pHandlers) {
+ AliHLTOUT::InvalidateBlocks(*pHandlers);
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
+ }
+ assert(pHandlers->size()==0);
+ delete pHandlers;
+ }
+
+ if (fpProprietaryHandlers) {
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
+ fpProprietaryHandlers=NULL;
+ if (pHandlers) {
+ AliHLTOUT::InvalidateBlocks(*pHandlers);
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
+ }
+ assert(pHandlers->size()==0);
+ delete pHandlers;
+ }
+ return 0;
+}
+
+void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
+{
+ // see header file for class documentation
+ void* p=NULL;
+ try {
+ p=(void*)new char[size];
+ }
+ catch (...) {
+ AliHLTLogging log;
+ log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
+ }
+ return p;
+}
+
+int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd )
+{
+ // see header file for class documentation
+ unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
+ void* block=AllocMemory(NULL, blocksize);
+ if (!block) return -ENOMEM;
+ memset(block, 0, blocksize);
+ *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
+ (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
+ (*edd)->fDataSize=size;
+ (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
+
+ return 0;
+}
+
+int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
+ AliRawReader* rawReader)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (runLoader || rawReader || nofEvents==0) {
+ if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
+ if (CheckStatus(kReady)) {
+ if (nofEvents==0) {
+ // special case to close the reconstruction
+ if (!CheckStatus(kError)) {
+ StopTasks();
+ DeinitTasks();
+ CleanupHLTOUTHandlers();
+ }
+ } else {
+ if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
+ AliHLTUInt64_t trgMask=0x1;
+ AliHLTUInt32_t timestamp=0;
+ AliHLTUInt32_t eventtype=0;
+ if (runLoader==NULL) {
+ // this is a quick workaround for the case of simulation
+ // the trigger framework is still under development, secondly, AliHLTSimulation
+ // does not yet add the emulated ECS parameters, so no CTP trigger is known in the HLT
+ // AliHLTTask will initialize one dummy CTP trigger class with bit 0, that's why the
+ // default trigger mask is 0x1
+ trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
+
+ // get the timestamp and type of the event from the raw reader
+ // this is currently only meaningfull for reconstruction (runloader==NULL)
+ timestamp=AliHLTMisc::Instance().GetTimeStamp(rawReader);
+ eventtype=AliHLTMisc::Instance().GetEventType(rawReader);
+ }
+ // the system always remains started after event processing, a specific
+ // call with nofEvents==0 is needed to execute the stop sequence
+ if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
+ }
+ }
+
+ // add the current HLTOUT task to the collection
+ if (fpHLTOUTTask) {
+ AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
+ if (pTask && (iResult=pTask->Init())>=0) {
+ if (pTask->GetNofDataBlocks()>0) {
+ AliHLTOUT* pHLTOUT=RequestHLTOUT();
+ if (pHLTOUT) {
+ pHLTOUT->AddSubCollection(pTask);
+ ReleaseHLTOUT(pHLTOUT);
+ } else {
+ HLTWarning("no HLTOUT instance available, output blocks of the chain are ignored");
+ }
+ }
+ } else {
+ HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
+ iResult=0;
+ }
+ }
+ } else {
+ HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
+ }
+ } else {
+ HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (runLoader || esd) {
+ HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
+ iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
+ } else {
+ HLTError("missing run loader/ESD instance(s)");
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pHLTOUT) return -EINVAL;
+ HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
+
+ //
+ // process all kChain handlers first
+ //
+ if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
+ HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
+ iResult=0;
+ }
+
+ if (!fpEsdHandlers)
+ fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
+ if (!fpProprietaryHandlers)
+ fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
+
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
+ if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
+
+ // invalidate all blocks
+ AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
+ AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
+
+ AliHLTComponentDataTypeList esdBlocks;
+
+ for (iResult=pHLTOUT->SelectFirstDataBlock();
+ iResult>=0;
+ iResult=pHLTOUT->SelectNextDataBlock()) {
+ AliHLTComponentDataType dt=kAliHLTVoidDataType;
+ AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
+ pHLTOUT->GetDataBlockDescription(dt, spec);
+ AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
+ AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
+
+ // default handling for ESD data blocks does not require an explicite handler
+ if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
+ handlerType=AliHLTModuleAgent::kEsd;
+ }
+ const char* pMsg="invalid";
+ switch (handlerType) {
+ case AliHLTModuleAgent::kEsd:
+ {
+ if (pHandler) {
+ // schedule for later processing
+ pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
+ } else {
+ AliHLTComponentDataTypeList::iterator element=esdBlocks.begin();
+ for (; element!=esdBlocks.end(); element++) {
+ if (*element==dt) {
+ HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str());
+ break;
+ }
+ }
+ if (element==esdBlocks.end()) esdBlocks.push_back(dt);
+
+ // write directly
+ const AliHLTUInt8_t* pBuffer=NULL;
+ AliHLTUInt32_t size=0;
+ if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
+ pHLTOUT->WriteESD(pBuffer, size, dt, esd);
+ pHLTOUT->ReleaseDataBuffer(pBuffer);
+ }
+ pHLTOUT->MarkDataBlockProcessed();
+ }
+ }
+ break;
+ case AliHLTModuleAgent::kRawReader:
+ // handled in the AliRawReaderHLT
+ break;
+ case AliHLTModuleAgent::kRawStream:
+ HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
+ pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
+ AliHLTComponent::DataType2Text(dt).c_str(), spec);
+ break;
+ case AliHLTModuleAgent::kChain:
+ HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
+ "New block of this type added by the chain? Skipping data block ...",
+ pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
+ AliHLTComponent::DataType2Text(dt).c_str(), spec);
+ break;
+ case AliHLTModuleAgent::kProprietary:
+ HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
+ pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
+ AliHLTComponent::DataType2Text(dt).c_str(), spec);
+ if (pHandler) {
+ AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
+ int res=pHandler->ProcessData(pHLTOUT);
+ if (res<0) {
+ HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
+ res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
+ AliHLTComponent::DataType2Text(dt).c_str(), spec);
+ }
+ }
+ break;
+ case AliHLTModuleAgent::kUnknownOutput:
+ pMsg="unknown";
+ // fall trough intended
+ default:
+ HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
+ pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
+ AliHLTComponent::DataType2Text(dt).c_str(), spec);
+ }
+ }
+ // TODO: the return value of SelectFirst/NextDataBlock must be
+ // changed in order to avoid this check
+ if (iResult==-ENOENT) iResult=0;
+
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
+
+ // process and write all esd data blocks
+ for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
+ AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
+ AliHLTOUTHandler* pHandler=*handler;
+ const AliHLTUInt8_t* pBuffer=NULL;
+ AliHLTUInt32_t size=0;
+ pHandler->ProcessData(pHLTOUT);
+ if ((size=pHandler->GetProcessedData(pBuffer))>0) {
+ AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
+ AliHLTComponentDataType dt=desc;
+ pHLTOUT->WriteESD(pBuffer, size, dt, esd);
+ pHandler->ReleaseProcessedData(pBuffer, size);
+ }
+ pHLTOUT->MarkDataBlocksProcessed(&(*handler));
+ }
+
+ // process all kProprietary data blocks
+ for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) {
+ AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
+ AliHLTOUTHandler* pHandler=*handler;
+ const AliHLTUInt8_t* pBuffer=NULL;
+ AliHLTUInt32_t size=0;
+ pHandler->ProcessData(pHLTOUT);
+ if ((size=pHandler->GetProcessedData(pBuffer))>0) {
+ HLTWarning("data produced by kProprietary handler ignored");
+ pHandler->ReleaseProcessedData(pBuffer, size);
+ }
+ pHLTOUT->MarkDataBlocksProcessed(&(*handler));
+ }
+
+ // remove all empty handlers form the list (handlers which did not get a block this time)
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
+
+ return iResult;
+}
+
+int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (!pHLTOUT) return -EINVAL;
+
+ if (!fpChainHandlers)
+ fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
+
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
+ if (!pChainHandlers) return -ENOMEM;
+
+ // invalidate all blocks
+ AliHLTOUT::InvalidateBlocks(*pChainHandlers);
+
+ // fill the list
+ pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
+
+ // process all defined chain handlers
+ AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
+ for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
+ if (chainHandler->IsEmpty()) continue;
+ AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
+ AliHLTOUTHandler* pHandler=*chainHandler;
+ const AliHLTUInt8_t* pBuffer=NULL;
+ AliHLTUInt32_t size=0;
+ pHandler->ProcessData(pHLTOUT);
+ if ((size=pHandler->GetProcessedData(pBuffer))>0) {
+ AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
+ //AliHLTComponentDataType dt=desc;
+
+ pHandler->ReleaseProcessedData(pBuffer, size);
+ }
+ pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
+ }
+
+ // remove all empty handlers form the list (handlers which did not get a block this time)
+ AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
+
+ return iResult;
+}
+
+int AliHLTSystem::LoadComponentLibraries(const char* libraries)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (libraries) {
+ if (fpComponentHandler) {
+ TString libs(libraries);
+ TObjArray* pTokens=libs.Tokenize(" ");
+ if (pTokens) {
+ int iEntries=pTokens->GetEntriesFast();
+ for (int i=0; i<iEntries && iResult>=0; i++) {
+ iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->String()).Data());
+ }
+ delete pTokens;
+ }
+ if (iResult>=0) {
+ SetStatusFlags(kLibrariesLoaded);
+ } else {
+ // lets see if we need this, probably not
+ //fpComponentHandler->UnloadLibraries();
+ ClearStatusFlags(kLibrariesLoaded);
+ }
+ } else {
+ iResult=-EFAULT;
+ HLTFatal("no component handler available");
+ }
+ } else {
+ iResult=-EINVAL;
+ }
+ return iResult;
+}
+
+int AliHLTSystem::Configure(AliRunLoader* runloader)
+{
+ // see header file for class documentation
+ return Configure(NULL, runloader);
+}
+
+int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)