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