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