]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTSystem.cxx
bugfix: check for output buffer size
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
CommitLineData
f23a6e1a 1// $Id$
2
c5123824 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//**************************************************************************
f23a6e1a 18
b22e91eb 19/** @file AliHLTSystem.cxx
20 @author Matthias Richter
21 @date
22 @brief Implementation of HLT module management.
23*/
f23a6e1a 24
0c0c9d99 25#if __GNUC__>= 3
f23a6e1a 26using namespace std;
27#endif
28
f3506ea2 29#include <cassert>
85869391 30#include "AliHLTStdIncludes.h"
f23a6e1a 31#include "AliHLTSystem.h"
32#include "AliHLTComponentHandler.h"
33#include "AliHLTComponent.h"
5ec8e281 34#include "AliHLTConfiguration.h"
c38ba6f9 35#include "AliHLTConfigurationHandler.h"
36#include "AliHLTTask.h"
242bb794 37#include "AliHLTModuleAgent.h"
8451168b 38#include "AliHLTOfflineInterface.h"
457ec821 39#include "AliHLTDataSource.h"
c5123824 40#include "AliHLTOUT.h"
41#include "AliHLTOUTHandler.h"
242bb794 42#include <TObjArray.h>
43#include <TObjString.h>
90ebac25 44#include <TStopwatch.h>
dba03d72 45//#include <TSystem.h>
c043fa2c 46#include <TROOT.h>
6a8e0bb4 47//#include <TInterpreter.h>
f23a6e1a 48
83670b1d 49/** HLT default component libraries */
6a8e0bb4 50const char* AliHLTSystem::fgkHLTDefaultLibs[]= {
83670b1d 51 "libAliHLTUtil.so",
8f471af0 52 "libAliHLTRCU.so",
83670b1d 53 "libAliHLTTPC.so",
54 // "libAliHLTSample.so",
511b6d88 55 //"libAliHLTPHOS.so",
887a669c 56 "libAliHLTMUON.so",
83670b1d 57 "libAliHLTTRD.so",
c5123824 58 "libAliHLTTrigger.so",
83670b1d 59 NULL
60};
61
b22e91eb 62/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 63ClassImp(AliHLTSystem)
64
83cb7e1d 65AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel)
85869391 66 :
b005ef92 67 fpComponentHandler(AliHLTComponentHandler::CreateHandler()),
68 fpConfigurationHandler(AliHLTConfigurationHandler::CreateHandler()),
242bb794 69 fTaskList(),
c043fa2c 70 fState(0),
dee38f1b 71 fChains(),
72 fStopwatches(new TObjArray),
73 fEventCount(-1),
b005ef92 74 fGoodEvents(-1),
75 fpChainHandlers(NULL),
76 fpEsdHandlers(NULL),
77 fpProprietaryHandlers(NULL)
f23a6e1a 78{
70ed7d01 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
5f5b708b 84
b005ef92 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 }
fc455fba 90
83cb7e1d 91 SetGlobalLoggingLevel(loglevel);
92 SetFrameworkLog(loglevel);
f23a6e1a 93 if (fpComponentHandler) {
94 AliHLTComponentEnvironment env;
95 memset(&env, 0, sizeof(AliHLTComponentEnvironment));
9ce4bf4a 96 env.fAllocMemoryFunc=AliHLTSystem::AllocMemory;
fc455fba 97 env.fLoggingFunc=NULL;
f23a6e1a 98 fpComponentHandler->SetEnvironment(&env);
db95fec3 99 InitAliLogFunc(fpComponentHandler);
a742f6f8 100 fpComponentHandler->AnnounceVersion();
85465857 101 } else {
102 HLTFatal("can not create Component Handler");
103 }
85465857 104 if (fpConfigurationHandler) {
105 AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
106 } else {
107 HLTFatal("can not create Configuration Handler");
f23a6e1a 108 }
109}
110
f23a6e1a 111AliHLTSystem::~AliHLTSystem()
112{
70ed7d01 113 // see header file for class documentation
fc455fba 114 fgNofInstances--;
2d7ff710 115 CleanTaskList();
fc455fba 116 AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
2d7ff710 117 if (fpConfigurationHandler) {
b005ef92 118 fpConfigurationHandler->Destroy();
2d7ff710 119 }
120 fpConfigurationHandler=NULL;
121
122 if (fpComponentHandler) {
b005ef92 123 fpComponentHandler->Destroy();
2d7ff710 124 }
125 fpComponentHandler=NULL;
f23a6e1a 126}
127
fc455fba 128int AliHLTSystem::fgNofInstances=0;
129
5ec8e281 130int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf)
131{
70ed7d01 132 // see header file for class documentation
6a8e0bb4 133 HLTLogKeyword("configuration handling");
5ec8e281 134 int iResult=0;
53feaef5 135 if (pConf) {
6a8e0bb4 136 HLTError("function not yet implemented");
137 iResult=-ENOSYS;
53feaef5 138 } else {
139 iResult=-EINVAL;
140 }
5ec8e281 141 return iResult;
142}
143
014d39ce 144int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec)
145{
70ed7d01 146 // see header file for class documentation
6a8e0bb4 147 HLTLogKeyword("configuration handling");
014d39ce 148 int iResult=0;
53feaef5 149 if (pConf) {
150 if (pPrec) {
151 // find the position
6a8e0bb4 152 HLTError("function not yet implemented");
153 iResult=-ENOSYS;
53feaef5 154 }
155 } else {
156 iResult=-EINVAL;
157 }
014d39ce 158 return iResult;
159}
5ec8e281 160
161int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf)
162{
70ed7d01 163 // see header file for class documentation
6a8e0bb4 164 HLTLogKeyword("configuration handling");
5ec8e281 165 int iResult=0;
53feaef5 166 if (pConf) {
6a8e0bb4 167 HLTError("function not yet implemented");
168 iResult=-ENOSYS;
53feaef5 169 } else {
170 iResult=-EINVAL;
171 }
5ec8e281 172 return iResult;
173}
174
a742f6f8 175int 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
5ec8e281 197int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
198{
70ed7d01 199 // see header file for class documentation
f23a6e1a 200 int iResult=0;
5ec8e281 201 if (pConf) {
202 AliHLTTask* pTask=NULL;
203 if ((pTask=FindTask(pConf->GetName()))!=NULL) {
204 if (pTask->GetConf()!=pConf) {
c5123824 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);
5ec8e281 206 iResult=-EEXIST;
5ec8e281 207 }
c043fa2c 208 // task for this configuration exists, terminate
209 pTask=NULL;
5ec8e281 210 } else if (pConf->SourcesResolved(1)!=1) {
85465857 211 HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
5ec8e281 212 iResult=-ENOLINK;
213 } else {
53feaef5 214 pTask=new AliHLTTask(pConf);
5ec8e281 215 if (pTask==NULL) {
216 iResult=-ENOMEM;
dba03d72 217 } else {
218 pTask->SetLocalLoggingLevel(GetLocalLoggingLevel());
5ec8e281 219 }
220 }
c043fa2c 221 static int iterationLevel=0;
222 if (pTask && iResult>=0) {
3b35e87c 223 // check for circular dependencies
5ec8e281 224 if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) {
3b35e87c 225 HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName());
5ec8e281 226 pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/);
85465857 227 HLTError("aborted ...");
5ec8e281 228 iResult=-ELOOP;
229 }
230 if (iResult>=0) {
231 // check whether all dependencies are already in the task list
232 // create the missing ones
3b35e87c 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
5ec8e281 238 fTaskList.Add(pTask);
239 AliHLTConfiguration* pDep=pConf->GetFirstSource();
240 while (pDep!=NULL && iResult>=0) {
c043fa2c 241 HLTDebug("iteration %d: checking dependency %s (%p)", iterationLevel, pDep->GetName(), pDep);
5ec8e281 242 if (FindTask(pDep->GetName())==NULL) {
c043fa2c 243 HLTDebug("iteration %d: building task list for configuration %s (%p)", iterationLevel, pDep->GetName(), pDep);
244 iterationLevel++;
5ec8e281 245 iResult=BuildTaskList(pDep);
c043fa2c 246 iterationLevel--;
5ec8e281 247 }
248 pDep=pConf->GetNextSource();
249 }
3b35e87c 250 // remove the temporarily added task
5ec8e281 251 fTaskList.Remove(pTask);
252
253 // insert the task and set the cross-links
254 if (iResult>=0) {
c043fa2c 255 HLTDebug("iteration %d: inserting task %s (%p)", iterationLevel, pTask->GetName(), pTask);
5ec8e281 256 iResult=InsertTask(pTask);
257 }
258 } else {
259 delete pTask;
260 pTask=NULL;
261 }
262 }
263 } else {
264 iResult=-EINVAL;
f23a6e1a 265 }
f23a6e1a 266 return iResult;
267}
268
5ec8e281 269int AliHLTSystem::CleanTaskList()
270{
70ed7d01 271 // see header file for class documentation
5ec8e281 272 int iResult=0;
273 TObjLink* lnk=NULL;
a742f6f8 274 while ((lnk=fTaskList.LastLink())!=NULL) {
5ec8e281 275 delete (lnk->GetObject());
a742f6f8 276 fTaskList.Remove(lnk);
5ec8e281 277 }
278 return iResult;
279}
280
281int AliHLTSystem::InsertTask(AliHLTTask* pTask)
282{
70ed7d01 283 // see header file for class documentation
5ec8e281 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();
85465857 290 //HLTDebug("checking \"%s\"", pCurr->GetName());
5ec8e281 291 iResult=pTask->Depends(pCurr);
292 if (iResult>0) {
293 iResult=pTask->SetDependency(pCurr);
294 pCurr->SetTarget(pTask);
85465857 295 HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName());
f23a6e1a 296 }
5ec8e281 297 if (pCurr->Depends(pTask)) {
3b35e87c 298 // circular dependency
299 HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName());
5ec8e281 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 }
a742f6f8 311 HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask));
5ec8e281 312 } else if (iResult>0) {
85465857 313 HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult);
5ec8e281 314 iResult=-ENOLINK;
f23a6e1a 315 }
5ec8e281 316 return iResult;
f23a6e1a 317}
318
5ec8e281 319AliHLTTask* AliHLTSystem::FindTask(const char* id)
320{
70ed7d01 321 // see header file for class documentation
5ec8e281 322 AliHLTTask* pTask=NULL;
323 if (id) {
f3506ea2 324 pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id));
5ec8e281 325 }
326 return pTask;
327}
f23a6e1a 328
5ec8e281 329void AliHLTSystem::PrintTaskList()
330{
70ed7d01 331 // see header file for class documentation
85465857 332 HLTLogKeyword("task list");
5ec8e281 333 TObjLink *lnk = NULL;
85465857 334 HLTMessage("Task List");
5ec8e281 335 lnk=fTaskList.FirstLink();
336 while (lnk) {
337 TObject* obj=lnk->GetObject();
338 if (obj) {
85465857 339 HLTMessage(" %s - status:", obj->GetName());
5ec8e281 340 AliHLTTask* pTask=(AliHLTTask*)obj;
341 pTask->PrintStatus();
342 } else {
343 }
344 lnk = lnk->Next();
345 }
346}
014d39ce 347
dee38f1b 348int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
014d39ce 349{
70ed7d01 350 // see header file for class documentation
014d39ce 351 int iResult=0;
242bb794 352 int iCount=0;
353 SetStatusFlags(kRunning);
dee38f1b 354 if (fEventCount>=0 || (iResult=InitTasks())>=0) {
355 if (fEventCount>=0 || (iResult=StartTasks())>=0) {
356 if (fEventCount==0) {
357 InitBenchmarking(fStopwatches);
358 } else {
032c5e5e 359 ResumeBenchmarking(fStopwatches);
dee38f1b 360 }
361 for (int i=fEventCount; i<fEventCount+iNofEvents && iResult>=0; i++) {
362 if ((iResult=ProcessTasks(i))>=0) {
363 fGoodEvents++;
242bb794 364 iCount++;
9ce4bf4a 365 } else {
9ce4bf4a 366 // TODO: define different running modes to either ignore errors in
367 // event processing or not
368 // currently ignored
dee38f1b 369 iResult=0;
9ce4bf4a 370 }
2d7ff710 371 }
dee38f1b 372 fEventCount+=iNofEvents;
373 if (bStop) StopTasks();
032c5e5e 374 else PauseBenchmarking(fStopwatches);
53feaef5 375 }
dee38f1b 376 if (bStop) DeinitTasks();
9ce4bf4a 377 }
90ebac25 378 if (iResult>=0) {
379 iResult=iCount;
ba7f962b 380 } else if (iResult==-126 /*ENOKEY*/) {
83670b1d 381 iResult=0; // do not propagate the error
90ebac25 382 }
242bb794 383 ClearStatusFlags(kRunning);
9ce4bf4a 384 return iResult;
385}
386
387int AliHLTSystem::InitTasks()
388{
70ed7d01 389 // see header file for class documentation
9ce4bf4a 390 int iResult=0;
391 TObjLink *lnk=fTaskList.FirstLink();
dee38f1b 392
fc455fba 393 if (lnk==NULL) {
3d6633ff 394 HLTWarning("Task list is empty, skipping HLT");
ba7f962b 395 return -126 /*ENOKEY*/;
fc455fba 396 }
9ce4bf4a 397 while (lnk && iResult>=0) {
398 TObject* obj=lnk->GetObject();
399 if (obj) {
400 AliHLTTask* pTask=(AliHLTTask*)obj;
401 iResult=pTask->Init(NULL, fpComponentHandler);
dba03d72 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);
9ce4bf4a 405 } else {
406 }
407 lnk = lnk->Next();
408 }
409 if (iResult<0) {
dee38f1b 410 HLTError("can not initialize task list, error %d", iResult);
53feaef5 411 }
dee38f1b 412
53feaef5 413 return iResult;
414}
415
90ebac25 416int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches)
417{
418 // see header file for class documentation
90ebac25 419 int iResult=0;
dee38f1b 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
90ebac25 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;
85f0cede 466 default:
467 HLTWarning("unknown component type %d", (int)pComp->GetComponentType());
90ebac25 468 }
469 }
470 } else {
471 }
472 lnk = lnk->Next();
473 }
474 return iResult;
475}
476
032c5e5e 477int 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
490int 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
503int AliHLTSystem::PrintBenchmarking(TObjArray* pStopwatches, int bClean) const
dee38f1b 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) {
032c5e5e 517 HLTImportant("HLT statistics:\n"
dee38f1b 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
53feaef5 542int AliHLTSystem::StartTasks()
543{
70ed7d01 544 // see header file for class documentation
53feaef5 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();
dba03d72 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);
53feaef5 555 } else {
556 }
557 lnk = lnk->Next();
558 }
559 if (iResult<0) {
dee38f1b 560 HLTError("can not start task list, error %d", iResult);
561 } else {
3dd8541e 562 SetStatusFlags(kStarted);
dee38f1b 563 fEventCount=0;
564 fGoodEvents=0;
457ec821 565 if ((iResult=SendControlEvent(kAliHLTDataTypeSOR))<0) {
566 HLTError("can not send SOR event");
567 }
53feaef5 568 }
569 return iResult;
570}
571
572int AliHLTSystem::ProcessTasks(Int_t eventNo)
573{
70ed7d01 574 // see header file for class documentation
53feaef5 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;
9ce4bf4a 582 iResult=pTask->ProcessTask(eventNo);
dba03d72 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);
53feaef5 586 } else {
587 }
588 lnk = lnk->Next();
589 }
dee38f1b 590
591 if (iResult>=0) {
8f471af0 592 HLTImportant("Event %d successfully finished (%d)", eventNo, iResult);
dee38f1b 593 iResult=0;
594 } else {
595 HLTError("Processing of event %d failed (%d)", eventNo, iResult);
596 }
597
53feaef5 598 return iResult;
599}
600
601int AliHLTSystem::StopTasks()
602{
70ed7d01 603 // see header file for class documentation
53feaef5 604 int iResult=0;
457ec821 605 if ((iResult=SendControlEvent(kAliHLTDataTypeEOR))<0) {
606 HLTError("can not send EOR event");
607 }
53feaef5 608 TObjLink *lnk=fTaskList.FirstLink();
457ec821 609 while (lnk) {
53feaef5 610 TObject* obj=lnk->GetObject();
611 if (obj) {
612 AliHLTTask* pTask=(AliHLTTask*)obj;
457ec821 613 int locResult=pTask->EndRun();
614 if (iResult>=0 && locResult<0) iResult=locResult;
dba03d72 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);
53feaef5 618 } else {
619 }
620 lnk = lnk->Next();
621 }
dee38f1b 622 PrintBenchmarking(fStopwatches, 1 /*clean*/);
3dd8541e 623 ClearStatusFlags(kStarted);
014d39ce 624 return iResult;
625}
9ce4bf4a 626
457ec821 627int 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
9ce4bf4a 654int AliHLTSystem::DeinitTasks()
655{
70ed7d01 656 // see header file for class documentation
9ce4bf4a 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();
dba03d72 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);
9ce4bf4a 667 } else {
668 }
669 lnk = lnk->Next();
670 }
dee38f1b 671 fEventCount=-1;
672 fGoodEvents=-1;
673
9ce4bf4a 674 return iResult;
675}
676
c043fa2c 677void* AliHLTSystem::AllocMemory( void* /*param*/, unsigned long size )
9ce4bf4a 678{
70ed7d01 679 // see header file for class documentation
c043fa2c 680 void* p=NULL;
681 try {
682 p=(void*)new char[size];
242bb794 683 }
c043fa2c 684 catch (...) {
685 AliHLTLogging log;
686 log.LoggingVarargs(kHLTLogError, "AliHLTSystem" , "AllocMemory" , __FILE__ , __LINE__ , "exeption during memory allocation" );
687 }
688 return p;
9ce4bf4a 689}
242bb794 690
691int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
692 AliRawReader* rawReader)
693{
694 // see header file for class documentation
695 int iResult=0;
dee38f1b 696 if (runLoader || rawReader || nofEvents==0) {
697 if (nofEvents>0) {HLTInfo("Run Loader %p, Raw Reader %p , %d event(s)", runLoader, rawReader, nofEvents);}
242bb794 698 if (CheckStatus(kReady)) {
dee38f1b 699 if (nofEvents==0) {
700 // special case to close the reconstruction
f3506ea2 701 if (!CheckStatus(kError)) {
dee38f1b 702 StopTasks();
703 DeinitTasks();
f3506ea2 704 }
dee38f1b 705 } else {
8451168b 706 if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
dee38f1b 707 // the system always remains started after event processing, a specific
f3506ea2 708 // call with nofEvents==0 is needed to execute the stop sequence
709 if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
dee38f1b 710 }
8451168b 711 }
242bb794 712 } else {
713 HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
714 }
715 } else {
0bf7536b 716 HLTError("missing RunLoader (%p)/RawReader (%p) instance", runLoader, rawReader);
242bb794 717 iResult=-EINVAL;
718 }
719 return iResult;
720}
721
af885e0f 722int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd)
242bb794 723{
724 // see header file for class documentation
725 int iResult=0;
dee38f1b 726 if (runLoader || esd) {
242bb794 727 HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd);
8451168b 728 iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd);
242bb794 729 } else {
730 HLTError("missing run loader/ESD instance(s)");
731 iResult=-EINVAL;
732 }
733 return iResult;
734}
735
c5123824 736int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
737{
738 // see header file for class documentation
739 int iResult=0;
740 if (!pHLTOUT) return -EINVAL;
c5123824 741 HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
0f1882a7 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
b005ef92 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);
90c37647 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;
83cb7e1d 770 pMasterESD=esd;
c5123824 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();
0f1882a7 779
780 // default handling for ESD data blocks does not require an explicite handler
f94e8c27 781 if (!pHandler && (dt==kAliHLTDataTypeESDObject || dt==kAliHLTDataTypeESDTree)) {
c5123824 782 handlerType=AliHLTModuleAgent::kEsd;
783 }
784 const char* pMsg="invalid";
785 switch (handlerType) {
786 case AliHLTModuleAgent::kEsd:
787 {
788 if (pHandler) {
0f1882a7 789 // schedule for later processing
b005ef92 790 pHLTOUT->InsertHandler(*pEsdHandlers, pHLTOUT->GetDataBlockHandlerDesc());
c5123824 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);
90c37647 797 if (pMasterESD) {
798 pHLTOUT->WriteESD(pBuffer, size, dt, pMasterESD);
799 pMasterESD=NULL;
800 }
c5123824 801 pHLTOUT->ReleaseDataBuffer(pBuffer);
802 }
0f1882a7 803 pHLTOUT->MarkDataBlockProcessed();
c5123824 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:
0f1882a7 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 ...",
c5123824 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
b005ef92 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;
c5123824 854 const AliHLTUInt8_t* pBuffer=NULL;
855 AliHLTUInt32_t size=0;
0f1882a7 856 pHandler->ProcessData(pHLTOUT);
c5123824 857 if ((size=pHandler->GetProcessedData(pBuffer))>0) {
b005ef92 858 AliHLTModuleAgent::AliHLTOUTHandlerDesc desc=*handler;
c5123824 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 }
b005ef92 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));
0f1882a7 882 }
883
b005ef92 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
0f1882a7 888 return iResult;
889}
890
891int AliHLTSystem::ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT)
892{
893 // see header file for class documentation
894 int iResult=0;
895 if (!pHLTOUT) return -EINVAL;
896
b005ef92 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);
0f1882a7 908
909 // process all defined chain handlers
910 AliHLTOUT::AliHLTOUTHandlerListEntryVector::iterator chainHandler;
b005ef92 911 for (chainHandler=pChainHandlers->begin(); chainHandler!=pChainHandlers->end() && iResult>=0; chainHandler++) {
0f1882a7 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));
c5123824 924 }
925
b005ef92 926 // remove all empty handlers form the list (handlers which did not get a block this time)
927 AliHLTOUT::RemoveEmptyDuplicateHandlers(*pChainHandlers);
928
c5123824 929 return iResult;
930}
931
242bb794 932int 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
964int AliHLTSystem::Configure(AliRunLoader* runloader)
dee38f1b 965{
966 // see header file for class documentation
f3506ea2 967 return Configure(NULL, runloader);
dee38f1b 968}
969
970int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
242bb794 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 }
e642a402 978 ClearStatusFlags(kTaskListCreated);
c215072c 979 if (CheckFilter(kHLTLogDebug))
980 AliHLTModuleAgent::PrintStatus();
c043fa2c 981 if (CheckStatus(kConfigurationLoaded)==0) {
dee38f1b 982 iResult=LoadConfigurations(rawReader, runloader);
c043fa2c 983 } else {
dee38f1b 984 if (fChains.Length()==0) {
703bcca6 985 HLTError("custom configuration(s) specified, but no configuration to run in local reconstruction, use \'chains=<chain,...>\' option");
c043fa2c 986 iResult=-ENOENT;
987 }
988 }
242bb794 989 if (iResult>=0) {
990 SetStatusFlags(kConfigurationLoaded);
c043fa2c 991 if (CheckFilter(kHLTLogDebug))
992 fpConfigurationHandler->PrintConfigurations();
f3506ea2 993 iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
242bb794 994 if (iResult>=0) {
995 SetStatusFlags(kTaskListCreated);
996 }
997 }
998 if (iResult<0) SetStatusFlags(kError);
999
1000 return iResult;
1001}
1002
c043fa2c 1003int AliHLTSystem::ScanOptions(const char* options)
1004{
1005 // see header file for class documentation
1006 int iResult=0;
1007 if (options) {
d76bc02a 1008 //AliHLTComponentHandler::TLibraryMode libMode=AliHLTComponentHandler::kDynamic;
83670b1d 1009 TString libs("");
c043fa2c 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 }
dba03d72 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 }
c043fa2c 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 }
d85f150c 1052 } else if (token.Contains("chains=")) {
dee38f1b 1053 TString param=token.ReplaceAll("chains=", "");
1054 fChains=param.ReplaceAll(",", " ");
703bcca6 1055 if (fChains.IsNull()) fChains=" "; // disable all chains
dba03d72 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 }
83670b1d 1068 } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
1069 libs+=token;
1070 libs+=" ";
c043fa2c 1071 } else {
1072 HLTWarning("unknown option \'%s\'", token.Data());
1073 }
1074 }
1075 delete pTokens;
1076 }
83670b1d 1077
1078 if (iResult>=0) {
1079 if (libs.IsNull()) {
6a8e0bb4 1080 const char** deflib=fgkHLTDefaultLibs;
83670b1d 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 }
c043fa2c 1092 }
1093 return iResult;
1094}
1095
242bb794 1096int 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
dee38f1b 1109int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
242bb794 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();
1d398268 1118 TString extralibs;
60b26a17 1119 while (pAgent && iResult>=0) {
1120 const char* deplibs=pAgent->GetRequiredComponentLibraries();
1121 if (deplibs) {
1d398268 1122 HLTDebug("required libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent);
1123 extralibs+=deplibs;
60b26a17 1124 }
1125 if (iResult>=0) {
1126 HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
dee38f1b 1127 pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
60b26a17 1128 pAgent=AliHLTModuleAgent::GetNextAgent();
1129 }
242bb794 1130 }
1d398268 1131 if (iResult>=0) {
1132 iResult=LoadComponentLibraries(extralibs.Data());
1133 }
1134
242bb794 1135 return iResult;
1136}
1137
f3506ea2 1138int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
242bb794 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;
f3506ea2 1151 int bHaveOutput=0;
1152
1153 // query chains
1154 TString chains;
1155 if (fChains.Length()>0) {
1156 chains=fChains;
8f471af0 1157 HLTImportant("custom reconstruction chain: %s", chains.Data());
f3506ea2 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) {
703bcca6 1163 if (!chains.IsNull()) chains+=" ";
f3506ea2 1164 chains+=agentchains;
1165 HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
1166 }
1167 pAgent=AliHLTModuleAgent::GetNextAgent();
c043fa2c 1168 }
f3506ea2 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 }
242bb794 1193 }
f3506ea2 1194 } else {
1195 HLTWarning("can not find configuration %s", pCID);
242bb794 1196 }
242bb794 1197 }
f3506ea2 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 ||
703bcca6 1207 fpComponentHandler->LoadLibrary("libHLTsim.so")>=0) {
f3506ea2 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 }
c043fa2c 1214 }
242bb794 1215 }
f3506ea2 1216
242bb794 1217 if (iResult>=0) SetStatusFlags(kTaskListCreated);
1218
1219 return iResult;
1220}
1221
1222int 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
1230int AliHLTSystem::GetStatusFlags()
1231{
1232 // see header file for class documentation
1233 return fState;
1234}
1235
1236int AliHLTSystem::SetStatusFlags(int flags)
1237{
1238 // see header file for class documentation
1239 fState|=flags;
1240 return fState;
1241}
1242
1243int AliHLTSystem::ClearStatusFlags(int flags)
1244{
1245 // see header file for class documentation
1246 fState&=~flags;
1247 return fState;
1248}
85f0cede 1249
1250void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol)
1251{
c043fa2c 1252 // see header file for class documentation
85f0cede 1253 if (fpComponentHandler==NULL) return NULL;
1254 return fpComponentHandler->FindSymbol(library, symbol);
1255}
dba03d72 1256
1257void AliHLTSystem::SetFrameworkLog(AliHLTComponentLogSeverity level)
1258{
6a8e0bb4 1259 // see header file for class documentation
dba03d72 1260 SetLocalLoggingLevel(level);
1261 if (fpComponentHandler) fpComponentHandler->SetLocalLoggingLevel(level);
1262 if (fpConfigurationHandler) fpConfigurationHandler->SetLocalLoggingLevel(level);
1263}