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