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