]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // $Id$ |
2 | ||
3 | /************************************************************************** | |
9be2600f | 4 | * This file is property of and copyright by the ALICE HLT Project * |
5 | * ALICE Experiment at CERN, All rights reserved. * | |
f23a6e1a | 6 | * * |
9be2600f | 7 | * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> * |
8 | * for The ALICE HLT Project. * | |
f23a6e1a | 9 | * * |
10 | * Permission to use, copy, modify and distribute this software and its * | |
11 | * documentation strictly for non-commercial purposes is hereby granted * | |
12 | * without fee, provided that the above copyright notice appears in all * | |
13 | * copies and that both the copyright notice and this permission notice * | |
14 | * appear in the supporting documentation. The authors make no claims * | |
15 | * about the suitability of this software for any purpose. It is * | |
16 | * provided "as is" without express or implied warranty. * | |
17 | **************************************************************************/ | |
18 | ||
b22e91eb | 19 | /** @file AliHLTSystem.cxx |
20 | @author Matthias Richter | |
21 | @date | |
22 | @brief Implementation of HLT module management. | |
23 | */ | |
f23a6e1a | 24 | |
0c0c9d99 | 25 | #if __GNUC__>= 3 |
f23a6e1a | 26 | using namespace std; |
27 | #endif | |
28 | ||
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" |
35 | #include "AliHLTTask.h" | |
242bb794 | 36 | #include "AliHLTModuleAgent.h" |
8451168b | 37 | #include "AliHLTOfflineInterface.h" |
242bb794 | 38 | #include <TObjArray.h> |
39 | #include <TObjString.h> | |
40 | #include <TString.h> | |
90ebac25 | 41 | #include <TStopwatch.h> |
f23a6e1a | 42 | |
b22e91eb | 43 | /** ROOT macro for the implementation of ROOT specific class methods */ |
f23a6e1a | 44 | ClassImp(AliHLTSystem) |
45 | ||
f23a6e1a | 46 | AliHLTSystem::AliHLTSystem() |
85869391 | 47 | : |
48 | fpComponentHandler(new AliHLTComponentHandler()), | |
49 | fpConfigurationHandler(new AliHLTConfigurationHandler()), | |
242bb794 | 50 | fTaskList(), |
51 | fState(0) | |
f23a6e1a | 52 | { |
70ed7d01 | 53 | // see header file for class documentation |
54 | // or | |
55 | // refer to README to build package | |
56 | // or | |
57 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
5f5b708b | 58 | |
fc455fba | 59 | if (fgNofInstances++>0) |
60 | HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time"); | |
61 | ||
5f5b708b | 62 | SetGlobalLoggingLevel(kHLTLogDefault); |
f23a6e1a | 63 | if (fpComponentHandler) { |
64 | AliHLTComponentEnvironment env; | |
65 | memset(&env, 0, sizeof(AliHLTComponentEnvironment)); | |
9ce4bf4a | 66 | env.fAllocMemoryFunc=AliHLTSystem::AllocMemory; |
fc455fba | 67 | env.fLoggingFunc=NULL; |
a742f6f8 | 68 | AliHLTComponentLogSeverity loglevel=fpComponentHandler->GetLocalLoggingLevel(); |
69 | fpComponentHandler->SetLocalLoggingLevel(kHLTLogError); | |
f23a6e1a | 70 | fpComponentHandler->SetEnvironment(&env); |
a742f6f8 | 71 | fpComponentHandler->LoadLibrary("libAliHLTUtil.so"); |
72 | fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)fpComponentHandler->FindSymbol("libAliHLTUtil.so", "AliDynamicMessage"); | |
73 | fpComponentHandler->SetLocalLoggingLevel(loglevel); | |
74 | if (fgAliLoggingFunc==NULL) { | |
75 | HLTError("symbol lookp failure: can not find AliDynamicMessage, switching to HLT logging system"); | |
76 | } | |
77 | fpComponentHandler->AnnounceVersion(); | |
85465857 | 78 | } else { |
79 | HLTFatal("can not create Component Handler"); | |
80 | } | |
85465857 | 81 | if (fpConfigurationHandler) { |
82 | AliHLTConfiguration::GlobalInit(fpConfigurationHandler); | |
83 | } else { | |
84 | HLTFatal("can not create Configuration Handler"); | |
f23a6e1a | 85 | } |
86 | } | |
87 | ||
85869391 | 88 | AliHLTSystem::AliHLTSystem(const AliHLTSystem&) |
89 | : | |
53feaef5 | 90 | AliHLTLogging(), |
85869391 | 91 | fpComponentHandler(NULL), |
92 | fpConfigurationHandler(NULL), | |
242bb794 | 93 | fTaskList(), |
94 | fState(0) | |
85869391 | 95 | { |
70ed7d01 | 96 | // see header file for class documentation |
fc455fba | 97 | if (fgNofInstances++>0) |
98 | HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time"); | |
99 | ||
85869391 | 100 | HLTFatal("copy constructor untested"); |
101 | } | |
102 | ||
103 | AliHLTSystem& AliHLTSystem::operator=(const AliHLTSystem&) | |
104 | { | |
70ed7d01 | 105 | // see header file for class documentation |
85869391 | 106 | HLTFatal("assignment operator untested"); |
107 | return *this; | |
108 | } | |
f23a6e1a | 109 | |
110 | AliHLTSystem::~AliHLTSystem() | |
111 | { | |
70ed7d01 | 112 | // see header file for class documentation |
fc455fba | 113 | fgNofInstances--; |
2d7ff710 | 114 | CleanTaskList(); |
fc455fba | 115 | AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler); |
2d7ff710 | 116 | if (fpConfigurationHandler) { |
117 | delete fpConfigurationHandler; | |
118 | } | |
119 | fpConfigurationHandler=NULL; | |
120 | ||
121 | if (fpComponentHandler) { | |
122 | delete fpComponentHandler; | |
123 | } | |
124 | fpComponentHandler=NULL; | |
f23a6e1a | 125 | } |
126 | ||
fc455fba | 127 | int AliHLTSystem::fgNofInstances=0; |
128 | ||
5ec8e281 | 129 | int AliHLTSystem::AddConfiguration(AliHLTConfiguration* pConf) |
130 | { | |
70ed7d01 | 131 | // see header file for class documentation |
5ec8e281 | 132 | int iResult=0; |
53feaef5 | 133 | if (pConf) { |
134 | } else { | |
135 | iResult=-EINVAL; | |
136 | } | |
5ec8e281 | 137 | return iResult; |
138 | } | |
139 | ||
014d39ce | 140 | int AliHLTSystem::InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec) |
141 | { | |
70ed7d01 | 142 | // see header file for class documentation |
014d39ce | 143 | int iResult=0; |
53feaef5 | 144 | if (pConf) { |
145 | if (pPrec) { | |
146 | // find the position | |
147 | } | |
148 | } else { | |
149 | iResult=-EINVAL; | |
150 | } | |
014d39ce | 151 | return iResult; |
152 | } | |
5ec8e281 | 153 | |
154 | int AliHLTSystem::DeleteConfiguration(AliHLTConfiguration* pConf) | |
155 | { | |
70ed7d01 | 156 | // see header file for class documentation |
5ec8e281 | 157 | int iResult=0; |
53feaef5 | 158 | if (pConf) { |
159 | } else { | |
160 | iResult=-EINVAL; | |
161 | } | |
5ec8e281 | 162 | return iResult; |
163 | } | |
164 | ||
a742f6f8 | 165 | int AliHLTSystem::BuildTaskList(const char* id) |
166 | { | |
167 | // see header file for class documentation | |
168 | int iResult=0; | |
169 | if (id) { | |
170 | if (fpConfigurationHandler) { | |
171 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(id); | |
172 | if (pConf) { | |
173 | iResult=BuildTaskList(pConf); | |
174 | } else { | |
175 | HLTError("unknown configuration \"%s\"", id); | |
176 | iResult=-EEXIST; | |
177 | } | |
178 | } else { | |
179 | iResult=-EFAULT; | |
180 | } | |
181 | } else { | |
182 | iResult=-EINVAL; | |
183 | } | |
184 | return iResult; | |
185 | } | |
186 | ||
5ec8e281 | 187 | int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf) |
188 | { | |
70ed7d01 | 189 | // see header file for class documentation |
f23a6e1a | 190 | int iResult=0; |
5ec8e281 | 191 | if (pConf) { |
192 | AliHLTTask* pTask=NULL; | |
193 | if ((pTask=FindTask(pConf->GetName()))!=NULL) { | |
194 | if (pTask->GetConf()!=pConf) { | |
85465857 | 195 | HLTError("configuration missmatch, 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 | 196 | iResult=-EEXIST; |
197 | pTask=NULL; | |
198 | } | |
199 | } else if (pConf->SourcesResolved(1)!=1) { | |
85465857 | 200 | HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName()); |
5ec8e281 | 201 | iResult=-ENOLINK; |
202 | } else { | |
53feaef5 | 203 | pTask=new AliHLTTask(pConf); |
5ec8e281 | 204 | if (pTask==NULL) { |
205 | iResult=-ENOMEM; | |
206 | } | |
207 | } | |
208 | if (pTask) { | |
3b35e87c | 209 | // check for circular dependencies |
5ec8e281 | 210 | if ((iResult=pConf->FollowDependency(pConf->GetName()))>0) { |
3b35e87c | 211 | HLTError("detected circular dependency for configuration \"%s\"", pTask->GetName()); |
5ec8e281 | 212 | pTask->PrintDependencyTree(pTask->GetName(), 1/*use the configuration list*/); |
85465857 | 213 | HLTError("aborted ..."); |
5ec8e281 | 214 | iResult=-ELOOP; |
215 | } | |
216 | if (iResult>=0) { | |
217 | // check whether all dependencies are already in the task list | |
218 | // create the missing ones | |
3b35e87c | 219 | // this step is an iterative process which calls this function again for the missing |
220 | // configurations, in order to avoid the currently processed task to be created | |
221 | // again it is added to the list temporarily and removed afterwards | |
222 | // This is of high importance to preserve the order of the tasks. Furthermore, the | |
223 | // InsertTask method has to be used in order to set all the cross links right | |
5ec8e281 | 224 | fTaskList.Add(pTask); |
225 | AliHLTConfiguration* pDep=pConf->GetFirstSource(); | |
226 | while (pDep!=NULL && iResult>=0) { | |
227 | if (FindTask(pDep->GetName())==NULL) { | |
228 | iResult=BuildTaskList(pDep); | |
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) { | |
237 | iResult=InsertTask(pTask); | |
238 | } | |
239 | } else { | |
240 | delete pTask; | |
241 | pTask=NULL; | |
242 | } | |
243 | } | |
244 | } else { | |
245 | iResult=-EINVAL; | |
f23a6e1a | 246 | } |
f23a6e1a | 247 | return iResult; |
248 | } | |
249 | ||
5ec8e281 | 250 | int AliHLTSystem::CleanTaskList() |
251 | { | |
70ed7d01 | 252 | // see header file for class documentation |
5ec8e281 | 253 | int iResult=0; |
254 | TObjLink* lnk=NULL; | |
a742f6f8 | 255 | while ((lnk=fTaskList.LastLink())!=NULL) { |
5ec8e281 | 256 | delete (lnk->GetObject()); |
a742f6f8 | 257 | fTaskList.Remove(lnk); |
5ec8e281 | 258 | } |
259 | return iResult; | |
260 | } | |
261 | ||
262 | int AliHLTSystem::InsertTask(AliHLTTask* pTask) | |
263 | { | |
70ed7d01 | 264 | // see header file for class documentation |
5ec8e281 | 265 | int iResult=0; |
266 | TObjLink *lnk = NULL; | |
267 | if ((iResult=pTask->CheckDependencies())>0) | |
268 | lnk=fTaskList.FirstLink(); | |
269 | while (lnk && iResult>0) { | |
270 | AliHLTTask* pCurr = (AliHLTTask*)lnk->GetObject(); | |
85465857 | 271 | //HLTDebug("checking \"%s\"", pCurr->GetName()); |
5ec8e281 | 272 | iResult=pTask->Depends(pCurr); |
273 | if (iResult>0) { | |
274 | iResult=pTask->SetDependency(pCurr); | |
275 | pCurr->SetTarget(pTask); | |
85465857 | 276 | HLTDebug("set dependency \"%s\" for configuration \"%s\"", pCurr->GetName(), pTask->GetName()); |
f23a6e1a | 277 | } |
5ec8e281 | 278 | if (pCurr->Depends(pTask)) { |
3b35e87c | 279 | // circular dependency |
280 | HLTError("circular dependency: can not resolve dependencies for configuration \"%s\"", pTask->GetName()); | |
5ec8e281 | 281 | iResult=-ELOOP; |
282 | } else if ((iResult=pTask->CheckDependencies())>0) { | |
283 | lnk = lnk->Next(); | |
284 | } | |
285 | } | |
286 | if (iResult==0) { | |
287 | if (lnk) { | |
288 | fTaskList.AddAfter(lnk, pTask); | |
289 | } else { | |
290 | fTaskList.AddFirst(pTask); | |
291 | } | |
a742f6f8 | 292 | HLTDebug("task \"%s\" (%p) inserted (size %d)", pTask->GetName(), pTask, sizeof(AliHLTTask)); |
5ec8e281 | 293 | } else if (iResult>0) { |
85465857 | 294 | HLTError("can not resolve dependencies for configuration \"%s\" (%d unresolved)", pTask->GetName(), iResult); |
5ec8e281 | 295 | iResult=-ENOLINK; |
f23a6e1a | 296 | } |
5ec8e281 | 297 | return iResult; |
f23a6e1a | 298 | } |
299 | ||
5ec8e281 | 300 | AliHLTTask* AliHLTSystem::FindTask(const char* id) |
301 | { | |
70ed7d01 | 302 | // see header file for class documentation |
5ec8e281 | 303 | AliHLTTask* pTask=NULL; |
304 | if (id) { | |
305 | pTask=(AliHLTTask*)fTaskList.FindObject(id); | |
306 | } | |
307 | return pTask; | |
308 | } | |
f23a6e1a | 309 | |
5ec8e281 | 310 | void AliHLTSystem::PrintTaskList() |
311 | { | |
70ed7d01 | 312 | // see header file for class documentation |
85465857 | 313 | HLTLogKeyword("task list"); |
5ec8e281 | 314 | TObjLink *lnk = NULL; |
85465857 | 315 | HLTMessage("Task List"); |
5ec8e281 | 316 | lnk=fTaskList.FirstLink(); |
317 | while (lnk) { | |
318 | TObject* obj=lnk->GetObject(); | |
319 | if (obj) { | |
85465857 | 320 | HLTMessage(" %s - status:", obj->GetName()); |
5ec8e281 | 321 | AliHLTTask* pTask=(AliHLTTask*)obj; |
322 | pTask->PrintStatus(); | |
323 | } else { | |
324 | } | |
325 | lnk = lnk->Next(); | |
326 | } | |
327 | } | |
014d39ce | 328 | |
53feaef5 | 329 | int AliHLTSystem::Run(Int_t iNofEvents) |
014d39ce | 330 | { |
70ed7d01 | 331 | // see header file for class documentation |
014d39ce | 332 | int iResult=0; |
242bb794 | 333 | int iCount=0; |
334 | SetStatusFlags(kRunning); | |
90ebac25 | 335 | TStopwatch StopwatchBase; StopwatchBase.Reset(); |
336 | TStopwatch StopwatchDA; StopwatchDA.Reset(); | |
337 | TStopwatch StopwatchInput; StopwatchInput.Reset(); | |
338 | TStopwatch StopwatchOutput; StopwatchOutput.Reset(); | |
339 | TObjArray Stopwatches; | |
340 | Stopwatches.AddAt(&StopwatchBase, (int)AliHLTComponent::kSWBase); | |
341 | Stopwatches.AddAt(&StopwatchDA, (int)AliHLTComponent::kSWDA); | |
342 | Stopwatches.AddAt(&StopwatchInput, (int)AliHLTComponent::kSWInput); | |
343 | Stopwatches.AddAt(&StopwatchOutput, (int)AliHLTComponent::kSWOutput); | |
344 | if ((iResult=InitTasks())>=0 && (iResult=InitBenchmarking(&Stopwatches))>=0) { | |
9ce4bf4a | 345 | if ((iResult=StartTasks())>=0) { |
346 | for (int i=0; i<iNofEvents && iResult>=0; i++) { | |
347 | iResult=ProcessTasks(i); | |
348 | if (iResult>=0) { | |
349 | HLTInfo("Event %d successfully finished (%d)", i, iResult); | |
350 | iResult=0; | |
242bb794 | 351 | iCount++; |
9ce4bf4a | 352 | } else { |
353 | HLTError("Processing of event %d failed (%d)", i, iResult); | |
354 | // TODO: define different running modes to either ignore errors in | |
355 | // event processing or not | |
356 | // currently ignored | |
357 | //iResult=0; | |
358 | } | |
2d7ff710 | 359 | } |
9ce4bf4a | 360 | StopTasks(); |
361 | } else { | |
362 | HLTError("can not start task list"); | |
53feaef5 | 363 | } |
9ce4bf4a | 364 | DeinitTasks(); |
fc455fba | 365 | } else if (iResult!=-ENOENT) { |
9ce4bf4a | 366 | HLTError("can not initialize task list"); |
367 | } | |
90ebac25 | 368 | if (iResult>=0) { |
369 | iResult=iCount; | |
370 | HLTInfo("HLT statistics:\n" | |
371 | " base: R:%.3fs C:%.3fs\n" | |
372 | " input: R:%.3fs C:%.3fs\n" | |
373 | " output: R:%.3fs C:%.3fs\n" | |
374 | " event processing : R:%.3fs C:%.3fs" | |
375 | , StopwatchBase.RealTime(),StopwatchBase.CpuTime() | |
376 | , StopwatchInput.RealTime(),StopwatchInput.CpuTime() | |
377 | , StopwatchOutput.RealTime(),StopwatchOutput.CpuTime() | |
378 | , StopwatchDA.RealTime(),StopwatchDA.CpuTime()); | |
379 | } | |
242bb794 | 380 | ClearStatusFlags(kRunning); |
9ce4bf4a | 381 | return iResult; |
382 | } | |
383 | ||
384 | int AliHLTSystem::InitTasks() | |
385 | { | |
70ed7d01 | 386 | // see header file for class documentation |
9ce4bf4a | 387 | int iResult=0; |
388 | TObjLink *lnk=fTaskList.FirstLink(); | |
fc455fba | 389 | if (lnk==NULL) { |
390 | HLTWarning("Task list is empty, aborting ..."); | |
391 | return -ENOENT; | |
392 | } | |
9ce4bf4a | 393 | while (lnk && iResult>=0) { |
394 | TObject* obj=lnk->GetObject(); | |
395 | if (obj) { | |
396 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
397 | iResult=pTask->Init(NULL, fpComponentHandler); | |
398 | } else { | |
399 | } | |
400 | lnk = lnk->Next(); | |
401 | } | |
402 | if (iResult<0) { | |
53feaef5 | 403 | } |
404 | return iResult; | |
405 | } | |
406 | ||
90ebac25 | 407 | int AliHLTSystem::InitBenchmarking(TObjArray* pStopwatches) |
408 | { | |
409 | // see header file for class documentation | |
410 | if (pStopwatches==NULL) return -EINVAL; | |
411 | ||
412 | int iResult=0; | |
413 | TObjLink *lnk=fTaskList.FirstLink(); | |
414 | while (lnk && iResult>=0) { | |
415 | TObject* obj=lnk->GetObject(); | |
416 | if (obj) { | |
417 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
418 | AliHLTComponent* pComp=NULL; | |
419 | if (iResult>=0 && (pComp=pTask->GetComponent())!=NULL) { | |
420 | switch (pComp->GetComponentType()) { | |
421 | case AliHLTComponent::kProcessor: | |
422 | pComp->SetStopwatches(pStopwatches); | |
423 | break; | |
424 | case AliHLTComponent::kSource: | |
425 | { | |
426 | // this switch determines whether the time consumption of the | |
427 | // AliHLTComponent base methods should be counted to the input | |
428 | // stopwatch or base stopwatch. | |
429 | //int inputBase=(int)AliHLTComponent::kSWBase; | |
430 | int inputBase=(int)AliHLTComponent::kSWInput; | |
431 | pComp->SetStopwatch(pStopwatches->At(inputBase), AliHLTComponent::kSWBase); | |
432 | pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWInput), AliHLTComponent::kSWDA); | |
433 | } | |
434 | break; | |
435 | case AliHLTComponent::kSink: | |
436 | { | |
437 | // this switch determines whether the time consumption of the | |
438 | // AliHLTComponent base methods should be counted to the output | |
439 | // stopwatch or base stopwatch. | |
440 | //int outputBase=(int)AliHLTComponent::kSWBase; | |
441 | int outputBase=(int)AliHLTComponent::kSWOutput; | |
442 | pComp->SetStopwatch(pStopwatches->At(outputBase), AliHLTComponent::kSWBase); | |
443 | pComp->SetStopwatch(pStopwatches->At((int)AliHLTComponent::kSWOutput), AliHLTComponent::kSWDA); | |
444 | } | |
445 | break; | |
85f0cede | 446 | default: |
447 | HLTWarning("unknown component type %d", (int)pComp->GetComponentType()); | |
90ebac25 | 448 | } |
449 | } | |
450 | } else { | |
451 | } | |
452 | lnk = lnk->Next(); | |
453 | } | |
454 | return iResult; | |
455 | } | |
456 | ||
53feaef5 | 457 | int AliHLTSystem::StartTasks() |
458 | { | |
70ed7d01 | 459 | // see header file for class documentation |
53feaef5 | 460 | int iResult=0; |
461 | TObjLink *lnk=fTaskList.FirstLink(); | |
462 | while (lnk && iResult>=0) { | |
463 | TObject* obj=lnk->GetObject(); | |
464 | if (obj) { | |
465 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
466 | iResult=pTask->StartRun(); | |
467 | } else { | |
468 | } | |
469 | lnk = lnk->Next(); | |
470 | } | |
471 | if (iResult<0) { | |
472 | } | |
473 | return iResult; | |
474 | } | |
475 | ||
476 | int AliHLTSystem::ProcessTasks(Int_t eventNo) | |
477 | { | |
70ed7d01 | 478 | // see header file for class documentation |
53feaef5 | 479 | int iResult=0; |
480 | HLTDebug("processing event no %d", eventNo); | |
481 | TObjLink *lnk=fTaskList.FirstLink(); | |
482 | while (lnk && iResult>=0) { | |
483 | TObject* obj=lnk->GetObject(); | |
484 | if (obj) { | |
485 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
9ce4bf4a | 486 | iResult=pTask->ProcessTask(eventNo); |
487 | HLTDebug("task %s finnished (%d)", pTask->GetName(), iResult); | |
53feaef5 | 488 | } else { |
489 | } | |
490 | lnk = lnk->Next(); | |
491 | } | |
492 | return iResult; | |
493 | } | |
494 | ||
495 | int AliHLTSystem::StopTasks() | |
496 | { | |
70ed7d01 | 497 | // see header file for class documentation |
53feaef5 | 498 | int iResult=0; |
499 | TObjLink *lnk=fTaskList.FirstLink(); | |
500 | while (lnk && iResult>=0) { | |
501 | TObject* obj=lnk->GetObject(); | |
502 | if (obj) { | |
503 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
504 | iResult=pTask->EndRun(); | |
505 | } else { | |
506 | } | |
507 | lnk = lnk->Next(); | |
508 | } | |
014d39ce | 509 | return iResult; |
510 | } | |
9ce4bf4a | 511 | |
512 | int AliHLTSystem::DeinitTasks() | |
513 | { | |
70ed7d01 | 514 | // see header file for class documentation |
9ce4bf4a | 515 | int iResult=0; |
516 | TObjLink *lnk=fTaskList.FirstLink(); | |
517 | while (lnk && iResult>=0) { | |
518 | TObject* obj=lnk->GetObject(); | |
519 | if (obj) { | |
520 | AliHLTTask* pTask=(AliHLTTask*)obj; | |
521 | iResult=pTask->Deinit(); | |
522 | } else { | |
523 | } | |
524 | lnk = lnk->Next(); | |
525 | } | |
526 | return iResult; | |
527 | } | |
528 | ||
529 | void* AliHLTSystem::AllocMemory( void* param, unsigned long size ) | |
530 | { | |
70ed7d01 | 531 | // see header file for class documentation |
242bb794 | 532 | if (param==NULL) { |
533 | // get rid of 'unused parameter' warning | |
534 | } | |
9ce4bf4a | 535 | return (void*)new char[size]; |
536 | } | |
242bb794 | 537 | |
538 | int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader, | |
539 | AliRawReader* rawReader) | |
540 | { | |
541 | // see header file for class documentation | |
542 | int iResult=0; | |
543 | if (runLoader) { | |
544 | HLTInfo("Run Loader %p, Raw Reader %p , %d events", runLoader, rawReader, nofEvents); | |
545 | if (CheckStatus(kReady)) { | |
8451168b | 546 | if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) { |
547 | iResult=Run(nofEvents); | |
548 | } | |
242bb794 | 549 | } else { |
550 | HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady); | |
551 | } | |
552 | } else { | |
553 | HLTError("missing run loader instance"); | |
554 | iResult=-EINVAL; | |
555 | } | |
556 | return iResult; | |
557 | } | |
558 | ||
559 | int AliHLTSystem::FillESD(int eventNo, AliRunLoader* runLoader, AliESD* esd) | |
560 | { | |
561 | // see header file for class documentation | |
562 | int iResult=0; | |
563 | if (runLoader) { | |
564 | HLTInfo("Event %d: Run Loader %p, ESD %p", eventNo, runLoader, esd); | |
8451168b | 565 | iResult=AliHLTOfflineInterface::FillComponentESDs(eventNo, runLoader, esd); |
242bb794 | 566 | } else { |
567 | HLTError("missing run loader/ESD instance(s)"); | |
568 | iResult=-EINVAL; | |
569 | } | |
570 | return iResult; | |
571 | } | |
572 | ||
573 | int AliHLTSystem::LoadComponentLibraries(const char* libraries) | |
574 | { | |
575 | // see header file for class documentation | |
576 | int iResult=0; | |
577 | if (libraries) { | |
578 | if (fpComponentHandler) { | |
579 | TString libs(libraries); | |
580 | TObjArray* pTokens=libs.Tokenize(" "); | |
581 | if (pTokens) { | |
582 | int iEntries=pTokens->GetEntries(); | |
583 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
584 | iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data()); | |
585 | } | |
586 | delete pTokens; | |
587 | } | |
588 | if (iResult>=0) { | |
589 | SetStatusFlags(kLibrariesLoaded); | |
590 | } else { | |
591 | // lets see if we need this, probably not | |
592 | //fpComponentHandler->UnloadLibraries(); | |
593 | ClearStatusFlags(kLibrariesLoaded); | |
594 | } | |
595 | } else { | |
596 | iResult=-EFAULT; | |
597 | HLTFatal("no component handler available"); | |
598 | } | |
599 | } else { | |
600 | iResult=-EINVAL; | |
601 | } | |
602 | return iResult; | |
603 | } | |
604 | ||
605 | int AliHLTSystem::Configure(AliRunLoader* runloader) | |
606 | { | |
607 | // see header file for class documentation | |
608 | int iResult=0; | |
609 | if (CheckStatus(kRunning)) { | |
610 | HLTError("HLT system in running state, can not configure"); | |
611 | return -EBUSY; | |
612 | } | |
c215072c | 613 | if (CheckFilter(kHLTLogDebug)) |
614 | AliHLTModuleAgent::PrintStatus(); | |
242bb794 | 615 | ClearStatusFlags(kConfigurationLoaded|kTaskListCreated); |
616 | iResult=LoadConfigurations(runloader); | |
617 | if (iResult>=0) { | |
618 | SetStatusFlags(kConfigurationLoaded); | |
619 | iResult=BuildTaskListsFromTopConfigurations(runloader); | |
620 | if (iResult>=0) { | |
621 | SetStatusFlags(kTaskListCreated); | |
622 | } | |
623 | } | |
624 | if (iResult<0) SetStatusFlags(kError); | |
625 | ||
626 | return iResult; | |
627 | } | |
628 | ||
629 | int AliHLTSystem::Reset(int bForce) | |
630 | { | |
631 | // see header file for class documentation | |
632 | int iResult=0; | |
633 | if (!bForce && CheckStatus(kRunning)) { | |
634 | HLTError("HLT system in running state, can not configure"); | |
635 | return -EBUSY; | |
636 | } | |
637 | CleanTaskList(); | |
638 | ClearStatusFlags(~kUninitialized); | |
639 | return iResult; | |
640 | } | |
641 | ||
642 | int AliHLTSystem::LoadConfigurations(AliRunLoader* runloader) | |
643 | { | |
644 | // see header file for class documentation | |
645 | if (CheckStatus(kRunning)) { | |
646 | HLTError("HLT system in running state, can not configure"); | |
647 | return -EBUSY; | |
648 | } | |
649 | int iResult=0; | |
650 | AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
60b26a17 | 651 | while (pAgent && iResult>=0) { |
652 | const char* deplibs=pAgent->GetRequiredComponentLibraries(); | |
653 | if (deplibs) { | |
c215072c | 654 | HLTDebug("load libraries \'%s\' for agent %s (%p)", deplibs, pAgent->GetName(), pAgent); |
60b26a17 | 655 | iResult=LoadComponentLibraries(deplibs); |
656 | } | |
657 | if (iResult>=0) { | |
658 | HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent); | |
659 | pAgent->CreateConfigurations(fpConfigurationHandler, runloader); | |
660 | pAgent=AliHLTModuleAgent::GetNextAgent(); | |
661 | } | |
242bb794 | 662 | } |
663 | return iResult; | |
664 | } | |
665 | ||
666 | int AliHLTSystem::BuildTaskListsFromTopConfigurations(AliRunLoader* runloader) | |
667 | { | |
668 | // see header file for class documentation | |
669 | if (CheckStatus(kRunning)) { | |
670 | HLTError("HLT system in running state, can not configure"); | |
671 | return -EBUSY; | |
672 | } | |
673 | if (!CheckStatus(kConfigurationLoaded)) { | |
674 | HLTWarning("configurations not yet loaded"); | |
675 | return 0; | |
676 | } | |
677 | ||
678 | int iResult=0; | |
679 | AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent(); | |
680 | while (pAgent && iResult>=0) { | |
90ebac25 | 681 | TString tops=pAgent->GetLocalRecConfigurations(runloader); |
242bb794 | 682 | HLTDebug("top configurations for agent %s (%p): %s", pAgent->GetName(), pAgent, tops.Data()); |
683 | TObjArray* pTokens=tops.Tokenize(" "); | |
684 | if (pTokens) { | |
685 | int iEntries=pTokens->GetEntries(); | |
686 | for (int i=0; i<iEntries && iResult>=0; i++) { | |
687 | const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data(); | |
688 | AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID); | |
689 | if (pConf) { | |
690 | iResult=BuildTaskList(pConf); | |
691 | } else { | |
692 | HLTWarning("can not find top configuration %s", pCID); | |
693 | } | |
694 | } | |
695 | delete pTokens; | |
696 | } | |
697 | ||
698 | pAgent=AliHLTModuleAgent::GetNextAgent(); | |
699 | } | |
700 | if (iResult>=0) SetStatusFlags(kTaskListCreated); | |
701 | ||
702 | return iResult; | |
703 | } | |
704 | ||
705 | int AliHLTSystem::CheckStatus(int flag) | |
706 | { | |
707 | // see header file for class documentation | |
708 | if (flag==kUninitialized && flag==fState) return 1; | |
709 | if ((fState&flag)==flag) return 1; | |
710 | return 0; | |
711 | } | |
712 | ||
713 | int AliHLTSystem::GetStatusFlags() | |
714 | { | |
715 | // see header file for class documentation | |
716 | return fState; | |
717 | } | |
718 | ||
719 | int AliHLTSystem::SetStatusFlags(int flags) | |
720 | { | |
721 | // see header file for class documentation | |
722 | fState|=flags; | |
723 | return fState; | |
724 | } | |
725 | ||
726 | int AliHLTSystem::ClearStatusFlags(int flags) | |
727 | { | |
728 | // see header file for class documentation | |
729 | fState&=~flags; | |
730 | return fState; | |
731 | } | |
85f0cede | 732 | |
733 | void* AliHLTSystem::FindDynamicSymbol(const char* library, const char* symbol) | |
734 | { | |
735 | if (fpComponentHandler==NULL) return NULL; | |
736 | return fpComponentHandler->FindSymbol(library, symbol); | |
737 | } |