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