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.
30 #include "AliHLTStdIncludes.h"
31 #include "AliHLTSystem.h"
32 #include "AliHLTComponentHandler.h"
33 #include "AliHLTComponent.h"
34 #include "AliHLTConfiguration.h"
35 #include "AliHLTConfigurationHandler.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 <TObjArray.h>
43 #include <TObjString.h>
44 #include <TStopwatch.h>
45 //#include <TSystem.h>
47 //#include <TInterpreter.h>
49 /** HLT default component libraries */
50 const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
54 // "libAliHLTSample.so",
58 "libAliHLTTrigger.so",
62 /** ROOT macro for the implementation of ROOT specific class methods */
63 ClassImp(AliHLTSystem)
65 AliHLTSystem::AliHLTSystem()
67 fpComponentHandler(new AliHLTComponentHandler()),
68 fpConfigurationHandler(new AliHLTConfigurationHandler()),
72 fStopwatches(new TObjArray),
76 // see header file for class documentation
78 // refer to README to build package
80 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
82 if (fgNofInstances++>0)
83 HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
85 SetGlobalLoggingLevel(kHLTLogDefault);
86 SetFrameworkLog(kHLTLogDefault);
87 if (fpComponentHandler) {
88 AliHLTComponentEnvironment env;
89 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
90 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
91 env.fLoggingFunc=NULL;
92 fpComponentHandler->SetEnvironment(&env);
93 InitAliLogFunc(fpComponentHandler);
94 fpComponentHandler->AnnounceVersion();
96 HLTFatal("can not create Component Handler");
98 if (fpConfigurationHandler) {
99 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
101 HLTFatal("can not create Configuration Handler");
105 AliHLTSystem::~AliHLTSystem()
107 // see header file for class documentation
110 AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
111 if (fpConfigurationHandler) {
112 delete fpConfigurationHandler;
114 fpConfigurationHandler=NULL;
116 if (fpComponentHandler) {
117 delete fpComponentHandler;
119 fpComponentHandler=NULL;
122 int AliHLTSystem::fgNofInstances=0;
124 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
126 // see header file for class documentation
127 HLTLogKeyword("configuration handling");
130 HLTError("function not yet implemented");
138 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
140 // see header file for class documentation
141 HLTLogKeyword("configuration handling");
146 HLTError("function not yet implemented");
155 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
157 // see header file for class documentation
158 HLTLogKeyword("configuration handling");
161 HLTError("function not yet implemented");
169 int AliHLTSystem::BuildTaskList(const char* id)
171 // see header file for class documentation
174 if (fpConfigurationHandler) {
175 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
177 iResult=BuildTaskList(pConf);
179 HLTError("unknown configuration \"%s\"", id);
191 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
193 // see header file for class documentation
196 AliHLTTask* pTask=NULL;
197 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
198 if (pTask->GetConf()!=pConf) {
199 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);
202 // task for this configuration exists, terminate
204 } else if (pConf->SourcesResolved(1)!=1) {
205 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
208 pTask=new AliHLTTask(pConf);
212 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
215 static int iterationLevel=0;
216 if (pTask && iResult>=0) {
217 // check for circular dependencies
218 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
219 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
220 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
221 HLTError("aborted ...");
225 // check whether all dependencies are already in the task list
226 // create the missing ones
227 // this step is an iterative process which calls this function again for the missing
228 // configurations, in order to avoid the currently processed task to be created
229 // again it is added to the list temporarily and removed afterwards
230 // This is of high importance to preserve the order of the tasks. Furthermore, the
231 // InsertTask method has to be used in order to set all the cross links right
232 fTaskList.Add(pTask);
233 AliHLTConfiguration* pDep=pConf->GetFirstSource();
234 while (pDep!=NULL && iResult>=0) {
235 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
236 if (FindTask(pDep->GetName())==NULL) {
237 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
239 iResult=BuildTaskList(pDep);
242 pDep=pConf->GetNextSource();
244 // remove the temporarily added task
245 fTaskList.Remove(pTask);
247 // insert the task and set the cross-links
249 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
250 iResult=InsertTask(pTask);
263 int AliHLTSystem::CleanTaskList()
265 // see header file for class documentation
268 while ((lnk=fTaskList.LastLink())!=NULL) {
269 delete (lnk->GetObject());
270 fTaskList.Remove(lnk);
275 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
277 // see header file for class documentation
279 TObjLink *lnk = NULL;
280 if ((iResult=pTask->CheckDependencies())>0)
281 lnk=fTaskList.FirstLink();
282 while (lnk && iResult>0) {
283 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
284 //HLTDebug("checking \"%s\"", pCurr->GetName());
285 iResult=pTask->Depends(pCurr);
287 iResult=pTask->SetDependency(pCurr);
288 pCurr->SetTarget(pTask);
289 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
291 if (pCurr->Depends(pTask)) {
292 // circular dependency
293 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
295 } else if ((iResult=pTask->CheckDependencies())>0) {
301 fTaskList.AddAfter(lnk, pTask);
303 fTaskList.AddFirst(pTask);
305 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
306 } else if (iResult>0) {
307 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
313 AliHLTTask* AliHLTSystem::FindTask(const char* id)
315 // see header file for class documentation
316 AliHLTTask* pTask=NULL;
318 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
323 void AliHLTSystem::PrintTaskList()
325 // see header file for class documentation
326 HLTLogKeyword("task list");
327 TObjLink *lnk = NULL;
328 HLTMessage("Task List");
329 lnk=fTaskList.FirstLink();
331 TObject* obj=lnk->GetObject();
333 HLTMessage(" %s - status:", obj->GetName());
334 AliHLTTask* pTask=(AliHLTTask*)obj;
335 pTask->PrintStatus();
342 int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
344 // see header file for class documentation
347 SetStatusFlags(kRunning);
348 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
349 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
350 if (fEventCount==0) {
351 InitBenchmarking(fStopwatches);
353 //ResumeBenchmarking(fStopwatches);
355 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
356 if ((iResult=ProcessTasks(i))>=0) {
360 // TODO: define different running modes to either ignore errors in
361 // event processing or not
366 fEventCount+=iNofEvents;
367 if (bStop) StopTasks();
368 //else PauseBenchmarking(fStopwatches);
370 if (bStop) DeinitTasks();
374 } else if (iResult==-126 /*ENOKEY*/) {
375 iResult=0; // do not propagate the error
377 ClearStatusFlags(kRunning);
381 int AliHLTSystem::InitTasks()
383 // see header file for class documentation
385 TObjLink *lnk=fTaskList.FirstLink();
388 HLTWarning("Task list is empty, skipping HLT");
389 return -126 /*ENOKEY*/;
391 while (lnk && iResult>=0) {
392 TObject* obj=lnk->GetObject();
394 AliHLTTask* pTask=(AliHLTTask*)obj;
395 iResult=pTask->Init(NULL, fpComponentHandler);
396 // ProcInfo_t ProcInfo;
397 // gSystem->GetProcInfo(&ProcInfo);
398 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
404 HLTError("can not initialize task list, error %d", iResult);
410 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
412 // see header file for class documentation
414 if (pStopwatches==NULL) return 0;
416 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
417 TStopwatch* pStopwatch= new TStopwatch;
420 pStopwatches->AddAt(pStopwatch, i);
427 TObjLink *lnk=fTaskList.FirstLink();
428 while (lnk && iResult>=0) {
429 TObject* obj=lnk->GetObject();
431 AliHLTTask* pTask=(AliHLTTask*)obj;
432 AliHLTComponent* pComp=NULL;
433 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
434 switch (pComp->GetComponentType()) {
435 case AliHLTComponent::kProcessor:
436 pComp->SetStopwatches(pStopwatches);
438 case AliHLTComponent::kSource:
440 // this switch determines whether the time consumption of the
441 // AliHLTComponent base methods should be counted to the input
442 // stopwatch or base stopwatch.
443 //int inputBase=(int)AliHLTComponent::kSWBase;
444 int inputBase=(int)AliHLTComponent::kSWInput;
445 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
446 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
449 case AliHLTComponent::kSink:
451 // this switch determines whether the time consumption of the
452 // AliHLTComponent base methods should be counted to the output
453 // stopwatch or base stopwatch.
454 //int outputBase=(int)AliHLTComponent::kSWBase;
455 int outputBase=(int)AliHLTComponent::kSWOutput;
456 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
457 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
461 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
471 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean)
473 // see header file for class documentation
475 if (pStopwatches==NULL) return 0;
477 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
478 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
484 if (iInitialized!=0) {
485 HLTInfo("HLT statistics:\n"
486 " base: R:%.3fs C:%.3fs\n"
487 " input: R:%.3fs C:%.3fs\n"
488 " output: R:%.3fs C:%.3fs\n"
489 " event processing : R:%.3fs C:%.3fs"
490 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
491 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
492 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
493 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
494 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
495 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
496 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
497 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
502 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
503 TObject* pObj=pStopwatches->RemoveAt(i);
504 if (pObj) delete pObj;
510 int AliHLTSystem::StartTasks()
512 // see header file for class documentation
514 TObjLink *lnk=fTaskList.FirstLink();
515 while (lnk && iResult>=0) {
516 TObject* obj=lnk->GetObject();
518 AliHLTTask* pTask=(AliHLTTask*)obj;
519 iResult=pTask->StartRun();
520 // ProcInfo_t ProcInfo;
521 // gSystem->GetProcInfo(&ProcInfo);
522 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
528 HLTError("can not start task list, error %d", iResult);
532 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
533 HLTError("can not send SOR event");
539 int AliHLTSystem::ProcessTasks(Int_t eventNo)
541 // see header file for class documentation
543 HLTDebug("processing event no %d", eventNo);
544 TObjLink *lnk=fTaskList.FirstLink();
545 while (lnk && iResult>=0) {
546 TObject* obj=lnk->GetObject();
548 AliHLTTask* pTask=(AliHLTTask*)obj;
549 iResult=pTask->ProcessTask(eventNo);
550 // ProcInfo_t ProcInfo;
551 // gSystem->GetProcInfo(&ProcInfo);
552 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
559 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
562 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
568 int AliHLTSystem::StopTasks()
570 // see header file for class documentation
572 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
573 HLTError("can not send EOR event");
575 TObjLink *lnk=fTaskList.FirstLink();
577 TObject* obj=lnk->GetObject();
579 AliHLTTask* pTask=(AliHLTTask*)obj;
580 int locResult=pTask->EndRun();
581 if (iResult>=0 && locResult<0) iResult=locResult;
582 // ProcInfo_t ProcInfo;
583 // gSystem->GetProcInfo(&ProcInfo);
584 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
589 PrintBenchmarking(fStopwatches, 1 /*clean*/);
593 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
595 // see header file for class documentation
597 // disabled for the moment
601 AliHLTRunDesc runDesc;
602 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
603 runDesc.fStructSize=sizeof(AliHLTRunDesc);
604 AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
605 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
606 TObjLink *lnk=fTaskList.FirstLink();
607 while (lnk && iResult>=0) {
608 TObject* obj=lnk->GetObject();
610 AliHLTTask* pTask=(AliHLTTask*)obj;
611 iResult=pTask->ProcessTask(-1);
616 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
620 int AliHLTSystem::DeinitTasks()
622 // see header file for class documentation
624 TObjLink *lnk=fTaskList.FirstLink();
625 while (lnk && iResult>=0) {
626 TObject* obj=lnk->GetObject();
628 AliHLTTask* pTask=(AliHLTTask*)obj;
629 iResult=pTask->Deinit();
630 // ProcInfo_t ProcInfo;
631 // gSystem->GetProcInfo(&ProcInfo);
632 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
643 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
645 // see header file for class documentation
648 p=(void*)new char[size];
652 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
657 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
658 AliRawReader* rawReader)
660 // see header file for class documentation
662 if (runLoader || rawReader || nofEvents==0) {
663 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
664 if (CheckStatus(kReady)) {
666 // special case to close the reconstruction
667 if (!CheckStatus(kError)) {
672 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
673 // the system always remains started after event processing, a specific
674 // call with nofEvents==0 is needed to execute the stop sequence
675 if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
679 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
682 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
688 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
690 // see header file for class documentation
692 if (runLoader || esd) {
693 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
694 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
696 HLTError("missing run loader/ESD instance(s)");
702 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
704 // see header file for class documentation
706 if (!pHLTOUT) return -EINVAL;
708 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
709 AliHLTOUT::AliHLTOUTHandlerListEntryVector esdHandlers;
710 for (iResult=pHLTOUT->SelectFirstDataBlock();
712 iResult=pHLTOUT->SelectNextDataBlock()) {
713 AliHLTComponentDataType dt=kAliHLTVoidDataType;
714 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
715 pHLTOUT->GetDataBlockDescription(dt, spec);
716 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
717 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
718 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
719 handlerType=AliHLTModuleAgent::kEsd;
721 const char* pMsg="invalid";
722 switch (handlerType) {
723 case AliHLTModuleAgent::kEsd:
726 // preprocess and write later
727 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
728 pHandler->ProcessData(pHLTOUT);
729 pHLTOUT->InsertHandler(esdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
732 const AliHLTUInt8_t* pBuffer=NULL;
733 AliHLTUInt32_t size=0;
734 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
735 pHLTOUT->WriteESD(pBuffer, size, dt);
736 pHLTOUT->ReleaseDataBuffer(pBuffer);
741 case AliHLTModuleAgent::kRawReader:
742 // handled in the AliRawReaderHLT
744 case AliHLTModuleAgent::kRawStream:
745 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
746 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
747 AliHLTComponent::DataType2Text(dt).c_str(), spec);
749 case AliHLTModuleAgent::kChain:
750 HLTWarning("HLTOUT handler type 'kChain' not yet implemented: agent %s, data type %s, specification %#x",
751 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
752 AliHLTComponent::DataType2Text(dt).c_str(), spec);
754 case AliHLTModuleAgent::kProprietary:
755 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
756 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
757 AliHLTComponent::DataType2Text(dt).c_str(), spec);
759 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
760 int res=pHandler->ProcessData(pHLTOUT);
762 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
763 res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
764 AliHLTComponent::DataType2Text(dt).c_str(), spec);
768 case AliHLTModuleAgent::kUnknownOutput:
770 // fall trough intended
772 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
773 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
774 AliHLTComponent::DataType2Text(dt).c_str(), spec);
777 // TODO: the return value of SelectFirst/NextDataBlock must be
778 // changed in order to avoid this check
779 if (iResult==-ENOENT) iResult=0;
781 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator esdHandler;
782 // write all postponed esd data blocks
783 // first come first serve: the ESD of the first handler is also filled into
784 // the main ESD. Has to be changed later.
785 AliESDEvent* pMasterESD=esd;
786 for (esdHandler=esdHandlers.begin(); esdHandler!=esdHandlers.end() && iResult>=0; esdHandler++) {
787 AliHLTOUTHandler* pHandler=*esdHandler;
788 const AliHLTUInt8_t* pBuffer=NULL;
789 AliHLTUInt32_t size=0;
790 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
791 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*esdHandler;
792 AliHLTComponentDataType dt=desc;
793 pHLTOUT->WriteESD(pBuffer, size, dt);
795 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
798 pHandler->ReleaseProcessedData(pBuffer, size);
805 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
807 // see header file for class documentation
810 if (fpComponentHandler) {
811 TString libs(libraries);
812 TObjArray* pTokens=libs.Tokenize(" ");
814 int iEntries=pTokens->GetEntries();
815 for (int i=0; i<iEntries && iResult>=0; i++) {
816 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
821 SetStatusFlags(kLibrariesLoaded);
823 // lets see if we need this, probably not
824 //fpComponentHandler->UnloadLibraries();
825 ClearStatusFlags(kLibrariesLoaded);
829 HLTFatal("no component handler available");
837 int AliHLTSystem::Configure(AliRunLoader* runloader)
839 // see header file for class documentation
840 return Configure(NULL, runloader);
843 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
845 // see header file for class documentation
847 if (CheckStatus(kRunning)) {
848 HLTError("HLT system in running state, can not configure");
851 ClearStatusFlags(kTaskListCreated);
852 if (CheckFilter(kHLTLogDebug))
853 AliHLTModuleAgent::PrintStatus();
854 if (CheckStatus(kConfigurationLoaded)==0) {
855 iResult=LoadConfigurations(rawReader, runloader);
857 if (fChains.Length()==0) {
858 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'localrec=<conf>\' option");
863 SetStatusFlags(kConfigurationLoaded);
864 if (CheckFilter(kHLTLogDebug))
865 fpConfigurationHandler->PrintConfigurations();
866 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
868 SetStatusFlags(kTaskListCreated);
871 if (iResult<0) SetStatusFlags(kError);
876 int AliHLTSystem::ScanOptions(const char* options)
878 // see header file for class documentation
881 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
883 TString alloptions(options);
884 TObjArray* pTokens=alloptions.Tokenize(" ");
886 int iEntries=pTokens->GetEntries();
887 for (int i=0; i<iEntries; i++) {
888 TString token=(((TObjString*)pTokens->At(i))->GetString());
889 if (token.Contains("loglevel=")) {
890 TString param=token.ReplaceAll("loglevel=", "");
891 if (param.IsDigit()) {
892 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
893 } else if (param.BeginsWith("0x") &&
894 param.Replace(0,2,"",0).IsHex()) {
896 sscanf(param.Data(),"%x", &severity);
897 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
899 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
901 } else if (token.Contains("frameworklog=")) {
902 TString param=token.ReplaceAll("frameworklog=", "");
903 if (param.IsDigit()) {
904 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
905 } else if (param.BeginsWith("0x") &&
906 param.Replace(0,2,"",0).IsHex()) {
908 sscanf(param.Data(),"%x", &severity);
909 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
911 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
913 } else if (token.Contains("alilog=off")) {
915 } else if (token.Contains("config=")) {
916 TString param=token.ReplaceAll("config=", "");
918 gROOT->Macro(param.Data(), &error);
920 SetStatusFlags(kConfigurationLoaded);
922 HLTError("can not execute macro \'%s\'", param.Data());
925 } else if (token.Contains("chains=")) {
926 TString param=token.ReplaceAll("chains=", "");
927 fChains=param.ReplaceAll(",", " ");
928 } else if (token.Contains("libmode=")) {
929 TString param=token.ReplaceAll("libmode=", "");
930 param.ReplaceAll(",", " ");
931 if (fpComponentHandler) {
932 if (param.CompareTo("static")==0) {
933 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
934 } else if (param.CompareTo("dynamic")==0) {
935 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
937 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
940 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
944 HLTWarning("unknown option \'%s\'", token.Data());
952 const char** deflib=fgkHLTDefaultLibs;
958 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
959 (LoadComponentLibraries(libs.Data())<0)) {
960 HLTError("error while loading HLT libraries");
968 int AliHLTSystem::Reset(int bForce)
970 // see header file for class documentation
972 if (!bForce && CheckStatus(kRunning)) {
973 HLTError("HLT system in running state, can not configure");
977 ClearStatusFlags(~kUninitialized);
981 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
983 // see header file for class documentation
984 if (CheckStatus(kRunning)) {
985 HLTError("HLT system in running state, can not configure");
989 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
990 while (pAgent && iResult>=0) {
991 const char* deplibs=pAgent->GetRequiredComponentLibraries();
993 HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
994 iResult=LoadComponentLibraries(deplibs);
997 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
998 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
999 pAgent=AliHLTModuleAgent::GetNextAgent();
1005 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1007 // see header file for class documentation
1008 if (CheckStatus(kRunning)) {
1009 HLTError("HLT system in running state, can not configure");
1012 if (!CheckStatus(kConfigurationLoaded)) {
1013 HLTWarning("configurations not yet loaded");
1022 if (fChains.Length()>0) {
1024 HLTImportant("custom reconstruction chain: %s", chains.Data());
1026 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1027 while ((pAgent || fChains.Length()>0) && iResult>=0) {
1028 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1030 if (!chains.IsNull()) chains+="";
1031 chains+=agentchains;
1032 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1034 pAgent=AliHLTModuleAgent::GetNextAgent();
1038 // build task list for chains
1039 TObjArray* pTokens=chains.Tokenize(" ");
1041 int iEntries=pTokens->GetEntries();
1042 for (int i=0; i<iEntries && iResult>=0; i++) {
1043 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1044 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1046 iResult=BuildTaskList(pConf);
1048 assert(fpComponentHandler!=NULL);
1049 TString cid=pConf->GetComponentID();
1050 if (cid.CompareTo("HLTOUT")==0) {
1051 // remove from the input of a global HLTOUT configuration
1052 chains.ReplaceAll(pCID, "");
1053 } else if (bHaveOutput==0) {
1054 // check whether this configuration produces data output
1055 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1057 chains.ReplaceAll(pCID, "");
1062 HLTWarning("can not find configuration %s", pCID);
1068 // build HLTOUT for simulation
1069 if (iResult>=0 && runloader) {
1071 // there are components in the chain which produce data which need to be
1072 // piped to an HLTOUT
1073 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1074 LoadComponentLibraries("libHLTsim.so")>=0) {
1075 AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
1076 iResult=BuildTaskList("_globalout_");
1078 HLTError("can not load libHLTsim.so and HLTOUT component");
1084 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1089 int AliHLTSystem::CheckStatus(int flag)
1091 // see header file for class documentation
1092 if (flag==kUninitialized && flag==fState) return 1;
1093 if ((fState&flag)==flag) return 1;
1097 int AliHLTSystem::GetStatusFlags()
1099 // see header file for class documentation
1103 int AliHLTSystem::SetStatusFlags(int flags)
1105 // see header file for class documentation
1110 int AliHLTSystem::ClearStatusFlags(int flags)
1112 // see header file for class documentation
1117 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1119 // see header file for class documentation
1120 if (fpComponentHandler==NULL) return NULL;
1121 return fpComponentHandler->FindSymbol(library, symbol);
1124 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1126 // see header file for class documentation
1127 SetLocalLoggingLevel(level);
1128 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1129 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);