2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project *
4 //* ALICE Experiment at CERN, All rights reserved. *
6 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 //* for The ALICE HLT Project. *
9 //* Permission to use, copy, modify and distribute this software and its *
10 //* documentation strictly for non-commercial purposes is hereby granted *
11 //* without fee, provided that the above copyright notice appears in all *
12 //* copies and that both the copyright notice and this permission notice *
13 //* appear in the supporting documentation. The authors make no claims *
14 //* about the suitability of this software for any purpose. It is *
15 //* provided "as is" without express or implied warranty. *
16 //**************************************************************************
18 /** @file AliHLTSystem.cxx
19 @author Matthias Richter
21 @brief Implementation of HLT module management.
29 #include "AliHLTStdIncludes.h"
30 #include "AliHLTSystem.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTComponent.h"
33 #include "AliHLTConfiguration.h"
34 #include "AliHLTConfigurationHandler.h"
35 #include "AliHLTOnlineConfiguration.h"
36 #include "AliHLTTask.h"
37 #include "AliHLTModuleAgent.h"
38 #include "AliHLTOfflineInterface.h"
39 #include "AliHLTDataSource.h"
40 #include "AliHLTOUT.h"
41 #include "AliHLTOUTHandler.h"
42 #include "AliHLTOUTTask.h"
43 #include "AliHLTControlTask.h"
44 #include "AliHLTDataBuffer.h"
45 #include "AliHLTMisc.h"
46 #include <TObjArray.h>
47 #include <TObjString.h>
48 #include <TStopwatch.h>
50 //#include <TSystem.h>
52 //#include <TInterpreter.h>
54 /** HLT default component libraries */
55 const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
59 // "libAliHLTSample.so",
69 "libAliHLTTrigger.so",
73 /** ROOT macro for the implementation of ROOT specific class methods */
74 ClassImp(AliHLTSystem)
76 AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name,
77 AliHLTComponentHandler* pCompHandler,
78 AliHLTConfigurationHandler* pConfHandler
80 : fpComponentHandler(pCompHandler==NULL?AliHLTComponentHandler::CreateHandler():pCompHandler)
81 , fpConfigurationHandler(pConfHandler==NULL?AliHLTConfigurationHandler::CreateHandler():pConfHandler),
85 fStopwatches(new TObjArray),
88 fpChainHandlers(NULL),
90 fpProprietaryHandlers(NULL),
97 , fUseHLTOUTComponentTypeGlobal(true)
99 // see header file for class documentation
101 // refer to README to build package
103 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
105 if (fgNofInstances++>0) {
106 // July 2008: multiple instances are now allowed
107 // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
108 //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
111 SetGlobalLoggingLevel(loglevel);
112 SetFrameworkLog(loglevel);
113 if (fpComponentHandler) {
114 AliHLTAnalysisEnvironment env;
115 memset(&env, 0, sizeof(AliHLTAnalysisEnvironment));
116 env.fStructSize=sizeof(AliHLTAnalysisEnvironment);
117 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
118 env.fGetEventDoneDataFunc=AliHLTSystem::AllocEventDoneData;
119 env.fLoggingFunc=NULL;
120 fpComponentHandler->SetEnvironment(&env);
121 InitAliLogFunc(fpComponentHandler);
122 if (fgNofInstances==1) {
123 fpComponentHandler->AnnounceVersion();
126 HLTFatal("can not create Component Handler");
128 if (fpConfigurationHandler==NULL) {
129 HLTFatal("can not create Configuration Handler");
133 AliHLTSystem::~AliHLTSystem()
135 // see header file for class documentation
137 CleanupHLTOUTHandlers();
139 if (fpConfigurationHandler) {
140 fpConfigurationHandler->Destroy();
142 fpConfigurationHandler=NULL;
144 if (fpComponentHandler) {
145 fpComponentHandler->Destroy();
147 fpComponentHandler=NULL;
150 // note: fpHLTOUTTask and fpControlTask are deleted by
154 int AliHLTSystem::fgNofInstances=0;
156 int AliHLTSystem::BuildTaskList(const char* id)
158 // see header file for class documentation
161 if (fpConfigurationHandler) {
162 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
164 iResult=BuildTaskList(pConf);
166 HLTError("unknown configuration \"%s\"", id);
178 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
180 // see header file for class documentation
183 AliHLTTask* pTask=NULL;
184 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
185 if (pTask->GetConf()!=pConf) {
186 HLTError("configuration mismatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
189 // task for this configuration exists, terminate
191 // check first if the configuration has all sources resolved, try to extract otherwise
192 } else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources()!=1) {
193 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
196 pTask=new AliHLTTask(pConf);
200 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
203 static int iterationLevel=0;
204 if (pTask && iResult>=0) {
205 // check for circular dependencies
206 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
207 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
208 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
209 HLTError("aborted ...");
213 // check whether all dependencies are already in the task list
214 // create the missing ones
215 // this step is an iterative process which calls this function again for the missing
216 // configurations, in order to avoid the currently processed task to be created
217 // again it is added to the list temporarily and removed afterwards
218 // This is of high importance to preserve the order of the tasks. Furthermore, the
219 // InsertTask method has to be used in order to set all the cross links right
220 fTaskList.Add(pTask);
221 AliHLTConfiguration* pDep=pConf->GetFirstSource();
222 while (pDep!=NULL && iResult>=0) {
223 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
224 if (FindTask(pDep->GetName())==NULL) {
225 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
227 iResult=BuildTaskList(pDep);
230 pDep=pConf->GetNextSource();
232 // remove the temporarily added task
233 fTaskList.Remove(pTask);
235 // insert the task and set the cross-links
237 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
238 iResult=InsertTask(pTask);
251 int AliHLTSystem::CleanTaskList()
253 // see header file for class documentation
258 while ((lnk=fTaskList.LastLink())!=NULL) {
259 delete (lnk->GetObject());
260 fTaskList.Remove(lnk);
266 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
268 // see header file for class documentation
270 if (fpControlTask==NULL) {
271 fpControlTask=new AliHLTControlTask;
272 if (!fpControlTask) return -ENOMEM;
273 fTaskList.AddFirst(fpControlTask);
275 TObjLink *controlLnk=NULL;
276 TObjLink *lnk = fTaskList.FirstLink();
277 assert(!lnk || lnk->GetObject()==fpControlTask || fpControlTask==NULL);
278 if (lnk && lnk->GetObject()==fpControlTask) {
279 if (pTask->GetConf() && pTask->GetConf()->GetFirstSource()==NULL) {
280 pTask->SetDependency(fpControlTask);
281 fpControlTask->SetTarget(pTask);
286 if ((iResult=pTask->CheckDependencies())<=0)
288 while (lnk && iResult>0) {
289 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
290 //HLTDebug("checking \"%s\"", pCurr->GetName());
291 iResult=pTask->Depends(pCurr);
293 iResult=pTask->SetDependency(pCurr);
294 pCurr->SetTarget(pTask);
295 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
297 if (pCurr->Depends(pTask)) {
298 // circular dependency
299 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
301 } else if ((iResult=pTask->CheckDependencies())>0) {
307 fTaskList.AddAfter(lnk, pTask);
308 } else if (controlLnk) {
309 fTaskList.AddAfter(controlLnk, pTask);
311 fTaskList.AddFirst(pTask);
313 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
314 } else if (iResult>0) {
315 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
321 AliHLTTask* AliHLTSystem::FindTask(const char* id)
323 // see header file for class documentation
324 AliHLTTask* pTask=NULL;
326 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
331 void AliHLTSystem::PrintTaskList()
333 // see header file for class documentation
334 HLTLogKeyword("task list");
335 TObjLink *lnk = NULL;
336 HLTMessage("Task List");
337 lnk=fTaskList.FirstLink();
339 TObject* obj=lnk->GetObject();
341 HLTMessage(" %s - status:", obj->GetName());
342 AliHLTTask* pTask=(AliHLTTask*)obj;
343 pTask->PrintStatus();
350 int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
351 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
352 AliHLTUInt32_t participatingDetectors)
354 // see header file for class documentation
357 SetStatusFlags(kRunning);
358 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
359 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
360 if (fEventCount==0) {
361 InitBenchmarking(fStopwatches);
363 // Matthias Oct 11 2008 this is a bug
364 // By resuming the stopwatches at this point, all continued counting, but the
365 // starting and stopping is controlled by the AliHLTStopwatchGuard
366 //ResumeBenchmarking(fStopwatches);
368 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
370 if (iNofEvents>1 && i==fEventCount) {
371 HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block");
373 // reset and prepare for new data
374 fpHLTOUTTask->Reset();
376 if (eventtype == 0) {
377 eventtype = gkAliEventTypeData;
378 participatingDetectors = 0x0;
380 if ((iResult=ProcessTasks(i, trgMask, timestamp, eventtype, participatingDetectors))>=0) {
384 // TODO: define different running modes to either ignore errors in
385 // event processing or not
389 AliHLTDataBuffer::SetGlobalEventCount(iCount);
391 fEventCount+=iNofEvents;
392 if (bStop) StopTasks();
393 else PauseBenchmarking(fStopwatches);
395 if (bStop) DeinitTasks();
399 } else if (iResult==-126 /*ENOKEY*/) {
400 iResult=0; // do not propagate the error
402 ClearStatusFlags(kRunning);
403 AliHLTDataBuffer::PrintStatistics();
407 int AliHLTSystem::InitTasks()
409 // see header file for class documentation
411 TObjLink *lnk=fTaskList.FirstLink();
414 HLTInfo("Task list is empty, skipping HLT");
415 return -126 /*ENOKEY*/;
417 while (lnk && iResult>=0) {
418 TObject* obj=lnk->GetObject();
420 AliHLTTask* pTask=(AliHLTTask*)obj;
421 iResult=pTask->Init(NULL, fpComponentHandler);
422 // ProcInfo_t ProcInfo;
423 // gSystem->GetProcInfo(&ProcInfo);
424 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
430 HLTError("can not initialize task list, error %d", iResult);
436 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
438 // see header file for class documentation
440 if (pStopwatches==NULL) return 0;
442 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
443 TStopwatch* pStopwatch= new TStopwatch;
446 pStopwatches->AddAt(pStopwatch, i);
453 TObjLink *lnk=fTaskList.FirstLink();
454 while (lnk && iResult>=0) {
455 TObject* obj=lnk->GetObject();
457 AliHLTTask* pTask=(AliHLTTask*)obj;
458 AliHLTComponent* pComp=NULL;
459 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
460 switch (pComp->GetComponentType()) {
461 case AliHLTComponent::kProcessor:
462 pComp->SetStopwatches(pStopwatches);
464 case AliHLTComponent::kSource:
466 // this switch determines whether the time consumption of the
467 // AliHLTComponent base methods should be counted to the input
468 // stopwatch or base stopwatch.
469 //int inputBase=(int)AliHLTComponent::kSWBase;
470 int inputBase=(int)AliHLTComponent::kSWInput;
471 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
472 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
475 case AliHLTComponent::kSink:
477 // this switch determines whether the time consumption of the
478 // AliHLTComponent base methods should be counted to the output
479 // stopwatch or base stopwatch.
480 //int outputBase=(int)AliHLTComponent::kSWBase;
481 int outputBase=(int)AliHLTComponent::kSWOutput;
482 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
483 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
487 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
497 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
499 // see header file for class documentation
500 if (pStopwatches==NULL) return 0;
502 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
503 if (!pStopwatches->At(i)) continue;
504 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
505 if (pSw) pSw->Stop();
510 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
512 // see header file for class documentation
513 if (pStopwatches==NULL) return 0;
515 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
516 if (!pStopwatches->At(i)) continue;
517 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
518 if (pSw) pSw->Continue();
523 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
525 // see header file for class documentation
527 if (pStopwatches==NULL) return 0;
529 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
530 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
536 if (iInitialized!=0) {
537 HLTImportant("HLT statistics:\n"
538 " base: R:%.3fs C:%.3fs\n"
539 " input: R:%.3fs C:%.3fs\n"
540 " output: R:%.3fs C:%.3fs\n"
541 " event processing : R:%.3fs C:%.3fs"
542 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
543 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
544 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
545 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
546 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
547 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
548 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
549 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
554 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
555 TObject* pObj=pStopwatches->RemoveAt(i);
556 if (pObj) delete pObj;
562 int AliHLTSystem::StartTasks()
564 // see header file for class documentation
566 TObjLink *lnk=fTaskList.FirstLink();
567 while (lnk && iResult>=0) {
568 TObject* obj=lnk->GetObject();
570 AliHLTTask* pTask=(AliHLTTask*)obj;
571 iResult=pTask->StartRun();
572 // ProcInfo_t ProcInfo;
573 // gSystem->GetProcInfo(&ProcInfo);
574 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
580 HLTError("can not start task list, error %d", iResult);
582 SetStatusFlags(kStarted);
585 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
586 HLTError("can not send SOR event: error %d", iResult);
592 int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask,
593 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
594 AliHLTUInt32_t participatingDetectors)
596 // see header file for class documentation
598 HLTDebug("processing event no %d", eventNo);
599 TObjLink *lnk=fTaskList.FirstLink();
601 TObject* obj=lnk->GetObject();
603 AliHLTTask* pTask=(AliHLTTask*)obj;
605 iResult=pTask->ProcessTask(eventNo, eventtype, trgMask, timestamp, participatingDetectors);
606 // ProcInfo_t ProcInfo;
607 // gSystem->GetProcInfo(&ProcInfo);
608 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
610 pTask->SubscribeSourcesAndSkip();
618 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
621 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
627 int AliHLTSystem::StopTasks()
629 // see header file for class documentation
631 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
632 HLTError("can not send EOR event");
635 // cleanup blocks from the last event. This is a bit awkward. All output
636 // blocks from the chains need to be stored in the HLTOUT task. Though,
637 // we do not know, whether HLTOUT is going to be processed or not.
639 fpHLTOUTTask->Reset();
641 TObjLink *lnk=fTaskList.FirstLink();
643 TObject* obj=lnk->GetObject();
645 AliHLTTask* pTask=(AliHLTTask*)obj;
646 int locResult=pTask->EndRun();
647 if (iResult>=0 && locResult<0) iResult=locResult;
648 // ProcInfo_t ProcInfo;
649 // gSystem->GetProcInfo(&ProcInfo);
650 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
655 PrintBenchmarking(fStopwatches, 1 /*clean*/);
656 if (fEventCount!=fGoodEvents) {
657 HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
659 ClearStatusFlags(kStarted);
663 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
665 // see header file for class documentation
668 AliHLTComponentBlockDataList controlBlocks;
669 AliHLTComponentBlockData bd;
671 // run decriptor block of type kAliHLTDataTypeSOR/kAliHLTDataTypeEOR
672 AliHLTComponent::FillBlockData(bd);
673 AliHLTRunDesc runDesc;
674 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
675 runDesc.fStructSize=sizeof(AliHLTRunDesc);
676 runDesc.fRunNo=AliHLTMisc::Instance().GetCDBRunNo();
678 bd.fSize=sizeof(AliHLTRunDesc);
680 bd.fSpecification=kAliHLTVoidDataSpec;
681 controlBlocks.push_back(bd);
683 // ECS parameter of type kAliHLTDataTypeECSParam
684 if (fECSParams.IsNull())
685 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";
686 AliHLTComponent::FillBlockData(bd);
687 bd.fPtr=(void*)fECSParams.Data();
688 bd.fSize=fECSParams.Length()+1;
689 bd.fDataType=kAliHLTDataTypeECSParam;
690 bd.fSpecification=kAliHLTVoidDataSpec;
691 controlBlocks.push_back(bd);
693 AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
694 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
695 TObjLink *lnk=fTaskList.FirstLink();
696 while (lnk && iResult>=0) {
697 TObject* obj=lnk->GetObject();
699 AliHLTTask* pTask=(AliHLTTask*)obj;
700 AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
701 if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
702 else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
703 else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
704 iResult=pTask->ProcessTask(-1, eventType, 0, 0);
710 // control events are not supposed to go into the HLTOUT
712 fpHLTOUTTask->Reset();
714 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
718 int AliHLTSystem::DeinitTasks()
720 // see header file for class documentation
722 TObjLink *lnk=fTaskList.LastLink();
724 TObject* obj=lnk->GetObject();
726 AliHLTTask* pTask=(AliHLTTask*)obj;
727 int localRes=pTask->Deinit();
728 if (iResult>=0) iResult=localRes;
729 // ProcInfo_t ProcInfo;
730 // gSystem->GetProcInfo(&ProcInfo);
731 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
742 int AliHLTSystem::CleanupHLTOUTHandlers()
744 // see header file for class documentation
745 if (fpChainHandlers) {
746 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
747 fpChainHandlers=NULL;
749 AliHLTOUT::InvalidateBlocks(*pHandlers);
750 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
752 assert(pHandlers->size()==0);
757 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
760 AliHLTOUT::InvalidateBlocks(*pHandlers);
761 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
763 assert(pHandlers->size()==0);
767 if (fpProprietaryHandlers) {
768 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
769 fpProprietaryHandlers=NULL;
771 AliHLTOUT::InvalidateBlocks(*pHandlers);
772 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
774 assert(pHandlers->size()==0);
780 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
782 // see header file for class documentation
785 p=(void*)new char[size];
789 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
794 int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd )
796 // see header file for class documentation
797 unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
798 void* block=AllocMemory(NULL, blocksize);
799 if (!block) return -ENOMEM;
800 memset(block, 0, blocksize);
801 *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
802 (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
803 (*edd)->fDataSize=size;
804 (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
809 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
810 AliRawReader* rawReader)
812 // see header file for class documentation
814 if (runLoader || rawReader || nofEvents==0) {
815 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
816 if (CheckStatus(kReady)) {
818 // special case to close the reconstruction
819 if (!CheckStatus(kError)) {
822 CleanupHLTOUTHandlers();
825 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
826 AliHLTUInt64_t trgMask=0x1;
827 AliHLTUInt32_t timestamp=0;
828 AliHLTUInt32_t eventtype=0;
829 if (runLoader==NULL) {
830 // this is a quick workaround for the case of simulation
831 // the trigger framework is still under development, secondly, AliHLTSimulation
832 // does not yet add the emulated ECS parameters, so no CTP trigger is known in the HLT
833 // AliHLTTask will initialize one dummy CTP trigger class with bit 0, that's why the
834 // default trigger mask is 0x1
835 trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
837 // get the timestamp and type of the event from the raw reader
838 // this is currently only meaningfull for reconstruction (runloader==NULL)
839 timestamp=AliHLTMisc::Instance().GetTimeStamp(rawReader);
840 eventtype=AliHLTMisc::Instance().GetEventType(rawReader);
842 // the system always remains started after event processing, a specific
843 // call with nofEvents==0 is needed to execute the stop sequence
844 if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
848 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
851 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
857 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
859 // see header file for class documentation
861 if (runLoader || esd) {
862 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
863 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
865 HLTError("missing run loader/ESD instance(s)");
871 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
873 // see header file for class documentation
875 if (!pHLTOUT) return -EINVAL;
876 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
878 // add the current HLTOUT task to the collection
880 AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
881 if (pTask && (iResult=pTask->Init())>=0) {
882 if (pTask->GetNofDataBlocks()>0) {
883 pHLTOUT->AddSubCollection(pTask);
886 HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
893 // process all kChain handlers first
895 if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
896 HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
901 fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
902 if (!fpProprietaryHandlers)
903 fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
905 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
906 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
907 if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
909 // invalidate all blocks
910 AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
911 AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
913 AliHLTComponentDataTypeList esdBlocks;
915 for (iResult=pHLTOUT->SelectFirstDataBlock();
917 iResult=pHLTOUT->SelectNextDataBlock()) {
918 AliHLTComponentDataType dt=kAliHLTVoidDataType;
919 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
920 pHLTOUT->GetDataBlockDescription(dt, spec);
921 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
922 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
924 // default handling for ESD data blocks does not require an explicite handler
925 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
926 handlerType=AliHLTModuleAgent::kEsd;
928 const char* pMsg="invalid";
929 switch (handlerType) {
930 case AliHLTModuleAgent::kEsd:
933 // schedule for later processing
934 pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
936 AliHLTComponentDataTypeList::iterator element=esdBlocks.begin();
937 for (; element!=esdBlocks.end(); element++) {
939 HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str());
943 if (element==esdBlocks.end()) esdBlocks.push_back(dt);
946 const AliHLTUInt8_t* pBuffer=NULL;
947 AliHLTUInt32_t size=0;
948 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
949 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
950 pHLTOUT->ReleaseDataBuffer(pBuffer);
952 pHLTOUT->MarkDataBlockProcessed();
956 case AliHLTModuleAgent::kRawReader:
957 // handled in the AliRawReaderHLT
959 case AliHLTModuleAgent::kRawStream:
960 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
961 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
962 AliHLTComponent::DataType2Text(dt).c_str(), spec);
964 case AliHLTModuleAgent::kChain:
965 HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
966 "New block of this type added by the chain? Skipping data block ...",
967 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
968 AliHLTComponent::DataType2Text(dt).c_str(), spec);
970 case AliHLTModuleAgent::kProprietary:
971 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
972 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
973 AliHLTComponent::DataType2Text(dt).c_str(), spec);
975 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
976 int res=pHandler->ProcessData(pHLTOUT);
978 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
979 res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
980 AliHLTComponent::DataType2Text(dt).c_str(), spec);
984 case AliHLTModuleAgent::kUnknownOutput:
986 // fall trough intended
988 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
989 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
990 AliHLTComponent::DataType2Text(dt).c_str(), spec);
993 // TODO: the return value of SelectFirst/NextDataBlock must be
994 // changed in order to avoid this check
995 if (iResult==-ENOENT) iResult=0;
997 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
999 // process and write all esd data blocks
1000 for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
1001 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1002 AliHLTOUTHandler* pHandler=*handler;
1003 const AliHLTUInt8_t* pBuffer=NULL;
1004 AliHLTUInt32_t size=0;
1005 pHandler->ProcessData(pHLTOUT);
1006 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1007 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
1008 AliHLTComponentDataType dt=desc;
1009 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
1010 pHandler->ReleaseProcessedData(pBuffer, size);
1012 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1015 // process all kProprietary data blocks
1016 for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) {
1017 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1018 AliHLTOUTHandler* pHandler=*handler;
1019 const AliHLTUInt8_t* pBuffer=NULL;
1020 AliHLTUInt32_t size=0;
1021 pHandler->ProcessData(pHLTOUT);
1022 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1023 HLTWarning("data produced by kProprietary handler ignored");
1024 pHandler->ReleaseProcessedData(pBuffer, size);
1026 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1029 // remove all empty handlers form the list (handlers which did not get a block this time)
1030 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
1031 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
1036 int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
1038 // see header file for class documentation
1040 if (!pHLTOUT) return -EINVAL;
1042 if (!fpChainHandlers)
1043 fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
1045 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
1046 if (!pChainHandlers) return -ENOMEM;
1048 // invalidate all blocks
1049 AliHLTOUT::InvalidateBlocks(*pChainHandlers);
1052 pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
1054 // process all defined chain handlers
1055 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
1056 for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
1057 if (chainHandler->IsEmpty()) continue;
1058 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
1059 AliHLTOUTHandler* pHandler=*chainHandler;
1060 const AliHLTUInt8_t* pBuffer=NULL;
1061 AliHLTUInt32_t size=0;
1062 pHandler->ProcessData(pHLTOUT);
1063 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1064 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
1065 //AliHLTComponentDataType dt=desc;
1067 pHandler->ReleaseProcessedData(pBuffer, size);
1069 pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
1072 // remove all empty handlers form the list (handlers which did not get a block this time)
1073 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
1078 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
1080 // see header file for class documentation
1083 if (fpComponentHandler) {
1084 TString libs(libraries);
1085 TObjArray* pTokens=libs.Tokenize(" ");
1087 int iEntries=pTokens->GetEntriesFast();
1088 for (int i=0; i<iEntries && iResult>=0; i++) {
1089 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
1094 SetStatusFlags(kLibrariesLoaded);
1096 // lets see if we need this, probably not
1097 //fpComponentHandler->UnloadLibraries();
1098 ClearStatusFlags(kLibrariesLoaded);
1102 HLTFatal("no component handler available");
1110 int AliHLTSystem::Configure(AliRunLoader* runloader)
1112 // see header file for class documentation
1113 return Configure(NULL, runloader);
1116 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
1118 // see header file for class documentation
1120 if (CheckStatus(kRunning)) {
1121 HLTError("HLT system in running state, can not configure");
1124 ClearStatusFlags(kTaskListCreated);
1125 if (CheckFilter(kHLTLogDebug))
1126 AliHLTModuleAgent::PrintStatus();
1127 if (CheckStatus(kConfigurationLoaded)==0) {
1128 iResult=LoadConfigurations(rawReader, runloader);
1130 if (fChains.Length()==0) {
1131 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
1136 SetStatusFlags(kConfigurationLoaded);
1137 if (CheckFilter(kHLTLogDebug))
1138 fpConfigurationHandler->PrintConfigurations();
1139 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
1141 SetStatusFlags(kTaskListCreated);
1144 if (iResult<0) SetStatusFlags(kError);
1149 int AliHLTSystem::ScanOptions(const char* options)
1151 // see header file for class documentation
1154 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
1156 TString excludelibs("");
1157 TString alloptions(options);
1158 TObjArray* pTokens=alloptions.Tokenize(" ");
1160 int iEntries=pTokens->GetEntriesFast();
1161 for (int i=0; i<iEntries; i++) {
1162 TString token=(((TObjString*)pTokens->At(i))->GetString());
1163 if (token.Contains("loglevel=")) {
1164 TString param=token.ReplaceAll("loglevel=", "");
1165 if (param.IsDigit()) {
1166 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
1167 } else if (param.BeginsWith("0x") &&
1168 param.Replace(0,2,"",0).IsHex()) {
1170 sscanf(param.Data(),"%x", &severity);
1171 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
1173 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1175 } else if (token.Contains("frameworklog=")) {
1176 TString param=token.ReplaceAll("frameworklog=", "");
1177 if (param.IsDigit()) {
1178 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
1179 } else if (param.BeginsWith("0x") &&
1180 param.Replace(0,2,"",0).IsHex()) {
1182 sscanf(param.Data(),"%x", &severity);
1183 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
1185 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1187 } else if (token.Contains("alilog=off")) {
1189 } else if (token.Contains("config=") || token.Contains("run-online-config")) {
1190 if (!CheckStatus(kConfigurationLoaded)) {
1192 AliHLTOnlineConfiguration* pConf = NULL;
1193 if (token.Contains("run-online-config")) {
1194 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry("HLT/Calib/OnlineConfig");
1196 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
1197 if (pObject && pObject->IsA() == AliHLTOnlineConfiguration::Class())
1198 pConf = (AliHLTOnlineConfiguration*)pObject;
1201 if (token.Contains("config=")) {
1202 TString param=token.ReplaceAll("config=", "");
1203 if (token.EndsWith(".xml", TString::kIgnoreCase)) {
1205 pConf = new AliHLTOnlineConfiguration;
1206 filesize = pConf->LoadConfiguration(param.Data());
1207 if (filesize <= 0) {
1208 HLTError("cannot load config \'%s\'", param.Data());
1212 gROOT->Macro(param.Data(), &error);
1214 SetStatusFlags(kConfigurationLoaded);
1216 HLTError("cannot execute macro \'%s\'", param.Data());
1222 error = pConf->Parse();
1224 fChains = pConf->GetDefaultChains();
1225 libs = pConf->GetComponentLibraries();
1227 SetStatusFlags(kConfigurationLoaded);
1229 HLTError("cannot parse online configuration");
1233 delete pConf; pConf=NULL;
1235 HLTWarning("HLT options has both a config file and run-online-config set");
1237 } else if (token.Contains("chains=")) {
1238 TString param=token.ReplaceAll("chains=", "");
1239 fChains=param.ReplaceAll(",", " ");
1240 if (fChains.IsNull()) fChains=" "; // disable all chains
1241 } else if (token.Contains("libmode=")) {
1242 TString param=token.ReplaceAll("libmode=", "");
1243 param.ReplaceAll(",", " ");
1244 if (fpComponentHandler) {
1245 if (param.CompareTo("static")==0) {
1246 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
1247 } else if (param.CompareTo("dynamic")==0) {
1248 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
1250 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
1253 } else if (token.BeginsWith("ECS=")) {
1254 fECSParams=token.ReplaceAll("ECS=", "");
1255 } else if (token.BeginsWith("hltout-mode=")) {
1256 // The actual parameter for argument 'hltout-mode' is treated in AliSimulation.
1257 // For AliHLTSystem the occurrence with parameter 'split' signals the use of the
1258 // separated HLTOUTComponents for digit and raw data. All others indicate
1259 // HLTOUTComponent type 'global' where the data generation is steered from global
1261 fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")==1;
1262 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1265 } else if (token.BeginsWith("!lib") && token.EndsWith(".so")) {
1269 HLTWarning("unknown option \'%s\'", token.Data());
1276 if (libs.IsNull()) {
1277 const char** deflib=fgkHLTDefaultLibs;
1278 for (;*deflib; deflib++) {
1279 if (excludelibs.Contains(*deflib)) continue;
1284 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
1285 (LoadComponentLibraries(libs.Data())<0)) {
1286 HLTError("error while loading HLT libraries");
1294 int AliHLTSystem::Reset(int bForce)
1296 // see header file for class documentation
1298 if (!bForce && CheckStatus(kRunning)) {
1299 HLTError("HLT system in running state, can not configure");
1303 ClearStatusFlags(~kUninitialized);
1307 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1309 // see header file for class documentation
1310 if (CheckStatus(kRunning)) {
1311 HLTError("HLT system in running state, can not configure");
1315 AliHLTModuleAgent* pAgent=NULL;
1317 // first check for the required libraries and load those
1319 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1320 pAgent && iResult>=0;
1321 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1322 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1324 HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1330 iResult=LoadComponentLibraries(extralibs.Data());
1333 // in order to register the configurations in the correct sequence
1334 // all agents need to be ordered with respect to the required
1335 // libraries. Ordering relies on the naming convention
1336 // libAliHLT<Module>.so
1338 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1339 pAgent && iResult>=0;
1340 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1341 AliHLTModuleAgent* pPrevDep=NULL;
1342 TString dependencies=pAgent->GetRequiredComponentLibraries();
1343 TObjArray* pTokens=dependencies.Tokenize(" ");
1345 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
1346 TString module=((TObjString*)pTokens->At(n))->GetString();
1347 HLTDebug(" checking %s", module.Data());
1348 module.ReplaceAll("libAliHLT", "");
1349 module.ReplaceAll(".so", "");
1351 for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep));
1352 pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) {
1353 HLTDebug(" checking %s == %s", module.Data(), pCurrent->GetModuleId());
1355 if (module.CompareTo(pCurrent->GetModuleId())==0) {
1365 // insert right after the last dependency
1366 agents.AddAfter(pPrevDep, pAgent);
1367 HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
1369 // insert at the beginning
1370 agents.AddFirst(pAgent);
1371 HLTDebug("insert %s at beginning", pAgent->GetModuleId());
1375 // now we load the configurations
1376 if (agents.GetEntries()) {
1377 TIter next(&agents);
1378 while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
1379 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1380 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1387 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1389 // see header file for class documentation
1390 if (CheckStatus(kRunning)) {
1391 HLTError("HLT system in running state, can not configure");
1394 if (!CheckStatus(kConfigurationLoaded)) {
1395 HLTWarning("configurations not yet loaded");
1404 if (fChains.Length()>0) {
1406 HLTImportant("custom reconstruction chain: %s", chains.Data());
1408 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1409 pAgent && iResult>=0;
1410 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1411 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1413 if (!chains.IsNull()) chains+=" ";
1414 chains+=agentchains;
1415 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1420 // build task list for chains
1421 TObjArray* pTokens=chains.Tokenize(" ");
1423 int iEntries=pTokens->GetEntriesFast();
1424 for (int i=0; i<iEntries && iResult>=0; i++) {
1425 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1426 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1428 iResult=BuildTaskList(pConf);
1429 if (true) { // condition was deprecated but kept for sake of svn diff
1430 // bHaveOutput variable has to be set for both running modes
1431 // AliHLTSimulation and AliHLTReconstruction
1432 assert(fpComponentHandler!=NULL);
1433 TString cid=pConf->GetComponentID();
1434 if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
1435 // remove from the input of a global HLTOUT configuration
1436 chains.ReplaceAll(pCID, "");
1437 } else if (bHaveOutput==0) {
1438 // check whether this configuration produces data output
1439 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1441 chains.ReplaceAll(pCID, "");
1446 HLTWarning("can not find configuration %s", pCID);
1452 // build HLTOUT for simulation
1453 if (iResult>=0 && runloader) {
1455 // there are components in the chain which produce data which need to be
1456 // piped to an HLTOUT
1458 // add the SchemaEvolutionComponent which analyzes the ROOT objects in
1459 // the output stream
1460 if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
1461 fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
1462 AliHLTConfiguration schemaevo("_schemaevolution_", "ROOTSchemaEvolutionComponent",
1463 chains.Data(), "-file=HLT.StreamerInfo.root");
1464 iResult=BuildTaskList("_schemaevolution_");
1466 HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
1469 // add the HLTOUT component
1470 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1471 fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
1472 // for the default HLTOUTComponent type 'global' the data generation is steered
1473 // by global flags from AliSimulation. This allows for emulation of the old
1474 // AliHLTSimulation behavior where only one chain is run on either digits or
1475 // simulated raw data and the HLT digits and raw files have been generated
1476 // depending on the configuration
1477 const char* HLTOUTComponentId="HLTOUT";
1478 if (!fUseHLTOUTComponentTypeGlobal) {
1479 // choose the type of output depending on the availability of
1481 if (rawReader) HLTOUTComponentId="HLTOUTraw";
1482 else HLTOUTComponentId="HLTOUTdigits";
1484 AliHLTConfiguration globalout("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
1485 iResult=BuildTaskList("_globalout_");
1487 HLTError("can not load libHLTsim.so and HLTOUT component");
1493 // build HLTOUT task for reconstruction
1494 // Matthias 08.07.2008 the rawReader is never set when running embedded into
1495 // AliReconstruction. The system is configured during AliHLTReconstructor::Init
1496 // where the RawReader is not available. It is available in the first invocation
1499 // That means that policy is slightly changed:
1500 // - if the run loader is available -> AliSimulation
1501 // - no run loader available -> AliReconstruction
1502 if (iResult>=0 && !runloader) {
1504 // there are components in the chain which produce data which need to be
1505 // piped to an HLTOUT sub-collection
1506 if (!fpHLTOUTTask) {
1507 iResult=AddHLTOUTTask(chains.Data());
1512 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1517 int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
1519 // see header file for class documentation
1521 if (!hltoutchains || hltoutchains[0]==0) return 0;
1523 // check chains for output
1524 TString chains=hltoutchains;
1525 TObjArray* pTokens=chains.Tokenize(" ");
1527 int iEntries=pTokens->GetEntriesFast();
1528 for (int i=0; i<iEntries && iResult>=0; i++) {
1529 const char* token=((TObjString*)pTokens->At(i))->GetString().Data();
1530 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
1532 TString cid=pConf->GetComponentID();
1533 if (fpComponentHandler->HasOutputData(cid.Data())) {
1537 HLTWarning("can not find configuration %s", token);
1539 // remove from the list of hltout chains
1540 chains.ReplaceAll(token, "");
1545 // do not create the HLTOUT task if none of the chains have output
1546 if (chains.IsNull()) return 0;
1548 // indicate the task to be available
1552 if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) {
1553 HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask);
1555 HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains \"%s\"",
1556 fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data());
1561 fpHLTOUTTask=new AliHLTOUTTask(chains);
1563 if (fpHLTOUTTask->GetConf() &&
1564 (fpHLTOUTTask->GetConf()->SourcesResolved()>0 ||
1565 fpHLTOUTTask->GetConf()->ExtractSources()>0)) {
1566 iResult=InsertTask(fpHLTOUTTask);
1568 HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
1573 delete fpHLTOUTTask;
1582 int AliHLTSystem::CheckStatus(int flag)
1584 // see header file for class documentation
1585 if (flag==kUninitialized && flag==fState) return 1;
1586 if ((fState&flag)==flag) return 1;
1590 int AliHLTSystem::GetStatusFlags()
1592 // see header file for class documentation
1596 int AliHLTSystem::SetStatusFlags(int flags)
1598 // see header file for class documentation
1603 int AliHLTSystem::ClearStatusFlags(int flags)
1605 // see header file for class documentation
1610 AliHLTfctVoid AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1612 // see header file for class documentation
1613 if (fpComponentHandler==NULL) return NULL;
1614 return fpComponentHandler->FindSymbol(library, symbol);
1617 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1619 // see header file for class documentation
1620 SetLocalLoggingLevel(level);
1621 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1622 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
1625 int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity,
1626 const char* originClass, const char* originFunc,
1627 const char* file, int line, ... ) const
1629 // see header file for function documentation
1633 va_start(args, line);
1635 if (!fName.IsNull())
1636 AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", fName.Data());
1637 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() /*append if non empty*/));
1643 int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
1645 // Init the HLTOUT instance for the current event.
1646 // The instance can be used by other classes to get hold on the data
1648 if (!instance) return -EINVAL;
1649 if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
1654 int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
1656 // Clear the HLTOUT instance.
1659 HLTWarning("HLTOUT instance still in use, potential problem due to invalid pointer ahead");
1663 if (target) *target=fpHLTOUT;
1668 AliHLTOUT* AliHLTSystem::RequestHLTOUT()
1670 // Get the HLTOUT instance.
1671 // User method for processing classes. To be released after use.
1672 if (!fpHLTOUT) return NULL;
1677 int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
1679 // Release the HLTOUT instance after use.
1680 if (!instance) return -EINVAL;
1681 if (instance!=fpHLTOUT) return -ENOENT;