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