2 //**************************************************************************
3 //* This file is property of and copyright by the *
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.
25 #include "AliHLTStdIncludes.h"
26 #include "AliHLTSystem.h"
27 #include "AliHLTComponentHandler.h"
28 #include "AliHLTComponent.h"
29 #include "AliHLTConfiguration.h"
30 #include "AliHLTConfigurationHandler.h"
31 #include "AliHLTOnlineConfiguration.h"
32 #include "AliHLTTask.h"
33 #include "AliHLTModuleAgent.h"
34 #include "AliHLTOfflineInterface.h"
35 #include "AliHLTDataSource.h"
36 #include "AliHLTOUT.h"
37 #include "AliHLTOUTHandler.h"
38 #include "AliHLTOUTTask.h"
39 #include "AliHLTControlTask.h"
40 #include "AliHLTDataBuffer.h"
41 #include "AliHLTMisc.h"
42 #include <TObjArray.h>
43 #include <TObjString.h>
44 #include <TStopwatch.h>
46 //#include <TSystem.h>
48 //#include <TInterpreter.h>
50 /** HLT default component libraries */
51 const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
55 // "libAliHLTSample.so",
65 "libAliHLTTrigger.so",
69 /** ROOT macro for the implementation of ROOT specific class methods */
70 ClassImp(AliHLTSystem)
72 AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name,
73 AliHLTComponentHandler* pCompHandler,
74 AliHLTConfigurationHandler* pConfHandler
76 : fpComponentHandler(pCompHandler==NULL?AliHLTComponentHandler::CreateHandler():pCompHandler)
77 , fpConfigurationHandler(pConfHandler==NULL?AliHLTConfigurationHandler::CreateHandler():pConfHandler),
81 fStopwatches(new TObjArray),
84 fpChainHandlers(NULL),
86 fpProprietaryHandlers(NULL),
93 , fUseHLTOUTComponentTypeGlobal(true)
96 // see header file for class documentation
98 // refer to README to build package
100 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
102 if (fgNofInstances++>0) {
103 // July 2008: multiple instances are now allowed
104 // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
105 //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
107 SetGlobalLoggingLevel(loglevel);
108 SetFrameworkLog(loglevel);
109 if (fpComponentHandler) {
110 AliHLTAnalysisEnvironment env;
111 memset(&env, 0, sizeof(AliHLTAnalysisEnvironment));
112 env.fStructSize=sizeof(AliHLTAnalysisEnvironment);
113 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
114 env.fGetEventDoneDataFunc=AliHLTSystem::AllocEventDoneData;
115 env.fLoggingFunc=NULL;
116 fpComponentHandler->SetEnvironment(&env);
117 InitAliLogFunc(fpComponentHandler);
118 if (fgNofInstances==1) {
119 fpComponentHandler->AnnounceVersion();
122 HLTFatal("can not create Component Handler");
124 if (fpConfigurationHandler==NULL) {
125 HLTFatal("can not create Configuration Handler");
129 AliHLTSystem::~AliHLTSystem()
131 // see header file for class documentation
133 CleanupHLTOUTHandlers();
135 if (fpConfigurationHandler) {
136 fpConfigurationHandler->Destroy();
138 fpConfigurationHandler=NULL;
140 if (fpComponentHandler) {
141 fpComponentHandler->Destroy();
143 fpComponentHandler=NULL;
146 // note: fpHLTOUTTask and fpControlTask are deleted by
150 int AliHLTSystem::fgNofInstances=0;
152 int AliHLTSystem::BuildTaskList(const char* id)
154 // see header file for class documentation
157 if (fpConfigurationHandler) {
158 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
160 iResult=BuildTaskList(pConf);
162 HLTError("unknown configuration \"%s\"", id);
174 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
176 // see header file for class documentation
179 AliHLTTask* pTask=NULL;
180 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
181 if (pTask->GetConf()!=pConf) {
182 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);
185 // task for this configuration exists, terminate
187 // check first if the configuration has all sources resolved, try to extract otherwise
188 } else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources(fpConfigurationHandler)!=1) {
189 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
192 pTask=new AliHLTTask(pConf);
196 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
199 static int iterationLevel=0;
200 if (pTask && iResult>=0) {
201 // check for circular dependencies
202 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
203 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
204 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
205 HLTError("aborted ...");
209 // check whether all dependencies are already in the task list
210 // create the missing ones
211 // this step is an iterative process which calls this function again for the missing
212 // configurations, in order to avoid the currently processed task to be created
213 // again it is added to the list temporarily and removed afterwards
214 // This is of high importance to preserve the order of the tasks. Furthermore, the
215 // InsertTask method has to be used in order to set all the cross links right
216 fTaskList.Add(pTask);
217 AliHLTConfiguration* pDep=pConf->GetFirstSource();
218 while (pDep!=NULL && iResult>=0) {
219 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
220 if (FindTask(pDep->GetName())==NULL) {
221 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
223 iResult=BuildTaskList(pDep);
226 pDep=pConf->GetNextSource();
228 // remove the temporarily added task
229 fTaskList.Remove(pTask);
231 // insert the task and set the cross-links
233 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
234 iResult=InsertTask(pTask);
247 int AliHLTSystem::CleanTaskList()
249 // see header file for class documentation
254 while ((lnk=fTaskList.LastLink())!=NULL) {
255 delete (lnk->GetObject());
256 fTaskList.Remove(lnk);
262 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
264 // see header file for class documentation
266 if (fpControlTask==NULL) {
267 fpControlTask=new AliHLTControlTask;
268 if (!fpControlTask) return -ENOMEM;
269 fTaskList.AddFirst(fpControlTask);
271 TObjLink *controlLnk=NULL;
272 TObjLink *lnk = fTaskList.FirstLink();
273 assert(!lnk || lnk->GetObject()==fpControlTask || fpControlTask==NULL);
274 if (lnk && lnk->GetObject()==fpControlTask) {
275 if (pTask->GetConf() && pTask->GetConf()->GetFirstSource()==NULL) {
276 pTask->SetDependency(fpControlTask);
277 fpControlTask->SetTarget(pTask);
282 if ((iResult=pTask->CheckDependencies())<=0)
284 while (lnk && iResult>0) {
285 AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
286 //HLTDebug("checking \"%s\"", pCurr->GetName());
287 iResult=pTask->Depends(pCurr);
289 iResult=pTask->SetDependency(pCurr);
290 pCurr->SetTarget(pTask);
291 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
293 if (pCurr->Depends(pTask)) {
294 // circular dependency
295 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
297 } else if ((iResult=pTask->CheckDependencies())>0) {
303 fTaskList.AddAfter(lnk, pTask);
304 } else if (controlLnk) {
305 fTaskList.AddAfter(controlLnk, pTask);
307 fTaskList.AddFirst(pTask);
309 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
310 } else if (iResult>0) {
311 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
317 AliHLTTask* AliHLTSystem::FindTask(const char* id)
319 // see header file for class documentation
320 AliHLTTask* pTask=NULL;
322 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
327 void AliHLTSystem::PrintTaskList()
329 // see header file for class documentation
330 HLTLogKeyword("task list");
331 TObjLink *lnk = NULL;
332 HLTMessage("Task List");
333 lnk=fTaskList.FirstLink();
335 TObject* obj=lnk->GetObject();
337 HLTMessage(" %s - status:", obj->GetName());
338 AliHLTTask* pTask=(AliHLTTask*)obj;
339 pTask->PrintStatus();
346 int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
347 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
348 AliHLTUInt32_t participatingDetectors)
350 return Run(iNofEvents, bStop, AliHLTTriggerMask_t(trgMask),
351 timestamp, eventtype, participatingDetectors);
354 int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTTriggerMask_t trgMask,
355 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
356 AliHLTUInt32_t participatingDetectors)
358 // see header file for class documentation
361 SetStatusFlags(kRunning);
362 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
363 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
364 if (fEventCount==0) {
365 InitBenchmarking(fStopwatches);
367 // Matthias Oct 11 2008 this is a bug
368 // By resuming the stopwatches at this point, all continued counting, but the
369 // starting and stopping is controlled by the AliHLTStopwatchGuard
370 //ResumeBenchmarking(fStopwatches);
372 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
374 if (iNofEvents>1 && i==fEventCount) {
375 HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block");
377 // reset and prepare for new data
378 fpHLTOUTTask->Reset();
380 if (eventtype == 0) {
381 eventtype = gkAliEventTypeData;
382 participatingDetectors = 0x0;
384 if ((iResult=ProcessTasks(i, trgMask, timestamp, eventtype, participatingDetectors))>=0) {
388 // TODO: define different running modes to either ignore errors in
389 // event processing or not
393 AliHLTDataBuffer::SetGlobalEventCount(iCount);
395 fEventCount+=iNofEvents;
396 if (bStop) StopTasks();
397 else PauseBenchmarking(fStopwatches);
399 if (bStop) DeinitTasks();
403 } else if (iResult==-126 /*ENOKEY*/) {
404 iResult=0; // do not propagate the error
406 ClearStatusFlags(kRunning);
407 AliHLTDataBuffer::PrintStatistics();
411 int AliHLTSystem::InitTasks()
413 // see header file for class documentation
415 TObjLink *lnk=fTaskList.FirstLink();
418 HLTInfo("Task list is empty, skipping HLT");
419 return -126 /*ENOKEY*/;
421 while (lnk && iResult>=0) {
422 TObject* obj=lnk->GetObject();
424 AliHLTTask* pTask=(AliHLTTask*)obj;
425 iResult=pTask->Init(NULL, fpComponentHandler);
426 // ProcInfo_t ProcInfo;
427 // gSystem->GetProcInfo(&ProcInfo);
428 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
434 HLTError("can not initialize task list, error %d", iResult);
440 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
442 // see header file for class documentation
444 if (pStopwatches==NULL) return 0;
446 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
447 TStopwatch* pStopwatch= new TStopwatch;
450 pStopwatches->AddAt(pStopwatch, i);
457 TObjLink *lnk=fTaskList.FirstLink();
458 while (lnk && iResult>=0) {
459 TObject* obj=lnk->GetObject();
461 AliHLTTask* pTask=(AliHLTTask*)obj;
462 AliHLTComponent* pComp=NULL;
463 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
464 switch (pComp->GetComponentType()) {
465 case AliHLTComponent::kProcessor:
466 pComp->SetStopwatches(pStopwatches);
468 case AliHLTComponent::kSource:
470 // this switch determines whether the time consumption of the
471 // AliHLTComponent base methods should be counted to the input
472 // stopwatch or base stopwatch.
473 //int inputBase=(int)AliHLTComponent::kSWBase;
474 int inputBase=(int)AliHLTComponent::kSWInput;
475 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
476 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
479 case AliHLTComponent::kSink:
481 // this switch determines whether the time consumption of the
482 // AliHLTComponent base methods should be counted to the output
483 // stopwatch or base stopwatch.
484 //int outputBase=(int)AliHLTComponent::kSWBase;
485 int outputBase=(int)AliHLTComponent::kSWOutput;
486 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
487 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
491 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
501 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
503 // see header file for class documentation
504 if (pStopwatches==NULL) return 0;
506 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
507 if (!pStopwatches->At(i)) continue;
508 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
509 if (pSw) pSw->Stop();
514 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
516 // see header file for class documentation
517 if (pStopwatches==NULL) return 0;
519 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
520 if (!pStopwatches->At(i)) continue;
521 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
522 if (pSw) pSw->Continue();
527 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
529 // see header file for class documentation
531 if (pStopwatches==NULL) return 0;
533 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
534 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
540 if (iInitialized!=0) {
541 HLTImportant("HLT statistics:\n"
542 " base: R:%.3fs C:%.3fs\n"
543 " input: R:%.3fs C:%.3fs\n"
544 " output: R:%.3fs C:%.3fs\n"
545 " event processing : R:%.3fs C:%.3fs"
546 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
547 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
548 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
549 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
550 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
551 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
552 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
553 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
558 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
559 TObject* pObj=pStopwatches->RemoveAt(i);
560 if (pObj) delete pObj;
566 int AliHLTSystem::StartTasks()
568 // see header file for class documentation
570 TObjLink *lnk=fTaskList.FirstLink();
571 while (lnk && iResult>=0) {
572 TObject* obj=lnk->GetObject();
574 AliHLTTask* pTask=(AliHLTTask*)obj;
575 iResult=pTask->StartRun();
576 // ProcInfo_t ProcInfo;
577 // gSystem->GetProcInfo(&ProcInfo);
578 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
584 HLTError("can not start task list, error %d", iResult);
586 SetStatusFlags(kStarted);
589 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
590 HLTError("can not send SOR event: error %d", iResult);
596 int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTTriggerMask_t trgMask,
597 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
598 AliHLTUInt32_t participatingDetectors)
600 // see header file for class documentation
602 HLTDebug("processing event no %d", eventNo);
603 TObjLink *lnk=fTaskList.FirstLink();
605 TObject* obj=lnk->GetObject();
607 AliHLTTask* pTask=(AliHLTTask*)obj;
609 iResult=pTask->ProcessTask(eventNo, eventtype, trgMask, timestamp, participatingDetectors);
610 // ProcInfo_t ProcInfo;
611 // gSystem->GetProcInfo(&ProcInfo);
612 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
614 pTask->SubscribeSourcesAndSkip();
622 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
625 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
631 int AliHLTSystem::StopTasks()
633 // see header file for class documentation
635 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
636 HLTError("can not send EOR event");
639 // cleanup blocks from the last event. This is a bit awkward. All output
640 // blocks from the chains need to be stored in the HLTOUT task. Though,
641 // we do not know, whether HLTOUT is going to be processed or not.
643 fpHLTOUTTask->Reset();
645 TObjLink *lnk=fTaskList.FirstLink();
647 TObject* obj=lnk->GetObject();
649 AliHLTTask* pTask=(AliHLTTask*)obj;
650 int locResult=pTask->EndRun();
651 if (iResult>=0 && locResult<0) iResult=locResult;
652 // ProcInfo_t ProcInfo;
653 // gSystem->GetProcInfo(&ProcInfo);
654 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
659 PrintBenchmarking(fStopwatches, 1 /*clean*/);
660 if (fEventCount!=fGoodEvents) {
661 HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
663 ClearStatusFlags(kStarted);
667 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
669 // see header file for class documentation
672 AliHLTComponentBlockDataList controlBlocks;
673 AliHLTComponentBlockData bd;
675 // run decriptor block of type kAliHLTDataTypeSOR/kAliHLTDataTypeEOR
676 AliHLTComponent::FillBlockData(bd);
677 AliHLTRunDesc runDesc;
678 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
679 runDesc.fStructSize=sizeof(AliHLTRunDesc);
680 runDesc.fRunNo=AliHLTMisc::Instance().GetCDBRunNo();
682 bd.fSize=sizeof(AliHLTRunDesc);
684 bd.fSpecification=kAliHLTVoidDataSpec;
685 controlBlocks.push_back(bd);
687 // ECS parameter of type kAliHLTDataTypeECSParam
688 if (fECSParams.IsNull())
689 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";
690 AliHLTComponent::FillBlockData(bd);
691 bd.fPtr=(void*)fECSParams.Data();
692 bd.fSize=fECSParams.Length()+1;
693 bd.fDataType=kAliHLTDataTypeECSParam;
694 bd.fSpecification=kAliHLTVoidDataSpec;
695 controlBlocks.push_back(bd);
697 AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
698 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
699 TObjLink *lnk=fTaskList.FirstLink();
700 while (lnk && iResult>=0) {
701 TObject* obj=lnk->GetObject();
703 AliHLTTask* pTask=(AliHLTTask*)obj;
704 AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
705 if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
706 else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
707 else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
708 iResult=pTask->ProcessTask(-1, eventType, 0, 0);
714 // control events are not supposed to go into the HLTOUT
716 fpHLTOUTTask->Reset();
718 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
722 int AliHLTSystem::DeinitTasks()
724 // see header file for class documentation
726 TObjLink *lnk=fTaskList.LastLink();
728 TObject* obj=lnk->GetObject();
730 AliHLTTask* pTask=(AliHLTTask*)obj;
731 int localRes=pTask->Deinit();
732 if (iResult>=0) iResult=localRes;
733 // ProcInfo_t ProcInfo;
734 // gSystem->GetProcInfo(&ProcInfo);
735 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
746 int AliHLTSystem::CleanupHLTOUTHandlers()
748 // see header file for class documentation
749 if (fpChainHandlers) {
750 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
751 fpChainHandlers=NULL;
753 AliHLTOUT::InvalidateBlocks(*pHandlers);
754 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
756 assert(pHandlers->size()==0);
761 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
764 AliHLTOUT::InvalidateBlocks(*pHandlers);
765 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
767 assert(pHandlers->size()==0);
771 if (fpProprietaryHandlers) {
772 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
773 fpProprietaryHandlers=NULL;
775 AliHLTOUT::InvalidateBlocks(*pHandlers);
776 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
778 assert(pHandlers->size()==0);
784 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
786 // see header file for class documentation
789 p=(void*)new char[size];
793 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
798 int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd )
800 // see header file for class documentation
801 unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
802 void* block=AllocMemory(NULL, blocksize);
803 if (!block) return -ENOMEM;
804 memset(block, 0, blocksize);
805 *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
806 (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
807 (*edd)->fDataSize=size;
808 (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
813 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
814 AliRawReader* rawReader)
816 // see header file for class documentation
818 if (runLoader || rawReader || nofEvents==0) {
819 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
820 if (CheckStatus(kReady)) {
822 // special case to close the reconstruction
823 if (!CheckStatus(kError)) {
826 CleanupHLTOUTHandlers();
829 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
830 AliHLTTriggerMask_t trgMask=0x1;
831 AliHLTUInt32_t timestamp=kMaxUInt;
832 AliHLTUInt32_t eventtype=0;
833 if (runLoader==NULL) {
834 // this is a quick workaround for the case of simulation
835 // the trigger framework is still under development, secondly, AliHLTSimulation
836 // does not yet add the emulated ECS parameters, so no CTP trigger is known in the HLT
837 // AliHLTTask will initialize one dummy CTP trigger class with bit 0, that's why the
838 // default trigger mask is 0x1
839 trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
841 // get the timestamp and type of the event from the raw reader
842 // this is currently only meaningfull for reconstruction (runloader==NULL)
843 timestamp=AliHLTMisc::Instance().GetTimeStamp(rawReader);
844 eventtype=AliHLTMisc::Instance().GetEventType(rawReader);
846 // the system always remains started after event processing, a specific
847 // call with nofEvents==0 is needed to execute the stop sequence
848 if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
852 // add the current HLTOUT task to the collection
854 AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
855 if (pTask && (iResult=pTask->Init())>=0) {
856 if (pTask->GetNofDataBlocks()>0) {
857 AliHLTOUT* pHLTOUT=RequestHLTOUT();
859 pHLTOUT->AddSubCollection(pTask);
860 ReleaseHLTOUT(pHLTOUT);
862 HLTWarning("no HLTOUT instance available, output blocks of the chain are ignored");
866 HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
871 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
874 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
880 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
882 // see header file for class documentation
884 if (runLoader || esd) {
885 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
886 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
888 HLTError("missing run loader/ESD instance(s)");
894 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
896 // see header file for class documentation
898 if (!pHLTOUT) return -EINVAL;
899 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
902 // process all kChain handlers first
904 if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
905 HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
910 fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
911 if (!fpProprietaryHandlers)
912 fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
914 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
915 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
916 if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
918 // invalidate all blocks
919 AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
920 AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
922 AliHLTComponentDataTypeList esdBlocks;
924 for (iResult=pHLTOUT->SelectFirstDataBlock();
926 iResult=pHLTOUT->SelectNextDataBlock()) {
927 AliHLTComponentDataType dt=kAliHLTVoidDataType;
928 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
929 pHLTOUT->GetDataBlockDescription(dt, spec);
930 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
931 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
933 // default handling for ESD data blocks does not require an explicite handler
934 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
935 handlerType=AliHLTModuleAgent::kEsd;
937 const char* pMsg="invalid";
938 switch (handlerType) {
939 case AliHLTModuleAgent::kEsd:
942 // schedule for later processing
943 pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
945 AliHLTComponentDataTypeList::iterator element=esdBlocks.begin();
946 for (; element!=esdBlocks.end(); element++) {
948 HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str());
952 if (element==esdBlocks.end()) esdBlocks.push_back(dt);
955 const AliHLTUInt8_t* pBuffer=NULL;
956 AliHLTUInt32_t size=0;
957 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
958 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
959 pHLTOUT->ReleaseDataBuffer(pBuffer);
961 pHLTOUT->MarkDataBlockProcessed();
965 case AliHLTModuleAgent::kRawReader:
966 // handled in the AliRawReaderHLT
968 case AliHLTModuleAgent::kRawStream:
969 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
970 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
971 AliHLTComponent::DataType2Text(dt).c_str(), spec);
973 case AliHLTModuleAgent::kChain:
974 HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
975 "New block of this type added by the chain? Skipping data block ...",
976 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
977 AliHLTComponent::DataType2Text(dt).c_str(), spec);
979 case AliHLTModuleAgent::kProprietary:
980 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
981 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
982 AliHLTComponent::DataType2Text(dt).c_str(), spec);
984 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
985 int res=pHandler->ProcessData(pHLTOUT);
987 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
988 res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
989 AliHLTComponent::DataType2Text(dt).c_str(), spec);
993 case AliHLTModuleAgent::kUnknownOutput:
995 // fall trough intended
997 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
998 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
999 AliHLTComponent::DataType2Text(dt).c_str(), spec);
1002 // TODO: the return value of SelectFirst/NextDataBlock must be
1003 // changed in order to avoid this check
1004 if (iResult==-ENOENT) iResult=0;
1006 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
1008 // process and write all esd data blocks
1009 for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
1010 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1011 AliHLTOUTHandler* pHandler=*handler;
1012 const AliHLTUInt8_t* pBuffer=NULL;
1013 AliHLTUInt32_t size=0;
1014 pHandler->ProcessData(pHLTOUT);
1015 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1016 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
1017 AliHLTComponentDataType dt=desc;
1018 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
1019 pHandler->ReleaseProcessedData(pBuffer, size);
1021 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1024 // process all kProprietary data blocks
1025 for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) {
1026 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1027 AliHLTOUTHandler* pHandler=*handler;
1028 const AliHLTUInt8_t* pBuffer=NULL;
1029 AliHLTUInt32_t size=0;
1030 pHandler->ProcessData(pHLTOUT);
1031 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1032 HLTWarning("data produced by kProprietary handler ignored");
1033 pHandler->ReleaseProcessedData(pBuffer, size);
1035 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1038 // remove all empty handlers form the list (handlers which did not get a block this time)
1039 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
1040 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
1045 int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
1047 // see header file for class documentation
1049 if (!pHLTOUT) return -EINVAL;
1051 if (!fpChainHandlers)
1052 fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
1054 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
1055 if (!pChainHandlers) return -ENOMEM;
1057 // invalidate all blocks
1058 AliHLTOUT::InvalidateBlocks(*pChainHandlers);
1061 pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
1063 // process all defined chain handlers
1064 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
1065 for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
1066 if (chainHandler->IsEmpty()) continue;
1067 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
1068 AliHLTOUTHandler* pHandler=*chainHandler;
1069 const AliHLTUInt8_t* pBuffer=NULL;
1070 AliHLTUInt32_t size=0;
1071 pHandler->ProcessData(pHLTOUT);
1072 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1073 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
1074 //AliHLTComponentDataType dt=desc;
1076 pHandler->ReleaseProcessedData(pBuffer, size);
1078 pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
1081 // remove all empty handlers form the list (handlers which did not get a block this time)
1082 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
1087 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
1089 // see header file for class documentation
1092 if (fpComponentHandler) {
1093 TString libs(libraries);
1094 TObjArray* pTokens=libs.Tokenize(" ");
1096 int iEntries=pTokens->GetEntriesFast();
1097 for (int i=0; i<iEntries && iResult>=0; i++) {
1098 if (!pTokens->At(i)) continue;
1099 iResult=fpComponentHandler->LoadLibrary(pTokens->At(i)->GetName());
1104 SetStatusFlags(kLibrariesLoaded);
1106 // lets see if we need this, probably not
1107 //fpComponentHandler->UnloadLibraries();
1108 ClearStatusFlags(kLibrariesLoaded);
1112 HLTFatal("no component handler available");
1120 int AliHLTSystem::Configure(AliRunLoader* runloader)
1122 // see header file for class documentation
1123 return Configure(NULL, runloader);
1126 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
1128 // see header file for class documentation
1130 if (CheckStatus(kRunning)) {
1131 HLTError("HLT system in running state, can not configure");
1134 ClearStatusFlags(kTaskListCreated);
1135 if (CheckFilter(kHLTLogDebug))
1136 AliHLTModuleAgent::PrintStatus();
1137 if (CheckStatus(kConfigurationLoaded)==0) {
1138 iResult=LoadConfigurations(rawReader, runloader);
1140 if (fChains.Length()==0) {
1141 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
1146 SetStatusFlags(kConfigurationLoaded);
1147 if (CheckFilter(kHLTLogDebug))
1148 fpConfigurationHandler->PrintConfigurations();
1149 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
1151 SetStatusFlags(kTaskListCreated);
1154 if (iResult<0) SetStatusFlags(kError);
1159 int AliHLTSystem::ScanOptions(const char* options)
1161 // see header file for class documentation
1164 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
1166 TString excludelibs("");
1167 TString alloptions(options);
1168 TObjArray* pTokens=alloptions.Tokenize(" ");
1170 int iEntries=pTokens->GetEntriesFast();
1171 for (int i=0; i<iEntries; i++) {
1172 if (!pTokens->At(i)) continue;
1173 TString token=pTokens->At(i)->GetName();
1174 if (token.Contains("loglevel=")) {
1175 TString param=token.ReplaceAll("loglevel=", "");
1176 if (param.IsDigit()) {
1177 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
1178 } else if (param.BeginsWith("0x") &&
1179 param.Replace(0,2,"",0).IsHex()) {
1181 sscanf(param.Data(),"%x", &severity);
1182 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
1184 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1186 } else if (token.Contains("frameworklog=")) {
1187 TString param=token.ReplaceAll("frameworklog=", "");
1188 if (param.IsDigit()) {
1189 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
1190 } else if (param.BeginsWith("0x") &&
1191 param.Replace(0,2,"",0).IsHex()) {
1193 sscanf(param.Data(),"%x", &severity);
1194 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
1196 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1198 } else if (token.Contains("alilog=off")) {
1200 } else if (token.Contains("config=") || token.Contains("run-online-config")) {
1201 if (!CheckStatus(kConfigurationLoaded)) {
1203 AliHLTOnlineConfiguration* pConf = NULL;
1204 if (token.Contains("run-online-config")) {
1205 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry("HLT/Calib/OnlineConfig");
1207 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
1208 if (pObject && pObject->IsA() == AliHLTOnlineConfiguration::Class())
1209 pConf = (AliHLTOnlineConfiguration*)pObject;
1212 if (token.Contains("config=")) {
1213 TString param=token.ReplaceAll("config=", "");
1214 if (token.EndsWith(".xml", TString::kIgnoreCase)) {
1216 pConf = new AliHLTOnlineConfiguration;
1217 filesize = pConf->LoadConfiguration(param.Data());
1218 if (filesize <= 0) {
1219 HLTError("cannot load config \'%s\'", param.Data());
1223 gROOT->Macro(param.Data(), &error);
1225 SetStatusFlags(kConfigurationLoaded);
1227 HLTError("cannot execute macro \'%s\'", param.Data());
1233 error = pConf->Parse();
1235 fChains = pConf->GetDefaultChains();
1236 libs = pConf->GetComponentLibraries();
1238 SetStatusFlags(kConfigurationLoaded);
1240 HLTError("cannot parse online configuration");
1244 delete pConf; pConf=NULL;
1246 HLTWarning("HLT options has both a config file and run-online-config set");
1248 } else if (token.Contains("chains=")) {
1249 TString param=token.ReplaceAll("chains=", "");
1250 fChains=param.ReplaceAll(",", " ");
1251 if (fChains.IsNull()) fChains=" "; // disable all chains
1252 } else if (token.Contains("libmode=")) {
1253 TString param=token.ReplaceAll("libmode=", "");
1254 param.ReplaceAll(",", " ");
1255 if (fpComponentHandler) {
1256 if (param.CompareTo("static")==0) {
1257 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
1258 } else if (param.CompareTo("dynamic")==0) {
1259 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
1261 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
1264 } else if (token.BeginsWith("ECS=")) {
1265 fECSParams=token.ReplaceAll("ECS=", "");
1266 } else if (token.BeginsWith("hltout-mode=")) {
1267 // The actual parameter for argument 'hltout-mode' is treated in AliSimulation.
1268 // For AliHLTSystem the occurrence with parameter 'split' signals the use of the
1269 // separated HLTOUTComponents for digit and raw data. All others indicate
1270 // HLTOUTComponent type 'global' where the data generation is steered from global
1272 fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")!=0;
1273 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1276 } else if (token.BeginsWith("!lib") && token.EndsWith(".so")) {
1280 HLTWarning("unknown option \'%s\'", token.Data());
1287 if (libs.IsNull()) {
1288 const char** deflib=fgkHLTDefaultLibs;
1289 for (;*deflib; deflib++) {
1290 if (excludelibs.Contains(*deflib)) continue;
1295 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
1296 (LoadComponentLibraries(libs.Data())<0)) {
1297 HLTError("error while loading HLT libraries");
1305 int AliHLTSystem::Reset(int bForce)
1307 // see header file for class documentation
1309 if (!bForce && CheckStatus(kRunning)) {
1310 HLTError("HLT system in running state, can not configure");
1314 ClearStatusFlags(~kUninitialized);
1318 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1320 // see header file for class documentation
1321 if (CheckStatus(kRunning)) {
1322 HLTError("HLT system in running state, can not configure");
1326 AliHLTModuleAgent* pAgent=NULL;
1328 // first check for the required libraries and load those
1330 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1331 pAgent && iResult>=0;
1332 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1333 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1335 HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1341 iResult=LoadComponentLibraries(extralibs.Data());
1344 // in order to register the configurations in the correct sequence
1345 // all agents need to be ordered with respect to the required
1346 // libraries. Ordering relies on the naming convention
1347 // libAliHLT<Module>.so
1349 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1350 pAgent && iResult>=0;
1351 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1352 AliHLTModuleAgent* pPrevDep=NULL;
1353 TString dependencies=pAgent->GetRequiredComponentLibraries();
1354 TObjArray* pTokens=dependencies.Tokenize(" ");
1356 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
1357 if (!pTokens->At(n)) continue;
1358 TString module=pTokens->At(n)->GetName();
1359 HLTDebug(" checking %s", module.Data());
1360 module.ReplaceAll("libAliHLT", "");
1361 module.ReplaceAll(".so", "");
1363 for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep));
1364 pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) {
1365 HLTDebug(" checking %s == %s", module.Data(), pCurrent->GetModuleId());
1367 if (module.CompareTo(pCurrent->GetModuleId())==0) {
1377 // insert right after the last dependency
1378 agents.AddAfter(pPrevDep, pAgent);
1379 HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
1381 // insert at the beginning
1382 agents.AddFirst(pAgent);
1383 HLTDebug("insert %s at beginning", pAgent->GetModuleId());
1387 // now we load the configurations
1388 if (agents.GetEntries()) {
1389 TIter next(&agents);
1390 while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
1391 if(fDetMask && !(fDetMask & pAgent->GetDetectorMask())) {
1392 HLTInfo("Skipping %s due to active detector mask.", pAgent->GetName());
1394 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1395 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1403 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1405 // see header file for class documentation
1406 if (CheckStatus(kRunning)) {
1407 HLTError("HLT system in running state, can not configure");
1410 if (!CheckStatus(kConfigurationLoaded)) {
1411 HLTWarning("configurations not yet loaded");
1415 if (!fpConfigurationHandler || !fpComponentHandler) return -EFAULT;
1422 if (fChains.Length()>0) {
1424 HLTImportant("custom reconstruction chain: %s", chains.Data());
1426 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1427 pAgent && iResult>=0;
1428 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1429 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1431 if (!chains.IsNull()) chains+=" ";
1432 chains+=agentchains;
1433 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1438 // build task list for chains
1439 TObjArray* pTokens=chains.Tokenize(" ");
1441 int iEntries=pTokens->GetEntriesFast();
1442 for (int i=0; i<iEntries && iResult>=0; i++) {
1443 if (!pTokens->At(i)) continue;
1444 const char* pCID=pTokens->At(i)->GetName();
1445 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1447 iResult=BuildTaskList(pConf);
1448 if (true) { // condition was deprecated but kept for sake of svn diff
1449 // bHaveOutput variable has to be set for both running modes
1450 // AliHLTSimulation and AliHLTReconstruction
1451 TString cid=pConf->GetComponentID();
1452 if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
1453 // remove from the input of a global HLTOUT configuration
1454 chains.ReplaceAll(pCID, "");
1455 } else if (bHaveOutput==0) {
1456 // check whether this configuration produces data output
1457 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1459 chains.ReplaceAll(pCID, "");
1464 HLTWarning("can not find configuration %s", pCID);
1470 // build HLTOUT for simulation
1471 if (iResult>=0 && runloader) {
1473 // there are components in the chain which produce data which need to be
1474 // piped to an HLTOUT
1476 // add the SchemaEvolutionComponent which analyzes the ROOT objects in
1477 // the output stream
1478 if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
1479 fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
1480 fpConfigurationHandler->CreateConfiguration("_schemaevolution_", "ROOTSchemaEvolutionComponent",
1481 chains.Data(), "-file=HLT.StreamerInfo.root");
1482 iResult=BuildTaskList("_schemaevolution_");
1484 HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
1487 // add the HLTOUT component
1488 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1489 fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
1490 // for the default HLTOUTComponent type 'global' the data generation is steered
1491 // by global flags from AliSimulation. This allows for emulation of the old
1492 // AliHLTSimulation behavior where only one chain is run on either digits or
1493 // simulated raw data and the HLT digits and raw files have been generated
1494 // depending on the configuration
1495 const char* HLTOUTComponentId="HLTOUT";
1496 if (!fUseHLTOUTComponentTypeGlobal) {
1497 // choose the type of output depending on the availability of
1499 if (rawReader) HLTOUTComponentId="HLTOUTraw";
1500 else HLTOUTComponentId="HLTOUTdigits";
1502 fpConfigurationHandler->CreateConfiguration("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
1503 iResult=BuildTaskList("_globalout_");
1505 HLTError("can not load libHLTsim.so and HLTOUT component");
1511 // build HLTOUT task for reconstruction
1512 // Matthias 08.07.2008 the rawReader is never set when running embedded into
1513 // AliReconstruction. The system is configured during AliHLTReconstructor::Init
1514 // where the RawReader is not available. It is available in the first invocation
1517 // That means that policy is slightly changed:
1518 // - if the run loader is available -> AliSimulation
1519 // - no run loader available -> AliReconstruction
1520 if (iResult>=0 && !runloader) {
1522 // there are components in the chain which produce data which need to be
1523 // piped to an HLTOUT sub-collection
1524 if (!fpHLTOUTTask) {
1525 iResult=AddHLTOUTTask(chains.Data());
1530 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1535 int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
1537 // see header file for class documentation
1539 if (!hltoutchains || hltoutchains[0]==0) return 0;
1541 // check chains for output
1542 TString chains=hltoutchains;
1543 TObjArray* pTokens=chains.Tokenize(" ");
1545 int iEntries=pTokens->GetEntriesFast();
1546 for (int i=0; i<iEntries && iResult>=0; i++) {
1547 if (!pTokens->At(i)) continue;
1548 const char* token=pTokens->At(i)->GetName();
1549 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
1551 TString cid=pConf->GetComponentID();
1552 if (fpComponentHandler->HasOutputData(cid.Data())) {
1556 HLTWarning("can not find configuration %s", token);
1558 // remove from the list of hltout chains
1559 chains.ReplaceAll(token, "");
1564 // do not create the HLTOUT task if none of the chains have output
1565 if (chains.IsNull()) return 0;
1567 // indicate the task to be available
1571 if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) {
1572 HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask);
1574 HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains \"%s\"",
1575 fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data());
1580 fpHLTOUTTask=new AliHLTOUTTask(chains);
1582 if (fpHLTOUTTask->GetConf() &&
1583 (fpHLTOUTTask->GetConf()->SourcesResolved()>0 ||
1584 fpHLTOUTTask->GetConf()->ExtractSources(fpConfigurationHandler)>0)) {
1585 iResult=InsertTask(fpHLTOUTTask);
1587 HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
1592 delete fpHLTOUTTask;
1601 int AliHLTSystem::CheckStatus(int flag)
1603 // see header file for class documentation
1604 if (flag==kUninitialized && flag==fState) return 1;
1605 if ((fState&flag)==flag) return 1;
1609 int AliHLTSystem::GetStatusFlags()
1611 // see header file for class documentation
1615 int AliHLTSystem::SetStatusFlags(int flags)
1617 // see header file for class documentation
1622 int AliHLTSystem::ClearStatusFlags(int flags)
1624 // see header file for class documentation
1629 AliHLTfctVoid AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1631 // see header file for class documentation
1632 if (fpComponentHandler==NULL) return NULL;
1633 return fpComponentHandler->FindSymbol(library, symbol);
1636 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1638 // see header file for class documentation
1639 SetLocalLoggingLevel(level);
1640 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1641 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
1644 int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity,
1645 const char* originClass, const char* originFunc,
1646 const char* file, int line, ... ) const
1648 // see header file for function documentation
1652 va_start(args, line);
1654 if (!fName.IsNull())
1655 AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", fName.Data());
1656 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() /*append if non empty*/));
1662 int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
1664 // Init the HLTOUT instance for the current event.
1665 // The instance can be used by other classes to get hold on the data
1667 if (!instance) return -EINVAL;
1668 if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
1673 int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
1675 // Clear the HLTOUT instance.
1678 HLTWarning("HLTOUT instance still in use, potential problem due to invalid pointer ahead");
1682 if (target) *target=fpHLTOUT;
1687 AliHLTOUT* AliHLTSystem::RequestHLTOUT()
1689 // Get the HLTOUT instance.
1690 // User method for processing classes. To be released after use.
1691 if (!fpHLTOUT) return NULL;
1696 int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
1698 // Release the HLTOUT instance after use.
1699 if (!instance) return -EINVAL;
1700 if (instance!=fpHLTOUT) return -ENOENT;