]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTSystem.cxx
9e30b65e72a90de8c4b96e61d724dd1c3e44f704
[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 "AliHLTStdIncludes.h"
30 #include "AliHLTSystem.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTComponent.h"
33 #include "AliHLTConfiguration.h"
34 #include "AliHLTConfigurationHandler.h"
35 #include "AliHLTTask.h"
36 #include "AliHLTModuleAgent.h"
37 #include "AliHLTOfflineInterface.h"
38 #include <TObjArray.h>
39 #include <TObjString.h>
40 #include <TStopwatch.h>
41 #include <TROOT.h>
42 #include <TInterpreter.h>
43
44 /** HLT default component libraries */
45 const char* kHLTDefaultLibs[]= {
46   "libAliHLTUtil.so", 
47   "libAliHLTTPC.so", 
48   //  "libAliHLTSample.so",
49   "libAliHLTPHOS.so",
50   //"libAliHLTMUON.so",
51   "libAliHLTTRD.so",
52   NULL
53 };
54
55 /** ROOT macro for the implementation of ROOT specific class methods */
56 ClassImp(AliHLTSystem)
57
58 AliHLTSystem::AliHLTSystem()
59   :
60   fpComponentHandler(new AliHLTComponentHandler()),
61   fpConfigurationHandler(new AliHLTConfigurationHandler()),
62   fTaskList(),
63   fState(0),
64   fLocalRec()
65 {
66   // see header file for class documentation
67   // or
68   // refer to README to build package
69   // or
70   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
71
72   if (fgNofInstances++>0)
73     HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
74
75   SetGlobalLoggingLevel(kHLTLogDefault);
76   if (fpComponentHandler) {
77     AliHLTComponentEnvironment env;
78     memset(&env, 0, sizeof(AliHLTComponentEnvironment));
79     env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
80     env.fLoggingFunc=NULL;
81     AliHLTComponentLogSeverity loglevel=fpComponentHandler->GetLocalLoggingLevel();
82     fpComponentHandler->SetLocalLoggingLevel(kHLTLogError);
83     fpComponentHandler->SetEnvironment(&env);
84     fpComponentHandler->LoadLibrary("libAliHLTUtil.so");
85     fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)fpComponentHandler->FindSymbol("libAliHLTUtil.so", "AliDynamicMessage");
86     fpComponentHandler->SetLocalLoggingLevel(loglevel);
87     if (fgAliLoggingFunc==NULL) {
88       HLTError("symbol lookp failure: can not find AliDynamicMessage, switching to HLT logging system");
89     }
90     fpComponentHandler->AnnounceVersion();
91   } else {
92     HLTFatal("can not create Component Handler");
93   }
94   if (fpConfigurationHandler) {
95     AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
96   } else {
97     HLTFatal("can not create Configuration Handler");
98   }
99 }
100
101 AliHLTSystem::~AliHLTSystem()
102 {
103   // see header file for class documentation
104   fgNofInstances--;
105   CleanTaskList();
106   AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
107   if (fpConfigurationHandler) {
108     delete fpConfigurationHandler;
109   }
110   fpConfigurationHandler=NULL;
111   
112   if (fpComponentHandler) {
113     delete fpComponentHandler;
114   }
115   fpComponentHandler=NULL;
116 }
117
118 int AliHLTSystem::fgNofInstances=0;
119
120 int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
121 {
122   // see header file for class documentation
123   int iResult=0;
124   if (pConf) {
125   } else {
126     iResult=-EINVAL;
127   }
128   return iResult;
129 }
130
131 int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
132 {
133   // see header file for class documentation
134   int iResult=0;
135   if (pConf) {
136     if (pPrec) {
137       // find the position
138     }
139   } else {
140     iResult=-EINVAL;
141   }
142   return iResult;
143 }
144
145 int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
146 {
147   // see header file for class documentation
148   int iResult=0;
149   if (pConf) {
150   } else {
151     iResult=-EINVAL;
152   }
153   return iResult;
154 }
155
156 int AliHLTSystem::BuildTaskList(const char* id)
157 {
158   // see header file for class documentation
159   int iResult=0;
160   if (id) {
161     if (fpConfigurationHandler) {
162       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id);
163       if (pConf) {
164         iResult=BuildTaskList(pConf);
165       } else {
166         HLTError("unknown configuration \"%s\"", id);
167         iResult=-EEXIST;
168       }
169     } else {
170       iResult=-EFAULT;
171     }
172   } else {
173     iResult=-EINVAL;
174   }
175   return iResult;
176 }
177
178 int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
179 {
180   // see header file for class documentation
181   int iResult=0;
182   if (pConf) {
183     AliHLTTask* pTask=NULL;
184     if ((pTask=FindTask(pConf->GetName()))!=NULL) {
185       if (pTask->GetConf()!=pConf) {
186         HLTError("configuration missmatch, there is already a task with configuration name \"%s\", but it is different. Most likely configuration %p is not registered properly", pConf->GetName(), pConf);
187         iResult=-EEXIST;
188       }
189       // task for this configuration exists, terminate
190       pTask=NULL;
191     } else if (pConf->SourcesResolved(1)!=1) {
192         HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
193         iResult=-ENOLINK;
194     } else {
195       pTask=new AliHLTTask(pConf);
196       if (pTask==NULL) {
197         iResult=-ENOMEM;
198       }
199     }
200     static int iterationLevel=0;
201     if (pTask && iResult>=0) {
202       // check for circular dependencies
203       if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
204         HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
205         pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
206         HLTError("aborted ...");
207         iResult=-ELOOP;
208       }
209       if (iResult>=0) {
210         // check whether all dependencies are already in the task list
211         // create the missing ones
212         // this step is an iterative process which calls this function again for the missing
213         // configurations, in order to avoid the currently processed task to be created
214         // again it is added to the list temporarily and removed afterwards
215         // This is of high importance to preserve the order of the tasks. Furthermore, the
216         // InsertTask method has to be used in order to set all the cross links right 
217         fTaskList.Add(pTask);
218         AliHLTConfiguration* pDep=pConf->GetFirstSource();
219         while (pDep!=NULL && iResult>=0) {
220           HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
221           if (FindTask(pDep->GetName())==NULL) {
222             HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
223             iterationLevel++;
224             iResult=BuildTaskList(pDep);
225             iterationLevel--;
226           }
227           pDep=pConf->GetNextSource();
228         }
229         // remove the temporarily added task
230         fTaskList.Remove(pTask);
231
232         // insert the task and set the cross-links
233         if (iResult>=0) {
234           HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
235           iResult=InsertTask(pTask);
236         }
237       } else {
238         delete pTask;
239         pTask=NULL;
240       }
241     }
242   } else {
243     iResult=-EINVAL;
244   }
245   return iResult;
246 }
247
248 int AliHLTSystem::CleanTaskList()
249 {
250   // see header file for class documentation
251   int iResult=0;
252   TObjLink* lnk=NULL;
253   while ((lnk=fTaskList.LastLink())!=NULL) {
254     delete (lnk->GetObject());
255     fTaskList.Remove(lnk);
256   }
257   return iResult;
258 }
259
260 int AliHLTSystem::InsertTask(AliHLTTask* pTask)
261 {
262   // see header file for class documentation
263   int iResult=0;
264   TObjLink *lnk = NULL;
265   if ((iResult=pTask->CheckDependencies())>0)
266     lnk=fTaskList.FirstLink();
267   while (lnk && iResult>0) {
268     AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject();
269     //HLTDebug("checking  \"%s\"", pCurr->GetName());
270     iResult=pTask->Depends(pCurr);
271     if (iResult>0) {
272       iResult=pTask->SetDependency(pCurr);
273       pCurr->SetTarget(pTask);
274       HLTDebug("set dependency  \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
275     }
276     if (pCurr->Depends(pTask)) {
277       // circular dependency
278       HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
279       iResult=-ELOOP;
280     } else if ((iResult=pTask->CheckDependencies())>0) {
281       lnk = lnk->Next();
282     }
283   }
284   if (iResult==0) {
285       if (lnk) {
286         fTaskList.AddAfter(lnk, pTask);
287       } else {
288         fTaskList.AddFirst(pTask);
289       }
290       HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
291   } else if (iResult>0) {
292     HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
293     iResult=-ENOLINK;
294   }
295   return iResult;
296 }
297
298 AliHLTTask* AliHLTSystem::FindTask(const char* id)
299 {
300   // see header file for class documentation
301   AliHLTTask* pTask=NULL;
302   if (id) {
303     pTask=(AliHLTTask*)fTaskList.FindObject(id); 
304   }
305   return pTask;
306 }
307
308 void AliHLTSystem::PrintTaskList()
309 {
310   // see header file for class documentation
311   HLTLogKeyword("task list");
312   TObjLink *lnk = NULL;
313   HLTMessage("Task List");
314   lnk=fTaskList.FirstLink();
315   while (lnk) {
316     TObject* obj=lnk->GetObject();
317     if (obj) {
318       HLTMessage("  %s - status:", obj->GetName());
319       AliHLTTask* pTask=(AliHLTTask*)obj;
320       pTask->PrintStatus();
321     } else {
322     }
323     lnk = lnk->Next();
324   }
325 }
326
327 int AliHLTSystem::Run(Int_t iNofEvents) 
328 {
329   // see header file for class documentation
330   int iResult=0;
331   int iCount=0;
332   SetStatusFlags(kRunning);
333   TStopwatch StopwatchBase; StopwatchBase.Reset();
334   TStopwatch StopwatchDA; StopwatchDA.Reset();
335   TStopwatch StopwatchInput; StopwatchInput.Reset();
336   TStopwatch StopwatchOutput; StopwatchOutput.Reset();
337   TObjArray Stopwatches;
338   Stopwatches.AddAt(&StopwatchBase, (int)AliHLTComponent::kSWBase);
339   Stopwatches.AddAt(&StopwatchDA, (int)AliHLTComponent::kSWDA);
340   Stopwatches.AddAt(&StopwatchInput, (int)AliHLTComponent::kSWInput);
341   Stopwatches.AddAt(&StopwatchOutput, (int)AliHLTComponent::kSWOutput);
342   if ((iResult=InitTasks())>=0 && (iResult=InitBenchmarking(&Stopwatches))>=0) {
343     if ((iResult=StartTasks())>=0) {
344       for (int i=0; i<iNofEvents && iResult>=0; i++) {
345         iResult=ProcessTasks(i);
346         if (iResult>=0) {
347           HLTInfo("Event %d successfully finished (%d)", i, iResult);
348           iResult=0;
349           iCount++;
350         } else {
351           HLTError("Processing of event %d failed (%d)", i, iResult);
352           // TODO: define different running modes to either ignore errors in
353           // event processing or not
354           // currently ignored 
355           //iResult=0;
356         }
357       }
358       StopTasks();
359     } else {
360       HLTError("can not start task list");
361     }
362     DeinitTasks();
363   } else if (iResult!=-ENOENT) {
364     HLTError("can not initialize task list");
365   }
366   if (iResult>=0) {
367     iResult=iCount;
368     HLTInfo("HLT statistics:\n"
369             "    base:              R:%.3fs C:%.3fs\n"
370             "    input:             R:%.3fs C:%.3fs\n"
371             "    output:            R:%.3fs C:%.3fs\n"
372             "    event processing : R:%.3fs C:%.3fs"
373             , StopwatchBase.RealTime(),StopwatchBase.CpuTime()
374             , StopwatchInput.RealTime(),StopwatchInput.CpuTime()
375             , StopwatchOutput.RealTime(),StopwatchOutput.CpuTime()
376             , StopwatchDA.RealTime(),StopwatchDA.CpuTime());
377   } else  if (iResult==-ENOENT) {
378     iResult=0; // do not propagate the error
379   }
380   ClearStatusFlags(kRunning);
381   return iResult;
382 }
383
384 int AliHLTSystem::InitTasks()
385 {
386   // see header file for class documentation
387   int iResult=0;
388   TObjLink *lnk=fTaskList.FirstLink();
389   if (lnk==NULL) {
390     HLTWarning("Task list is empty, aborting ...");
391     return -ENOENT;
392   }
393   while (lnk && iResult>=0) {
394     TObject* obj=lnk->GetObject();
395     if (obj) {
396       AliHLTTask* pTask=(AliHLTTask*)obj;
397       iResult=pTask->Init(NULL, fpComponentHandler);
398     } else {
399     }
400     lnk = lnk->Next();
401   }
402   if (iResult<0) {
403   }
404   return iResult;
405 }
406
407 int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
408 {
409   // see header file for class documentation
410   if (pStopwatches==NULL) return -EINVAL;
411
412   int iResult=0;
413   TObjLink *lnk=fTaskList.FirstLink();
414   while (lnk && iResult>=0) {
415     TObject* obj=lnk->GetObject();
416     if (obj) {
417       AliHLTTask* pTask=(AliHLTTask*)obj;
418       AliHLTComponent* pComp=NULL;
419       if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) {
420         switch (pComp->GetComponentType()) {
421         case AliHLTComponent::kProcessor:
422           pComp->SetStopwatches(pStopwatches);
423           break;
424         case AliHLTComponent::kSource:
425           {
426             // this switch determines whether the time consumption of the
427             // AliHLTComponent base methods should be counted to the input
428             // stopwatch or base stopwatch.
429             //int inputBase=(int)AliHLTComponent::kSWBase;
430             int inputBase=(int)AliHLTComponent::kSWInput;
431             pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase);
432             pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA);
433           }
434           break;
435         case AliHLTComponent::kSink:
436           {
437             // this switch determines whether the time consumption of the
438             // AliHLTComponent base methods should be counted to the output
439             // stopwatch or base stopwatch.
440             //int outputBase=(int)AliHLTComponent::kSWBase;
441             int outputBase=(int)AliHLTComponent::kSWOutput;
442             pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase);
443             pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA);
444           }
445           break;
446         default:
447           HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
448         }
449       }
450     } else {
451     }
452     lnk = lnk->Next();
453   }
454   return iResult;
455 }
456
457 int AliHLTSystem::StartTasks()
458 {
459   // see header file for class documentation
460   int iResult=0;
461   TObjLink *lnk=fTaskList.FirstLink();
462   while (lnk && iResult>=0) {
463     TObject* obj=lnk->GetObject();
464     if (obj) {
465       AliHLTTask* pTask=(AliHLTTask*)obj;
466       iResult=pTask->StartRun();
467     } else {
468     }
469     lnk = lnk->Next();
470   }
471   if (iResult<0) {
472   }
473   return iResult;
474 }
475
476 int AliHLTSystem::ProcessTasks(Int_t eventNo)
477 {
478   // see header file for class documentation
479   int iResult=0;
480   HLTDebug("processing event no %d", eventNo);
481   TObjLink *lnk=fTaskList.FirstLink();
482   while (lnk && iResult>=0) {
483     TObject* obj=lnk->GetObject();
484     if (obj) {
485       AliHLTTask* pTask=(AliHLTTask*)obj;
486       iResult=pTask->ProcessTask(eventNo);
487       HLTDebug("task %s finnished (%d)", pTask->GetName(), iResult);
488     } else {
489     }
490     lnk = lnk->Next();
491   }
492   return iResult;
493 }
494
495 int AliHLTSystem::StopTasks()
496 {
497   // see header file for class documentation
498   int iResult=0;
499   TObjLink *lnk=fTaskList.FirstLink();
500   while (lnk && iResult>=0) {
501     TObject* obj=lnk->GetObject();
502     if (obj) {
503       AliHLTTask* pTask=(AliHLTTask*)obj;
504       iResult=pTask->EndRun();
505     } else {
506     }
507     lnk = lnk->Next();
508   }
509   return iResult;
510 }
511
512 int AliHLTSystem::DeinitTasks()
513 {
514   // see header file for class documentation
515   int iResult=0;
516   TObjLink *lnk=fTaskList.FirstLink();
517   while (lnk && iResult>=0) {
518     TObject* obj=lnk->GetObject();
519     if (obj) {
520       AliHLTTask* pTask=(AliHLTTask*)obj;
521       iResult=pTask->Deinit();
522     } else {
523     }
524     lnk = lnk->Next();
525   }
526   return iResult;
527 }
528
529 void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
530 {
531   // see header file for class documentation
532   void* p=NULL;
533   try {
534     p=(void*)new char[size];
535   }
536   catch (...) {
537     AliHLTLogging log;
538     log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
539   }
540   return p;
541 }
542
543 int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader, 
544                               AliRawReader* rawReader)
545 {
546   // see header file for class documentation
547   int iResult=0;
548   if (runLoader) {
549     HLTInfo("Run Loader %p, Raw Reader %p , %d events", runLoader, rawReader, nofEvents);
550     if (CheckStatus(kReady)) {
551       if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
552         iResult=Run(nofEvents);
553       }
554     } else {
555       HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
556     }
557   } else {
558     HLTError("missing run loader instance");
559     iResult=-EINVAL;
560   }
561   return iResult;
562 }
563
564 int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
565 {
566   // see header file for class documentation
567   int iResult=0;
568   if (runLoader) {
569     HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
570     iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
571   } else {
572     HLTError("missing run loader/ESD instance(s)");
573     iResult=-EINVAL;
574   }
575   return iResult;
576 }
577
578 int AliHLTSystem::LoadComponentLibraries(const char* libraries)
579 {
580   // see header file for class documentation
581   int iResult=0;
582   if (libraries) {
583     if (fpComponentHandler) {
584       TString libs(libraries);
585       TObjArray* pTokens=libs.Tokenize(" ");
586       if (pTokens) {
587         int iEntries=pTokens->GetEntries();
588         for (int i=0; i<iEntries && iResult>=0; i++) {
589           iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
590         }
591         delete pTokens;
592       }
593       if (iResult>=0) {
594         SetStatusFlags(kLibrariesLoaded);
595       } else {
596         // lets see if we need this, probably not
597         //fpComponentHandler->UnloadLibraries();
598         ClearStatusFlags(kLibrariesLoaded);
599       }
600     } else {
601       iResult=-EFAULT;
602       HLTFatal("no component handler available");
603     }
604   } else {
605     iResult=-EINVAL;
606   }
607   return iResult;
608 }
609
610 int AliHLTSystem::Configure(AliRunLoader* runloader)
611 {
612   // see header file for class documentation
613   int iResult=0;
614   if (CheckStatus(kRunning)) {
615     HLTError("HLT system in running state, can not configure");
616     return -EBUSY;
617   }
618   ClearStatusFlags(kConfigurationLoaded|kTaskListCreated);
619   if (CheckFilter(kHLTLogDebug))
620     AliHLTModuleAgent::PrintStatus();
621   if (CheckStatus(kConfigurationLoaded)==0) {
622     iResult=LoadConfigurations(runloader);
623   } else {
624     if (fLocalRec.Length()==0) {
625       HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'localrec=<conf>\' option");
626       iResult=-ENOENT;
627     }
628   }
629   if (iResult>=0) {
630     SetStatusFlags(kConfigurationLoaded);
631     if (CheckFilter(kHLTLogDebug))
632       fpConfigurationHandler->PrintConfigurations();
633     iResult=BuildTaskListsFromTopConfigurations(runloader);
634     if (iResult>=0) {
635       SetStatusFlags(kTaskListCreated);
636     }
637   }
638   if (iResult<0) SetStatusFlags(kError);
639   
640   return iResult;
641 }
642
643 int AliHLTSystem::ScanOptions(const char* options)
644 {
645   // see header file for class documentation
646   int iResult=0;
647   if (options) {
648     TString libs("");
649     TString alloptions(options);
650     TObjArray* pTokens=alloptions.Tokenize(" ");
651     if (pTokens) {
652       int iEntries=pTokens->GetEntries();
653       for (int i=0; i<iEntries; i++) {
654         TString token=(((TObjString*)pTokens->At(i))->GetString());
655         if (token.Contains("loglevel=")) {
656           TString param=token.ReplaceAll("loglevel=", "");
657           if (param.IsDigit()) {
658             SetGlobalLoggingLevel((AliHLTComponentLogSeverity)param.Atoi());
659           } else if (param.BeginsWith("0x") &&
660                      param.Replace(0,2,"",0).IsHex()) {
661             int severity=0;
662             sscanf(param.Data(),"%x", &severity);
663             SetGlobalLoggingLevel((AliHLTComponentLogSeverity)severity);
664           } else {
665             HLTWarning("wrong parameter for option \'loglevel=\', (hex) number expected");
666           }
667         } else if (token.Contains("alilog=off")) {
668           SwitchAliLog(0);
669         } else if (token.Contains("config=")) {
670           TString param=token.ReplaceAll("config=", "");
671           Int_t error=0;
672           gROOT->Macro(param.Data(), &error);
673           if (error==0) {
674             SetStatusFlags(kConfigurationLoaded);
675           } else {
676             HLTError("can not execute macro \'%s\'", param.Data());
677             iResult=-EBADF;
678           }
679         } else if (token.Contains("localrec=")) {
680           TString param=token.ReplaceAll("localrec=", "");
681           fLocalRec=param.ReplaceAll(",", " ");
682         } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
683           libs+=token;
684           libs+=" ";
685         } else {
686           HLTWarning("unknown option \'%s\'", token.Data());
687         }
688       }
689       delete pTokens;
690     }
691
692     if (iResult>=0) {
693       if (libs.IsNull()) {
694         const char** deflib=kHLTDefaultLibs;
695         while (*deflib) {
696           libs+=*deflib++;
697           libs+=" ";
698         }
699       }
700       if ((!CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
701           (LoadComponentLibraries(libs.Data())<0)) {
702         HLTError("error while loading HLT libraries");
703         iResult=-EFAULT;
704       }
705     }
706   }
707   return iResult;
708 }
709
710 int AliHLTSystem::Reset(int bForce)
711 {
712   // see header file for class documentation
713   int iResult=0;
714   if (!bForce && CheckStatus(kRunning)) {
715     HLTError("HLT system in running state, can not configure");
716     return -EBUSY;
717   }
718   CleanTaskList();
719   ClearStatusFlags(~kUninitialized);
720   return iResult;
721 }
722
723 int AliHLTSystem::LoadConfigurations(AliRunLoader* runloader)
724 {
725   // see header file for class documentation
726   if (CheckStatus(kRunning)) {
727     HLTError("HLT system in running state, can not configure");
728     return -EBUSY;
729   }
730   int iResult=0;
731   AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
732   while (pAgent && iResult>=0) {
733     const char* deplibs=pAgent->GetRequiredComponentLibraries();
734     if (deplibs) {
735       HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
736       iResult=LoadComponentLibraries(deplibs);
737     }
738     if (iResult>=0) {
739       HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
740       pAgent->CreateConfigurations(fpConfigurationHandler, runloader);
741       pAgent=AliHLTModuleAgent::GetNextAgent();
742     }
743   }
744   return iResult;
745 }
746
747 int AliHLTSystem::BuildTaskListsFromTopConfigurations(AliRunLoader* runloader)
748 {
749   // see header file for class documentation
750   if (CheckStatus(kRunning)) {
751     HLTError("HLT system in running state, can not configure");
752     return -EBUSY;
753   }
754   if (!CheckStatus(kConfigurationLoaded)) {
755     HLTWarning("configurations not yet loaded");
756     return 0;
757   }
758
759   int iResult=0;
760   AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
761   while ((pAgent || fLocalRec.Length()>0) && iResult>=0) {
762     TString tops;
763     if (fLocalRec.Length()>0) {
764       tops=fLocalRec;
765       HLTInfo("custom local reconstruction configurations: %s", tops.Data());
766     } else {
767       tops=pAgent->GetLocalRecConfigurations(runloader);
768       HLTInfo("local reconstruction configurations for agent %s (%p): %s", pAgent->GetName(), pAgent, tops.Data());
769     }
770     TObjArray* pTokens=tops.Tokenize(" ");
771     if (pTokens) {
772       int iEntries=pTokens->GetEntries();
773       for (int i=0; i<iEntries && iResult>=0; i++) {
774         const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
775         AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
776         if (pConf) {
777           iResult=BuildTaskList(pConf);
778         } else {
779           HLTWarning("can not find top configuration %s", pCID);
780         }
781       }
782       delete pTokens;
783     }
784     
785     if (fLocalRec.Length()>0) {
786       break; // ignore the agents
787     }
788     pAgent=AliHLTModuleAgent::GetNextAgent();
789   }
790   if (iResult>=0) SetStatusFlags(kTaskListCreated);
791
792   return iResult;
793 }
794
795 int AliHLTSystem::CheckStatus(int flag)
796 {
797   // see header file for class documentation
798   if (flag==kUninitialized && flag==fState) return 1;
799   if ((fState&flag)==flag) return 1;
800   return 0;
801 }
802
803 int AliHLTSystem::GetStatusFlags()
804 {
805   // see header file for class documentation
806   return fState;
807 }
808
809 int AliHLTSystem::SetStatusFlags(int flags)
810 {
811   // see header file for class documentation
812   fState|=flags;
813   return fState;
814 }
815
816 int AliHLTSystem::ClearStatusFlags(int flags)
817 {
818   // see header file for class documentation
819   fState&=~flags;
820   return fState;
821 }
822
823 void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
824 {
825   // see header file for class documentation
826   if (fpComponentHandler==NULL) return NULL;
827   return fpComponentHandler->FindSymbol(library, symbol);
828 }