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