]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTSystem.cxx
- singleton functionality added for component and configuration handler
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTSystem.cxx
20     @author Matthias Richter
21     @date   
22     @brief  Implementation of HLT module management.
23 */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28
29 #include <cassert>
30 #include "AliHLTStdIncludes.h"
31 #include "AliHLTSystem.h"
32 #include "AliHLTComponentHandler.h"
33 #include "AliHLTComponent.h"
34 #include "AliHLTConfiguration.h"
35 #include "AliHLTConfigurationHandler.h"
36 #include "AliHLTTask.h"
37 #include "AliHLTModuleAgent.h"
38 #include "AliHLTOfflineInterface.h"
39 #include "AliHLTDataSource.h"
40 #include "AliHLTOUT.h"
41 #include "AliHLTOUTHandler.h"
42 #include <TObjArray.h>
43 #include <TObjString.h>
44 #include <TStopwatch.h>
45 //#include <TSystem.h>
46 #include <TROOT.h>
47 //#include <TInterpreter.h>
48
49 /** HLT default component libraries */
50 const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
51   "libAliHLTUtil.so", 
52   "libAliHLTRCU.so", 
53   "libAliHLTTPC.so", 
54   //  "libAliHLTSample.so",
55   //"libAliHLTPHOS.so",
56   "libAliHLTMUON.so",
57   "libAliHLTTRD.so",
58   "libAliHLTTrigger.so",
59   NULL
60 };
61
62 /** ROOT macro for the implementation of ROOT specific class methods */
63 ClassImp(AliHLTSystem)
64
65 AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel)
66   :
67   fpComponentHandler(AliHLTComponentHandler::CreateHandler()),
68   fpConfigurationHandler(AliHLTConfigurationHandler::CreateHandler()),
69   fTaskList(),
70   fState(0),
71   fChains(),
72   fStopwatches(new TObjArray),
73   fEventCount(-1),
74   fGoodEvents(-1),
75   fpChainHandlers(NULL),
76   fpEsdHandlers(NULL),
77   fpProprietaryHandlers(NULL)
78 {
79   // see header file for class documentation
80   // or
81   // refer to README to build package
82   // or
83   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
84
85   if (fgNofInstances++>0) {
86     // July 2008: multiple instances are now allowed
87     // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
88     //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
89   }
90
91   SetGlobalLoggingLevel(loglevel);
92   SetFrameworkLog(loglevel);
93   if (fpComponentHandler) {
94     AliHLTComponentEnvironment env;
95     memset(&env, 0, sizeof(AliHLTComponentEnvironment));
96     env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
97     env.fLoggingFunc=NULL;
98     fpComponentHandler->SetEnvironment(&env);
99     InitAliLogFunc(fpComponentHandler);
100     fpComponentHandler->AnnounceVersion();
101   } else {
102     HLTFatal("can not create Component Handler");
103   }
104   if (fpConfigurationHandler) {
105     AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
106   } else {
107     HLTFatal("can not create Configuration Handler");
108   }
109 }
110
111 AliHLTSystem::~AliHLTSystem()
112 {
113   // see header file for class documentation
114   fgNofInstances--;
115   CleanTaskList();
116   AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
117   if (fpConfigurationHandler) {
118     fpConfigurationHandler->Destroy();
119   }
120   fpConfigurationHandler=NULL;
121   
122   if (fpComponentHandler) {
123     fpComponentHandler->Destroy();
124   }
125   fpComponentHandler=NULL;
126 }
127
128 int AliHLTSystem::fgNofInstances=0;
129
130 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
131 {
132   // see header file for class documentation
133   HLTLogKeyword("configuration handling");
134   int iResult=0;
135   if (pConf) {
136     HLTError("function not yet implemented");
137     iResult=-ENOSYS;
138   } else {
139     iResult=-EINVAL;
140   }
141   return iResult;
142 }
143
144 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
145 {
146   // see header file for class documentation
147   HLTLogKeyword("configuration handling");
148   int iResult=0;
149   if (pConf) {
150     if (pPrec) {
151       // find the position
152       HLTError("function not yet implemented");
153       iResult=-ENOSYS;
154     }
155   } else {
156     iResult=-EINVAL;
157   }
158   return iResult;
159 }
160
161 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
162 {
163   // see header file for class documentation
164   HLTLogKeyword("configuration handling");
165   int iResult=0;
166   if (pConf) {
167     HLTError("function not yet implemented");
168     iResult=-ENOSYS;
169   } else {
170     iResult=-EINVAL;
171   }
172   return iResult;
173 }
174
175 int AliHLTSystem::BuildTaskList(const char* id)
176 {
177   // see header file for class documentation
178   int iResult=0;
179   if (id) {
180     if (fpConfigurationHandler) {
181       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
182       if (pConf) {
183         iResult=BuildTaskList(pConf);
184       } else {
185         HLTError("unknown configuration \"%s\"", id);
186         iResult=-EEXIST;
187       }
188     } else {
189       iResult=-EFAULT;
190     }
191   } else {
192     iResult=-EINVAL;
193   }
194   return iResult;
195 }
196
197 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
198 {
199   // see header file for class documentation
200   int iResult=0;
201   if (pConf) {
202     AliHLTTask* pTask=NULL;
203     if ((pTask=FindTask(pConf->GetName()))!=NULL) {
204       if (pTask->GetConf()!=pConf) {
205         HLTError("configuration mismatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
206         iResult=-EEXIST;
207       }
208       // task for this configuration exists, terminate
209       pTask=NULL;
210     } else if (pConf->SourcesResolved(1)!=1) {
211         HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
212         iResult=-ENOLINK;
213     } else {
214       pTask=new AliHLTTask(pConf);
215       if (pTask==NULL) {
216         iResult=-ENOMEM;
217       } else {
218         pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
219       }
220     }
221     static int iterationLevel=0;
222     if (pTask && iResult>=0) {
223       // check for circular dependencies
224       if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
225         HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
226         pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
227         HLTError("aborted ...");
228         iResult=-ELOOP;
229       }
230       if (iResult>=0) {
231         // check whether all dependencies are already in the task list
232         // create the missing ones
233         // this step is an iterative process which calls this function again for the missing
234         // configurations, in order to avoid the currently processed task to be created
235         // again it is added to the list temporarily and removed afterwards
236         // This is of high importance to preserve the order of the tasks. Furthermore, the
237         // InsertTask method has to be used in order to set all the cross links right 
238         fTaskList.Add(pTask);
239         AliHLTConfiguration* pDep=pConf->GetFirstSource();
240         while (pDep!=NULL && iResult>=0) {
241           HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
242           if (FindTask(pDep->GetName())==NULL) {
243             HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
244             iterationLevel++;
245             iResult=BuildTaskList(pDep);
246             iterationLevel--;
247           }
248           pDep=pConf->GetNextSource();
249         }
250         // remove the temporarily added task
251         fTaskList.Remove(pTask);
252
253         // insert the task and set the cross-links
254         if (iResult>=0) {
255           HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
256           iResult=InsertTask(pTask);
257         }
258       } else {
259         delete pTask;
260         pTask=NULL;
261       }
262     }
263   } else {
264     iResult=-EINVAL;
265   }
266   return iResult;
267 }
268
269 int AliHLTSystem::CleanTaskList()
270 {
271   // see header file for class documentation
272   int iResult=0;
273   TObjLink* lnk=NULL;
274   while ((lnk=fTaskList.LastLink())!=NULL) {
275     delete (lnk->GetObject());
276     fTaskList.Remove(lnk);
277   }
278   return iResult;
279 }
280
281 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
282 {
283   // see header file for class documentation
284   int iResult=0;
285   TObjLink *lnk = NULL;
286   if ((iResult=pTask->CheckDependencies())>0)
287     lnk=fTaskList.FirstLink();
288   while (lnk && iResult>0) {
289     AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
290     //HLTDebug("checking  \"%s\"", pCurr->GetName());
291     iResult=pTask->Depends(pCurr);
292     if (iResult>0) {
293       iResult=pTask->SetDependency(pCurr);
294       pCurr->SetTarget(pTask);
295       HLTDebug("set dependency  \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
296     }
297     if (pCurr->Depends(pTask)) {
298       // circular dependency
299       HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
300       iResult=-ELOOP;
301     } else if ((iResult=pTask->CheckDependencies())>0) {
302       lnk = lnk->Next();
303     }
304   }
305   if (iResult==0) {
306       if (lnk) {
307         fTaskList.AddAfter(lnk, pTask);
308       } else {
309         fTaskList.AddFirst(pTask);
310       }
311       HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
312   } else if (iResult>0) {
313     HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
314     iResult=-ENOLINK;
315   }
316   return iResult;
317 }
318
319 AliHLTTask* AliHLTSystem::FindTask(const char* id)
320 {
321   // see header file for class documentation
322   AliHLTTask* pTask=NULL;
323   if (id) {
324     pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id)); 
325   }
326   return pTask;
327 }
328
329 void AliHLTSystem::PrintTaskList()
330 {
331   // see header file for class documentation
332   HLTLogKeyword("task list");
333   TObjLink *lnk = NULL;
334   HLTMessage("Task List");
335   lnk=fTaskList.FirstLink();
336   while (lnk) {
337     TObject* obj=lnk->GetObject();
338     if (obj) {
339       HLTMessage("  %s - status:", obj->GetName());
340       AliHLTTask* pTask=(AliHLTTask*)obj;
341       pTask->PrintStatus();
342     } else {
343     }
344     lnk = lnk->Next();
345   }
346 }
347
348 int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
349 {
350   // see header file for class documentation
351   int iResult=0;
352   int iCount=0;
353   SetStatusFlags(kRunning);
354   if (fEventCount>=0 || (iResult=InitTasks())>=0) {
355     if (fEventCount>=0 || (iResult=StartTasks())>=0) {
356       if (fEventCount==0) {
357         InitBenchmarking(fStopwatches);
358       } else {
359         ResumeBenchmarking(fStopwatches);    
360       }
361       for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
362         if ((iResult=ProcessTasks(i))>=0) {
363           fGoodEvents++;
364           iCount++;
365         } else {
366           // TODO: define different running modes to either ignore errors in
367           // event processing or not
368           // currently ignored 
369           iResult=0;
370         }
371       }
372       fEventCount+=iNofEvents;
373       if (bStop) StopTasks();
374       else PauseBenchmarking(fStopwatches);
375     }
376     if (bStop) DeinitTasks();
377   }
378   if (iResult>=0) {
379     iResult=iCount;
380   } else  if (iResult==-126 /*ENOKEY*/) {
381     iResult=0; // do not propagate the error
382   }
383   ClearStatusFlags(kRunning);
384   return iResult;
385 }
386
387 int AliHLTSystem::InitTasks()
388 {
389   // see header file for class documentation
390   int iResult=0;
391   TObjLink *lnk=fTaskList.FirstLink();
392
393   if (lnk==NULL) {
394     HLTWarning("Task list is empty, skipping HLT");
395     return -126 /*ENOKEY*/;
396   }
397   while (lnk && iResult>=0) {
398     TObject* obj=lnk->GetObject();
399     if (obj) {
400       AliHLTTask* pTask=(AliHLTTask*)obj;
401       iResult=pTask->Init(NULL, fpComponentHandler);
402 //       ProcInfo_t ProcInfo;
403 //       gSystem->GetProcInfo(&ProcInfo);
404 //       HLTInfo("task %s initialized (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
405     } else {
406     }
407     lnk = lnk->Next();
408   }
409   if (iResult<0) {
410     HLTError("can not initialize task list, error %d", iResult);
411   }
412
413   return iResult;
414 }
415
416 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
417 {
418   // see header file for class documentation
419   int iResult=0;
420   if (pStopwatches==NULL) return 0;
421
422   for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
423     TStopwatch* pStopwatch= new TStopwatch;
424     if (pStopwatch) {
425       pStopwatch->Reset();
426       pStopwatches->AddAt(pStopwatch, i);
427     } else {
428       iResult=-ENOMEM;
429       break;
430     }
431   }
432
433   TObjLink *lnk=fTaskList.FirstLink();
434   while (lnk && iResult>=0) {
435     TObject* obj=lnk->GetObject();
436     if (obj) {
437       AliHLTTask* pTask=(AliHLTTask*)obj;
438       AliHLTComponent* pComp=NULL;
439       if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
440         switch (pComp->GetComponentType()) {
441         case AliHLTComponent::kProcessor:
442           pComp->SetStopwatches(pStopwatches);
443           break;
444         case AliHLTComponent::kSource:
445           {
446             // this switch determines whether the time consumption of the
447             // AliHLTComponent base methods should be counted to the input
448             // stopwatch or base stopwatch.
449             //int inputBase=(int)AliHLTComponent::kSWBase;
450             int inputBase=(int)AliHLTComponent::kSWInput;
451             pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
452             pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
453           }
454           break;
455         case AliHLTComponent::kSink:
456           {
457             // this switch determines whether the time consumption of the
458             // AliHLTComponent base methods should be counted to the output
459             // stopwatch or base stopwatch.
460             //int outputBase=(int)AliHLTComponent::kSWBase;
461             int outputBase=(int)AliHLTComponent::kSWOutput;
462             pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
463             pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
464           }
465           break;
466         default:
467           HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
468         }
469       }
470     } else {
471     }
472     lnk = lnk->Next();
473   }
474   return iResult;
475 }
476
477 int AliHLTSystem::PauseBenchmarking(TObjArray* pStopwatches) const
478 {
479   // see header file for class documentation
480   if (pStopwatches==NULL) return 0;
481
482   for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
483     if (!pStopwatches->At(i)) continue;
484     TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
485     if (pSw) pSw->Stop();
486   }
487   return 0;
488 }
489
490 int AliHLTSystem::ResumeBenchmarking(TObjArray* pStopwatches) const
491 {
492   // see header file for class documentation
493   if (pStopwatches==NULL) return 0;
494
495   for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
496     if (!pStopwatches->At(i)) continue;
497     TStopwatch* pSw=dynamic_cast<TStopwatch*>(pStopwatches->At(i));
498     if (pSw) pSw->Continue();
499   }
500   return 0;
501 }
502
503 int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
504 {
505   // see header file for class documentation
506   int iInitialized=1;
507   if (pStopwatches==NULL) return 0;
508
509   for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
510     if (!dynamic_cast<TStopwatch*>(pStopwatches->At(i))) {
511       iInitialized=0;
512       break;
513     }
514   }
515
516   if (iInitialized!=0) {
517     HLTImportant("HLT statistics:\n"
518             "    base:              R:%.3fs C:%.3fs\n"
519             "    input:             R:%.3fs C:%.3fs\n"
520             "    output:            R:%.3fs C:%.3fs\n"
521             "    event processing : R:%.3fs C:%.3fs"
522             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->RealTime()
523             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWBase))->CpuTime()
524             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->RealTime()
525             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWInput))->CpuTime()
526             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->RealTime()
527             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWOutput))->CpuTime()
528             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->RealTime()
529             , dynamic_cast<TStopwatch*>(pStopwatches->At(AliHLTComponent::kSWDA))->CpuTime()
530             );
531   }
532
533   if (bClean) {
534     for (int i=0; i<(int)AliHLTComponent::kSWTypeCount; i++) {
535       TObject* pObj=pStopwatches->RemoveAt(i);
536       if (pObj) delete pObj;
537     }
538   }
539   return 0;
540 }
541
542 int AliHLTSystem::StartTasks()
543 {
544   // see header file for class documentation
545   int iResult=0;
546   TObjLink *lnk=fTaskList.FirstLink();
547   while (lnk && iResult>=0) {
548     TObject* obj=lnk->GetObject();
549     if (obj) {
550       AliHLTTask* pTask=(AliHLTTask*)obj;
551       iResult=pTask->StartRun();
552 //       ProcInfo_t ProcInfo;
553 //       gSystem->GetProcInfo(&ProcInfo);
554 //       HLTInfo("task %s started (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
555     } else {
556     }
557     lnk = lnk->Next();
558   }
559   if (iResult<0) {
560     HLTError("can not start task list, error %d", iResult);
561   } else {
562     SetStatusFlags(kStarted);
563     fEventCount=0;
564     fGoodEvents=0;
565     if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
566       HLTError("can not send SOR event");
567     }
568   }
569   return iResult;
570 }
571
572 int AliHLTSystem::ProcessTasks(Int_t eventNo)
573 {
574   // see header file for class documentation
575   int iResult=0;
576   HLTDebug("processing event no %d", eventNo);
577   TObjLink *lnk=fTaskList.FirstLink();
578   while (lnk && iResult>=0) {
579     TObject* obj=lnk->GetObject();
580     if (obj) {
581       AliHLTTask* pTask=(AliHLTTask*)obj;
582       iResult=pTask->ProcessTask(eventNo);
583 //       ProcInfo_t ProcInfo;
584 //       gSystem->GetProcInfo(&ProcInfo);
585 //       HLTInfo("task %s processed (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
586     } else {
587     }
588     lnk = lnk->Next();
589   }
590
591   if (iResult>=0) {
592     HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
593     iResult=0;
594   } else {
595     HLTError("Processing of event %d failed (%d)", eventNo, iResult);
596   }
597
598   return iResult;
599 }
600
601 int AliHLTSystem::StopTasks()
602 {
603   // see header file for class documentation
604   int iResult=0;
605   if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
606     HLTError("can not send EOR event");
607   }
608   TObjLink *lnk=fTaskList.FirstLink();
609   while (lnk) {
610     TObject* obj=lnk->GetObject();
611     if (obj) {
612       AliHLTTask* pTask=(AliHLTTask*)obj;
613       int locResult=pTask->EndRun();
614       if (iResult>=0 && locResult<0) iResult=locResult;
615 //       ProcInfo_t ProcInfo;
616 //       gSystem->GetProcInfo(&ProcInfo);
617 //       HLTInfo("task %s stopped (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
618     } else {
619     }
620     lnk = lnk->Next();
621   }
622   PrintBenchmarking(fStopwatches, 1 /*clean*/);
623   ClearStatusFlags(kStarted);
624   return iResult;
625 }
626
627 int AliHLTSystem::SendControlEvent(AliHLTComponentDataType dt)
628 {
629   // see header file for class documentation
630
631   // disabled for the moment
632   return 0;
633
634   int iResult=0;
635   AliHLTRunDesc runDesc;
636   memset(&runDesc, 0, sizeof(AliHLTRunDesc));
637   runDesc.fStructSize=sizeof(AliHLTRunDesc);
638   AliHLTDataSource::AliSpecialEventGuard g(&runDesc, dt, kAliHLTVoidDataSpec);
639   HLTDebug("sending event %s, run descriptor %p", AliHLTComponent::DataType2Text(dt).c_str(), &runDesc);
640   TObjLink *lnk=fTaskList.FirstLink();
641   while (lnk && iResult>=0) {
642     TObject* obj=lnk->GetObject();
643     if (obj) {
644       AliHLTTask* pTask=(AliHLTTask*)obj;
645       iResult=pTask->ProcessTask(-1);
646     } else {
647     }
648     lnk = lnk->Next();
649   }
650   HLTDebug("event %s done (%d)", AliHLTComponent::DataType2Text(dt).c_str(), iResult);
651   return iResult;
652 }
653
654 int AliHLTSystem::DeinitTasks()
655 {
656   // see header file for class documentation
657   int iResult=0;
658   TObjLink *lnk=fTaskList.FirstLink();
659   while (lnk && iResult>=0) {
660     TObject* obj=lnk->GetObject();
661     if (obj) {
662       AliHLTTask* pTask=(AliHLTTask*)obj;
663       iResult=pTask->Deinit();
664 //       ProcInfo_t ProcInfo;
665 //       gSystem->GetProcInfo(&ProcInfo);
666 //       HLTInfo("task %s cleaned (%d), current memory usage %d %d", pTask->GetName(), iResult, ProcInfo.fMemResident, ProcInfo.fMemVirtual);
667     } else {
668     }
669     lnk = lnk->Next();
670   }
671   fEventCount=-1;
672   fGoodEvents=-1;
673
674   return iResult;
675 }
676
677 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
678 {
679   // see header file for class documentation
680   void* p=NULL;
681   try {
682     p=(void*)new char[size];
683   }
684   catch (...) {
685     AliHLTLogging log;
686     log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
687   }
688   return p;
689 }
690
691 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader, 
692                               AliRawReader* rawReader)
693 {
694   // see header file for class documentation
695   int iResult=0;
696   if (runLoader || rawReader || nofEvents==0) {
697     if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
698     if (CheckStatus(kReady)) {
699       if (nofEvents==0) {
700         // special case to close the reconstruction
701         if (!CheckStatus(kError)) {
702         StopTasks();
703         DeinitTasks();
704         }
705       } else {
706       if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
707         // the system always remains started after event processing, a specific
708         // call with nofEvents==0 is needed to execute the stop sequence
709         if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
710       }
711       }
712     } else {
713       HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
714     }
715   } else {
716     HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
717     iResult=-EINVAL;
718   }
719   return iResult;
720 }
721
722 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
723 {
724   // see header file for class documentation
725   int iResult=0;
726   if (runLoader || esd) {
727     HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
728     iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
729   } else {
730     HLTError("missing run loader/ESD instance(s)");
731     iResult=-EINVAL;
732   }
733   return iResult;
734 }
735
736 int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
737 {
738   // see header file for class documentation
739   int iResult=0;
740   if (!pHLTOUT) return -EINVAL;
741   HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
742
743   //
744   // process all kChain handlers first
745   //
746   if ((iResult=ProcessHLTOUTkChain(pHLTOUT))<0) {
747     HLTWarning("Processing of kChain-type data blocks failed with error code %d", iResult);
748     iResult=0;
749   } 
750
751   if (!fpEsdHandlers)
752     fpEsdHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
753   if (!fpProprietaryHandlers)
754     fpProprietaryHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
755
756   AliHLTOUT::AliHLTOUTHandlerListEntryVector* pEsdHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpEsdHandlers);
757   AliHLTOUT::AliHLTOUTHandlerListEntryVector* pProprietaryHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpProprietaryHandlers);
758   if (!pEsdHandlers || !pProprietaryHandlers) return -ENOMEM;
759
760   // invalidate all blocks
761   AliHLTOUT::InvalidateBlocks(*pEsdHandlers);
762   AliHLTOUT::InvalidateBlocks(*pProprietaryHandlers);
763
764   // first come first serve: the ESD of the first handler is also filled into
765   // the main ESD. Has to be changed later.
766   // currently, merging to the provided ESDs crashes at the level of the
767   // TTree::Fill in AliReconstruction, furthermore, the wrong ESD is passed
768   // by the framework
769   AliESDEvent* pMasterESD=NULL;
770   pMasterESD=esd;
771   for (iResult=pHLTOUT->SelectFirstDataBlock();
772        iResult>=0;
773        iResult=pHLTOUT->SelectNextDataBlock()) {
774     AliHLTComponentDataType dt=kAliHLTVoidDataType;
775     AliHLTUInt32_t spec=kAliHLTVoidDataSpec;
776     pHLTOUT->GetDataBlockDescription(dt, spec);
777     AliHLTOUTHandler* pHandler=pHLTOUT->GetHandler();
778     AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=pHLTOUT->GetDataBlockHandlerType();
779
780     // default handling for ESD data blocks does not require an explicite handler
781     if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
782       handlerType=AliHLTModuleAgent::kEsd;
783     }
784     const char* pMsg="invalid";
785     switch (handlerType) {
786     case AliHLTModuleAgent::kEsd:
787       {
788         if (pHandler) {
789           // schedule for later processing
790           pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
791         } else {
792           // write directly
793           const AliHLTUInt8_t* pBuffer=NULL;
794           AliHLTUInt32_t size=0;
795           if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
796             pHLTOUT->WriteESD(pBuffer, size, dt);
797             if (pMasterESD) {
798               pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
799               pMasterESD=NULL;
800             }
801             pHLTOUT->ReleaseDataBuffer(pBuffer);
802           }
803           pHLTOUT->MarkDataBlockProcessed();
804         }
805       }
806       break;
807     case AliHLTModuleAgent::kRawReader:
808       // handled in the AliRawReaderHLT
809       break;
810     case AliHLTModuleAgent::kRawStream:
811       HLTWarning("HLTOUT handler type 'kRawStream' not yet implemented: agent %s, data type %s, specification %#x",
812                  pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
813                  AliHLTComponent::DataType2Text(dt).c_str(), spec);
814       break;
815     case AliHLTModuleAgent::kChain:
816       HLTWarning("HLTOUT handler type 'kChain' has already been processed: agent %s, data type %s, specification %#x\n"
817                  "New block of this type added by the chain? Skipping data block ...",
818                  pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
819                  AliHLTComponent::DataType2Text(dt).c_str(), spec);
820       break;
821     case AliHLTModuleAgent::kProprietary:
822       HLTDebug("processing proprietary data: agent %s, data type %s, specification %#x",
823                  pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
824                  AliHLTComponent::DataType2Text(dt).c_str(), spec);
825       if (pHandler) {
826         AliHLTOUT::AliHLTOUTLockGuard g(pHLTOUT);
827         int res=pHandler->ProcessData(pHLTOUT);
828         if (res<0) {
829           HLTWarning("processing proprietary data failed (%d): agent %s, data type %s, specification %#x",
830                      res, pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
831                      AliHLTComponent::DataType2Text(dt).c_str(), spec);
832         }
833       }
834       break;
835     case AliHLTModuleAgent::kUnknownOutput:
836       pMsg="unknown";
837       // fall trough intended
838     default:
839       HLTWarning("%s handler type: agent %s, data type %s, specification %#x, ... skipping data block",
840                  pMsg, pHLTOUT->GetAgent()?pHLTOUT->GetAgent()->GetModuleId():"invalid",
841                  AliHLTComponent::DataType2Text(dt).c_str(), spec);
842     }
843   }
844   // TODO: the return value of SelectFirst/NextDataBlock must be
845   // changed in order to avoid this check
846   if (iResult==-ENOENT) iResult=0;
847
848   AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator handler;
849
850   // process and write all esd data blocks
851   for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
852     AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));     
853     AliHLTOUTHandler* pHandler=*handler;
854     const AliHLTUInt8_t* pBuffer=NULL;
855     AliHLTUInt32_t size=0;
856     pHandler->ProcessData(pHLTOUT);
857     if ((size=pHandler->GetProcessedData(pBuffer))>0) {
858       AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
859       AliHLTComponentDataType dt=desc;
860       pHLTOUT->WriteESD(pBuffer, size, dt);
861       if (pMasterESD) {
862         pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
863         pMasterESD=NULL;
864       }
865       pHandler->ReleaseProcessedData(pBuffer, size);
866     }
867     pHLTOUT->MarkDataBlocksProcessed(&(*handler));
868   }
869
870   // process all kProprietary data blocks
871   for (handler=pEsdHandlers->begin(); handler!=pEsdHandlers->end() && iResult>=0; handler++) {
872     AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*handler));     
873     AliHLTOUTHandler* pHandler=*handler;
874     const AliHLTUInt8_t* pBuffer=NULL;
875     AliHLTUInt32_t size=0;
876     pHandler->ProcessData(pHLTOUT);
877     if ((size=pHandler->GetProcessedData(pBuffer))>0) {
878       HLTWarning("data produced by kProprietary handler ignored");
879       pHandler->ReleaseProcessedData(pBuffer, size);
880     }
881     pHLTOUT->MarkDataBlocksProcessed(&(*handler));
882   }
883
884   // remove all empty handlers form the list (handlers which did not get a block this time)
885   AliHLTOUT::RemoveEmptyDuplicateHandlers(*pEsdHandlers);
886   AliHLTOUT::RemoveEmptyDuplicateHandlers(*pProprietaryHandlers);
887
888   return iResult;
889 }
890
891 int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
892 {
893   // see header file for class documentation
894   int iResult=0;
895   if (!pHLTOUT) return -EINVAL;
896
897   if (!fpChainHandlers)
898     fpChainHandlers=new AliHLTOUT::AliHLTOUTHandlerListEntryVector;
899
900   AliHLTOUT::AliHLTOUTHandlerListEntryVector* pChainHandlers=reinterpret_cast<AliHLTOUT::AliHLTOUTHandlerListEntryVector*>(fpChainHandlers);
901   if (!pChainHandlers) return -ENOMEM;
902
903   // invalidate all blocks
904   AliHLTOUT::InvalidateBlocks(*pChainHandlers);
905
906   // fill the list
907   pHLTOUT->FillHandlerList(*pChainHandlers, AliHLTModuleAgent::kChain);
908
909   // process all defined chain handlers
910   AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
911   for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
912     AliHLTOUT::AliHLTOUTSelectionGuard g(pHLTOUT, &(*chainHandler));        
913     AliHLTOUTHandler* pHandler=*chainHandler;
914     const AliHLTUInt8_t* pBuffer=NULL;
915     AliHLTUInt32_t size=0;
916     pHandler->ProcessData(pHLTOUT);
917     if ((size=pHandler->GetProcessedData(pBuffer))>0) {
918       AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*chainHandler;
919       AliHLTComponentDataType dt=desc;
920
921       pHandler->ReleaseProcessedData(pBuffer, size);
922     }
923     pHLTOUT->MarkDataBlocksProcessed(&(*chainHandler));
924   }
925
926   // remove all empty handlers form the list (handlers which did not get a block this time)
927   AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
928
929   return iResult;
930 }
931
932 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
933 {
934   // see header file for class documentation
935   int iResult=0;
936   if (libraries) {
937     if (fpComponentHandler) {
938       TString libs(libraries);
939       TObjArray* pTokens=libs.Tokenize(" ");
940       if (pTokens) {
941         int iEntries=pTokens->GetEntries();
942         for (int i=0; i<iEntries && iResult>=0; i++) {
943           iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
944         }
945         delete pTokens;
946       }
947       if (iResult>=0) {
948         SetStatusFlags(kLibrariesLoaded);
949       } else {
950         // lets see if we need this, probably not
951         //fpComponentHandler->UnloadLibraries();
952         ClearStatusFlags(kLibrariesLoaded);
953       }
954     } else {
955       iResult=-EFAULT;
956       HLTFatal("no component handler available");
957     }
958   } else {
959     iResult=-EINVAL;
960   }
961   return iResult;
962 }
963
964 int AliHLTSystem::Configure(AliRunLoader* runloader)
965 {
966   // see header file for class documentation
967   return Configure(NULL, runloader);
968 }
969
970 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
971 {
972   // see header file for class documentation
973   int iResult=0;
974   if (CheckStatus(kRunning)) {
975     HLTError("HLT system in running state, can not configure");
976     return -EBUSY;
977   }
978   ClearStatusFlags(kTaskListCreated);
979   if (CheckFilter(kHLTLogDebug))
980     AliHLTModuleAgent::PrintStatus();
981   if (CheckStatus(kConfigurationLoaded)==0) {
982     iResult=LoadConfigurations(rawReader, runloader);
983   } else {
984     if (fChains.Length()==0) {
985       HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
986       iResult=-ENOENT;
987     }
988   }
989   if (iResult>=0) {
990     SetStatusFlags(kConfigurationLoaded);
991     if (CheckFilter(kHLTLogDebug))
992       fpConfigurationHandler->PrintConfigurations();
993     iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
994     if (iResult>=0) {
995       SetStatusFlags(kTaskListCreated);
996     }
997   }
998   if (iResult<0) SetStatusFlags(kError);
999   
1000   return iResult;
1001 }
1002
1003 int AliHLTSystem::ScanOptions(const char* options)
1004 {
1005   // see header file for class documentation
1006   int iResult=0;
1007   if (options) {
1008     //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
1009     TString libs("");
1010     TString alloptions(options);
1011     TObjArray* pTokens=alloptions.Tokenize(" ");
1012     if (pTokens) {
1013       int iEntries=pTokens->GetEntries();
1014       for (int i=0; i<iEntries; i++) {
1015         TString token=(((TObjString*)pTokens->At(i))->GetString());
1016         if (token.Contains("loglevel=")) {
1017           TString param=token.ReplaceAll("loglevel=", "");
1018           if (param.IsDigit()) {
1019             SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
1020           } else if (param.BeginsWith("0x") &&
1021                      param.Replace(0,2,"",0).IsHex()) {
1022             int severity=0;
1023             sscanf(param.Data(),"%x", &severity);
1024             SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
1025           } else {
1026             HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1027           }
1028         } else if (token.Contains("frameworklog=")) {
1029           TString param=token.ReplaceAll("frameworklog=", "");
1030           if (param.IsDigit()) {
1031             SetFrameworkLog((AliHLTComponentLogSeverity)param.Atoi());
1032           } else if (param.BeginsWith("0x") &&
1033                      param.Replace(0,2,"",0).IsHex()) {
1034             int severity=0;
1035             sscanf(param.Data(),"%x", &severity);
1036             SetFrameworkLog((AliHLTComponentLogSeverity)severity);
1037           } else {
1038             HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
1039           }
1040         } else if (token.Contains("alilog=off")) {
1041           SwitchAliLog(0);
1042         } else if (token.Contains("config=")) {
1043           TString param=token.ReplaceAll("config=", "");
1044           Int_t error=0;
1045           gROOT->Macro(param.Data(), &error);
1046           if (error==0) {
1047             SetStatusFlags(kConfigurationLoaded);
1048           } else {
1049             HLTError("can not execute macro \'%s\'", param.Data());
1050             iResult=-EBADF;
1051           }
1052         } else if (token.Contains("chains=")) {
1053           TString param=token.ReplaceAll("chains=", "");
1054           fChains=param.ReplaceAll(",", " ");
1055           if (fChains.IsNull()) fChains=" "; // disable all chains
1056         } else if (token.Contains("libmode=")) {
1057           TString param=token.ReplaceAll("libmode=", "");
1058           param.ReplaceAll(",", " ");
1059           if (fpComponentHandler) {
1060             if (param.CompareTo("static")==0) {
1061               fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kStatic);
1062             } else if (param.CompareTo("dynamic")==0) {
1063               fpComponentHandler->SetLibraryMode(AliHLTComponentHandler::kDynamic);
1064             } else {
1065               HLTWarning("wrong argument for option \'libmode=\', use \'static\' or \'dynamic\'");
1066             }
1067           }
1068         } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1069           libs+=token;
1070           libs+=" ";
1071         } else {
1072           HLTWarning("unknown option \'%s\'", token.Data());
1073         }
1074       }
1075       delete pTokens;
1076     }
1077
1078     if (iResult>=0) {
1079       if (libs.IsNull()) {
1080         const char** deflib=fgkHLTDefaultLibs;
1081         while (*deflib) {
1082           libs+=*deflib++;
1083           libs+=" ";
1084         }
1085       }
1086       if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
1087           (LoadComponentLibraries(libs.Data())<0)) {
1088         HLTError("error while loading HLT libraries");
1089         iResult=-EFAULT;
1090       }
1091     }
1092   }
1093   return iResult;
1094 }
1095
1096 int AliHLTSystem::Reset(int bForce)
1097 {
1098   // see header file for class documentation
1099   int iResult=0;
1100   if (!bForce && CheckStatus(kRunning)) {
1101     HLTError("HLT system in running state, can not configure");
1102     return -EBUSY;
1103   }
1104   CleanTaskList();
1105   ClearStatusFlags(~kUninitialized);
1106   return iResult;
1107 }
1108
1109 int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
1110 {
1111   // see header file for class documentation
1112   if (CheckStatus(kRunning)) {
1113     HLTError("HLT system in running state, can not configure");
1114     return -EBUSY;
1115   }
1116   int iResult=0;
1117   AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1118   TString extralibs;
1119   while (pAgent && iResult>=0) {
1120     const char* deplibs=pAgent->GetRequiredComponentLibraries();
1121     if (deplibs) {
1122       HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1123       extralibs+=deplibs;
1124     }
1125     if (iResult>=0) {
1126       HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
1127       pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
1128       pAgent=AliHLTModuleAgent::GetNextAgent();
1129     }
1130   }
1131   if (iResult>=0) {
1132     iResult=LoadComponentLibraries(extralibs.Data());
1133   }
1134
1135   return iResult;
1136 }
1137
1138 int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
1139 {
1140   // see header file for class documentation
1141   if (CheckStatus(kRunning)) {
1142     HLTError("HLT system in running state, can not configure");
1143     return -EBUSY;
1144   }
1145   if (!CheckStatus(kConfigurationLoaded)) {
1146     HLTWarning("configurations not yet loaded");
1147     return 0;
1148   }
1149
1150   int iResult=0;
1151   int bHaveOutput=0;
1152
1153   // query chains
1154   TString chains;
1155   if (fChains.Length()>0) {
1156     chains=fChains;
1157     HLTImportant("custom reconstruction chain: %s", chains.Data());
1158   } else {
1159     AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
1160     while ((pAgent || fChains.Length()>0) && iResult>=0) {
1161       const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
1162       if (agentchains) {
1163         if (!chains.IsNull()) chains+=" ";
1164         chains+=agentchains;
1165         HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1166       }
1167       pAgent=AliHLTModuleAgent::GetNextAgent();
1168     }
1169   }
1170
1171   // build task list for chains
1172   TObjArray* pTokens=chains.Tokenize(" ");
1173   if (pTokens) {
1174     int iEntries=pTokens->GetEntries();
1175     for (int i=0; i<iEntries && iResult>=0; i++) {
1176       const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
1177       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
1178       if (pConf) {
1179         iResult=BuildTaskList(pConf);
1180         if (runloader) {
1181           assert(fpComponentHandler!=NULL);
1182           TString cid=pConf->GetComponentID();
1183           if (cid.CompareTo("HLTOUT")==0) {
1184             // remove from the input of a global HLTOUT configuration
1185             chains.ReplaceAll(pCID, "");
1186           } else if (bHaveOutput==0) {
1187             // check whether this configuration produces data output
1188             if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
1189               bHaveOutput=0;
1190               chains.ReplaceAll(pCID, "");
1191             }
1192           }
1193         }
1194       } else {
1195         HLTWarning("can not find configuration %s", pCID);
1196       }
1197     }
1198     delete pTokens;
1199   }
1200
1201   // build HLTOUT for simulation
1202   if (iResult>=0 && runloader) {
1203     if (bHaveOutput) {
1204       // there are components in the chain which produce data which need to be
1205       // piped to an HLTOUT
1206       if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
1207           fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
1208         AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
1209         iResult=BuildTaskList("_globalout_");
1210       } else {
1211         HLTError("can not load libHLTsim.so and HLTOUT component");
1212         iResult=-EFAULT;
1213       }
1214     }
1215   }
1216
1217   if (iResult>=0) SetStatusFlags(kTaskListCreated);
1218
1219   return iResult;
1220 }
1221
1222 int AliHLTSystem::CheckStatus(int flag)
1223 {
1224   // see header file for class documentation
1225   if (flag==kUninitialized && flag==fState) return 1;
1226   if ((fState&flag)==flag) return 1;
1227   return 0;
1228 }
1229
1230 int AliHLTSystem::GetStatusFlags()
1231 {
1232   // see header file for class documentation
1233   return fState;
1234 }
1235
1236 int AliHLTSystem::SetStatusFlags(int flags)
1237 {
1238   // see header file for class documentation
1239   fState|=flags;
1240   return fState;
1241 }
1242
1243 int AliHLTSystem::ClearStatusFlags(int flags)
1244 {
1245   // see header file for class documentation
1246   fState&=~flags;
1247   return fState;
1248 }
1249
1250 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1251 {
1252   // see header file for class documentation
1253   if (fpComponentHandler==NULL) return NULL;
1254   return fpComponentHandler->FindSymbol(library, symbol);
1255 }
1256
1257 void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level) 
1258 {
1259   // see header file for class documentation
1260   SetLocalLoggingLevel(level);
1261   if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1262   if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
1263 }