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(AliHLTComponentLogSeverity loglevel)
67 fpComponentHandler(AliHLTComponentHandler::CreateHandler()),
68 fpConfigurationHandler(AliHLTConfigurationHandler::CreateHandler()),
72 fStopwatches(new TObjArray),
75 fpChainHandlers(NULL),
77 fpProprietaryHandlers(NULL)
79 // see header file for class documentation
81 // refer to README to build package
83 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85 if (fgNofInstances++>0) {
86 // July 2008: multiple instances are now allowed
87 // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
88 //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
91 SetGlobalLoggingLevel(loglevel);
92 SetFrameworkLog(loglevel);
93 if (fpComponentHandler) {
94 AliHLTComponentEnvironment env;
95 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
96 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
97 env.fLoggingFunc=NULL;
98 fpComponentHandler->SetEnvironment(&env);
99 InitAliLogFunc(fpComponentHandler);
100 fpComponentHandler->AnnounceVersion();
102 HLTFatal("can not create Component Handler");
104 if (fpConfigurationHandler) {
105 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
107 HLTFatal("can not create Configuration Handler");
111 AliHLTSystem::~AliHLTSystem()
113 // see header file for class documentation
116 AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
117 if (fpConfigurationHandler) {
118 fpConfigurationHandler->Destroy();
120 fpConfigurationHandler=NULL;
122 if (fpComponentHandler) {
123 fpComponentHandler->Destroy();
125 fpComponentHandler=NULL;
128 int AliHLTSystem::fgNofInstances=0;
130 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
132 // see header file for class documentation
133 HLTLogKeyword("configuration handling");
136 HLTError("function not yet implemented");
144 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
146 // see header file for class documentation
147 HLTLogKeyword("configuration handling");
152 HLTError("function not yet implemented");
161 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
163 // see header file for class documentation
164 HLTLogKeyword("configuration handling");
167 HLTError("function not yet implemented");
175 int AliHLTSystem::BuildTaskList(const char* id)
177 // see header file for class documentation
180 if (fpConfigurationHandler) {
181 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
183 iResult=BuildTaskList(pConf);
185 HLTError("unknown configuration \"%s\"", id);
197 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
199 // see header file for class documentation
202 AliHLTTask* pTask=NULL;
203 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
204 if (pTask->GetConf()!=pConf) {
205 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);
208 // task for this configuration exists, terminate
210 } else if (pConf->SourcesResolved(1)!=1) {
211 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
214 pTask=new AliHLTTask(pConf);
218 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
221 static int iterationLevel=0;
222 if (pTask && iResult>=0) {
223 // check for circular dependencies
224 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
225 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
226 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
227 HLTError("aborted ...");
231 // check whether all dependencies are already in the task list
232 // create the missing ones
233 // this step is an iterative process which calls this function again for the missing
234 // configurations, in order to avoid the currently processed task to be created
235 // again it is added to the list temporarily and removed afterwards
236 // This is of high importance to preserve the order of the tasks. Furthermore, the
237 // InsertTask method has to be used in order to set all the cross links right
238 fTaskList.Add(pTask);
239 AliHLTConfiguration* pDep=pConf->GetFirstSource();
240 while (pDep!=NULL && iResult>=0) {
241 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
242 if (FindTask(pDep->GetName())==NULL) {
243 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
245 iResult=BuildTaskList(pDep);
248 pDep=pConf->GetNextSource();
250 // remove the temporarily added task
251 fTaskList.Remove(pTask);
253 // insert the task and set the cross-links
255 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
256 iResult=InsertTask(pTask);
269 int AliHLTSystem::CleanTaskList()
271 // see header file for class documentation
274 while ((lnk=fTaskList.LastLink())!=NULL) {
275 delete (lnk->GetObject());
276 fTaskList.Remove(lnk);
281 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
283 // see header file for class documentation
285 TObjLink *lnk = NULL;
286 if ((iResult=pTask->CheckDependencies())>0)
287 lnk=fTaskList.FirstLink();
288 while (lnk && iResult>0) {
289 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
290 //HLTDebug("checking \"%s\"", pCurr->GetName());
291 iResult=pTask->Depends(pCurr);
293 iResult=pTask->SetDependency(pCurr);
294 pCurr->SetTarget(pTask);
295 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
297 if (pCurr->Depends(pTask)) {
298 // circular dependency
299 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
301 } else if ((iResult=pTask->CheckDependencies())>0) {
307 fTaskList.AddAfter(lnk, pTask);
309 fTaskList.AddFirst(pTask);
311 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
312 } else if (iResult>0) {
313 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
319 AliHLTTask* AliHLTSystem::FindTask(const char* id)
321 // see header file for class documentation
322 AliHLTTask* pTask=NULL;
324 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
329 void AliHLTSystem::PrintTaskList()
331 // see header file for class documentation
332 HLTLogKeyword("task list");
333 TObjLink *lnk = NULL;
334 HLTMessage("Task List");
335 lnk=fTaskList.FirstLink();
337 TObject* obj=lnk->GetObject();
339 HLTMessage(" %s - status:", obj->GetName());
340 AliHLTTask* pTask=(AliHLTTask*)obj;
341 pTask->PrintStatus();
348 int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
350 // see header file for class documentation
353 SetStatusFlags(kRunning);
354 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
355 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
356 if (fEventCount==0) {
357 InitBenchmarking(fStopwatches);
359 ResumeBenchmarking(fStopwatches);
361 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
362 if ((iResult=ProcessTasks(i))>=0) {
366 // TODO: define different running modes to either ignore errors in
367 // event processing or not
372 fEventCount+=iNofEvents;
373 if (bStop) StopTasks();
374 else PauseBenchmarking(fStopwatches);
376 if (bStop) DeinitTasks();
380 } else if (iResult==-126 /*ENOKEY*/) {
381 iResult=0; // do not propagate the error
383 ClearStatusFlags(kRunning);
387 int AliHLTSystem::InitTasks()
389 // see header file for class documentation
391 TObjLink *lnk=fTaskList.FirstLink();
394 HLTWarning("Task list is empty, skipping HLT");
395 return -126 /*ENOKEY*/;
397 while (lnk && iResult>=0) {
398 TObject* obj=lnk->GetObject();
400 AliHLTTask* pTask=(AliHLTTask*)obj;
401 iResult=pTask->Init(NULL, fpComponentHandler);
402 // ProcInfo_t ProcInfo;
403 // gSystem->GetProcInfo(&ProcInfo);
404 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
410 HLTError("can not initialize task list, error %d", iResult);
416 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
418 // see header file for class documentation
420 if (pStopwatches==NULL) return 0;
422 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
423 TStopwatch* pStopwatch= new TStopwatch;
426 pStopwatches->AddAt(pStopwatch, i);
433 TObjLink *lnk=fTaskList.FirstLink();
434 while (lnk && iResult>=0) {
435 TObject* obj=lnk->GetObject();
437 AliHLTTask* pTask=(AliHLTTask*)obj;
438 AliHLTComponent* pComp=NULL;
439 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
440 switch (pComp->GetComponentType()) {
441 case AliHLTComponent::kProcessor:
442 pComp->SetStopwatches(pStopwatches);
444 case AliHLTComponent::kSource:
446 // this switch determines whether the time consumption of the
447 // AliHLTComponent base methods should be counted to the input
448 // stopwatch or base stopwatch.
449 //int inputBase=(int)AliHLTComponent::kSWBase;
450 int inputBase=(int)AliHLTComponent::kSWInput;
451 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
452 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
455 case AliHLTComponent::kSink:
457 // this switch determines whether the time consumption of the
458 // AliHLTComponent base methods should be counted to the output
459 // stopwatch or base stopwatch.
460 //int outputBase=(int)AliHLTComponent::kSWBase;
461 int outputBase=(int)AliHLTComponent::kSWOutput;
462 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
463 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
467 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
477 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
479 // see header file for class documentation
480 if (pStopwatches==NULL) return 0;
482 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
483 if (!pStopwatches->At(i)) continue;
484 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
485 if (pSw) pSw->Stop();
490 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
492 // see header file for class documentation
493 if (pStopwatches==NULL) return 0;
495 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
496 if (!pStopwatches->At(i)) continue;
497 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
498 if (pSw) pSw->Continue();
503 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
505 // see header file for class documentation
507 if (pStopwatches==NULL) return 0;
509 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
510 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
516 if (iInitialized!=0) {
517 HLTImportant("HLT statistics:\n"
518 " base: R:%.3fs C:%.3fs\n"
519 " input: R:%.3fs C:%.3fs\n"
520 " output: R:%.3fs C:%.3fs\n"
521 " event processing : R:%.3fs C:%.3fs"
522 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
523 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
524 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
525 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
526 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
527 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
528 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
529 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
534 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
535 TObject* pObj=pStopwatches->RemoveAt(i);
536 if (pObj) delete pObj;
542 int AliHLTSystem::StartTasks()
544 // see header file for class documentation
546 TObjLink *lnk=fTaskList.FirstLink();
547 while (lnk && iResult>=0) {
548 TObject* obj=lnk->GetObject();
550 AliHLTTask* pTask=(AliHLTTask*)obj;
551 iResult=pTask->StartRun();
552 // ProcInfo_t ProcInfo;
553 // gSystem->GetProcInfo(&ProcInfo);
554 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
560 HLTError("can not start task list, error %d", iResult);
562 SetStatusFlags(kStarted);
565 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
566 HLTError("can not send SOR event");
572 int AliHLTSystem::ProcessTasks(Int_t eventNo)
574 // see header file for class documentation
576 HLTDebug("processing event no %d", eventNo);
577 TObjLink *lnk=fTaskList.FirstLink();
578 while (lnk && iResult>=0) {
579 TObject* obj=lnk->GetObject();
581 AliHLTTask* pTask=(AliHLTTask*)obj;
582 iResult=pTask->ProcessTask(eventNo);
583 // ProcInfo_t ProcInfo;
584 // gSystem->GetProcInfo(&ProcInfo);
585 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
592 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
595 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
601 int AliHLTSystem::StopTasks()
603 // see header file for class documentation
605 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
606 HLTError("can not send EOR event");
608 TObjLink *lnk=fTaskList.FirstLink();
610 TObject* obj=lnk->GetObject();
612 AliHLTTask* pTask=(AliHLTTask*)obj;
613 int locResult=pTask->EndRun();
614 if (iResult>=0 && locResult<0) iResult=locResult;
615 // ProcInfo_t ProcInfo;
616 // gSystem->GetProcInfo(&ProcInfo);
617 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
622 PrintBenchmarking(fStopwatches, 1 /*clean*/);
623 ClearStatusFlags(kStarted);
627 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
629 // see header file for class documentation
631 // disabled for the moment
635 AliHLTRunDesc runDesc;
636 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
637 runDesc.fStructSize=sizeof(AliHLTRunDesc);
638 AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
639 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
640 TObjLink *lnk=fTaskList.FirstLink();
641 while (lnk && iResult>=0) {
642 TObject* obj=lnk->GetObject();
644 AliHLTTask* pTask=(AliHLTTask*)obj;
645 iResult=pTask->ProcessTask(-1);
650 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
654 int AliHLTSystem::DeinitTasks()
656 // see header file for class documentation
658 TObjLink *lnk=fTaskList.FirstLink();
659 while (lnk && iResult>=0) {
660 TObject* obj=lnk->GetObject();
662 AliHLTTask* pTask=(AliHLTTask*)obj;
663 iResult=pTask->Deinit();
664 // ProcInfo_t ProcInfo;
665 // gSystem->GetProcInfo(&ProcInfo);
666 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
677 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
679 // see header file for class documentation
682 p=(void*)new char[size];
686 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
691 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
692 AliRawReader* rawReader)
694 // see header file for class documentation
696 if (runLoader || rawReader || nofEvents==0) {
697 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
698 if (CheckStatus(kReady)) {
700 // special case to close the reconstruction
701 if (!CheckStatus(kError)) {
706 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
707 // the system always remains started after event processing, a specific
708 // call with nofEvents==0 is needed to execute the stop sequence
709 if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
713 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
716 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
722 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
724 // see header file for class documentation
726 if (runLoader || esd) {
727 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
728 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
730 HLTError("missing run loader/ESD instance(s)");
736 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
738 // see header file for class documentation
740 if (!pHLTOUT) return -EINVAL;
741 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
744 // process all kChain handlers first
746 if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
747 HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
752 fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
753 if (!fpProprietaryHandlers)
754 fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
756 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
757 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
758 if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
760 // invalidate all blocks
761 AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
762 AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
764 // first come first serve: the ESD of the first handler is also filled into
765 // the main ESD. Has to be changed later.
766 // currently, merging to the provided ESDs crashes at the level of the
767 // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed
769 AliESDEvent* pMasterESD=NULL;
771 for (iResult=pHLTOUT->SelectFirstDataBlock();
773 iResult=pHLTOUT->SelectNextDataBlock()) {
774 AliHLTComponentDataType dt=kAliHLTVoidDataType;
775 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
776 pHLTOUT->GetDataBlockDescription(dt, spec);
777 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
778 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
780 // default handling for ESD data blocks does not require an explicite handler
781 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
782 handlerType=AliHLTModuleAgent::kEsd;
784 const char* pMsg="invalid";
785 switch (handlerType) {
786 case AliHLTModuleAgent::kEsd:
789 // schedule for later processing
790 pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
793 const AliHLTUInt8_t* pBuffer=NULL;
794 AliHLTUInt32_t size=0;
795 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
796 pHLTOUT->WriteESD(pBuffer, size, dt);
798 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
801 pHLTOUT->ReleaseDataBuffer(pBuffer);
803 pHLTOUT->MarkDataBlockProcessed();
807 case AliHLTModuleAgent::kRawReader:
808 // handled in the AliRawReaderHLT
810 case AliHLTModuleAgent::kRawStream:
811 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
812 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
813 AliHLTComponent::DataType2Text(dt).c_str(), spec);
815 case AliHLTModuleAgent::kChain:
816 HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
817 "New block of this type added by the chain? Skipping data block ...",
818 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
819 AliHLTComponent::DataType2Text(dt).c_str(), spec);
821 case AliHLTModuleAgent::kProprietary:
822 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
823 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
824 AliHLTComponent::DataType2Text(dt).c_str(), spec);
826 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
827 int res=pHandler->ProcessData(pHLTOUT);
829 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
830 res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
831 AliHLTComponent::DataType2Text(dt).c_str(), spec);
835 case AliHLTModuleAgent::kUnknownOutput:
837 // fall trough intended
839 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
840 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
841 AliHLTComponent::DataType2Text(dt).c_str(), spec);
844 // TODO: the return value of SelectFirst/NextDataBlock must be
845 // changed in order to avoid this check
846 if (iResult==-ENOENT) iResult=0;
848 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
850 // process and write all esd data blocks
851 for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
852 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
853 AliHLTOUTHandler* pHandler=*handler;
854 const AliHLTUInt8_t* pBuffer=NULL;
855 AliHLTUInt32_t size=0;
856 pHandler->ProcessData(pHLTOUT);
857 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
858 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
859 AliHLTComponentDataType dt=desc;
860 pHLTOUT->WriteESD(pBuffer, size, dt);
862 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
865 pHandler->ReleaseProcessedData(pBuffer, size);
867 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
870 // process all kProprietary data blocks
871 for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
872 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
873 AliHLTOUTHandler* pHandler=*handler;
874 const AliHLTUInt8_t* pBuffer=NULL;
875 AliHLTUInt32_t size=0;
876 pHandler->ProcessData(pHLTOUT);
877 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
878 HLTWarning("data produced by kProprietary handler ignored");
879 pHandler->ReleaseProcessedData(pBuffer, size);
881 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
884 // remove all empty handlers form the list (handlers which did not get a block this time)
885 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
886 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
891 int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
893 // see header file for class documentation
895 if (!pHLTOUT) return -EINVAL;
897 if (!fpChainHandlers)
898 fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
900 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
901 if (!pChainHandlers) return -ENOMEM;
903 // invalidate all blocks
904 AliHLTOUT::InvalidateBlocks(*pChainHandlers);
907 pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
909 // process all defined chain handlers
910 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
911 for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
912 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
913 AliHLTOUTHandler* pHandler=*chainHandler;
914 const AliHLTUInt8_t* pBuffer=NULL;
915 AliHLTUInt32_t size=0;
916 pHandler->ProcessData(pHLTOUT);
917 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
918 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
919 AliHLTComponentDataType dt=desc;
921 pHandler->ReleaseProcessedData(pBuffer, size);
923 pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
926 // remove all empty handlers form the list (handlers which did not get a block this time)
927 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
932 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
934 // see header file for class documentation
937 if (fpComponentHandler) {
938 TString libs(libraries);
939 TObjArray* pTokens=libs.Tokenize(" ");
941 int iEntries=pTokens->GetEntries();
942 for (int i=0; i<iEntries && iResult>=0; i++) {
943 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
948 SetStatusFlags(kLibrariesLoaded);
950 // lets see if we need this, probably not
951 //fpComponentHandler->UnloadLibraries();
952 ClearStatusFlags(kLibrariesLoaded);
956 HLTFatal("no component handler available");
964 int AliHLTSystem::Configure(AliRunLoader* runloader)
966 // see header file for class documentation
967 return Configure(NULL, runloader);
970 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
972 // see header file for class documentation
974 if (CheckStatus(kRunning)) {
975 HLTError("HLT system in running state, can not configure");
978 ClearStatusFlags(kTaskListCreated);
979 if (CheckFilter(kHLTLogDebug))
980 AliHLTModuleAgent::PrintStatus();
981 if (CheckStatus(kConfigurationLoaded)==0) {
982 iResult=LoadConfigurations(rawReader, runloader);
984 if (fChains.Length()==0) {
985 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
990 SetStatusFlags(kConfigurationLoaded);
991 if (CheckFilter(kHLTLogDebug))
992 fpConfigurationHandler->PrintConfigurations();
993 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
995 SetStatusFlags(kTaskListCreated);
998 if (iResult<0) SetStatusFlags(kError);
1003 int AliHLTSystem::ScanOptions(const char* options)
1005 // see header file for class documentation
1008 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
1010 TString alloptions(options);
1011 TObjArray* pTokens=alloptions.Tokenize(" ");
1013 int iEntries=pTokens->GetEntries();
1014 for (int i=0; i<iEntries; i++) {
1015 TString token=(((TObjString*)pTokens->At(i))->GetString());
1016 if (token.Contains("loglevel=")) {
1017 TString param=token.ReplaceAll("loglevel=", "");
1018 if (param.IsDigit()) {
1019 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
1020 } else if (param.BeginsWith("0x") &&
1021 param.Replace(0,2,"",0).IsHex()) {
1023 sscanf(param.Data(),"%x", &severity);
1024 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
1026 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1028 } else if (token.Contains("frameworklog=")) {
1029 TString param=token.ReplaceAll("frameworklog=", "");
1030 if (param.IsDigit()) {
1031 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
1032 } else if (param.BeginsWith("0x") &&
1033 param.Replace(0,2,"",0).IsHex()) {
1035 sscanf(param.Data(),"%x", &severity);
1036 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
1038 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1040 } else if (token.Contains("alilog=off")) {
1042 } else if (token.Contains("config=")) {
1043 TString param=token.ReplaceAll("config=", "");
1045 gROOT->Macro(param.Data(), &error);
1047 SetStatusFlags(kConfigurationLoaded);
1049 HLTError("can not execute macro \'%s\'", param.Data());
1052 } else if (token.Contains("chains=")) {
1053 TString param=token.ReplaceAll("chains=", "");
1054 fChains=param.ReplaceAll(",", " ");
1055 if (fChains.IsNull()) fChains=" "; // disable all chains
1056 } else if (token.Contains("libmode=")) {
1057 TString param=token.ReplaceAll("libmode=", "");
1058 param.ReplaceAll(",", " ");
1059 if (fpComponentHandler) {
1060 if (param.CompareTo("static")==0) {
1061 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
1062 } else if (param.CompareTo("dynamic")==0) {
1063 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
1065 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
1068 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1072 HLTWarning("unknown option \'%s\'", token.Data());
1079 if (libs.IsNull()) {
1080 const char** deflib=fgkHLTDefaultLibs;
1086 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
1087 (LoadComponentLibraries(libs.Data())<0)) {
1088 HLTError("error while loading HLT libraries");
1096 int AliHLTSystem::Reset(int bForce)
1098 // see header file for class documentation
1100 if (!bForce && CheckStatus(kRunning)) {
1101 HLTError("HLT system in running state, can not configure");
1105 ClearStatusFlags(~kUninitialized);
1109 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1111 // see header file for class documentation
1112 if (CheckStatus(kRunning)) {
1113 HLTError("HLT system in running state, can not configure");
1117 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1119 while (pAgent && iResult>=0) {
1120 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1122 HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1126 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1127 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1128 pAgent=AliHLTModuleAgent::GetNextAgent();
1132 iResult=LoadComponentLibraries(extralibs.Data());
1138 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1140 // see header file for class documentation
1141 if (CheckStatus(kRunning)) {
1142 HLTError("HLT system in running state, can not configure");
1145 if (!CheckStatus(kConfigurationLoaded)) {
1146 HLTWarning("configurations not yet loaded");
1155 if (fChains.Length()>0) {
1157 HLTImportant("custom reconstruction chain: %s", chains.Data());
1159 AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1160 while ((pAgent || fChains.Length()>0) && iResult>=0) {
1161 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1163 if (!chains.IsNull()) chains+=" ";
1164 chains+=agentchains;
1165 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1167 pAgent=AliHLTModuleAgent::GetNextAgent();
1171 // build task list for chains
1172 TObjArray* pTokens=chains.Tokenize(" ");
1174 int iEntries=pTokens->GetEntries();
1175 for (int i=0; i<iEntries && iResult>=0; i++) {
1176 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1177 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1179 iResult=BuildTaskList(pConf);
1181 assert(fpComponentHandler!=NULL);
1182 TString cid=pConf->GetComponentID();
1183 if (cid.CompareTo("HLTOUT")==0) {
1184 // remove from the input of a global HLTOUT configuration
1185 chains.ReplaceAll(pCID, "");
1186 } else if (bHaveOutput==0) {
1187 // check whether this configuration produces data output
1188 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1190 chains.ReplaceAll(pCID, "");
1195 HLTWarning("can not find configuration %s", pCID);
1201 // build HLTOUT for simulation
1202 if (iResult>=0 && runloader) {
1204 // there are components in the chain which produce data which need to be
1205 // piped to an HLTOUT
1206 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1207 fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
1208 AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
1209 iResult=BuildTaskList("_globalout_");
1211 HLTError("can not load libHLTsim.so and HLTOUT component");
1217 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1222 int AliHLTSystem::CheckStatus(int flag)
1224 // see header file for class documentation
1225 if (flag==kUninitialized && flag==fState) return 1;
1226 if ((fState&flag)==flag) return 1;
1230 int AliHLTSystem::GetStatusFlags()
1232 // see header file for class documentation
1236 int AliHLTSystem::SetStatusFlags(int flags)
1238 // see header file for class documentation
1243 int AliHLTSystem::ClearStatusFlags(int flags)
1245 // see header file for class documentation
1250 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1252 // see header file for class documentation
1253 if (fpComponentHandler==NULL) return NULL;
1254 return fpComponentHandler->FindSymbol(library, symbol);
1257 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1259 // see header file for class documentation
1260 SetLocalLoggingLevel(level);
1261 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1262 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);