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)
95 // see header file for class documentation
97 // refer to README to build package
99 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
101 if (fgNofInstances++>0) {
102 // July 2008: multiple instances are now allowed
103 // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
104 //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 // see header file for class documentation
353 SetStatusFlags(kRunning);
354 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
355 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
356 if (fEventCount==0) {
357 InitBenchmarking(fStopwatches);
359 // Matthias Oct 11 2008 this is a bug
360 // By resuming the stopwatches at this point, all continued counting, but the
361 // starting and stopping is controlled by the AliHLTStopwatchGuard
362 //ResumeBenchmarking(fStopwatches);
364 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
366 if (iNofEvents>1 && i==fEventCount) {
367 HLTWarning("can not add more than one event to the HLTOUT, skipping all but last block");
369 // reset and prepare for new data
370 fpHLTOUTTask->Reset();
372 if (eventtype == 0) {
373 eventtype = gkAliEventTypeData;
374 participatingDetectors = 0x0;
376 if ((iResult=ProcessTasks(i, trgMask, timestamp, eventtype, participatingDetectors))>=0) {
380 // TODO: define different running modes to either ignore errors in
381 // event processing or not
385 AliHLTDataBuffer::SetGlobalEventCount(iCount);
387 fEventCount+=iNofEvents;
388 if (bStop) StopTasks();
389 else PauseBenchmarking(fStopwatches);
391 if (bStop) DeinitTasks();
395 } else if (iResult==-126 /*ENOKEY*/) {
396 iResult=0; // do not propagate the error
398 ClearStatusFlags(kRunning);
399 AliHLTDataBuffer::PrintStatistics();
403 int AliHLTSystem::InitTasks()
405 // see header file for class documentation
407 TObjLink *lnk=fTaskList.FirstLink();
410 HLTInfo("Task list is empty, skipping HLT");
411 return -126 /*ENOKEY*/;
413 while (lnk && iResult>=0) {
414 TObject* obj=lnk->GetObject();
416 AliHLTTask* pTask=(AliHLTTask*)obj;
417 iResult=pTask->Init(NULL, fpComponentHandler);
418 // ProcInfo_t ProcInfo;
419 // gSystem->GetProcInfo(&ProcInfo);
420 // HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
426 HLTError("can not initialize task list, error %d", iResult);
432 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
434 // see header file for class documentation
436 if (pStopwatches==NULL) return 0;
438 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
439 TStopwatch* pStopwatch= new TStopwatch;
442 pStopwatches->AddAt(pStopwatch, i);
449 TObjLink *lnk=fTaskList.FirstLink();
450 while (lnk && iResult>=0) {
451 TObject* obj=lnk->GetObject();
453 AliHLTTask* pTask=(AliHLTTask*)obj;
454 AliHLTComponent* pComp=NULL;
455 if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
456 switch (pComp->GetComponentType()) {
457 case AliHLTComponent::kProcessor:
458 pComp->SetStopwatches(pStopwatches);
460 case AliHLTComponent::kSource:
462 // this switch determines whether the time consumption of the
463 // AliHLTComponent base methods should be counted to the input
464 // stopwatch or base stopwatch.
465 //int inputBase=(int)AliHLTComponent::kSWBase;
466 int inputBase=(int)AliHLTComponent::kSWInput;
467 pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
468 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
471 case AliHLTComponent::kSink:
473 // this switch determines whether the time consumption of the
474 // AliHLTComponent base methods should be counted to the output
475 // stopwatch or base stopwatch.
476 //int outputBase=(int)AliHLTComponent::kSWBase;
477 int outputBase=(int)AliHLTComponent::kSWOutput;
478 pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
479 pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
483 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
493 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
495 // see header file for class documentation
496 if (pStopwatches==NULL) return 0;
498 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
499 if (!pStopwatches->At(i)) continue;
500 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
501 if (pSw) pSw->Stop();
506 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
508 // see header file for class documentation
509 if (pStopwatches==NULL) return 0;
511 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
512 if (!pStopwatches->At(i)) continue;
513 TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
514 if (pSw) pSw->Continue();
519 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
521 // see header file for class documentation
523 if (pStopwatches==NULL) return 0;
525 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
526 if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
532 if (iInitialized!=0) {
533 HLTImportant("HLT statistics:\n"
534 " base: R:%.3fs C:%.3fs\n"
535 " input: R:%.3fs C:%.3fs\n"
536 " output: R:%.3fs C:%.3fs\n"
537 " event processing : R:%.3fs C:%.3fs"
538 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
539 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
540 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
541 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
542 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
543 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
544 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
545 , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
550 for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
551 TObject* pObj=pStopwatches->RemoveAt(i);
552 if (pObj) delete pObj;
558 int AliHLTSystem::StartTasks()
560 // see header file for class documentation
562 TObjLink *lnk=fTaskList.FirstLink();
563 while (lnk && iResult>=0) {
564 TObject* obj=lnk->GetObject();
566 AliHLTTask* pTask=(AliHLTTask*)obj;
567 iResult=pTask->StartRun();
568 // ProcInfo_t ProcInfo;
569 // gSystem->GetProcInfo(&ProcInfo);
570 // HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
576 HLTError("can not start task list, error %d", iResult);
578 SetStatusFlags(kStarted);
581 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
582 HLTError("can not send SOR event: error %d", iResult);
588 int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask,
589 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
590 AliHLTUInt32_t participatingDetectors)
592 // see header file for class documentation
594 HLTDebug("processing event no %d", eventNo);
595 TObjLink *lnk=fTaskList.FirstLink();
597 TObject* obj=lnk->GetObject();
599 AliHLTTask* pTask=(AliHLTTask*)obj;
601 iResult=pTask->ProcessTask(eventNo, eventtype, trgMask, timestamp, participatingDetectors);
602 // ProcInfo_t ProcInfo;
603 // gSystem->GetProcInfo(&ProcInfo);
604 // HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
606 pTask->SubscribeSourcesAndSkip();
614 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
617 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
623 int AliHLTSystem::StopTasks()
625 // see header file for class documentation
627 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
628 HLTError("can not send EOR event");
631 // cleanup blocks from the last event. This is a bit awkward. All output
632 // blocks from the chains need to be stored in the HLTOUT task. Though,
633 // we do not know, whether HLTOUT is going to be processed or not.
635 fpHLTOUTTask->Reset();
637 TObjLink *lnk=fTaskList.FirstLink();
639 TObject* obj=lnk->GetObject();
641 AliHLTTask* pTask=(AliHLTTask*)obj;
642 int locResult=pTask->EndRun();
643 if (iResult>=0 && locResult<0) iResult=locResult;
644 // ProcInfo_t ProcInfo;
645 // gSystem->GetProcInfo(&ProcInfo);
646 // HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
651 PrintBenchmarking(fStopwatches, 1 /*clean*/);
652 if (fEventCount!=fGoodEvents) {
653 HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
655 ClearStatusFlags(kStarted);
659 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
661 // see header file for class documentation
664 AliHLTComponentBlockDataList controlBlocks;
665 AliHLTComponentBlockData bd;
667 // run decriptor block of type kAliHLTDataTypeSOR/kAliHLTDataTypeEOR
668 AliHLTComponent::FillBlockData(bd);
669 AliHLTRunDesc runDesc;
670 memset(&runDesc, 0, sizeof(AliHLTRunDesc));
671 runDesc.fStructSize=sizeof(AliHLTRunDesc);
672 runDesc.fRunNo=AliHLTMisc::Instance().GetCDBRunNo();
674 bd.fSize=sizeof(AliHLTRunDesc);
676 bd.fSpecification=kAliHLTVoidDataSpec;
677 controlBlocks.push_back(bd);
679 // ECS parameter of type kAliHLTDataTypeECSParam
680 if (fECSParams.IsNull())
681 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";
682 AliHLTComponent::FillBlockData(bd);
683 bd.fPtr=(void*)fECSParams.Data();
684 bd.fSize=fECSParams.Length()+1;
685 bd.fDataType=kAliHLTDataTypeECSParam;
686 bd.fSpecification=kAliHLTVoidDataSpec;
687 controlBlocks.push_back(bd);
689 AliHLTControlTask::AliHLTControlEventGuard g(fpControlTask, controlBlocks);
690 HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
691 TObjLink *lnk=fTaskList.FirstLink();
692 while (lnk && iResult>=0) {
693 TObject* obj=lnk->GetObject();
695 AliHLTTask* pTask=(AliHLTTask*)obj;
696 AliHLTUInt32_t eventType=gkAliEventTypeUnknown;
697 if (dt==kAliHLTDataTypeSOR) eventType=gkAliEventTypeStartOfRun;
698 else if (dt==kAliHLTDataTypeEOR) eventType=gkAliEventTypeEndOfRun;
699 else HLTWarning("unknown control event %s", AliHLTComponent::DataType2Text(dt).c_str());
700 iResult=pTask->ProcessTask(-1, eventType, 0, 0);
706 // control events are not supposed to go into the HLTOUT
708 fpHLTOUTTask->Reset();
710 HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
714 int AliHLTSystem::DeinitTasks()
716 // see header file for class documentation
718 TObjLink *lnk=fTaskList.LastLink();
720 TObject* obj=lnk->GetObject();
722 AliHLTTask* pTask=(AliHLTTask*)obj;
723 int localRes=pTask->Deinit();
724 if (iResult>=0) iResult=localRes;
725 // ProcInfo_t ProcInfo;
726 // gSystem->GetProcInfo(&ProcInfo);
727 // HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
738 int AliHLTSystem::CleanupHLTOUTHandlers()
740 // see header file for class documentation
741 if (fpChainHandlers) {
742 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
743 fpChainHandlers=NULL;
745 AliHLTOUT::InvalidateBlocks(*pHandlers);
746 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
748 assert(pHandlers->size()==0);
753 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
756 AliHLTOUT::InvalidateBlocks(*pHandlers);
757 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
759 assert(pHandlers->size()==0);
763 if (fpProprietaryHandlers) {
764 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
765 fpProprietaryHandlers=NULL;
767 AliHLTOUT::InvalidateBlocks(*pHandlers);
768 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pHandlers);
770 assert(pHandlers->size()==0);
776 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
778 // see header file for class documentation
781 p=(void*)new char[size];
785 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
790 int AliHLTSystem::AllocEventDoneData( void* /*param*/, AliHLTEventID_t /*eventID*/, unsigned long size, AliHLTComponentEventDoneData** edd )
792 // see header file for class documentation
793 unsigned long blocksize=sizeof(AliHLTComponentEventDoneData)+size;
794 void* block=AllocMemory(NULL, blocksize);
795 if (!block) return -ENOMEM;
796 memset(block, 0, blocksize);
797 *edd=reinterpret_cast<AliHLTComponentEventDoneData*>(block);
798 (*edd)->fStructSize=sizeof(AliHLTComponentEventDoneData);
799 (*edd)->fDataSize=size;
800 (*edd)->fData=reinterpret_cast<AliHLTUInt8_t*>(block)+sizeof(AliHLTComponentEventDoneData);
805 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
806 AliRawReader* rawReader)
808 // see header file for class documentation
810 if (runLoader || rawReader || nofEvents==0) {
811 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
812 if (CheckStatus(kReady)) {
814 // special case to close the reconstruction
815 if (!CheckStatus(kError)) {
818 CleanupHLTOUTHandlers();
821 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
822 AliHLTUInt64_t trgMask=0x1;
823 AliHLTUInt32_t timestamp=0;
824 AliHLTUInt32_t eventtype=0;
825 if (runLoader==NULL) {
826 // this is a quick workaround for the case of simulation
827 // the trigger framework is still under development, secondly, AliHLTSimulation
828 // does not yet add the emulated ECS parameters, so no CTP trigger is known in the HLT
829 // AliHLTTask will initialize one dummy CTP trigger class with bit 0, that's why the
830 // default trigger mask is 0x1
831 trgMask=AliHLTMisc::Instance().GetTriggerMask(rawReader);
833 // get the timestamp and type of the event from the raw reader
834 // this is currently only meaningfull for reconstruction (runloader==NULL)
835 timestamp=AliHLTMisc::Instance().GetTimeStamp(rawReader);
836 eventtype=AliHLTMisc::Instance().GetEventType(rawReader);
838 // the system always remains started after event processing, a specific
839 // call with nofEvents==0 is needed to execute the stop sequence
840 if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
844 // add the current HLTOUT task to the collection
846 AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
847 if (pTask && (iResult=pTask->Init())>=0) {
848 if (pTask->GetNofDataBlocks()>0) {
849 AliHLTOUT* pHLTOUT=RequestHLTOUT();
851 pHLTOUT->AddSubCollection(pTask);
852 ReleaseHLTOUT(pHLTOUT);
854 HLTWarning("no HLTOUT instance available, output blocks of the chain are ignored");
858 HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
863 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
866 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
872 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
874 // see header file for class documentation
876 if (runLoader || esd) {
877 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
878 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
880 HLTError("missing run loader/ESD instance(s)");
886 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
888 // see header file for class documentation
890 if (!pHLTOUT) return -EINVAL;
891 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
894 // process all kChain handlers first
896 if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
897 HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
902 fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
903 if (!fpProprietaryHandlers)
904 fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
906 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
907 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
908 if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
910 // invalidate all blocks
911 AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
912 AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
914 AliHLTComponentDataTypeList esdBlocks;
916 for (iResult=pHLTOUT->SelectFirstDataBlock();
918 iResult=pHLTOUT->SelectNextDataBlock()) {
919 AliHLTComponentDataType dt=kAliHLTVoidDataType;
920 AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
921 pHLTOUT->GetDataBlockDescription(dt, spec);
922 AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
923 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
925 // default handling for ESD data blocks does not require an explicite handler
926 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
927 handlerType=AliHLTModuleAgent::kEsd;
929 const char* pMsg="invalid";
930 switch (handlerType) {
931 case AliHLTModuleAgent::kEsd:
934 // schedule for later processing
935 pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
937 AliHLTComponentDataTypeList::iterator element=esdBlocks.begin();
938 for (; element!=esdBlocks.end(); element++) {
940 HLTWarning("multiple ESDs of identical data type %s, please add appropriate handler to merge ESDs", AliHLTComponent::DataType2Text(dt).c_str());
944 if (element==esdBlocks.end()) esdBlocks.push_back(dt);
947 const AliHLTUInt8_t* pBuffer=NULL;
948 AliHLTUInt32_t size=0;
949 if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
950 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
951 pHLTOUT->ReleaseDataBuffer(pBuffer);
953 pHLTOUT->MarkDataBlockProcessed();
957 case AliHLTModuleAgent::kRawReader:
958 // handled in the AliRawReaderHLT
960 case AliHLTModuleAgent::kRawStream:
961 HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
962 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
963 AliHLTComponent::DataType2Text(dt).c_str(), spec);
965 case AliHLTModuleAgent::kChain:
966 HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
967 "New block of this type added by the chain? Skipping data block ...",
968 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
969 AliHLTComponent::DataType2Text(dt).c_str(), spec);
971 case AliHLTModuleAgent::kProprietary:
972 HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
973 pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
974 AliHLTComponent::DataType2Text(dt).c_str(), spec);
976 AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
977 int res=pHandler->ProcessData(pHLTOUT);
979 HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
980 res, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
981 AliHLTComponent::DataType2Text(dt).c_str(), spec);
985 case AliHLTModuleAgent::kUnknownOutput:
987 // fall trough intended
989 HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
990 pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"<invalid>",
991 AliHLTComponent::DataType2Text(dt).c_str(), spec);
994 // TODO: the return value of SelectFirst/NextDataBlock must be
995 // changed in order to avoid this check
996 if (iResult==-ENOENT) iResult=0;
998 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
1000 // process and write all esd data blocks
1001 for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
1002 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1003 AliHLTOUTHandler* pHandler=*handler;
1004 const AliHLTUInt8_t* pBuffer=NULL;
1005 AliHLTUInt32_t size=0;
1006 pHandler->ProcessData(pHLTOUT);
1007 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1008 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
1009 AliHLTComponentDataType dt=desc;
1010 pHLTOUT->WriteESD(pBuffer, size, dt, esd);
1011 pHandler->ReleaseProcessedData(pBuffer, size);
1013 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1016 // process all kProprietary data blocks
1017 for (handler=pProprietaryHandlers->begin(); handler!=pProprietaryHandlers->end() && iResult>=0; handler++) {
1018 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));
1019 AliHLTOUTHandler* pHandler=*handler;
1020 const AliHLTUInt8_t* pBuffer=NULL;
1021 AliHLTUInt32_t size=0;
1022 pHandler->ProcessData(pHLTOUT);
1023 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1024 HLTWarning("data produced by kProprietary handler ignored");
1025 pHandler->ReleaseProcessedData(pBuffer, size);
1027 pHLTOUT->MarkDataBlocksProcessed(&(*handler));
1030 // remove all empty handlers form the list (handlers which did not get a block this time)
1031 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
1032 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
1037 int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
1039 // see header file for class documentation
1041 if (!pHLTOUT) return -EINVAL;
1043 if (!fpChainHandlers)
1044 fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
1046 AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
1047 if (!pChainHandlers) return -ENOMEM;
1049 // invalidate all blocks
1050 AliHLTOUT::InvalidateBlocks(*pChainHandlers);
1053 pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
1055 // process all defined chain handlers
1056 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
1057 for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
1058 if (chainHandler->IsEmpty()) continue;
1059 AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));
1060 AliHLTOUTHandler* pHandler=*chainHandler;
1061 const AliHLTUInt8_t* pBuffer=NULL;
1062 AliHLTUInt32_t size=0;
1063 pHandler->ProcessData(pHLTOUT);
1064 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
1065 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
1066 //AliHLTComponentDataType dt=desc;
1068 pHandler->ReleaseProcessedData(pBuffer, size);
1070 pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
1073 // remove all empty handlers form the list (handlers which did not get a block this time)
1074 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
1079 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
1081 // see header file for class documentation
1084 if (fpComponentHandler) {
1085 TString libs(libraries);
1086 TObjArray* pTokens=libs.Tokenize(" ");
1088 int iEntries=pTokens->GetEntriesFast();
1089 for (int i=0; i<iEntries && iResult>=0; i++) {
1090 if (!pTokens->At(i)) continue;
1091 iResult=fpComponentHandler->LoadLibrary(pTokens->At(i)->GetName());
1096 SetStatusFlags(kLibrariesLoaded);
1098 // lets see if we need this, probably not
1099 //fpComponentHandler->UnloadLibraries();
1100 ClearStatusFlags(kLibrariesLoaded);
1104 HLTFatal("no component handler available");
1112 int AliHLTSystem::Configure(AliRunLoader* runloader)
1114 // see header file for class documentation
1115 return Configure(NULL, runloader);
1118 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
1120 // see header file for class documentation
1122 if (CheckStatus(kRunning)) {
1123 HLTError("HLT system in running state, can not configure");
1126 ClearStatusFlags(kTaskListCreated);
1127 if (CheckFilter(kHLTLogDebug))
1128 AliHLTModuleAgent::PrintStatus();
1129 if (CheckStatus(kConfigurationLoaded)==0) {
1130 iResult=LoadConfigurations(rawReader, runloader);
1132 if (fChains.Length()==0) {
1133 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
1138 SetStatusFlags(kConfigurationLoaded);
1139 if (CheckFilter(kHLTLogDebug))
1140 fpConfigurationHandler->PrintConfigurations();
1141 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
1143 SetStatusFlags(kTaskListCreated);
1146 if (iResult<0) SetStatusFlags(kError);
1151 int AliHLTSystem::ScanOptions(const char* options)
1153 // see header file for class documentation
1156 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
1158 TString excludelibs("");
1159 TString alloptions(options);
1160 TObjArray* pTokens=alloptions.Tokenize(" ");
1162 int iEntries=pTokens->GetEntriesFast();
1163 for (int i=0; i<iEntries; i++) {
1164 if (!pTokens->At(i)) continue;
1165 TString token=pTokens->At(i)->GetName();
1166 if (token.Contains("loglevel=")) {
1167 TString param=token.ReplaceAll("loglevel=", "");
1168 if (param.IsDigit()) {
1169 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
1170 } else if (param.BeginsWith("0x") &&
1171 param.Replace(0,2,"",0).IsHex()) {
1173 sscanf(param.Data(),"%x", &severity);
1174 SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
1176 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1178 } else if (token.Contains("frameworklog=")) {
1179 TString param=token.ReplaceAll("frameworklog=", "");
1180 if (param.IsDigit()) {
1181 SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
1182 } else if (param.BeginsWith("0x") &&
1183 param.Replace(0,2,"",0).IsHex()) {
1185 sscanf(param.Data(),"%x", &severity);
1186 SetFrameworkLog((AliHLTComponentLogSeverity)severity);
1188 HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1190 } else if (token.Contains("alilog=off")) {
1192 } else if (token.Contains("config=") || token.Contains("run-online-config")) {
1193 if (!CheckStatus(kConfigurationLoaded)) {
1195 AliHLTOnlineConfiguration* pConf = NULL;
1196 if (token.Contains("run-online-config")) {
1197 AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry("HLT/Calib/OnlineConfig");
1199 TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
1200 if (pObject && pObject->IsA() == AliHLTOnlineConfiguration::Class())
1201 pConf = (AliHLTOnlineConfiguration*)pObject;
1204 if (token.Contains("config=")) {
1205 TString param=token.ReplaceAll("config=", "");
1206 if (token.EndsWith(".xml", TString::kIgnoreCase)) {
1208 pConf = new AliHLTOnlineConfiguration;
1209 filesize = pConf->LoadConfiguration(param.Data());
1210 if (filesize <= 0) {
1211 HLTError("cannot load config \'%s\'", param.Data());
1215 gROOT->Macro(param.Data(), &error);
1217 SetStatusFlags(kConfigurationLoaded);
1219 HLTError("cannot execute macro \'%s\'", param.Data());
1225 error = pConf->Parse();
1227 fChains = pConf->GetDefaultChains();
1228 libs = pConf->GetComponentLibraries();
1230 SetStatusFlags(kConfigurationLoaded);
1232 HLTError("cannot parse online configuration");
1236 delete pConf; pConf=NULL;
1238 HLTWarning("HLT options has both a config file and run-online-config set");
1240 } else if (token.Contains("chains=")) {
1241 TString param=token.ReplaceAll("chains=", "");
1242 fChains=param.ReplaceAll(",", " ");
1243 if (fChains.IsNull()) fChains=" "; // disable all chains
1244 } else if (token.Contains("libmode=")) {
1245 TString param=token.ReplaceAll("libmode=", "");
1246 param.ReplaceAll(",", " ");
1247 if (fpComponentHandler) {
1248 if (param.CompareTo("static")==0) {
1249 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
1250 } else if (param.CompareTo("dynamic")==0) {
1251 fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
1253 HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
1256 } else if (token.BeginsWith("ECS=")) {
1257 fECSParams=token.ReplaceAll("ECS=", "");
1258 } else if (token.BeginsWith("hltout-mode=")) {
1259 // The actual parameter for argument 'hltout-mode' is treated in AliSimulation.
1260 // For AliHLTSystem the occurrence with parameter 'split' signals the use of the
1261 // separated HLTOUTComponents for digit and raw data. All others indicate
1262 // HLTOUTComponent type 'global' where the data generation is steered from global
1264 fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")!=0;
1265 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1268 } else if (token.BeginsWith("!lib") && token.EndsWith(".so")) {
1272 HLTWarning("unknown option \'%s\'", token.Data());
1279 if (libs.IsNull()) {
1280 const char** deflib=fgkHLTDefaultLibs;
1281 for (;*deflib; deflib++) {
1282 if (excludelibs.Contains(*deflib)) continue;
1287 if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
1288 (LoadComponentLibraries(libs.Data())<0)) {
1289 HLTError("error while loading HLT libraries");
1297 int AliHLTSystem::Reset(int bForce)
1299 // see header file for class documentation
1301 if (!bForce && CheckStatus(kRunning)) {
1302 HLTError("HLT system in running state, can not configure");
1306 ClearStatusFlags(~kUninitialized);
1310 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1312 // see header file for class documentation
1313 if (CheckStatus(kRunning)) {
1314 HLTError("HLT system in running state, can not configure");
1318 AliHLTModuleAgent* pAgent=NULL;
1320 // first check for the required libraries and load those
1322 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1323 pAgent && iResult>=0;
1324 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1325 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1327 HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1333 iResult=LoadComponentLibraries(extralibs.Data());
1336 // in order to register the configurations in the correct sequence
1337 // all agents need to be ordered with respect to the required
1338 // libraries. Ordering relies on the naming convention
1339 // libAliHLT<Module>.so
1341 for (pAgent=AliHLTModuleAgent::GetFirstAgent();
1342 pAgent && iResult>=0;
1343 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1344 AliHLTModuleAgent* pPrevDep=NULL;
1345 TString dependencies=pAgent->GetRequiredComponentLibraries();
1346 TObjArray* pTokens=dependencies.Tokenize(" ");
1348 for (int n=0; n<pTokens->GetEntriesFast(); n++) {
1349 if (!pTokens->At(n)) continue;
1350 TString module=pTokens->At(n)->GetName();
1351 HLTDebug(" checking %s", module.Data());
1352 module.ReplaceAll("libAliHLT", "");
1353 module.ReplaceAll(".so", "");
1355 for (AliHLTModuleAgent* pCurrent=dynamic_cast<AliHLTModuleAgent*>(pPrevDep==NULL?agents.First():agents.After(pPrevDep));
1356 pCurrent!=NULL; pCurrent=dynamic_cast<AliHLTModuleAgent*>(agents.After(pCurrent))) {
1357 HLTDebug(" checking %s == %s", module.Data(), pCurrent->GetModuleId());
1359 if (module.CompareTo(pCurrent->GetModuleId())==0) {
1369 // insert right after the last dependency
1370 agents.AddAfter(pPrevDep, pAgent);
1371 HLTDebug("insert %s after %s", pAgent->GetModuleId(), pPrevDep->GetModuleId());
1373 // insert at the beginning
1374 agents.AddFirst(pAgent);
1375 HLTDebug("insert %s at beginning", pAgent->GetModuleId());
1379 // now we load the configurations
1380 if (agents.GetEntries()) {
1381 TIter next(&agents);
1382 while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
1383 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1384 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1391 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1393 // see header file for class documentation
1394 if (CheckStatus(kRunning)) {
1395 HLTError("HLT system in running state, can not configure");
1398 if (!CheckStatus(kConfigurationLoaded)) {
1399 HLTWarning("configurations not yet loaded");
1403 if (!fpConfigurationHandler || !fpComponentHandler) return -EFAULT;
1410 if (fChains.Length()>0) {
1412 HLTImportant("custom reconstruction chain: %s", chains.Data());
1414 for (AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1415 pAgent && iResult>=0;
1416 pAgent=AliHLTModuleAgent::GetNextAgent()) {
1417 const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1419 if (!chains.IsNull()) chains+=" ";
1420 chains+=agentchains;
1421 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1426 // build task list for chains
1427 TObjArray* pTokens=chains.Tokenize(" ");
1429 int iEntries=pTokens->GetEntriesFast();
1430 for (int i=0; i<iEntries && iResult>=0; i++) {
1431 if (!pTokens->At(i)) continue;
1432 const char* pCID=pTokens->At(i)->GetName();
1433 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1435 iResult=BuildTaskList(pConf);
1436 if (true) { // condition was deprecated but kept for sake of svn diff
1437 // bHaveOutput variable has to be set for both running modes
1438 // AliHLTSimulation and AliHLTReconstruction
1439 TString cid=pConf->GetComponentID();
1440 if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
1441 // remove from the input of a global HLTOUT configuration
1442 chains.ReplaceAll(pCID, "");
1443 } else if (bHaveOutput==0) {
1444 // check whether this configuration produces data output
1445 if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1447 chains.ReplaceAll(pCID, "");
1452 HLTWarning("can not find configuration %s", pCID);
1458 // build HLTOUT for simulation
1459 if (iResult>=0 && runloader) {
1461 // there are components in the chain which produce data which need to be
1462 // piped to an HLTOUT
1464 // add the SchemaEvolutionComponent which analyzes the ROOT objects in
1465 // the output stream
1466 if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
1467 fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
1468 fpConfigurationHandler->CreateConfiguration("_schemaevolution_", "ROOTSchemaEvolutionComponent",
1469 chains.Data(), "-file=HLT.StreamerInfo.root");
1470 iResult=BuildTaskList("_schemaevolution_");
1472 HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
1475 // add the HLTOUT component
1476 if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1477 fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
1478 // for the default HLTOUTComponent type 'global' the data generation is steered
1479 // by global flags from AliSimulation. This allows for emulation of the old
1480 // AliHLTSimulation behavior where only one chain is run on either digits or
1481 // simulated raw data and the HLT digits and raw files have been generated
1482 // depending on the configuration
1483 const char* HLTOUTComponentId="HLTOUT";
1484 if (!fUseHLTOUTComponentTypeGlobal) {
1485 // choose the type of output depending on the availability of
1487 if (rawReader) HLTOUTComponentId="HLTOUTraw";
1488 else HLTOUTComponentId="HLTOUTdigits";
1490 fpConfigurationHandler->CreateConfiguration("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
1491 iResult=BuildTaskList("_globalout_");
1493 HLTError("can not load libHLTsim.so and HLTOUT component");
1499 // build HLTOUT task for reconstruction
1500 // Matthias 08.07.2008 the rawReader is never set when running embedded into
1501 // AliReconstruction. The system is configured during AliHLTReconstructor::Init
1502 // where the RawReader is not available. It is available in the first invocation
1505 // That means that policy is slightly changed:
1506 // - if the run loader is available -> AliSimulation
1507 // - no run loader available -> AliReconstruction
1508 if (iResult>=0 && !runloader) {
1510 // there are components in the chain which produce data which need to be
1511 // piped to an HLTOUT sub-collection
1512 if (!fpHLTOUTTask) {
1513 iResult=AddHLTOUTTask(chains.Data());
1518 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1523 int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
1525 // see header file for class documentation
1527 if (!hltoutchains || hltoutchains[0]==0) return 0;
1529 // check chains for output
1530 TString chains=hltoutchains;
1531 TObjArray* pTokens=chains.Tokenize(" ");
1533 int iEntries=pTokens->GetEntriesFast();
1534 for (int i=0; i<iEntries && iResult>=0; i++) {
1535 if (!pTokens->At(i)) continue;
1536 const char* token=pTokens->At(i)->GetName();
1537 AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
1539 TString cid=pConf->GetComponentID();
1540 if (fpComponentHandler->HasOutputData(cid.Data())) {
1544 HLTWarning("can not find configuration %s", token);
1546 // remove from the list of hltout chains
1547 chains.ReplaceAll(token, "");
1552 // do not create the HLTOUT task if none of the chains have output
1553 if (chains.IsNull()) return 0;
1555 // indicate the task to be available
1559 if (strcmp(chains.Data(), fpHLTOUTTask->GetSourceChains())==0) {
1560 HLTWarning("HLTOUT task already added for chains \"%s\" %p", chains.Data(), fpHLTOUTTask);
1562 HLTError("HLTOUT task already added for chains \"%s\" %p, ignoring new chains \"%s\"",
1563 fpHLTOUTTask->GetSourceChains(), fpHLTOUTTask, chains.Data());
1568 fpHLTOUTTask=new AliHLTOUTTask(chains);
1570 if (fpHLTOUTTask->GetConf() &&
1571 (fpHLTOUTTask->GetConf()->SourcesResolved()>0 ||
1572 fpHLTOUTTask->GetConf()->ExtractSources(fpConfigurationHandler)>0)) {
1573 iResult=InsertTask(fpHLTOUTTask);
1575 HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
1580 delete fpHLTOUTTask;
1589 int AliHLTSystem::CheckStatus(int flag)
1591 // see header file for class documentation
1592 if (flag==kUninitialized && flag==fState) return 1;
1593 if ((fState&flag)==flag) return 1;
1597 int AliHLTSystem::GetStatusFlags()
1599 // see header file for class documentation
1603 int AliHLTSystem::SetStatusFlags(int flags)
1605 // see header file for class documentation
1610 int AliHLTSystem::ClearStatusFlags(int flags)
1612 // see header file for class documentation
1617 AliHLTfctVoid AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1619 // see header file for class documentation
1620 if (fpComponentHandler==NULL) return NULL;
1621 return fpComponentHandler->FindSymbol(library, symbol);
1624 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1626 // see header file for class documentation
1627 SetLocalLoggingLevel(level);
1628 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1629 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
1632 int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity,
1633 const char* originClass, const char* originFunc,
1634 const char* file, int line, ... ) const
1636 // see header file for function documentation
1640 va_start(args, line);
1642 if (!fName.IsNull())
1643 AliHLTLogging::SetLogString(this, " (%p)", "%s_pfmt_: ", fName.Data());
1644 iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, !fName.IsNull() /*append if non empty*/));
1650 int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
1652 // Init the HLTOUT instance for the current event.
1653 // The instance can be used by other classes to get hold on the data
1655 if (!instance) return -EINVAL;
1656 if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
1661 int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
1663 // Clear the HLTOUT instance.
1666 HLTWarning("HLTOUT instance still in use, potential problem due to invalid pointer ahead");
1670 if (target) *target=fpHLTOUT;
1675 AliHLTOUT* AliHLTSystem::RequestHLTOUT()
1677 // Get the HLTOUT instance.
1678 // User method for processing classes. To be released after use.
1679 if (!fpHLTOUT) return NULL;
1684 int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
1686 // Release the HLTOUT instance after use.
1687 if (!instance) return -EINVAL;
1688 if (instance!=fpHLTOUT) return -ENOENT;