2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project *
4 //* ALICE Experiment at CERN, All rights reserved. *
6 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 //* for The ALICE HLT Project. *
9 //* Permission to use, copy, modify and distribute this software and its *
10 //* documentation strictly for non-commercial purposes is hereby granted *
11 //* without fee, provided that the above copyright notice appears in all *
12 //* copies and that both the copyright notice and this permission notice *
13 //* appear in the supporting documentation. The authors make no claims *
14 //* about the suitability of this software for any purpose. It is *
15 //* provided "as is" without express or implied warranty. *
16 //**************************************************************************
18 /** @file AliHLTSystem.cxx
19 @author Matthias Richter
21 @brief Implementation of HLT module management.
29 #include "AliHLTStdIncludes.h"
30 #include "AliHLTSystem.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTComponent.h"
33 #include "AliHLTConfiguration.h"
34 #include "AliHLTConfigurationHandler.h"
35 #include "AliHLTOnlineConfiguration.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 "AliHLTOUTTask.h"
43 #include "AliHLTControlTask.h"
44 #include "AliHLTDataBuffer.h"
45 #include "AliHLTMisc.h"
46 #include <TObjArray.h>
47 #include <TObjString.h>
48 #include <TStopwatch.h>
50 //#include <TSystem.h>
52 //#include <TInterpreter.h>
54 /** HLT default component libraries */
55 const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
59 // "libAliHLTSample.so",
69 "libAliHLTTrigger.so",
73 /** ROOT macro for the implementation of ROOT specific class methods */
74 ClassImp(AliHLTSystem)
76 AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name,
77 AliHLTComponentHandler* pCompHandler,
78 AliHLTConfigurationHandler* pConfHandler
80 : fpComponentHandler(pCompHandler==NULL?AliHLTComponentHandler::CreateHandler():pCompHandler)
81 , fpConfigurationHandler(pConfHandler==NULL?AliHLTConfigurationHandler::CreateHandler():pConfHandler),
85 fStopwatches(new TObjArray),
88 fpChainHandlers(NULL),
90 fpProprietaryHandlers(NULL),
97 , fUseHLTOUTComponentTypeGlobal(true)
99 // see header file for class documentation
101 // refer to README to build package
103 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
105 if (fgNofInstances++>0) {
106 // July 2008: multiple instances are now allowed
107 // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
108 //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
111 SetGlobalLoggingLevel(loglevel);
112 SetFrameworkLog(loglevel);
113 if (fpComponentHandler) {
114 AliHLTAnalysisEnvironment env;
115 memset(&env, 0, sizeof(AliHLTAnalysisEnvironment));
116 env.fStructSize=sizeof(AliHLTAnalysisEnvironment);
117 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
118 env.fGetEventDoneDataFunc=AliHLTSystem::AllocEventDoneData;
119 env.fLoggingFunc=NULL;
120 fpComponentHandler->SetEnvironment(&env);
121 InitAliLogFunc(fpComponentHandler);
122 if (fgNofInstances==1) {
123 fpComponentHandler->AnnounceVersion();
126 HLTFatal("can not create Component Handler");
128 if (fpConfigurationHandler==NULL) {
129 HLTFatal("can not create Configuration Handler");
133 AliHLTSystem::~AliHLTSystem()
135 // see header file for class documentation
137 CleanupHLTOUTHandlers();
139 if (fpConfigurationHandler) {
140 fpConfigurationHandler->Destroy();
142 fpConfigurationHandler=NULL;
144 if (fpComponentHandler) {
145 fpComponentHandler->Destroy();
147 fpComponentHandler=NULL;
150 // note: fpHLTOUTTask and fpControlTask are deleted by
154 int AliHLTSystem::fgNofInstances=0;
156 int AliHLTSystem::BuildTaskList(const char* id)
158 // see header file for class documentation
161 if (fpConfigurationHandler) {
162 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
164 iResult=BuildTaskList(pConf);
166 HLTError("unknown configuration \"%s\"", id);
178 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
180 // see header file for class documentation
183 AliHLTTask* pTask=NULL;
184 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
185 if (pTask->GetConf()!=pConf) {
186 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);
189 // task for this configuration exists, terminate
191 // check first if the configuration has all sources resolved, try to extract otherwise
192 } else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources()!=1) {
193 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
196 pTask=new AliHLTTask(pConf);
200 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
203 static int iterationLevel=0;
204 if (pTask && iResult>=0) {
205 // check for circular dependencies
206 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
207 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
208 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
209 HLTError("aborted ...");
213 // check whether all dependencies are already in the task list
214 // create the missing ones
215 // this step is an iterative process which calls this function again for the missing
216 // configurations, in order to avoid the currently processed task to be created
217 // again it is added to the list temporarily and removed afterwards
218 // This is of high importance to preserve the order of the tasks. Furthermore, the
219 // InsertTask method has to be used in order to set all the cross links right
220 fTaskList.Add(pTask);
221 AliHLTConfiguration* pDep=pConf->GetFirstSource();
222 while (pDep!=NULL && iResult>=0) {
223 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
224 if (FindTask(pDep->GetName())==NULL) {
225 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
227 iResult=BuildTaskList(pDep);
230 pDep=pConf->GetNextSource();
232 // remove the temporarily added task
233 fTaskList.Remove(pTask);
235 // insert the task and set the cross-links
237 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
238 iResult=InsertTask(pTask);
251 int AliHLTSystem::CleanTaskList()
253 // see header file for class documentation
258 while ((lnk=fTaskList.LastLink())!=NULL) {
259 delete (lnk->GetObject());
260 fTaskList.Remove(lnk);
266 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
268 // see header file for class documentation
270 if (fpControlTask==NULL) {
271 fpControlTask=new AliHLTControlTask;
272 if (!fpControlTask) return -ENOMEM;
273 fTaskList.AddFirst(fpControlTask);
275 TObjLink *controlLnk=NULL;
276 TObjLink *lnk = fTaskList.FirstLink();
277 assert(!lnk || lnk->GetObject()==fpControlTask || fpControlTask==NULL);
278 if (lnk && lnk->GetObject()==fpControlTask) {
279 if (pTask->GetConf() && pTask->GetConf()->GetFirstSource()==NULL) {
280 pTask->SetDependency(fpControlTask);
281 fpControlTask->SetTarget(pTask);
286 if ((iResult=pTask->CheckDependencies())<=0)
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);
308 } else if (controlLnk) {
309 fTaskList.AddAfter(controlLnk, pTask);
311 fTaskList.AddFirst(pTask);
313 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
314 } else if (iResult>0) {
315 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
321 AliHLTTask* AliHLTSystem::FindTask(const char* id)
323 // see header file for class documentation
324 AliHLTTask* pTask=NULL;
326 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
331 void AliHLTSystem::PrintTaskList()
333 // see header file for class documentation
334 HLTLogKeyword("task list");
335 TObjLink *lnk = NULL;
336 HLTMessage("Task List");
337 lnk=fTaskList.FirstLink();
339 TObject* obj=lnk->GetObject();
341 HLTMessage(" %s - status:", obj->GetName());
342 AliHLTTask* pTask=(AliHLTTask*)obj;
343 pTask->PrintStatus();
350 int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
351 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
352 AliHLTUInt32_t participatingDetectors)
354 // see header file for class documentation
357 SetStatusFlags(kRunning);
358 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
359 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
360 if (fEventCount==0) {
361 InitBenchmarking(fStopwatches);
363 // Matthias Oct 11 2008 this is a bug
364 // By resuming the stopwatches at this point, all continued counting, but the
365 // starting and stopping is controlled by the AliHLTStopwatchGuard
366 //ResumeBenchmarking(fStopwatches);
368 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
370 if (iNofEvents>1 && i==fEventCount) {
371 HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block");
373 // reset and prepare for new data
374 fpHLTOUTTask->Reset();
376 if (eventtype == 0) {
377 eventtype = gkAliEventTypeData;
378 participatingDetectors = 0x0;
380 if ((iResult=ProcessTasks(i, trgMask, timestamp, eventtype, participatingDetectors))>=0) {
384 // TODO: define different running modes to either ignore errors in
385 // event processing or not
389 AliHLTDataBuffer::SetGlobalEventCount(iCount);
391 fEventCount+=iNofEvents;
392 if (bStop) StopTasks();
393 else PauseBenchmarking(fStopwatches);
395 if (bStop) DeinitTasks();
399 } else if (iResult==-126 /*ENOKEY*/) {
400 iResult=0; // do not propagate the error
402 ClearStatusFlags(kRunning);
403 AliHLTDataBuffer::PrintStatistics();
407 int AliHLTSystem::InitTasks()
409 // see header file for class documentation
411 TObjLink *lnk=fTaskList.FirstLink();
414 HLTInfo("Task list is empty, skipping HLT");
415 return -126 /*ENOKEY*/;
417 while (lnk && iResult>=0) {
418 TObject* obj=lnk->GetObject();
420 AliHLTTask* pTask=(AliHLTTask*)obj;
421 iResult=pTask->Init(NULL, fpComponentHandler);
422 // ProcInfo_t ProcInfo;
423 // gSystem->GetProcInfo(&ProcInfo);
424 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
430 HLTError("can not initialize task list, error %d", iResult);
436 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
438 // see header file for class documentation
440 if (pStopwatches==NULL) return 0;
442 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
443 TStopwatch* pStopwatch= new TStopwatch;
446 pStopwatches->AddAt(pStopwatch, i);
453 TObjLink *lnk=fTaskList.FirstLink();
454 while (lnk && iResult>=0) {
455 TObject* obj=lnk->GetObject();
457 AliHLTTask* pTask=(AliHLTTask*)obj;
458 AliHLTComponent* pComp=NULL;
459 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
460 switch (pComp->GetComponentType()) {
461 case AliHLTComponent::kProcessor:
462 pComp->SetStopwatches(pStopwatches);
464 case AliHLTComponent::kSource:
466 // this switch determines whether the time consumption of the
467 // AliHLTComponent base methods should be counted to the input
468 // stopwatch or base stopwatch.
469 //int inputBase=(int)AliHLTComponent::kSWBase;
470 int inputBase=(int)AliHLTComponent::kSWInput;
471 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
472 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
475 case AliHLTComponent::kSink:
477 // this switch determines whether the time consumption of the
478 // AliHLTComponent base methods should be counted to the output
479 // stopwatch or base stopwatch.
480 //int outputBase=(int)AliHLTComponent::kSWBase;
481 int outputBase=(int)AliHLTComponent::kSWOutput;
482 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
483 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
487 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
497 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
499 // see header file for class documentation
500 if (pStopwatches==NULL) return 0;
502 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
503 if (!pStopwatches->At(i)) continue;
504 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
505 if (pSw) pSw->Stop();
510 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
512 // see header file for class documentation
513 if (pStopwatches==NULL) return 0;
515 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
516 if (!pStopwatches->At(i)) continue;
517 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
518 if (pSw) pSw->Continue();
523 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
525 // see header file for class documentation
527 if (pStopwatches==NULL) return 0;
529 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
530 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
536 if (iInitialized!=0) {
537 HLTImportant("HLT statistics:\n"
538 " base: R:%.3fs C:%.3fs\n"
539 " input: R:%.3fs C:%.3fs\n"
540 " output: R:%.3fs C:%.3fs\n"
541 " event processing : R:%.3fs C:%.3fs"
542 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
543 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
544 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
545 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
546 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
547 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
548 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
549 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
554 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
555 TObject* pObj=pStopwatches->RemoveAt(i);
556 if (pObj) delete pObj;
562 int AliHLTSystem::StartTasks()
564 // see header file for class documentation
566 TObjLink *lnk=fTaskList.FirstLink();
567 while (lnk && iResult>=0) {
568 TObject* obj=lnk->GetObject();
570 AliHLTTask* pTask=(AliHLTTask*)obj;
571 iResult=pTask->StartRun();
572 // ProcInfo_t ProcInfo;
573 // gSystem->GetProcInfo(&ProcInfo);
574 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
580 HLTError("can not start task list, error %d", iResult);
582 SetStatusFlags(kStarted);
585 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
586 HLTError("can not send SOR event: error %d", iResult);
592 int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask,
593 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
594 AliHLTUInt32_t participatingDetectors)
596 // see header file for class documentation
598 HLTDebug("processing event no %d", eventNo);
599 TObjLink *lnk=fTaskList.FirstLink();
601 TObject* obj=lnk->GetObject();
603 AliHLTTask* pTask=(AliHLTTask*)obj;
605 iResult=pTask->ProcessTask(eventNo, eventtype, trgMask, timestamp, participatingDetectors);
606 // ProcInfo_t ProcInfo;
607 // gSystem->GetProcInfo(&ProcInfo);
608 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
610 pTask->SubscribeSourcesAndSkip();
618 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
621 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
627 int AliHLTSystem::StopTasks()
629 // see header file for class documentation
631 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
632 HLTError("can not send EOR event");
635 // cleanup blocks from the last event. This is a bit awkward. All output
636 // blocks from the chains need to be stored in the HLTOUT task. Though,
637 // we do not know, whether HLTOUT is going to be processed or not.
639 fpHLTOUTTask->Reset();
641 TObjLink *lnk=fTaskList.FirstLink();
643 TObject* obj=lnk->GetObject();
645 AliHLTTask* pTask=(AliHLTTask*)obj;
646 int locResult=pTask->EndRun();
647 if (iResult>=0 && locResult<0) iResult=locResult;
648 // ProcInfo_t ProcInfo;
649 // gSystem->GetProcInfo(&ProcInfo);
650 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
655 PrintBenchmarking(fStopwatches, 1 /*clean*/);
656 if (fEventCount!=fGoodEvents) {
657 HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
659 ClearStatusFlags(kStarted);
663 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
665 // see header file for class documentation
668 AliHLTComponentBlockDataList controlBlocks;
669 AliHLTComponentBlockData bd;
671 // run decriptor block of type kAliHLTDataTypeSOR/kAliHLTDataTypeEOR
672 AliHLTComponent::FillBlockData(bd);
673 AliHLTRunDesc runDesc;
674 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
675 runDesc.fStructSize=sizeof(AliHLTRunDesc);
676 runDesc.fRunNo=AliHLTMisc::Instance().GetCDBRunNo();
678 bd.fSize=sizeof(AliHLTRunDesc);
680 bd.fSpecification=kAliHLTVoidDataSpec;
681 controlBlocks.push_back(bd);
683 // ECS parameter of type kAliHLTDataTypeECSParam
684 if (fECSParams.IsNull())
685 fECSParams="CTP_TRIGGER_CLASS=00:DUMMY-TRIGGER-ALL:00-01-02-03-04-05-06-07-08-09-10-11-12-13-14-15-16-17";
686 AliHLTComponent::FillBlockData(bd);
687 bd.fPtr=(void*)fECSParams.Data();
688 bd.fSize=fECSParams.Length()+1;
689 bd.fDataType=kAliHLTDataTypeECSParam;
690 bd.fSpecification=kAliHLTVoidDataSpec;
691 controlBlocks.push_back(bd);
693 AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
694 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
695 TObjLink *lnk=fTaskList.FirstLink();
696 while (lnk && iResult>=0) {
697 TObject* obj=lnk->GetObject();
699 AliHLTTask* pTask=(AliHLTTask*)obj;
700 AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
701 if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
702 else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
703 else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
704 iResult=pTask->ProcessTask(-1, eventType, 0, 0);
710 // control events are not supposed to go into the HLTOUT
712 fpHLTOUTTask->Reset();
714 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
718 int AliHLTSystem::DeinitTasks()
720 // see header file for class documentation
722 TObjLink *lnk=fTaskList.LastLink();
724 TObject* obj=lnk->GetObject();
726 AliHLTTask* pTask=(AliHLTTask*)obj;
727 int localRes=pTask->Deinit();
728 if (iResult>=0) iResult=localRes;
729 // ProcInfo_t ProcInfo;
730 // gSystem->GetProcInfo(&ProcInfo);
731 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
742 int AliHLTSystem::CleanupHLTOUTHandlers()
744 // see header file for class documentation
745 if (fpChainHandlers) {
746 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
747 fpChainHandlers=NULL;
749 AliHLTOUT::InvalidateBlocks(*pHandlers);
750 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
752 assert(pHandlers->size()==0);
757 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
760 AliHLTOUT::InvalidateBlocks(*pHandlers);
761 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
763 assert(pHandlers->size()==0);
767 if (fpProprietaryHandlers) {
768 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
769 fpProprietaryHandlers=NULL;
771 AliHLTOUT::InvalidateBlocks(*pHandlers);
772 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
774 assert(pHandlers->size()==0);
780 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
782 // see header file for class documentation
785 p=(void*)new char[size];
789 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
794 int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd )
796 // see header file for class documentation
797 unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
798 void* block=AllocMemory(NULL, blocksize);
799 if (!block) return -ENOMEM;
800 memset(block, 0, blocksize);
801 *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
802 (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
803 (*edd)->fDataSize=size;
804 (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
809 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
810 AliRawReader* rawReader)
812 // see header file for class documentation
814 if (runLoader || rawReader || nofEvents==0) {
815 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
816 if (CheckStatus(kReady)) {
818 // special case to close the reconstruction
819 if (!CheckStatus(kError)) {
822 CleanupHLTOUTHandlers();
825 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
826 AliHLTUInt64_t trgMask=0x1;
827 AliHLTUInt32_t timestamp=0;
828 AliHLTUInt32_t eventtype=0;
829 if (runLoader==NULL) {
830 // this is a quick workaround for the case of simulation
831 // the trigger framework is still under development, secondly, AliHLTSimulation
832 // does not yet add the emulated ECS parameters, so no CTP trigger is known in the HLT
833 // AliHLTTask will initialize one dummy CTP trigger class with bit 0, that's why the
834 // default trigger mask is 0x1
835 trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
837 // get the timestamp and type of the event from the raw reader
838 // this is currently only meaningfull for reconstruction (runloader==NULL)
839 timestamp=AliHLTMisc::Instance().GetTimeStamp(rawReader);
840 eventtype=AliHLTMisc::Instance().GetEventType(rawReader);
842 // the system always remains started after event processing, a specific
843 // call with nofEvents==0 is needed to execute the stop sequence
844 if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
848 // add the current HLTOUT task to the collection
850 AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
851 if (pTask && (iResult=pTask->Init())>=0) {
852 if (pTask->GetNofDataBlocks()>0) {
853 AliHLTOUT* pHLTOUT=RequestHLTOUT();
855 pHLTOUT->AddSubCollection(pTask);
856 ReleaseHLTOUT(pHLTOUT);
858 HLTWarning("no HLTOUT instance available, output blocks of the chain are ignored");
862 HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
867 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
870 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
876 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
878 // see header file for class documentation
880 if (runLoader || esd) {
881 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
882 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
884 HLTError("missing run loader/ESD instance(s)");
890 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
892 // see header file for class documentation
894 if (!pHLTOUT) return -EINVAL;
895 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
898 // process all kChain handlers first
900 if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
901 HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
906 fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
907 if (!fpProprietaryHandlers)
908 fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
910 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
911 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
912 if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
914 // invalidate all blocks
915 AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
916 AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
918 AliHLTComponentDataTypeList esdBlocks;
920 for (iResult=pHLTOUT->SelectFirstDataBlock();
922 iResult=pHLTOUT->SelectNextDataBlock()) {
923 AliHLTComponentDataType dt=kAliHLTVoidDataType;
924 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
925 pHLTOUT->GetDataBlockDescription(dt, spec);
926 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
927 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
929 // default handling for ESD data blocks does not require an explicite handler
930 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
931 handlerType=AliHLTModuleAgent::kEsd;
933 const char* pMsg="invalid";
934 switch (handlerType) {
935 case AliHLTModuleAgent::kEsd:
938 // schedule for later processing
939 pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
941 AliHLTComponentDataTypeList::iterator element=esdBlocks.begin();
942 for (; element!=esdBlocks.end(); element++) {
944 HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str());
948 if (element==esdBlocks.end()) esdBlocks.push_back(dt);
951 const AliHLTUInt8_t* pBuffer=NULL;
952 AliHLTUInt32_t size=0;
953 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
954 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
955 pHLTOUT->ReleaseDataBuffer(pBuffer);
957 pHLTOUT->MarkDataBlockProcessed();
961 case AliHLTModuleAgent::kRawReader:
962 // handled in the AliRawReaderHLT
964 case AliHLTModuleAgent::kRawStream:
965 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
966 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
967 AliHLTComponent::DataType2Text(dt).c_str(), spec);
969 case AliHLTModuleAgent::kChain:
970 HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
971 "New block of this type added by the chain? Skipping data block ...",
972 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
973 AliHLTComponent::DataType2Text(dt).c_str(), spec);
975 case AliHLTModuleAgent::kProprietary:
976 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
977 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
978 AliHLTComponent::DataType2Text(dt).c_str(), spec);
980 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
981 int res=pHandler->ProcessData(pHLTOUT);
983 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
984 res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
985 AliHLTComponent::DataType2Text(dt).c_str(), spec);
989 case AliHLTModuleAgent::kUnknownOutput:
991 // fall trough intended
993 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
994 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
995 AliHLTComponent::DataType2Text(dt).c_str(), spec);
998 // TODO: the return value of SelectFirst/NextDataBlock must be
999 // changed in order to avoid this check
1000 if (iResult==-ENOENT) iResult=0;
1002 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
1004 // process and write all esd data blocks
1005 for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
1006 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1007 AliHLTOUTHandler* pHandler=*handler;
1008 const AliHLTUInt8_t* pBuffer=NULL;
1009 AliHLTUInt32_t size=0;
1010 pHandler->ProcessData(pHLTOUT);
1011 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1012 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
1013 AliHLTComponentDataType dt=desc;
1014 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
1015 pHandler->ReleaseProcessedData(pBuffer, size);
1017 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1020 // process all kProprietary data blocks
1021 for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) {
1022 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1023 AliHLTOUTHandler* pHandler=*handler;
1024 const AliHLTUInt8_t* pBuffer=NULL;
1025 AliHLTUInt32_t size=0;
1026 pHandler->ProcessData(pHLTOUT);
1027 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1028 HLTWarning("data produced by kProprietary handler ignored");
1029 pHandler->ReleaseProcessedData(pBuffer, size);
1031 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1034 // remove all empty handlers form the list (handlers which did not get a block this time)
1035 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
1036 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
1041 int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
1043 // see header file for class documentation
1045 if (!pHLTOUT) return -EINVAL;
1047 if (!fpChainHandlers)
1048 fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
1050 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
1051 if (!pChainHandlers) return -ENOMEM;
1053 // invalidate all blocks
1054 AliHLTOUT::InvalidateBlocks(*pChainHandlers);
1057 pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
1059 // process all defined chain handlers
1060 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
1061 for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
1062 if (chainHandler->IsEmpty()) continue;
1063 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
1064 AliHLTOUTHandler* pHandler=*chainHandler;
1065 const AliHLTUInt8_t* pBuffer=NULL;
1066 AliHLTUInt32_t size=0;
1067 pHandler->ProcessData(pHLTOUT);
1068 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1069 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
1070 //AliHLTComponentDataType dt=desc;
1072 pHandler->ReleaseProcessedData(pBuffer, size);
1074 pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
1077 // remove all empty handlers form the list (handlers which did not get a block this time)
1078 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
1083 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
1085 // see header file for class documentation
1088 if (fpComponentHandler) {
1089 TString libs(libraries);
1090 TObjArray* pTokens=libs.Tokenize(" ");
1092 int iEntries=pTokens->GetEntriesFast();
1093 for (int i=0; i<iEntries && iResult>=0; i++) {
1094 iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
1099 SetStatusFlags(kLibrariesLoaded);
1101 // lets see if we need this, probably not
1102 //fpComponentHandler->UnloadLibraries();
1103 ClearStatusFlags(kLibrariesLoaded);
1107 HLTFatal("no component handler available");
1115 int AliHLTSystem::Configure(AliRunLoader* runloader)
1117 // see header file for class documentation
1118 return Configure(NULL, runloader);
1121 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
1123 // see header file for class documentation
1125 if (CheckStatus(kRunning)) {
1126 HLTError("HLT system in running state, can not configure");
1129 ClearStatusFlags(kTaskListCreated);
1130 if (CheckFilter(kHLTLogDebug))
1131 AliHLTModuleAgent::PrintStatus();
1132 if (CheckStatus(kConfigurationLoaded)==0) {
1133 iResult=LoadConfigurations(rawReader, runloader);
1135 if (fChains.Length()==0) {
1136 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
1141 SetStatusFlags(kConfigurationLoaded);
1142 if (CheckFilter(kHLTLogDebug))
1143 fpConfigurationHandler->PrintConfigurations();
1144 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
1146 SetStatusFlags(kTaskListCreated);
1149 if (iResult<0) SetStatusFlags(kError);
1154 int AliHLTSystem::ScanOptions(const char* options)
1156 // see header file for class documentation
1159 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
1161 TString excludelibs("");
1162 TString alloptions(options);
1163 TObjArray* pTokens=alloptions.Tokenize(" ");
1165 int iEntries=pTokens->GetEntriesFast();
1166 for (int i=0; i<iEntries; i++) {
1167 TString token=(((TObjString*)pTokens->At(i))->GetString());
1168 if (token.Contains("loglevel=")) {
1169 TString param=token.ReplaceAll("loglevel=", "");
1170 if (param.IsDigit()) {
1171 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
1172 } else if (param.BeginsWith("0x") &&
1173 param.Replace(0,2,"",0).IsHex()) {
1175 sscanf(param.Data(),"%x", &severity);
1176 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
1178 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1180 } else if (token.Contains("frameworklog=")) {
1181 TString param=token.ReplaceAll("frameworklog=", "");
1182 if (param.IsDigit()) {
1183 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
1184 } else if (param.BeginsWith("0x") &&
1185 param.Replace(0,2,"",0).IsHex()) {
1187 sscanf(param.Data(),"%x", &severity);
1188 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
1190 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1192 } else if (token.Contains("alilog=off")) {
1194 } else if (token.Contains("config=") || token.Contains("run-online-config")) {
1195 if (!CheckStatus(kConfigurationLoaded)) {
1197 AliHLTOnlineConfiguration* pConf = NULL;
1198 if (token.Contains("run-online-config")) {
1199 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry("HLT/Calib/OnlineConfig");
1201 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
1202 if (pObject && pObject->IsA() == AliHLTOnlineConfiguration::Class())
1203 pConf = (AliHLTOnlineConfiguration*)pObject;
1206 if (token.Contains("config=")) {
1207 TString param=token.ReplaceAll("config=", "");
1208 if (token.EndsWith(".xml", TString::kIgnoreCase)) {
1210 pConf = new AliHLTOnlineConfiguration;
1211 filesize = pConf->LoadConfiguration(param.Data());
1212 if (filesize <= 0) {
1213 HLTError("cannot load config \'%s\'", param.Data());
1217 gROOT->Macro(param.Data(), &error);
1219 SetStatusFlags(kConfigurationLoaded);
1221 HLTError("cannot execute macro \'%s\'", param.Data());
1227 error = pConf->Parse();
1229 fChains = pConf->GetDefaultChains();
1230 libs = pConf->GetComponentLibraries();
1232 SetStatusFlags(kConfigurationLoaded);
1234 HLTError("cannot parse online configuration");
1238 delete pConf; pConf=NULL;
1240 HLTWarning("HLT options has both a config file and run-online-config set");
1242 } else if (token.Contains("chains=")) {
1243 TString param=token.ReplaceAll("chains=", "");
1244 fChains=param.ReplaceAll(",", " ");
1245 if (fChains.IsNull()) fChains=" "; // disable all chains
1246 } else if (token.Contains("libmode=")) {
1247 TString param=token.ReplaceAll("libmode=", "");
1248 param.ReplaceAll(",", " ");
1249 if (fpComponentHandler) {
1250 if (param.CompareTo("static")==0) {
1251 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
1252 } else if (param.CompareTo("dynamic")==0) {
1253 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
1255 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
1258 } else if (token.BeginsWith("ECS=")) {
1259 fECSParams=token.ReplaceAll("ECS=", "");
1260 } else if (token.BeginsWith("hltout-mode=")) {
1261 // The actual parameter for argument 'hltout-mode' is treated in AliSimulation.
1262 // For AliHLTSystem the occurrence with parameter 'split' signals the use of the
1263 // separated HLTOUTComponents for digit and raw data. All others indicate
1264 // HLTOUTComponent type 'global' where the data generation is steered from global
1266 fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")==1;
1267 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1270 } else if (token.BeginsWith("!lib") && token.EndsWith(".so")) {
1274 HLTWarning("unknown option \'%s\'", token.Data());
1281 if (libs.IsNull()) {
1282 const char** deflib=fgkHLTDefaultLibs;
1283 for (;*deflib; deflib++) {
1284 if (excludelibs.Contains(*deflib)) continue;
1289 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
1290 (LoadComponentLibraries(libs.Data())<0)) {
1291 HLTError("error while loading HLT libraries");
1299 int AliHLTSystem::Reset(int bForce)
1301 // see header file for class documentation
1303 if (!bForce && CheckStatus(kRunning)) {
1304 HLTError("HLT system in running state, can not configure");
1308 ClearStatusFlags(~kUninitialized);
1312 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1314 // see header file for class documentation
1315 if (CheckStatus(kRunning)) {
1316 HLTError("HLT system in running state, can not configure");
1320 AliHLTModuleAgent* pAgent=NULL;
1322 // first check for the required libraries and load those
1324 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1325 pAgent && iResult>=0;
1326 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1327 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1329 HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1335 iResult=LoadComponentLibraries(extralibs.Data());
1338 // in order to register the configurations in the correct sequence
1339 // all agents need to be ordered with respect to the required
1340 // libraries. Ordering relies on the naming convention
1341 // libAliHLT<Module>.so
1343 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1344 pAgent && iResult>=0;
1345 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1346 AliHLTModuleAgent* pPrevDep=NULL;
1347 TString dependencies=pAgent->GetRequiredComponentLibraries();
1348 TObjArray* pTokens=dependencies.Tokenize(" ");
1350 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
1351 TString module=((TObjString*)pTokens->At(n))->GetString();
1352 HLTDebug(" checking %s", module.Data());
1353 module.ReplaceAll("libAliHLT", "");
1354 module.ReplaceAll(".so", "");
1356 for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep));
1357 pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) {
1358 HLTDebug(" checking %s == %s", module.Data(), pCurrent->GetModuleId());
1360 if (module.CompareTo(pCurrent->GetModuleId())==0) {
1370 // insert right after the last dependency
1371 agents.AddAfter(pPrevDep, pAgent);
1372 HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
1374 // insert at the beginning
1375 agents.AddFirst(pAgent);
1376 HLTDebug("insert %s at beginning", pAgent->GetModuleId());
1380 // now we load the configurations
1381 if (agents.GetEntries()) {
1382 TIter next(&agents);
1383 while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
1384 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1385 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1392 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1394 // see header file for class documentation
1395 if (CheckStatus(kRunning)) {
1396 HLTError("HLT system in running state, can not configure");
1399 if (!CheckStatus(kConfigurationLoaded)) {
1400 HLTWarning("configurations not yet loaded");
1409 if (fChains.Length()>0) {
1411 HLTImportant("custom reconstruction chain: %s", chains.Data());
1413 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1414 pAgent && iResult>=0;
1415 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1416 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1418 if (!chains.IsNull()) chains+=" ";
1419 chains+=agentchains;
1420 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1425 // build task list for chains
1426 TObjArray* pTokens=chains.Tokenize(" ");
1428 int iEntries=pTokens->GetEntriesFast();
1429 for (int i=0; i<iEntries && iResult>=0; i++) {
1430 const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1431 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1433 iResult=BuildTaskList(pConf);
1434 if (true) { // condition was deprecated but kept for sake of svn diff
1435 // bHaveOutput variable has to be set for both running modes
1436 // AliHLTSimulation and AliHLTReconstruction
1437 assert(fpComponentHandler!=NULL);
1438 TString cid=pConf->GetComponentID();
1439 if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
1440 // remove from the input of a global HLTOUT configuration
1441 chains.ReplaceAll(pCID, "");
1442 } else if (bHaveOutput==0) {
1443 // check whether this configuration produces data output
1444 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1446 chains.ReplaceAll(pCID, "");
1451 HLTWarning("can not find configuration %s", pCID);
1457 // build HLTOUT for simulation
1458 if (iResult>=0 && runloader) {
1460 // there are components in the chain which produce data which need to be
1461 // piped to an HLTOUT
1463 // add the SchemaEvolutionComponent which analyzes the ROOT objects in
1464 // the output stream
1465 if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
1466 fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
1467 AliHLTConfiguration schemaevo("_schemaevolution_", "ROOTSchemaEvolutionComponent",
1468 chains.Data(), "-file=HLT.StreamerInfo.root");
1469 iResult=BuildTaskList("_schemaevolution_");
1471 HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
1474 // add the HLTOUT component
1475 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1476 fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
1477 // for the default HLTOUTComponent type 'global' the data generation is steered
1478 // by global flags from AliSimulation. This allows for emulation of the old
1479 // AliHLTSimulation behavior where only one chain is run on either digits or
1480 // simulated raw data and the HLT digits and raw files have been generated
1481 // depending on the configuration
1482 const char* HLTOUTComponentId="HLTOUT";
1483 if (!fUseHLTOUTComponentTypeGlobal) {
1484 // choose the type of output depending on the availability of
1486 if (rawReader) HLTOUTComponentId="HLTOUTraw";
1487 else HLTOUTComponentId="HLTOUTdigits";
1489 AliHLTConfiguration globalout("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
1490 iResult=BuildTaskList("_globalout_");
1492 HLTError("can not load libHLTsim.so and HLTOUT component");
1498 // build HLTOUT task for reconstruction
1499 // Matthias 08.07.2008 the rawReader is never set when running embedded into
1500 // AliReconstruction. The system is configured during AliHLTReconstructor::Init
1501 // where the RawReader is not available. It is available in the first invocation
1504 // That means that policy is slightly changed:
1505 // - if the run loader is available -> AliSimulation
1506 // - no run loader available -> AliReconstruction
1507 if (iResult>=0 && !runloader) {
1509 // there are components in the chain which produce data which need to be
1510 // piped to an HLTOUT sub-collection
1511 if (!fpHLTOUTTask) {
1512 iResult=AddHLTOUTTask(chains.Data());
1517 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1522 int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
1524 // see header file for class documentation
1526 if (!hltoutchains || hltoutchains[0]==0) return 0;
1528 // check chains for output
1529 TString chains=hltoutchains;
1530 TObjArray* pTokens=chains.Tokenize(" ");
1532 int iEntries=pTokens->GetEntriesFast();
1533 for (int i=0; i<iEntries && iResult>=0; i++) {
1534 const char* token=((TObjString*)pTokens->At(i))->GetString().Data();
1535 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
1537 TString cid=pConf->GetComponentID();
1538 if (fpComponentHandler->HasOutputData(cid.Data())) {
1542 HLTWarning("can not find configuration %s", token);
1544 // remove from the list of hltout chains
1545 chains.ReplaceAll(token, "");
1550 // do not create the HLTOUT task if none of the chains have output
1551 if (chains.IsNull()) return 0;
1553 // indicate the task to be available
1557 if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) {
1558 HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask);
1560 HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains \"%s\"",
1561 fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data());
1566 fpHLTOUTTask=new AliHLTOUTTask(chains);
1568 if (fpHLTOUTTask->GetConf() &&
1569 (fpHLTOUTTask->GetConf()->SourcesResolved()>0 ||
1570 fpHLTOUTTask->GetConf()->ExtractSources()>0)) {
1571 iResult=InsertTask(fpHLTOUTTask);
1573 HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
1578 delete fpHLTOUTTask;
1587 int AliHLTSystem::CheckStatus(int flag)
1589 // see header file for class documentation
1590 if (flag==kUninitialized && flag==fState) return 1;
1591 if ((fState&flag)==flag) return 1;
1595 int AliHLTSystem::GetStatusFlags()
1597 // see header file for class documentation
1601 int AliHLTSystem::SetStatusFlags(int flags)
1603 // see header file for class documentation
1608 int AliHLTSystem::ClearStatusFlags(int flags)
1610 // see header file for class documentation
1615 AliHLTfctVoid AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1617 // see header file for class documentation
1618 if (fpComponentHandler==NULL) return NULL;
1619 return fpComponentHandler->FindSymbol(library, symbol);
1622 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1624 // see header file for class documentation
1625 SetLocalLoggingLevel(level);
1626 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1627 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
1630 int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity,
1631 const char* originClass, const char* originFunc,
1632 const char* file, int line, ... ) const
1634 // see header file for function documentation
1638 va_start(args, line);
1640 if (!fName.IsNull())
1641 AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", fName.Data());
1642 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() /*append if non empty*/));
1648 int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
1650 // Init the HLTOUT instance for the current event.
1651 // The instance can be used by other classes to get hold on the data
1653 if (!instance) return -EINVAL;
1654 if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
1659 int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
1661 // Clear the HLTOUT instance.
1664 HLTWarning("HLTOUT instance still in use, potential problem due to invalid pointer ahead");
1668 if (target) *target=fpHLTOUT;
1673 AliHLTOUT* AliHLTSystem::RequestHLTOUT()
1675 // Get the HLTOUT instance.
1676 // User method for processing classes. To be released after use.
1677 if (!fpHLTOUT) return NULL;
1682 int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
1684 // Release the HLTOUT instance after use.
1685 if (!instance) return -EINVAL;
1686 if (instance!=fpHLTOUT) return -ENOENT;