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);
559 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
560 HLTError("can not send SOR event");
566 int AliHLTSystem::ProcessTasks(Int_t eventNo)
568 // see header file for class documentation
570 HLTDebug("processing event no %d", eventNo);
571 TObjLink *lnk=fTaskList.FirstLink();
572 while (lnk && iResult>=0) {
573 TObject* obj=lnk->GetObject();
575 AliHLTTask* pTask=(AliHLTTask*)obj;
576 iResult=pTask->ProcessTask(eventNo);
577 // ProcInfo_t ProcInfo;
578 // gSystem->GetProcInfo(&ProcInfo);
579 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
586 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
589 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
595 int AliHLTSystem::StopTasks()
597 // see header file for class documentation
599 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
600 HLTError("can not send EOR event");
602 TObjLink *lnk=fTaskList.FirstLink();
604 TObject* obj=lnk->GetObject();
606 AliHLTTask* pTask=(AliHLTTask*)obj;
607 int locResult=pTask->EndRun();
608 if (iResult>=0 && locResult<0) iResult=locResult;
609 // ProcInfo_t ProcInfo;
610 // gSystem->GetProcInfo(&ProcInfo);
611 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
616 PrintBenchmarking(fStopwatches, 1 /*clean*/);
620 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
622 // see header file for class documentation
624 // disabled for the moment
628 AliHLTRunDesc runDesc;
629 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
630 runDesc.fStructSize=sizeof(AliHLTRunDesc);
631 AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
632 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
633 TObjLink *lnk=fTaskList.FirstLink();
634 while (lnk && iResult>=0) {
635 TObject* obj=lnk->GetObject();
637 AliHLTTask* pTask=(AliHLTTask*)obj;
638 iResult=pTask->ProcessTask(-1);
643 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
647 int AliHLTSystem::DeinitTasks()
649 // see header file for class documentation
651 TObjLink *lnk=fTaskList.FirstLink();
652 while (lnk && iResult>=0) {
653 TObject* obj=lnk->GetObject();
655 AliHLTTask* pTask=(AliHLTTask*)obj;
656 iResult=pTask->Deinit();
657 // ProcInfo_t ProcInfo;
658 // gSystem->GetProcInfo(&ProcInfo);
659 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
670 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
672 // see header file for class documentation
675 p=(void*)new char[size];
679 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
684 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
685 AliRawReader* rawReader)
687 // see header file for class documentation
689 if (runLoader || rawReader || nofEvents==0) {
690 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
691 if (CheckStatus(kReady)) {
693 // special case to close the reconstruction
694 if (!CheckStatus(kError)) {
699 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
700 // the system always remains started after event processing, a specific
701 // call with nofEvents==0 is needed to execute the stop sequence
702 if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
706 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
709 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
715 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
717 // see header file for class documentation
719 if (runLoader || esd) {
720 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
721 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
723 HLTError("missing run loader/ESD instance(s)");
729 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
731 // see header file for class documentation
733 if (!pHLTOUT) return -EINVAL;
735 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
736 AliHLTOUT::AliHLTOUTHandlerListEntryVector esdHandlers;
738 // first come first serve: the ESD of the first handler is also filled into
739 // the main ESD. Has to be changed later.
740 // currently, merging to the provided ESDs crashes at the level of the
741 // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed
743 AliESDEvent* pMasterESD=NULL;
744 if (bWriteGlobalEsd) pMasterESD=esd;
745 for (iResult=pHLTOUT->SelectFirstDataBlock();
747 iResult=pHLTOUT->SelectNextDataBlock()) {
748 AliHLTComponentDataType dt=kAliHLTVoidDataType;
749 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
750 pHLTOUT->GetDataBlockDescription(dt, spec);
751 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
752 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
753 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
754 handlerType=AliHLTModuleAgent::kEsd;
756 const char* pMsg="invalid";
757 switch (handlerType) {
758 case AliHLTModuleAgent::kEsd:
761 // preprocess and write later
762 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
763 pHandler->ProcessData(pHLTOUT);
764 pHLTOUT->InsertHandler(esdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
767 const AliHLTUInt8_t* pBuffer=NULL;
768 AliHLTUInt32_t size=0;
769 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
770 pHLTOUT->WriteESD(pBuffer, size, dt);
772 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
775 pHLTOUT->ReleaseDataBuffer(pBuffer);
780 case AliHLTModuleAgent::kRawReader:
781 // handled in the AliRawReaderHLT
783 case AliHLTModuleAgent::kRawStream:
784 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
785 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
786 AliHLTComponent::DataType2Text(dt).c_str(), spec);
788 case AliHLTModuleAgent::kChain:
789 HLTWarning("HLTOUT handler type 'kChain' not yet implemented: agent %s, data type %s, specification %#x",
790 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
791 AliHLTComponent::DataType2Text(dt).c_str(), spec);
793 case AliHLTModuleAgent::kProprietary:
794 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
795 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
796 AliHLTComponent::DataType2Text(dt).c_str(), spec);
798 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
799 int res=pHandler->ProcessData(pHLTOUT);
801 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
802 res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
803 AliHLTComponent::DataType2Text(dt).c_str(), spec);
807 case AliHLTModuleAgent::kUnknownOutput:
809 // fall trough intended
811 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
812 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
813 AliHLTComponent::DataType2Text(dt).c_str(), spec);
816 // TODO: the return value of SelectFirst/NextDataBlock must be
817 // changed in order to avoid this check
818 if (iResult==-ENOENT) iResult=0;
820 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator esdHandler;
821 // write all postponed esd data blocks
822 for (esdHandler=esdHandlers.begin(); esdHandler!=esdHandlers.end() && iResult>=0; esdHandler++) {
823 AliHLTOUTHandler* pHandler=*esdHandler;
824 const AliHLTUInt8_t* pBuffer=NULL;
825 AliHLTUInt32_t size=0;
826 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
827 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*esdHandler;
828 AliHLTComponentDataType dt=desc;
829 pHLTOUT->WriteESD(pBuffer, size, dt);
831 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
834 pHandler->ReleaseProcessedData(pBuffer, size);
841 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
843 // see header file for class documentation
846 if (fpComponentHandler) {
847 TString libs(libraries);
848 TObjArray* pTokens=libs.Tokenize(" ");
850 int iEntries=pTokens->GetEntries();
851 for (int i=0; i<iEntries && iResult>=0; i++) {
852 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
857 SetStatusFlags(kLibrariesLoaded);
859 // lets see if we need this, probably not
860 //fpComponentHandler->UnloadLibraries();
861 ClearStatusFlags(kLibrariesLoaded);
865 HLTFatal("no component handler available");
873 int AliHLTSystem::Configure(AliRunLoader* runloader)
875 // see header file for class documentation
876 return Configure(NULL, runloader);
879 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
881 // see header file for class documentation
883 if (CheckStatus(kRunning)) {
884 HLTError("HLT system in running state, can not configure");
887 ClearStatusFlags(kTaskListCreated);
888 if (CheckFilter(kHLTLogDebug))
889 AliHLTModuleAgent::PrintStatus();
890 if (CheckStatus(kConfigurationLoaded)==0) {
891 iResult=LoadConfigurations(rawReader, runloader);
893 if (fChains.Length()==0) {
894 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'localrec=<conf>\' option");
899 SetStatusFlags(kConfigurationLoaded);
900 if (CheckFilter(kHLTLogDebug))
901 fpConfigurationHandler->PrintConfigurations();
902 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
904 SetStatusFlags(kTaskListCreated);
907 if (iResult<0) SetStatusFlags(kError);
912 int AliHLTSystem::ScanOptions(const char* options)
914 // see header file for class documentation
917 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
919 TString alloptions(options);
920 TObjArray* pTokens=alloptions.Tokenize(" ");
922 int iEntries=pTokens->GetEntries();
923 for (int i=0; i<iEntries; i++) {
924 TString token=(((TObjString*)pTokens->At(i))->GetString());
925 if (token.Contains("loglevel=")) {
926 TString param=token.ReplaceAll("loglevel=", "");
927 if (param.IsDigit()) {
928 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
929 } else if (param.BeginsWith("0x") &&
930 param.Replace(0,2,"",0).IsHex()) {
932 sscanf(param.Data(),"%x", &severity);
933 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
935 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
937 } else if (token.Contains("frameworklog=")) {
938 TString param=token.ReplaceAll("frameworklog=", "");
939 if (param.IsDigit()) {
940 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
941 } else if (param.BeginsWith("0x") &&
942 param.Replace(0,2,"",0).IsHex()) {
944 sscanf(param.Data(),"%x", &severity);
945 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
947 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
949 } else if (token.Contains("alilog=off")) {
951 } else if (token.Contains("config=")) {
952 TString param=token.ReplaceAll("config=", "");
954 gROOT->Macro(param.Data(), &error);
956 SetStatusFlags(kConfigurationLoaded);
958 HLTError("can not execute macro \'%s\'", param.Data());
961 } else if (token.Contains("chains=")) {
962 TString param=token.ReplaceAll("chains=", "");
963 fChains=param.ReplaceAll(",", " ");
964 } else if (token.Contains("libmode=")) {
965 TString param=token.ReplaceAll("libmode=", "");
966 param.ReplaceAll(",", " ");
967 if (fpComponentHandler) {
968 if (param.CompareTo("static")==0) {
969 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
970 } else if (param.CompareTo("dynamic")==0) {
971 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
973 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
976 } else if (token.Contains("globalesd")) {
977 bWriteGlobalEsd=true;
978 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
982 HLTWarning("unknown option \'%s\'", token.Data());
990 const char** deflib=fgkHLTDefaultLibs;
996 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
997 (LoadComponentLibraries(libs.Data())<0)) {
998 HLTError("error while loading HLT libraries");
1006 int AliHLTSystem::Reset(int bForce)
1008 // see header file for class documentation
1010 if (!bForce && CheckStatus(kRunning)) {
1011 HLTError("HLT system in running state, can not configure");
1015 ClearStatusFlags(~kUninitialized);
1019 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1021 // see header file for class documentation
1022 if (CheckStatus(kRunning)) {
1023 HLTError("HLT system in running state, can not configure");
1027 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1028 while (pAgent && iResult>=0) {
1029 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1031 HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1032 iResult=LoadComponentLibraries(deplibs);
1035 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1036 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1037 pAgent=AliHLTModuleAgent::GetNextAgent();
1043 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1045 // see header file for class documentation
1046 if (CheckStatus(kRunning)) {
1047 HLTError("HLT system in running state, can not configure");
1050 if (!CheckStatus(kConfigurationLoaded)) {
1051 HLTWarning("configurations not yet loaded");
1060 if (fChains.Length()>0) {
1062 HLTImportant("custom reconstruction chain: %s", chains.Data());
1064 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1065 while ((pAgent || fChains.Length()>0) && iResult>=0) {
1066 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1068 if (!chains.IsNull()) chains+="";
1069 chains+=agentchains;
1070 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1072 pAgent=AliHLTModuleAgent::GetNextAgent();
1076 // build task list for chains
1077 TObjArray* pTokens=chains.Tokenize(" ");
1079 int iEntries=pTokens->GetEntries();
1080 for (int i=0; i<iEntries && iResult>=0; i++) {
1081 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1082 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1084 iResult=BuildTaskList(pConf);
1086 assert(fpComponentHandler!=NULL);
1087 TString cid=pConf->GetComponentID();
1088 if (cid.CompareTo("HLTOUT")==0) {
1089 // remove from the input of a global HLTOUT configuration
1090 chains.ReplaceAll(pCID, "");
1091 } else if (bHaveOutput==0) {
1092 // check whether this configuration produces data output
1093 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1095 chains.ReplaceAll(pCID, "");
1100 HLTWarning("can not find configuration %s", pCID);
1106 // build HLTOUT for simulation
1107 if (iResult>=0 && runloader) {
1109 // there are components in the chain which produce data which need to be
1110 // piped to an HLTOUT
1111 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1112 LoadComponentLibraries("libHLTsim.so")>=0) {
1113 AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
1114 iResult=BuildTaskList("_globalout_");
1116 HLTError("can not load libHLTsim.so and HLTOUT component");
1122 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1127 int AliHLTSystem::CheckStatus(int flag)
1129 // see header file for class documentation
1130 if (flag==kUninitialized && flag==fState) return 1;
1131 if ((fState&flag)==flag) return 1;
1135 int AliHLTSystem::GetStatusFlags()
1137 // see header file for class documentation
1141 int AliHLTSystem::SetStatusFlags(int flags)
1143 // see header file for class documentation
1148 int AliHLTSystem::ClearStatusFlags(int flags)
1150 // see header file for class documentation
1155 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1157 // see header file for class documentation
1158 if (fpComponentHandler==NULL) return NULL;
1159 return fpComponentHandler->FindSymbol(library, symbol);
1162 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1164 // see header file for class documentation
1165 SetLocalLoggingLevel(level);
1166 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1167 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);