3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTSystem.cxx
20 @author Matthias Richter
22 @brief Implementation of HLT module management.
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
36 #include "AliHLTStdIncludes.h"
37 #include "AliHLTSystem.h"
38 #include "AliHLTComponentHandler.h"
39 #include "AliHLTComponent.h"
40 #include "AliHLTConfiguration.h"
41 #include "AliHLTConfigurationHandler.h"
42 #include "AliHLTTask.h"
43 #include "AliHLTModuleAgent.h"
44 #include "AliHLTOfflineInterface.h"
45 #include "AliHLTDataSource.h"
46 #include <TObjArray.h>
47 #include <TObjString.h>
48 #include <TStopwatch.h>
49 //#include <TSystem.h>
51 //#include <TInterpreter.h>
53 /** HLT default component libraries */
54 const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
57 // "libAliHLTSample.so",
64 /** ROOT macro for the implementation of ROOT specific class methods */
65 ClassImp(AliHLTSystem)
67 AliHLTSystem::AliHLTSystem()
69 fpComponentHandler(new AliHLTComponentHandler()),
70 fpConfigurationHandler(new AliHLTConfigurationHandler()),
74 fStopwatches(new TObjArray),
78 // see header file for class documentation
80 // refer to README to build package
82 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
84 if (fgNofInstances++>0)
85 HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
87 SetGlobalLoggingLevel(kHLTLogDefault);
88 SetFrameworkLog(kHLTLogDefault);
89 if (fpComponentHandler) {
90 AliHLTComponentEnvironment env;
91 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
92 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
93 env.fLoggingFunc=NULL;
94 fpComponentHandler->SetEnvironment(&env);
95 InitAliLogFunc(fpComponentHandler);
96 fpComponentHandler->AnnounceVersion();
98 HLTFatal("can not create Component Handler");
100 if (fpConfigurationHandler) {
101 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
103 HLTFatal("can not create Configuration Handler");
107 AliHLTSystem::~AliHLTSystem()
109 // see header file for class documentation
112 AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
113 if (fpConfigurationHandler) {
114 delete fpConfigurationHandler;
116 fpConfigurationHandler=NULL;
118 if (fpComponentHandler) {
119 delete fpComponentHandler;
121 fpComponentHandler=NULL;
124 int AliHLTSystem::fgNofInstances=0;
126 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
128 // see header file for class documentation
129 HLTLogKeyword("configuration handling");
132 HLTError("function not yet implemented");
140 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
142 // see header file for class documentation
143 HLTLogKeyword("configuration handling");
148 HLTError("function not yet implemented");
157 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
159 // see header file for class documentation
160 HLTLogKeyword("configuration handling");
163 HLTError("function not yet implemented");
171 int AliHLTSystem::BuildTaskList(const char* id)
173 // see header file for class documentation
176 if (fpConfigurationHandler) {
177 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
179 iResult=BuildTaskList(pConf);
181 HLTError("unknown configuration \"%s\"", id);
193 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
195 // see header file for class documentation
198 AliHLTTask* pTask=NULL;
199 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
200 if (pTask->GetConf()!=pConf) {
201 HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
204 // task for this configuration exists, terminate
206 } else if (pConf->SourcesResolved(1)!=1) {
207 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
210 pTask=new AliHLTTask(pConf);
214 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
217 static int iterationLevel=0;
218 if (pTask && iResult>=0) {
219 // check for circular dependencies
220 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
221 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
222 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
223 HLTError("aborted ...");
227 // check whether all dependencies are already in the task list
228 // create the missing ones
229 // this step is an iterative process which calls this function again for the missing
230 // configurations, in order to avoid the currently processed task to be created
231 // again it is added to the list temporarily and removed afterwards
232 // This is of high importance to preserve the order of the tasks. Furthermore, the
233 // InsertTask method has to be used in order to set all the cross links right
234 fTaskList.Add(pTask);
235 AliHLTConfiguration* pDep=pConf->GetFirstSource();
236 while (pDep!=NULL && iResult>=0) {
237 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
238 if (FindTask(pDep->GetName())==NULL) {
239 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
241 iResult=BuildTaskList(pDep);
244 pDep=pConf->GetNextSource();
246 // remove the temporarily added task
247 fTaskList.Remove(pTask);
249 // insert the task and set the cross-links
251 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
252 iResult=InsertTask(pTask);
265 int AliHLTSystem::CleanTaskList()
267 // see header file for class documentation
270 while ((lnk=fTaskList.LastLink())!=NULL) {
271 delete (lnk->GetObject());
272 fTaskList.Remove(lnk);
277 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
279 // see header file for class documentation
281 TObjLink *lnk = NULL;
282 if ((iResult=pTask->CheckDependencies())>0)
283 lnk=fTaskList.FirstLink();
284 while (lnk && iResult>0) {
285 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
286 //HLTDebug("checking \"%s\"", pCurr->GetName());
287 iResult=pTask->Depends(pCurr);
289 iResult=pTask->SetDependency(pCurr);
290 pCurr->SetTarget(pTask);
291 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
293 if (pCurr->Depends(pTask)) {
294 // circular dependency
295 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
297 } else if ((iResult=pTask->CheckDependencies())>0) {
303 fTaskList.AddAfter(lnk, pTask);
305 fTaskList.AddFirst(pTask);
307 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
308 } else if (iResult>0) {
309 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
315 AliHLTTask* AliHLTSystem::FindTask(const char* id)
317 // see header file for class documentation
318 AliHLTTask* pTask=NULL;
320 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
325 void AliHLTSystem::PrintTaskList()
327 // see header file for class documentation
328 HLTLogKeyword("task list");
329 TObjLink *lnk = NULL;
330 HLTMessage("Task List");
331 lnk=fTaskList.FirstLink();
333 TObject* obj=lnk->GetObject();
335 HLTMessage(" %s - status:", obj->GetName());
336 AliHLTTask* pTask=(AliHLTTask*)obj;
337 pTask->PrintStatus();
344 int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
346 // see header file for class documentation
349 SetStatusFlags(kRunning);
350 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
351 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
352 if (fEventCount==0) {
353 InitBenchmarking(fStopwatches);
355 //ResumeBenchmarking(fStopwatches);
357 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
358 if ((iResult=ProcessTasks(i))>=0) {
362 // TODO: define different running modes to either ignore errors in
363 // event processing or not
368 fEventCount+=iNofEvents;
369 if (bStop) StopTasks();
370 //else PauseBenchmarking(fStopwatches);
372 if (bStop) DeinitTasks();
376 } else if (iResult==-126 /*ENOKEY*/) {
377 iResult=0; // do not propagate the error
379 ClearStatusFlags(kRunning);
383 int AliHLTSystem::InitTasks()
385 // see header file for class documentation
387 TObjLink *lnk=fTaskList.FirstLink();
390 HLTWarning("Task list is empty, skipping HLT");
391 return -126 /*ENOKEY*/;
393 while (lnk && iResult>=0) {
394 TObject* obj=lnk->GetObject();
396 AliHLTTask* pTask=(AliHLTTask*)obj;
397 iResult=pTask->Init(NULL, fpComponentHandler);
398 // ProcInfo_t ProcInfo;
399 // gSystem->GetProcInfo(&ProcInfo);
400 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
406 HLTError("can not initialize task list, error %d", iResult);
412 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
414 // see header file for class documentation
416 if (pStopwatches==NULL) return 0;
418 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
419 TStopwatch* pStopwatch= new TStopwatch;
422 pStopwatches->AddAt(pStopwatch, i);
429 TObjLink *lnk=fTaskList.FirstLink();
430 while (lnk && iResult>=0) {
431 TObject* obj=lnk->GetObject();
433 AliHLTTask* pTask=(AliHLTTask*)obj;
434 AliHLTComponent* pComp=NULL;
435 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
436 switch (pComp->GetComponentType()) {
437 case AliHLTComponent::kProcessor:
438 pComp->SetStopwatches(pStopwatches);
440 case AliHLTComponent::kSource:
442 // this switch determines whether the time consumption of the
443 // AliHLTComponent base methods should be counted to the input
444 // stopwatch or base stopwatch.
445 //int inputBase=(int)AliHLTComponent::kSWBase;
446 int inputBase=(int)AliHLTComponent::kSWInput;
447 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
448 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
451 case AliHLTComponent::kSink:
453 // this switch determines whether the time consumption of the
454 // AliHLTComponent base methods should be counted to the output
455 // stopwatch or base stopwatch.
456 //int outputBase=(int)AliHLTComponent::kSWBase;
457 int outputBase=(int)AliHLTComponent::kSWOutput;
458 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
459 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
463 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
473 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean)
475 // see header file for class documentation
477 if (pStopwatches==NULL) return 0;
479 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
480 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
486 if (iInitialized!=0) {
487 HLTInfo("HLT statistics:\n"
488 " base: R:%.3fs C:%.3fs\n"
489 " input: R:%.3fs C:%.3fs\n"
490 " output: R:%.3fs C:%.3fs\n"
491 " event processing : R:%.3fs C:%.3fs"
492 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
493 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
494 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
495 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
496 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
497 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
498 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
499 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
504 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
505 TObject* pObj=pStopwatches->RemoveAt(i);
506 if (pObj) delete pObj;
512 int AliHLTSystem::StartTasks()
514 // see header file for class documentation
516 TObjLink *lnk=fTaskList.FirstLink();
517 while (lnk && iResult>=0) {
518 TObject* obj=lnk->GetObject();
520 AliHLTTask* pTask=(AliHLTTask*)obj;
521 iResult=pTask->StartRun();
522 // ProcInfo_t ProcInfo;
523 // gSystem->GetProcInfo(&ProcInfo);
524 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
530 HLTError("can not start task list, error %d", iResult);
534 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
535 HLTError("can not send SOR event");
541 int AliHLTSystem::ProcessTasks(Int_t eventNo)
543 // see header file for class documentation
545 HLTDebug("processing event no %d", eventNo);
546 TObjLink *lnk=fTaskList.FirstLink();
547 while (lnk && iResult>=0) {
548 TObject* obj=lnk->GetObject();
550 AliHLTTask* pTask=(AliHLTTask*)obj;
551 iResult=pTask->ProcessTask(eventNo);
552 // ProcInfo_t ProcInfo;
553 // gSystem->GetProcInfo(&ProcInfo);
554 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
561 HLTInfo("Event %d successfully finished (%d)", eventNo, iResult);
564 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
570 int AliHLTSystem::StopTasks()
572 // see header file for class documentation
574 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
575 HLTError("can not send EOR event");
577 TObjLink *lnk=fTaskList.FirstLink();
579 TObject* obj=lnk->GetObject();
581 AliHLTTask* pTask=(AliHLTTask*)obj;
582 int locResult=pTask->EndRun();
583 if (iResult>=0 && locResult<0) iResult=locResult;
584 // ProcInfo_t ProcInfo;
585 // gSystem->GetProcInfo(&ProcInfo);
586 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
591 PrintBenchmarking(fStopwatches, 1 /*clean*/);
595 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
597 // see header file for class documentation
599 // disabled for the moment
603 AliHLTRunDesc runDesc;
604 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
605 runDesc.fStructSize=sizeof(AliHLTRunDesc);
606 AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
607 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
608 TObjLink *lnk=fTaskList.FirstLink();
609 while (lnk && iResult>=0) {
610 TObject* obj=lnk->GetObject();
612 AliHLTTask* pTask=(AliHLTTask*)obj;
613 iResult=pTask->ProcessTask(-1);
618 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
622 int AliHLTSystem::DeinitTasks()
624 // see header file for class documentation
626 TObjLink *lnk=fTaskList.FirstLink();
627 while (lnk && iResult>=0) {
628 TObject* obj=lnk->GetObject();
630 AliHLTTask* pTask=(AliHLTTask*)obj;
631 iResult=pTask->Deinit();
632 // ProcInfo_t ProcInfo;
633 // gSystem->GetProcInfo(&ProcInfo);
634 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
645 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
647 // see header file for class documentation
650 p=(void*)new char[size];
654 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
659 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
660 AliRawReader* rawReader)
662 // see header file for class documentation
664 if (runLoader || rawReader || nofEvents==0) {
665 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
666 if (CheckStatus(kReady)) {
668 // special case to close the reconstruction
669 if (!CheckStatus(kError)) {
674 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
675 // the system always remains started after event processing, a specific
676 // call with nofEvents==0 is needed to execute the stop sequence
677 if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
681 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
684 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
690 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
692 // see header file for class documentation
694 if (runLoader || esd) {
695 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
696 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
698 HLTError("missing run loader/ESD instance(s)");
704 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
706 // see header file for class documentation
709 if (fpComponentHandler) {
710 TString libs(libraries);
711 TObjArray* pTokens=libs.Tokenize(" ");
713 int iEntries=pTokens->GetEntries();
714 for (int i=0; i<iEntries && iResult>=0; i++) {
715 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
720 SetStatusFlags(kLibrariesLoaded);
722 // lets see if we need this, probably not
723 //fpComponentHandler->UnloadLibraries();
724 ClearStatusFlags(kLibrariesLoaded);
728 HLTFatal("no component handler available");
736 int AliHLTSystem::Configure(AliRunLoader* runloader)
738 // see header file for class documentation
739 return Configure(NULL, runloader);
742 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
744 // see header file for class documentation
746 if (CheckStatus(kRunning)) {
747 HLTError("HLT system in running state, can not configure");
750 ClearStatusFlags(kTaskListCreated);
751 if (CheckFilter(kHLTLogDebug))
752 AliHLTModuleAgent::PrintStatus();
753 if (CheckStatus(kConfigurationLoaded)==0) {
754 iResult=LoadConfigurations(rawReader, runloader);
756 if (fChains.Length()==0) {
757 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'localrec=<conf>\' option");
762 SetStatusFlags(kConfigurationLoaded);
763 if (CheckFilter(kHLTLogDebug))
764 fpConfigurationHandler->PrintConfigurations();
765 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
767 SetStatusFlags(kTaskListCreated);
770 if (iResult<0) SetStatusFlags(kError);
775 int AliHLTSystem::ScanOptions(const char* options)
777 // see header file for class documentation
780 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
782 TString alloptions(options);
783 TObjArray* pTokens=alloptions.Tokenize(" ");
785 int iEntries=pTokens->GetEntries();
786 for (int i=0; i<iEntries; i++) {
787 TString token=(((TObjString*)pTokens->At(i))->GetString());
788 if (token.Contains("loglevel=")) {
789 TString param=token.ReplaceAll("loglevel=", "");
790 if (param.IsDigit()) {
791 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
792 } else if (param.BeginsWith("0x") &&
793 param.Replace(0,2,"",0).IsHex()) {
795 sscanf(param.Data(),"%x", &severity);
796 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
798 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
800 } else if (token.Contains("frameworklog=")) {
801 TString param=token.ReplaceAll("frameworklog=", "");
802 if (param.IsDigit()) {
803 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
804 } else if (param.BeginsWith("0x") &&
805 param.Replace(0,2,"",0).IsHex()) {
807 sscanf(param.Data(),"%x", &severity);
808 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
810 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
812 } else if (token.Contains("alilog=off")) {
814 } else if (token.Contains("config=")) {
815 TString param=token.ReplaceAll("config=", "");
817 gROOT->Macro(param.Data(), &error);
819 SetStatusFlags(kConfigurationLoaded);
821 HLTError("can not execute macro \'%s\'", param.Data());
824 } else if (token.Contains("chains=")) {
825 TString param=token.ReplaceAll("chains=", "");
826 fChains=param.ReplaceAll(",", " ");
827 } else if (token.Contains("libmode=")) {
828 TString param=token.ReplaceAll("libmode=", "");
829 param.ReplaceAll(",", " ");
830 if (fpComponentHandler) {
831 if (param.CompareTo("static")==0) {
832 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
833 } else if (param.CompareTo("dynamic")==0) {
834 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
836 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
839 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
843 HLTWarning("unknown option \'%s\'", token.Data());
851 const char** deflib=fgkHLTDefaultLibs;
857 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
858 (LoadComponentLibraries(libs.Data())<0)) {
859 HLTError("error while loading HLT libraries");
867 int AliHLTSystem::Reset(int bForce)
869 // see header file for class documentation
871 if (!bForce && CheckStatus(kRunning)) {
872 HLTError("HLT system in running state, can not configure");
876 ClearStatusFlags(~kUninitialized);
880 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
882 // see header file for class documentation
883 if (CheckStatus(kRunning)) {
884 HLTError("HLT system in running state, can not configure");
888 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
889 while (pAgent && iResult>=0) {
890 const char* deplibs=pAgent->GetRequiredComponentLibraries();
892 HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
893 iResult=LoadComponentLibraries(deplibs);
896 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
897 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
898 pAgent=AliHLTModuleAgent::GetNextAgent();
904 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
906 // see header file for class documentation
907 if (CheckStatus(kRunning)) {
908 HLTError("HLT system in running state, can not configure");
911 if (!CheckStatus(kConfigurationLoaded)) {
912 HLTWarning("configurations not yet loaded");
921 if (fChains.Length()>0) {
923 HLTInfo("custom reconstruction chain: %s", chains.Data());
925 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
926 while ((pAgent || fChains.Length()>0) && iResult>=0) {
927 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
929 if (!chains.IsNull()) chains+="";
931 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
933 pAgent=AliHLTModuleAgent::GetNextAgent();
937 // build task list for chains
938 TObjArray* pTokens=chains.Tokenize(" ");
940 int iEntries=pTokens->GetEntries();
941 for (int i=0; i<iEntries && iResult>=0; i++) {
942 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
943 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
945 iResult=BuildTaskList(pConf);
947 assert(fpComponentHandler!=NULL);
948 TString cid=pConf->GetComponentID();
949 if (cid.CompareTo("HLTOUT")==0) {
950 // remove from the input of a global HLTOUT configuration
951 chains.ReplaceAll(pCID, "");
952 } else if (bHaveOutput==0) {
953 // check whether this configuration produces data output
954 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
956 chains.ReplaceAll(pCID, "");
961 HLTWarning("can not find configuration %s", pCID);
967 // build HLTOUT for simulation
968 if (iResult>=0 && runloader) {
970 // there are components in the chain which produce data which need to be
971 // piped to an HLTOUT
972 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
973 LoadComponentLibraries("libHLTsim.so")>=0) {
974 AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
975 iResult=BuildTaskList("_globalout_");
977 HLTError("can not load libHLTsim.so and HLTOUT component");
983 if (iResult>=0) SetStatusFlags(kTaskListCreated);
988 int AliHLTSystem::CheckStatus(int flag)
990 // see header file for class documentation
991 if (flag==kUninitialized && flag==fState) return 1;
992 if ((fState&flag)==flag) return 1;
996 int AliHLTSystem::GetStatusFlags()
998 // see header file for class documentation
1002 int AliHLTSystem::SetStatusFlags(int flags)
1004 // see header file for class documentation
1009 int AliHLTSystem::ClearStatusFlags(int flags)
1011 // see header file for class documentation
1016 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1018 // see header file for class documentation
1019 if (fpComponentHandler==NULL) return NULL;
1020 return fpComponentHandler->FindSymbol(library, symbol);
1023 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1025 // see header file for class documentation
1026 SetLocalLoggingLevel(level);
1027 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1028 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);