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),
75 bWriteGlobalEsd(false)
77 // see header file for class documentation
79 // refer to README to build package
81 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
83 if (fgNofInstances++>0)
84 HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
86 SetGlobalLoggingLevel(kHLTLogDefault);
87 SetFrameworkLog(kHLTLogDefault);
88 if (fpComponentHandler) {
89 AliHLTComponentEnvironment env;
90 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
91 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
92 env.fLoggingFunc=NULL;
93 fpComponentHandler->SetEnvironment(&env);
94 InitAliLogFunc(fpComponentHandler);
95 fpComponentHandler->AnnounceVersion();
97 HLTFatal("can not create Component Handler");
99 if (fpConfigurationHandler) {
100 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
102 HLTFatal("can not create Configuration Handler");
106 AliHLTSystem::~AliHLTSystem()
108 // see header file for class documentation
111 AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
112 if (fpConfigurationHandler) {
113 delete fpConfigurationHandler;
115 fpConfigurationHandler=NULL;
117 if (fpComponentHandler) {
118 delete fpComponentHandler;
120 fpComponentHandler=NULL;
123 int AliHLTSystem::fgNofInstances=0;
125 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
127 // see header file for class documentation
128 HLTLogKeyword("configuration handling");
131 HLTError("function not yet implemented");
139 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
141 // see header file for class documentation
142 HLTLogKeyword("configuration handling");
147 HLTError("function not yet implemented");
156 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
158 // see header file for class documentation
159 HLTLogKeyword("configuration handling");
162 HLTError("function not yet implemented");
170 int AliHLTSystem::BuildTaskList(const char* id)
172 // see header file for class documentation
175 if (fpConfigurationHandler) {
176 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
178 iResult=BuildTaskList(pConf);
180 HLTError("unknown configuration \"%s\"", id);
192 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
194 // see header file for class documentation
197 AliHLTTask* pTask=NULL;
198 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
199 if (pTask->GetConf()!=pConf) {
200 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);
203 // task for this configuration exists, terminate
205 } else if (pConf->SourcesResolved(1)!=1) {
206 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
209 pTask=new AliHLTTask(pConf);
213 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
216 static int iterationLevel=0;
217 if (pTask && iResult>=0) {
218 // check for circular dependencies
219 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
220 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
221 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
222 HLTError("aborted ...");
226 // check whether all dependencies are already in the task list
227 // create the missing ones
228 // this step is an iterative process which calls this function again for the missing
229 // configurations, in order to avoid the currently processed task to be created
230 // again it is added to the list temporarily and removed afterwards
231 // This is of high importance to preserve the order of the tasks. Furthermore, the
232 // InsertTask method has to be used in order to set all the cross links right
233 fTaskList.Add(pTask);
234 AliHLTConfiguration* pDep=pConf->GetFirstSource();
235 while (pDep!=NULL && iResult>=0) {
236 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
237 if (FindTask(pDep->GetName())==NULL) {
238 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
240 iResult=BuildTaskList(pDep);
243 pDep=pConf->GetNextSource();
245 // remove the temporarily added task
246 fTaskList.Remove(pTask);
248 // insert the task and set the cross-links
250 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
251 iResult=InsertTask(pTask);
264 int AliHLTSystem::CleanTaskList()
266 // see header file for class documentation
269 while ((lnk=fTaskList.LastLink())!=NULL) {
270 delete (lnk->GetObject());
271 fTaskList.Remove(lnk);
276 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
278 // see header file for class documentation
280 TObjLink *lnk = NULL;
281 if ((iResult=pTask->CheckDependencies())>0)
282 lnk=fTaskList.FirstLink();
283 while (lnk && iResult>0) {
284 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
285 //HLTDebug("checking \"%s\"", pCurr->GetName());
286 iResult=pTask->Depends(pCurr);
288 iResult=pTask->SetDependency(pCurr);
289 pCurr->SetTarget(pTask);
290 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
292 if (pCurr->Depends(pTask)) {
293 // circular dependency
294 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
296 } else if ((iResult=pTask->CheckDependencies())>0) {
302 fTaskList.AddAfter(lnk, pTask);
304 fTaskList.AddFirst(pTask);
306 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
307 } else if (iResult>0) {
308 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
314 AliHLTTask* AliHLTSystem::FindTask(const char* id)
316 // see header file for class documentation
317 AliHLTTask* pTask=NULL;
319 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
324 void AliHLTSystem::PrintTaskList()
326 // see header file for class documentation
327 HLTLogKeyword("task list");
328 TObjLink *lnk = NULL;
329 HLTMessage("Task List");
330 lnk=fTaskList.FirstLink();
332 TObject* obj=lnk->GetObject();
334 HLTMessage(" %s - status:", obj->GetName());
335 AliHLTTask* pTask=(AliHLTTask*)obj;
336 pTask->PrintStatus();
343 int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
345 // see header file for class documentation
348 SetStatusFlags(kRunning);
349 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
350 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
351 if (fEventCount==0) {
352 InitBenchmarking(fStopwatches);
354 ResumeBenchmarking(fStopwatches);
356 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
357 if ((iResult=ProcessTasks(i))>=0) {
361 // TODO: define different running modes to either ignore errors in
362 // event processing or not
367 fEventCount+=iNofEvents;
368 if (bStop) StopTasks();
369 else PauseBenchmarking(fStopwatches);
371 if (bStop) DeinitTasks();
375 } else if (iResult==-126 /*ENOKEY*/) {
376 iResult=0; // do not propagate the error
378 ClearStatusFlags(kRunning);
382 int AliHLTSystem::InitTasks()
384 // see header file for class documentation
386 TObjLink *lnk=fTaskList.FirstLink();
389 HLTWarning("Task list is empty, skipping HLT");
390 return -126 /*ENOKEY*/;
392 while (lnk && iResult>=0) {
393 TObject* obj=lnk->GetObject();
395 AliHLTTask* pTask=(AliHLTTask*)obj;
396 iResult=pTask->Init(NULL, fpComponentHandler);
397 // ProcInfo_t ProcInfo;
398 // gSystem->GetProcInfo(&ProcInfo);
399 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
405 HLTError("can not initialize task list, error %d", iResult);
411 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
413 // see header file for class documentation
415 if (pStopwatches==NULL) return 0;
417 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
418 TStopwatch* pStopwatch= new TStopwatch;
421 pStopwatches->AddAt(pStopwatch, i);
428 TObjLink *lnk=fTaskList.FirstLink();
429 while (lnk && iResult>=0) {
430 TObject* obj=lnk->GetObject();
432 AliHLTTask* pTask=(AliHLTTask*)obj;
433 AliHLTComponent* pComp=NULL;
434 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
435 switch (pComp->GetComponentType()) {
436 case AliHLTComponent::kProcessor:
437 pComp->SetStopwatches(pStopwatches);
439 case AliHLTComponent::kSource:
441 // this switch determines whether the time consumption of the
442 // AliHLTComponent base methods should be counted to the input
443 // stopwatch or base stopwatch.
444 //int inputBase=(int)AliHLTComponent::kSWBase;
445 int inputBase=(int)AliHLTComponent::kSWInput;
446 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
447 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
450 case AliHLTComponent::kSink:
452 // this switch determines whether the time consumption of the
453 // AliHLTComponent base methods should be counted to the output
454 // stopwatch or base stopwatch.
455 //int outputBase=(int)AliHLTComponent::kSWBase;
456 int outputBase=(int)AliHLTComponent::kSWOutput;
457 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
458 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
462 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
472 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
474 // see header file for class documentation
475 if (pStopwatches==NULL) return 0;
477 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
478 if (!pStopwatches->At(i)) continue;
479 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
480 if (pSw) pSw->Stop();
485 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
487 // see header file for class documentation
488 if (pStopwatches==NULL) return 0;
490 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
491 if (!pStopwatches->At(i)) continue;
492 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
493 if (pSw) pSw->Continue();
498 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
500 // see header file for class documentation
502 if (pStopwatches==NULL) return 0;
504 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
505 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
511 if (iInitialized!=0) {
512 HLTImportant("HLT statistics:\n"
513 " base: R:%.3fs C:%.3fs\n"
514 " input: R:%.3fs C:%.3fs\n"
515 " output: R:%.3fs C:%.3fs\n"
516 " event processing : R:%.3fs C:%.3fs"
517 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
518 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
519 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
520 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
521 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
522 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
523 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
524 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
529 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
530 TObject* pObj=pStopwatches->RemoveAt(i);
531 if (pObj) delete pObj;
537 int AliHLTSystem::StartTasks()
539 // see header file for class documentation
541 TObjLink *lnk=fTaskList.FirstLink();
542 while (lnk && iResult>=0) {
543 TObject* obj=lnk->GetObject();
545 AliHLTTask* pTask=(AliHLTTask*)obj;
546 iResult=pTask->StartRun();
547 // ProcInfo_t ProcInfo;
548 // gSystem->GetProcInfo(&ProcInfo);
549 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
555 HLTError("can not start task list, error %d", iResult);
557 SetStatusFlags(kStarted);
560 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
561 HLTError("can not send SOR event");
567 int AliHLTSystem::ProcessTasks(Int_t eventNo)
569 // see header file for class documentation
571 HLTDebug("processing event no %d", eventNo);
572 TObjLink *lnk=fTaskList.FirstLink();
573 while (lnk && iResult>=0) {
574 TObject* obj=lnk->GetObject();
576 AliHLTTask* pTask=(AliHLTTask*)obj;
577 iResult=pTask->ProcessTask(eventNo);
578 // ProcInfo_t ProcInfo;
579 // gSystem->GetProcInfo(&ProcInfo);
580 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
587 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
590 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
596 int AliHLTSystem::StopTasks()
598 // see header file for class documentation
600 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
601 HLTError("can not send EOR event");
603 TObjLink *lnk=fTaskList.FirstLink();
605 TObject* obj=lnk->GetObject();
607 AliHLTTask* pTask=(AliHLTTask*)obj;
608 int locResult=pTask->EndRun();
609 if (iResult>=0 && locResult<0) iResult=locResult;
610 // ProcInfo_t ProcInfo;
611 // gSystem->GetProcInfo(&ProcInfo);
612 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
617 PrintBenchmarking(fStopwatches, 1 /*clean*/);
618 ClearStatusFlags(kStarted);
622 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
624 // see header file for class documentation
626 // disabled for the moment
630 AliHLTRunDesc runDesc;
631 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
632 runDesc.fStructSize=sizeof(AliHLTRunDesc);
633 AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
634 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
635 TObjLink *lnk=fTaskList.FirstLink();
636 while (lnk && iResult>=0) {
637 TObject* obj=lnk->GetObject();
639 AliHLTTask* pTask=(AliHLTTask*)obj;
640 iResult=pTask->ProcessTask(-1);
645 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
649 int AliHLTSystem::DeinitTasks()
651 // see header file for class documentation
653 TObjLink *lnk=fTaskList.FirstLink();
654 while (lnk && iResult>=0) {
655 TObject* obj=lnk->GetObject();
657 AliHLTTask* pTask=(AliHLTTask*)obj;
658 iResult=pTask->Deinit();
659 // ProcInfo_t ProcInfo;
660 // gSystem->GetProcInfo(&ProcInfo);
661 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
672 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
674 // see header file for class documentation
677 p=(void*)new char[size];
681 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
686 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
687 AliRawReader* rawReader)
689 // see header file for class documentation
691 if (runLoader || rawReader || nofEvents==0) {
692 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
693 if (CheckStatus(kReady)) {
695 // special case to close the reconstruction
696 if (!CheckStatus(kError)) {
701 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
702 // the system always remains started after event processing, a specific
703 // call with nofEvents==0 is needed to execute the stop sequence
704 if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
708 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
711 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
717 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
719 // see header file for class documentation
721 if (runLoader || esd) {
722 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
723 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
725 HLTError("missing run loader/ESD instance(s)");
731 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
733 // see header file for class documentation
735 if (!pHLTOUT) return -EINVAL;
737 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
738 AliHLTOUT::AliHLTOUTHandlerListEntryVector esdHandlers;
740 // first come first serve: the ESD of the first handler is also filled into
741 // the main ESD. Has to be changed later.
742 // currently, merging to the provided ESDs crashes at the level of the
743 // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed
745 AliESDEvent* pMasterESD=NULL;
746 if (bWriteGlobalEsd) pMasterESD=esd;
747 for (iResult=pHLTOUT->SelectFirstDataBlock();
749 iResult=pHLTOUT->SelectNextDataBlock()) {
750 AliHLTComponentDataType dt=kAliHLTVoidDataType;
751 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
752 pHLTOUT->GetDataBlockDescription(dt, spec);
753 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
754 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
755 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
756 handlerType=AliHLTModuleAgent::kEsd;
758 const char* pMsg="invalid";
759 switch (handlerType) {
760 case AliHLTModuleAgent::kEsd:
763 // preprocess and write later
764 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
765 pHandler->ProcessData(pHLTOUT);
766 pHLTOUT->InsertHandler(esdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
769 const AliHLTUInt8_t* pBuffer=NULL;
770 AliHLTUInt32_t size=0;
771 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
772 pHLTOUT->WriteESD(pBuffer, size, dt);
774 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
777 pHLTOUT->ReleaseDataBuffer(pBuffer);
782 case AliHLTModuleAgent::kRawReader:
783 // handled in the AliRawReaderHLT
785 case AliHLTModuleAgent::kRawStream:
786 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
787 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
788 AliHLTComponent::DataType2Text(dt).c_str(), spec);
790 case AliHLTModuleAgent::kChain:
791 HLTWarning("HLTOUT handler type 'kChain' not yet implemented: agent %s, data type %s, specification %#x",
792 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
793 AliHLTComponent::DataType2Text(dt).c_str(), spec);
795 case AliHLTModuleAgent::kProprietary:
796 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
797 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
798 AliHLTComponent::DataType2Text(dt).c_str(), spec);
800 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
801 int res=pHandler->ProcessData(pHLTOUT);
803 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
804 res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
805 AliHLTComponent::DataType2Text(dt).c_str(), spec);
809 case AliHLTModuleAgent::kUnknownOutput:
811 // fall trough intended
813 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
814 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
815 AliHLTComponent::DataType2Text(dt).c_str(), spec);
818 // TODO: the return value of SelectFirst/NextDataBlock must be
819 // changed in order to avoid this check
820 if (iResult==-ENOENT) iResult=0;
822 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator esdHandler;
823 // write all postponed esd data blocks
824 for (esdHandler=esdHandlers.begin(); esdHandler!=esdHandlers.end() && iResult>=0; esdHandler++) {
825 AliHLTOUTHandler* pHandler=*esdHandler;
826 const AliHLTUInt8_t* pBuffer=NULL;
827 AliHLTUInt32_t size=0;
828 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
829 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*esdHandler;
830 AliHLTComponentDataType dt=desc;
831 pHLTOUT->WriteESD(pBuffer, size, dt);
833 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
836 pHandler->ReleaseProcessedData(pBuffer, size);
843 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
845 // see header file for class documentation
848 if (fpComponentHandler) {
849 TString libs(libraries);
850 TObjArray* pTokens=libs.Tokenize(" ");
852 int iEntries=pTokens->GetEntries();
853 for (int i=0; i<iEntries && iResult>=0; i++) {
854 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
859 SetStatusFlags(kLibrariesLoaded);
861 // lets see if we need this, probably not
862 //fpComponentHandler->UnloadLibraries();
863 ClearStatusFlags(kLibrariesLoaded);
867 HLTFatal("no component handler available");
875 int AliHLTSystem::Configure(AliRunLoader* runloader)
877 // see header file for class documentation
878 return Configure(NULL, runloader);
881 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
883 // see header file for class documentation
885 if (CheckStatus(kRunning)) {
886 HLTError("HLT system in running state, can not configure");
889 ClearStatusFlags(kTaskListCreated);
890 if (CheckFilter(kHLTLogDebug))
891 AliHLTModuleAgent::PrintStatus();
892 if (CheckStatus(kConfigurationLoaded)==0) {
893 iResult=LoadConfigurations(rawReader, runloader);
895 if (fChains.Length()==0) {
896 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'localrec=<conf>\' option");
901 SetStatusFlags(kConfigurationLoaded);
902 if (CheckFilter(kHLTLogDebug))
903 fpConfigurationHandler->PrintConfigurations();
904 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
906 SetStatusFlags(kTaskListCreated);
909 if (iResult<0) SetStatusFlags(kError);
914 int AliHLTSystem::ScanOptions(const char* options)
916 // see header file for class documentation
919 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
921 TString alloptions(options);
922 TObjArray* pTokens=alloptions.Tokenize(" ");
924 int iEntries=pTokens->GetEntries();
925 for (int i=0; i<iEntries; i++) {
926 TString token=(((TObjString*)pTokens->At(i))->GetString());
927 if (token.Contains("loglevel=")) {
928 TString param=token.ReplaceAll("loglevel=", "");
929 if (param.IsDigit()) {
930 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
931 } else if (param.BeginsWith("0x") &&
932 param.Replace(0,2,"",0).IsHex()) {
934 sscanf(param.Data(),"%x", &severity);
935 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
937 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
939 } else if (token.Contains("frameworklog=")) {
940 TString param=token.ReplaceAll("frameworklog=", "");
941 if (param.IsDigit()) {
942 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
943 } else if (param.BeginsWith("0x") &&
944 param.Replace(0,2,"",0).IsHex()) {
946 sscanf(param.Data(),"%x", &severity);
947 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
949 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
951 } else if (token.Contains("alilog=off")) {
953 } else if (token.Contains("config=")) {
954 TString param=token.ReplaceAll("config=", "");
956 gROOT->Macro(param.Data(), &error);
958 SetStatusFlags(kConfigurationLoaded);
960 HLTError("can not execute macro \'%s\'", param.Data());
963 } else if (token.Contains("chains=")) {
964 TString param=token.ReplaceAll("chains=", "");
965 fChains=param.ReplaceAll(",", " ");
966 } else if (token.Contains("libmode=")) {
967 TString param=token.ReplaceAll("libmode=", "");
968 param.ReplaceAll(",", " ");
969 if (fpComponentHandler) {
970 if (param.CompareTo("static")==0) {
971 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
972 } else if (param.CompareTo("dynamic")==0) {
973 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
975 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
978 } else if (token.Contains("globalesd")) {
979 bWriteGlobalEsd=true;
980 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
984 HLTWarning("unknown option \'%s\'", token.Data());
992 const char** deflib=fgkHLTDefaultLibs;
998 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
999 (LoadComponentLibraries(libs.Data())<0)) {
1000 HLTError("error while loading HLT libraries");
1008 int AliHLTSystem::Reset(int bForce)
1010 // see header file for class documentation
1012 if (!bForce && CheckStatus(kRunning)) {
1013 HLTError("HLT system in running state, can not configure");
1017 ClearStatusFlags(~kUninitialized);
1021 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1023 // see header file for class documentation
1024 if (CheckStatus(kRunning)) {
1025 HLTError("HLT system in running state, can not configure");
1029 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1030 while (pAgent && iResult>=0) {
1031 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1033 HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1034 iResult=LoadComponentLibraries(deplibs);
1037 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1038 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1039 pAgent=AliHLTModuleAgent::GetNextAgent();
1045 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1047 // see header file for class documentation
1048 if (CheckStatus(kRunning)) {
1049 HLTError("HLT system in running state, can not configure");
1052 if (!CheckStatus(kConfigurationLoaded)) {
1053 HLTWarning("configurations not yet loaded");
1062 if (fChains.Length()>0) {
1064 HLTImportant("custom reconstruction chain: %s", chains.Data());
1066 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1067 while ((pAgent || fChains.Length()>0) && iResult>=0) {
1068 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1070 if (!chains.IsNull()) chains+="";
1071 chains+=agentchains;
1072 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1074 pAgent=AliHLTModuleAgent::GetNextAgent();
1078 // build task list for chains
1079 TObjArray* pTokens=chains.Tokenize(" ");
1081 int iEntries=pTokens->GetEntries();
1082 for (int i=0; i<iEntries && iResult>=0; i++) {
1083 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1084 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1086 iResult=BuildTaskList(pConf);
1088 assert(fpComponentHandler!=NULL);
1089 TString cid=pConf->GetComponentID();
1090 if (cid.CompareTo("HLTOUT")==0) {
1091 // remove from the input of a global HLTOUT configuration
1092 chains.ReplaceAll(pCID, "");
1093 } else if (bHaveOutput==0) {
1094 // check whether this configuration produces data output
1095 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1097 chains.ReplaceAll(pCID, "");
1102 HLTWarning("can not find configuration %s", pCID);
1108 // build HLTOUT for simulation
1109 if (iResult>=0 && runloader) {
1111 // there are components in the chain which produce data which need to be
1112 // piped to an HLTOUT
1113 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1114 LoadComponentLibraries("libHLTsim.so")>=0) {
1115 AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
1116 iResult=BuildTaskList("_globalout_");
1118 HLTError("can not load libHLTsim.so and HLTOUT component");
1124 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1129 int AliHLTSystem::CheckStatus(int flag)
1131 // see header file for class documentation
1132 if (flag==kUninitialized && flag==fState) return 1;
1133 if ((fState&flag)==flag) return 1;
1137 int AliHLTSystem::GetStatusFlags()
1139 // see header file for class documentation
1143 int AliHLTSystem::SetStatusFlags(int flags)
1145 // see header file for class documentation
1150 int AliHLTSystem::ClearStatusFlags(int flags)
1152 // see header file for class documentation
1157 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1159 // see header file for class documentation
1160 if (fpComponentHandler==NULL) return NULL;
1161 return fpComponentHandler->FindSymbol(library, symbol);
1164 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1166 // see header file for class documentation
1167 SetLocalLoggingLevel(level);
1168 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1169 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);